mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-26 07:58:52 +01:00
fix several crashers that prevented network games from working when
MAX_COLS was larger than 16. In order that old-style messages on relay be readable by new-style code on device, modified server.c's protocol to include stream version. But: unless I come up with a better way of doing this all devices will have to be upgraded at the same time: old won't be able to read the new format as it's done here.
This commit is contained in:
parent
379e5f1d96
commit
bdb8e6f03c
5 changed files with 58 additions and 37 deletions
|
@ -850,11 +850,10 @@ void
|
|||
model_makeTurnFromStream( ModelCtxt* model, XP_U16 playerNum,
|
||||
XWStreamCtxt* stream )
|
||||
{
|
||||
XP_U16 numTiles;
|
||||
XP_U16 numTiles, ii;
|
||||
Tile blank = dict_getBlankTile( model_getDictionary(model) );
|
||||
XP_U16 nColsNBits =
|
||||
STREAM_VERS_BIGBOARD > stream_getVersion( stream ) ? 4 :
|
||||
NUMCOLS_NBITS;
|
||||
XP_U16 version = stream_getVersion( stream );
|
||||
XP_U16 nColsNBits = STREAM_VERS_BIGBOARD > version ? 4 : NUMCOLS_NBITS;
|
||||
|
||||
model_resetCurrentTurn( model, playerNum );
|
||||
|
||||
|
@ -862,7 +861,7 @@ model_makeTurnFromStream( ModelCtxt* model, XP_U16 playerNum,
|
|||
|
||||
XP_LOGF( "%s: numTiles=%d", __func__, numTiles );
|
||||
|
||||
while ( numTiles-- ) {
|
||||
for ( ii = 0; ii < numTiles; ++ii ) {
|
||||
XP_S16 foundAt;
|
||||
Tile moveTile;
|
||||
Tile tileFace = (Tile)stream_getBits( stream, TILE_NBITS );
|
||||
|
|
|
@ -145,6 +145,7 @@ static void sendBadWordMsgs( ServerCtxt* server );
|
|||
static XP_Bool handleIllegalWord( ServerCtxt* server,
|
||||
XWStreamCtxt* incoming );
|
||||
static void tellMoveWasLegal( ServerCtxt* server );
|
||||
static void writeProto( XWStreamCtxt* stream, XW_Proto proto );
|
||||
#endif
|
||||
|
||||
#define PICK_NEXT -1
|
||||
|
@ -515,7 +516,7 @@ server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
if ( server->nv.gameState == XWSTATE_NONE ) {
|
||||
stream_open( stream );
|
||||
|
||||
stream_putBits( stream, XWPROTO_NBITS, XWPROTO_DEVICE_REGISTRATION );
|
||||
writeProto( stream, XWPROTO_DEVICE_REGISTRATION );
|
||||
|
||||
nPlayers = gi->nPlayers;
|
||||
XP_ASSERT( nPlayers > 0 );
|
||||
|
@ -1095,8 +1096,10 @@ client_readInitialMessage( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
PoolContext* pool;
|
||||
|
||||
/* version; any dependencies here? */
|
||||
XP_U8 streamVersion = stream_getU8( stream );
|
||||
stream_setVersion( stream, streamVersion );
|
||||
if ( STREAM_SAVE_PREVWORDS >= stream_getVersion( stream ) ) {
|
||||
XP_U8 streamVersion = stream_getU8( stream );
|
||||
stream_setVersion( stream, streamVersion );
|
||||
}
|
||||
|
||||
gameID = stream_getU32( stream );
|
||||
XP_LOGF( "read gameID of %lx; calling comms_setConnID", gameID );
|
||||
|
@ -1234,11 +1237,7 @@ server_sendInitialMessage( ServerCtxt* server )
|
|||
DictionaryCtxt* dict = model_getDictionary(model);
|
||||
XP_ASSERT( !!stream );
|
||||
stream_open( stream );
|
||||
stream_putBits( stream, XWPROTO_NBITS, XWPROTO_CLIENT_SETUP );
|
||||
|
||||
/* write version for server's benefit; use old version until format
|
||||
changes */
|
||||
stream_putU8( stream, CUR_STREAM_VERS );
|
||||
writeProto( stream, XWPROTO_CLIENT_SETUP );
|
||||
|
||||
XP_LOGF( "putting gameID %lx into msg", gameID );
|
||||
stream_putU32( stream, gameID );
|
||||
|
@ -1323,6 +1322,7 @@ printCode(char* intro, XW_Proto code)
|
|||
caseStr( str, XWPROTO_MOVE_CONFIRM );
|
||||
caseStr( str, XWPROTO_CLIENT_REQ_END_GAME );
|
||||
caseStr( str, XWPROTO_END_GAME );
|
||||
caseStr( str, XWPROTO_NEW_PROTO );
|
||||
}
|
||||
|
||||
XP_STATUSF( "\t%s for %s", intro, str );
|
||||
|
@ -1343,7 +1343,7 @@ messageStreamWithHeader( ServerCtxt* server, XP_U16 devIndex, XW_Proto code )
|
|||
stream = util_makeStreamFromAddr( server->vol.util, channelNo );
|
||||
|
||||
stream_open( stream );
|
||||
stream_putBits( stream, XWPROTO_NBITS, code );
|
||||
writeProto( stream, code );
|
||||
|
||||
return stream;
|
||||
} /* messageStreamWithHeader */
|
||||
|
@ -2440,15 +2440,34 @@ server_handleUndo( ServerCtxt* server )
|
|||
} /* server_handleUndo */
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
static void
|
||||
writeProto( XWStreamCtxt* stream, XW_Proto proto )
|
||||
{
|
||||
stream_putBits( stream, XWPROTO_NBITS, XWPROTO_NEW_PROTO );
|
||||
stream_putBits( stream, XWPROTO_NBITS, proto );
|
||||
stream_putU8( stream, CUR_STREAM_VERS );
|
||||
}
|
||||
|
||||
static XW_Proto
|
||||
readProto( XWStreamCtxt* stream )
|
||||
{
|
||||
XP_U8 version = STREAM_SAVE_PREVWORDS; /* version prior to fmt change */
|
||||
XW_Proto proto = (XW_Proto)stream_getBits( stream, XWPROTO_NBITS );
|
||||
if ( XWPROTO_NEW_PROTO == proto ) {
|
||||
proto = (XW_Proto)stream_getBits( stream, XWPROTO_NBITS );
|
||||
version = stream_getU8( stream );
|
||||
}
|
||||
stream_setVersion( stream, version );
|
||||
return proto;
|
||||
}
|
||||
|
||||
XP_Bool
|
||||
server_receiveMessage( ServerCtxt* server, XWStreamCtxt* incoming )
|
||||
{
|
||||
XW_Proto code;
|
||||
XP_Bool accepted = XP_FALSE;
|
||||
XW_Proto code = readProto( incoming );
|
||||
|
||||
code = (XW_Proto)stream_getBits( incoming, XWPROTO_NBITS );
|
||||
|
||||
printCode("Receiving", code);
|
||||
printCode( "Receiving", code );
|
||||
|
||||
if ( code == XWPROTO_DEVICE_REGISTRATION ) {
|
||||
/* This message is special: doesn't have the header that's possible
|
||||
|
|
|
@ -44,6 +44,8 @@ typedef enum {
|
|||
//XWPROTO_MOVEMADE_INFO, /* info about tiles placed and received */
|
||||
,XWPROTO_CLIENT_REQ_END_GAME /* non-server wants to end the game */
|
||||
,XWPROTO_END_GAME /* server says to end game */
|
||||
|
||||
,XWPROTO_NEW_PROTO
|
||||
} XW_Proto;
|
||||
|
||||
#define XWPROTO_NBITS 4
|
||||
|
|
|
@ -528,6 +528,8 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
|
|||
gint trayTop;
|
||||
gint boardTop = 0;
|
||||
XP_U16 netStatWidth = 0;
|
||||
gint nCols = globals->cGlobals.params->gi.boardSize;
|
||||
gint nRows = nCols;
|
||||
|
||||
if ( globals->draw == NULL ) {
|
||||
createOrLoadObjects( globals );
|
||||
|
@ -541,25 +543,23 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
|
|||
bdHeight = widget->allocation.height - (GTK_TOP_MARGIN + GTK_BOTTOM_MARGIN)
|
||||
- GTK_MIN_TRAY_SCALEV - GTK_BOTTOM_MARGIN;
|
||||
|
||||
hscale = bdWidth / GTK_NUM_COLS;
|
||||
hscale = bdWidth / nCols;
|
||||
if ( 0 != globals->cGlobals.params->nHidden ) {
|
||||
vscale = hscale;
|
||||
} else {
|
||||
vscale = (bdHeight / (GTK_NUM_ROWS + GTK_TRAY_HT_ROWS)); /* makd tray
|
||||
height 3x cell
|
||||
height */
|
||||
vscale = (bdHeight / (nCols + GTK_TRAY_HT_ROWS)); /* makd tray height
|
||||
3x cell height */
|
||||
}
|
||||
|
||||
if ( !globals->cGlobals.params->verticalScore ) {
|
||||
boardTop += GTK_HOR_SCORE_HEIGHT;
|
||||
}
|
||||
|
||||
trayTop = boardTop + (vscale * GTK_NUM_ROWS);
|
||||
trayTop = boardTop + (vscale * nRows);
|
||||
/* move tray up if part of board's meant to be hidden */
|
||||
trayTop -= vscale * globals->cGlobals.params->nHidden;
|
||||
board_setPos( globals->cGlobals.game.board, GTK_BOARD_LEFT, boardTop,
|
||||
hscale*GTK_NUM_COLS, vscale * GTK_NUM_ROWS,
|
||||
hscale * 2, XP_FALSE );
|
||||
hscale * nCols, vscale * nRows, hscale * 2, XP_FALSE );
|
||||
/* board_setScale( globals->cGlobals.game.board, hscale, vscale ); */
|
||||
globals->gridOn = XP_TRUE;
|
||||
|
||||
|
@ -569,16 +569,16 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
|
|||
|
||||
timerTop = GTK_TIMER_TOP;
|
||||
if ( globals->cGlobals.params->verticalScore ) {
|
||||
timerLeft = GTK_BOARD_LEFT + (hscale*GTK_NUM_COLS) + 1;
|
||||
timerLeft = GTK_BOARD_LEFT + (hscale*nCols) + 1;
|
||||
board_setScoreboardLoc( globals->cGlobals.game.board,
|
||||
timerLeft,
|
||||
GTK_VERT_SCORE_TOP,
|
||||
GTK_VERT_SCORE_WIDTH,
|
||||
vscale*GTK_NUM_COLS,
|
||||
vscale*nCols,
|
||||
XP_FALSE );
|
||||
|
||||
} else {
|
||||
timerLeft = GTK_BOARD_LEFT + (hscale*GTK_NUM_COLS)
|
||||
timerLeft = GTK_BOARD_LEFT + (hscale*nCols)
|
||||
- GTK_TIMER_WIDTH - netStatWidth;
|
||||
board_setScoreboardLoc( globals->cGlobals.game.board,
|
||||
GTK_BOARD_LEFT, GTK_HOR_SCORE_TOP,
|
||||
|
@ -598,7 +598,7 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
|
|||
GTK_TIMER_WIDTH, GTK_HOR_SCORE_HEIGHT );
|
||||
|
||||
board_setTrayLoc( globals->cGlobals.game.board, GTK_TRAY_LEFT, trayTop,
|
||||
hscale * GTK_NUM_COLS, vscale * GTK_TRAY_HT_ROWS + 10,
|
||||
hscale * nCols, vscale * GTK_TRAY_HT_ROWS + 10,
|
||||
GTK_DIVIDER_WIDTH );
|
||||
|
||||
setCtrlsForTray( globals );
|
||||
|
@ -1251,7 +1251,8 @@ handle_hide_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
|||
XP_Bool draw = XP_FALSE;
|
||||
|
||||
if ( globals->cGlobals.params->nHidden > 0 ) {
|
||||
globals->adjustment->page_size = GTK_NUM_ROWS;
|
||||
gint nRows = globals->cGlobals.params->gi.boardSize;
|
||||
globals->adjustment->page_size = nRows;
|
||||
globals->adjustment->value = 0.0;
|
||||
|
||||
gtk_signal_emit_by_name( GTK_OBJECT(globals->adjustment), "changed" );
|
||||
|
@ -1341,7 +1342,7 @@ setCtrlsForTray( GtkAppGlobals* XP_UNUSED(globals) )
|
|||
XP_S16 nHidden = globals->cGlobals.params->nHidden;
|
||||
|
||||
if ( nHidden != 0 ) {
|
||||
XP_U16 pageSize = GTK_NUM_ROWS;
|
||||
XP_U16 pageSize = nRows;
|
||||
|
||||
if ( state == TRAY_HIDDEN ) { /* we recover what tray covers */
|
||||
nHidden -= GTK_TRAY_HT_ROWS;
|
||||
|
@ -1373,7 +1374,8 @@ gtk_util_yOffsetChange( XW_UtilCtxt* uc, XP_U16 maxOffset,
|
|||
{
|
||||
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
||||
if ( !!globals->adjustment ) {
|
||||
globals->adjustment->page_size = GTK_NUM_ROWS - maxOffset;
|
||||
gint nRows = globals->cGlobals.params->gi.boardSize;
|
||||
globals->adjustment->page_size = nRows - maxOffset;
|
||||
globals->adjustment->value = newOffset;
|
||||
gtk_adjustment_value_changed( GTK_ADJUSTMENT(globals->adjustment) );
|
||||
}
|
||||
|
@ -2317,9 +2319,10 @@ gtkmain( LaunchParams* params, int argc, char *argv[] )
|
|||
/* install scrollbar even if not needed -- since zooming can make it
|
||||
needed later */
|
||||
GtkWidget* vscrollbar;
|
||||
gint nRows = globals.cGlobals.params->gi.boardSize;
|
||||
globals.adjustment = (GtkAdjustment*)
|
||||
gtk_adjustment_new( 0, 0, GTK_NUM_ROWS, 1, 2,
|
||||
GTK_NUM_ROWS-globals.cGlobals.params->nHidden );
|
||||
gtk_adjustment_new( 0, 0, nRows, 1, 2,
|
||||
nRows - globals.cGlobals.params->nHidden );
|
||||
vscrollbar = gtk_vscrollbar_new( globals.adjustment );
|
||||
g_signal_connect( GTK_OBJECT(globals.adjustment), "value_changed",
|
||||
G_CALLBACK(scroll_value_changed), &globals );
|
||||
|
|
|
@ -132,8 +132,6 @@ typedef struct GtkAppGlobals {
|
|||
/* DictionaryCtxt* gtk_dictionary_make(); */
|
||||
int gtkmain( LaunchParams* params, int argc, char *argv[] );
|
||||
|
||||
#define GTK_NUM_COLS 15
|
||||
#define GTK_NUM_ROWS 15
|
||||
#define GTK_MIN_SCALE 12 /* was 14 */
|
||||
|
||||
#define GTK_MIN_TRAY_SCALEH 24
|
||||
|
@ -156,7 +154,7 @@ int gtkmain( LaunchParams* params, int argc, char *argv[] );
|
|||
#define GTK_TIMER_WIDTH 40
|
||||
#define GTK_NETSTAT_WIDTH 20
|
||||
#define GTK_TIMER_TOP GTK_HOR_SCORE_TOP
|
||||
#define GTK_HOR_SCORE_WIDTH ((GTK_MIN_SCALE*MAX_COLS)-GTK_TIMER_PAD)
|
||||
#define GTK_HOR_SCORE_WIDTH ((GTK_MIN_SCALE*20)-GTK_TIMER_PAD)
|
||||
#define GTK_VERT_SCORE_WIDTH 40
|
||||
|
||||
#define GTK_BOARD_TOP (GTK_SCORE_TOP + GTK_SCORE_HEIGHT \
|
||||
|
|
Loading…
Add table
Reference in a new issue