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.
This commit is contained in:
Eric House 2024-02-20 15:02:48 -08:00
parent 32760c8570
commit d446d3d463
3 changed files with 15 additions and 7 deletions

View file

@ -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;

View file

@ -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 ) ) {

View file

@ -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()