From d446d3d46391105b65bc523ca84e7db869756294 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 20 Feb 2024 15:02:48 -0800 Subject: [PATCH] always send from a local player Seeing assertion failures with >2 dev games. I think the selPlayer variable doesn't always point at a local player, so don't use it. --- xwords4/common/board.c | 7 +++++-- xwords4/common/server.c | 9 +++++++-- xwords4/linux/scripts/netGamesTest.py | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/xwords4/common/board.c b/xwords4/common/board.c index 52680aade..09cad1deb 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -93,6 +93,8 @@ static void dictChanged( void* p_board, XWEnv xwe, XP_S16 playerNum, const DictionaryCtxt* newDict ); static void boardTurnChanged( XWEnv xwe, void* closure ); +static XP_S16 chooseBestSelPlayer( const BoardCtxt* board ); + static void boardGameOver( XWEnv xwe, void* closure, XP_S16 quitter ); static void setArrow( BoardCtxt* board, XWEnv xwe, XP_U16 row, XP_U16 col, XP_Bool* vp ); @@ -893,7 +895,8 @@ board_canHint( const BoardCtxt* board ) void board_sendChat( const BoardCtxt* board, XWEnv xwe, const XP_UCHAR* msg ) { - server_sendChat( board->server, xwe, msg, board->selPlayer ); + XP_S16 turn = chooseBestSelPlayer( board ); + server_sendChat( board->server, xwe, msg, turn ); } #endif @@ -1877,7 +1880,7 @@ board_hideTray( BoardCtxt* board, XWEnv xwe ) } /* board_hideTray */ static XP_S16 -chooseBestSelPlayer( BoardCtxt* board ) +chooseBestSelPlayer( const BoardCtxt* board ) { ServerCtxt* server = board->server; diff --git a/xwords4/common/server.c b/xwords4/common/server.c index 04b56cbd4..66f696c0d 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -1090,6 +1090,7 @@ sendChatToClientsExcept( ServerCtxt* server, XWEnv xwe, XP_U16 skip, void server_sendChat( ServerCtxt* server, XWEnv xwe, const XP_UCHAR* msg, XP_S16 from ) { + XP_ASSERT( -1 == from || server->vol.gi->players[from].isLocal ); XP_U32 timestamp = dutil_getCurSeconds( server->vol.dutil, xwe ); if ( server->vol.gi->serverRole == SERVER_ISCLIENT ) { sendChatTo( server, xwe, HOST_DEVICE, msg, from, timestamp ); @@ -1102,8 +1103,12 @@ static XP_Bool receiveChat( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* incoming ) { XP_UCHAR* msg = stringFromStream( server->mpool, incoming ); - XP_S16 from = 1 <= stream_getSize( incoming ) - ? stream_getU8( incoming ) : -1; + XP_S16 from = -1; + if ( 1 <= stream_getSize( incoming ) ) { + from = stream_getU8( incoming ); + XP_ASSERT( !server->vol.gi->players[from].isLocal ); + } + XP_U32 timestamp = sizeof(timestamp) <= stream_getSize( incoming ) ? stream_getU32( incoming ) : 0; if ( amHost( server ) ) { diff --git a/xwords4/linux/scripts/netGamesTest.py b/xwords4/linux/scripts/netGamesTest.py index 9b537d14d..dc6d60bc6 100755 --- a/xwords4/linux/scripts/netGamesTest.py +++ b/xwords4/linux/scripts/netGamesTest.py @@ -280,7 +280,7 @@ class Device(): if gids: random.shuffle(gids) gid = gids[0] - response = self._sendWaitReply('sendChat', gid=gid, msg=Device.nextChatMsg()) + response = self._sendWaitReply('sendChat', gid=gid, msg=Device.nextChatMsg(self.host)) success = response.get('success', False) return success @@ -633,9 +633,9 @@ class Device(): self._launchProc() @staticmethod - def nextChatMsg(): + def nextChatMsg(sender): Device._nextChatID += 1 - return 'Chat msg {}'.format(Device._nextChatID) + return 'chat msg {}: Hi, this is {}'.format(Device._nextChatID, sender) def openOnExit(args): devs = Device.getAll()