recover from corrupt chat player index

This should never happen, but it did and I want to stop local crashes to
investigate.
This commit is contained in:
Eric House 2020-03-25 22:27:01 -07:00 committed by Eric House
parent 45ae6c0fca
commit 3b80e51439
2 changed files with 5 additions and 2 deletions

View file

@ -162,8 +162,9 @@ public class ChatDelegate extends DelegateBase {
TextView view = (TextView)row.findViewById( R.id.chat_row_text );
view.setText( msg );
view = (TextView)row.findViewById( R.id.chat_row_name );
view.setText( getString( R.string.chat_sender_fmt,
m_names[playerIndx] ) );
String name = playerIndx < m_names.length ? m_names[playerIndx] : "<???>";
view.setText( getString( R.string.chat_sender_fmt, name ) );
if ( tsSeconds > 0 ) {
long now = 1000L * Utils.getCurSeconds();

View file

@ -722,6 +722,7 @@ sendChatTo( ServerCtxt* server, XP_U16 devIndex, const XP_UCHAR* msg,
XWStreamCtxt* stream = messageStreamWithHeader( server, devIndex,
XWPROTO_CHAT );
stringToStream( stream, msg );
XP_ASSERT( from < server->vol.gi->nPlayers );
stream_putU8( stream, from );
stream_putU32( stream, timestamp );
stream_destroy( stream );
@ -765,6 +766,7 @@ receiveChat( ServerCtxt* server, XWStreamCtxt* incoming )
sendChatToClientsExcept( server, sourceClientIndex, msg, from,
timestamp );
}
XP_ASSERT( from < server->vol.gi->nPlayers );
util_showChat( server->vol.util, msg, from, timestamp );
XP_FREE( server->mpool, msg );
return XP_TRUE;