diff --git a/xwords4/linux/cursesmain.c b/xwords4/linux/cursesmain.c index df914d613..471ff84eb 100644 --- a/xwords4/linux/cursesmain.c +++ b/xwords4/linux/cursesmain.c @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */ /* - * Copyright 2000-2007 by Eric House (xwords@eehouse.org). All rights + * Copyright 2000-2008 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or @@ -768,9 +768,6 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch ) if ( numEvents > 0 && (globals->fdArray[fdIndex].revents & POLLIN) != 0 ) { - int nBytes; - unsigned char buf[256]; - struct sockaddr_in addr_sock; --numEvents; @@ -781,6 +778,9 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch ) (*globals->cGlobals.acceptor)( globals->fdArray[fdIndex].fd, globals ); } else { +#ifndef XWFEATURE_STANDALONE_ONLY + unsigned char buf[256]; + int nBytes; /* It's a normal data socket */ if ( 0 ) { #ifdef XWFEATURE_RELAY @@ -801,6 +801,7 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch ) if ( nBytes != -1 ) { XWStreamCtxt* inboundS; + struct sockaddr_in addr_sock; redraw = XP_FALSE; XP_STATUSF( "linuxReceive=>%d", nBytes ); @@ -836,7 +837,9 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch ) curses_util_requestTime(globals->cGlobals.params->util); } } - +#else + XP_ASSERT(0); /* no socket activity in standalone game! */ +#endif /* #ifndef XWFEATURE_STANDALONE_ONLY */ } ++fdIndex; } @@ -924,6 +927,7 @@ curses_util_warnIllegalWord( XW_UtilCtxt* XP_UNUSED(uc), return XP_FALSE; } /* curses_util_warnIllegalWord */ +#ifndef XWFEATURE_STANDALONE_ONLY static void cursesSendOnClose( XWStreamCtxt* stream, void* closure ) { @@ -946,6 +950,7 @@ curses_util_makeStreamFromAddr(XW_UtilCtxt* uc, XP_PlayerAddr channelNo ) cursesSendOnClose ); return stream; } /* curses_util_makeStreamFromAddr */ +#endif static void setupCursesUtilCallbacks( CursesAppGlobals* globals, XW_UtilCtxt* util ) @@ -956,8 +961,9 @@ setupCursesUtilCallbacks( CursesAppGlobals* globals, XW_UtilCtxt* util ) util->vtable->m_util_askPassword = curses_util_askPassword; util->vtable->m_util_yOffsetChange = curses_util_yOffsetChange; util->vtable->m_util_warnIllegalWord = curses_util_warnIllegalWord; +#ifndef XWFEATURE_STANDALONE_ONLY util->vtable->m_util_makeStreamFromAddr = curses_util_makeStreamFromAddr; - +#endif util->vtable->m_util_userQuery = curses_util_userQuery; util->vtable->m_util_userPickTile = curses_util_userPickTile; util->vtable->m_util_trayHiddenChange = curses_util_trayHiddenChange; @@ -972,6 +978,7 @@ setupCursesUtilCallbacks( CursesAppGlobals* globals, XW_UtilCtxt* util ) util->closure = globals; } /* setupCursesUtilCallbacks */ +#ifndef XWFEATURE_STANDALONE_ONLY static void sendOnClose( XWStreamCtxt* stream, void* closure ) { @@ -980,6 +987,7 @@ sendOnClose( XWStreamCtxt* stream, void* closure ) XP_ASSERT( !!globals->cGlobals.game.comms ); comms_send( globals->cGlobals.game.comms, stream ); } /* sendOnClose */ +#endif static XP_Bool handleKeyEvent( CursesAppGlobals* globals, MenuList* list, char ch ) @@ -1055,14 +1063,15 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) gameID = (XP_U16)util_getCurSeconds( globals.cGlobals.params->util ); game_makeNewGame( MEMPOOL &globals.cGlobals.game, ¶ms->gi, params->util, (DrawCtx*)globals.draw, - gameID, &globals.cp, linux_send, + gameID, &globals.cp, LINUX_SEND, IF_CH(linux_reset) &globals ); +#ifndef XWFEATURE_STANDALONE_ONLY if ( globals.cGlobals.game.comms ) { CommsAddrRec addr; if ( 0 ) { -#ifdef XWFEATURE_RELAY +# ifdef XWFEATURE_RELAY } else if ( params->conType == COMMS_CONN_RELAY ) { addr.conType = COMMS_CONN_RELAY; addr.u.ip_relay.ipAddr = 0; /* ??? */ @@ -1071,18 +1080,19 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) sizeof(addr.u.ip_relay.hostName) - 1 ); XP_STRNCPY( addr.u.ip_relay.cookie, params->connInfo.relay.cookie, sizeof(addr.u.ip_relay.cookie) - 1 ); -#endif -#ifdef XWFEATURE_BLUETOOTH +# endif +# ifdef XWFEATURE_BLUETOOTH } else if ( params->conType == COMMS_CONN_BT ) { addr.conType = COMMS_CONN_BT; XP_ASSERT( sizeof(addr.u.bt.btAddr) >= sizeof(params->connInfo.bt.hostAddr)); XP_MEMCPY( &addr.u.bt.btAddr, ¶ms->connInfo.bt.hostAddr, sizeof(params->connInfo.bt.hostAddr) ); -#endif +# endif } comms_setAddr( globals.cGlobals.game.comms, &addr ); } +#endif model_setDictionary( globals.cGlobals.game.model, params->dict ); @@ -1102,6 +1112,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) board_invalAll( globals.cGlobals.game.board ); +#ifndef XWFEATURE_STANDALONE_ONLY /* send any events that need to get off before the event loop begins */ if ( !isServer ) { if ( 1 /* stream_open( params->info.clientInfo.stream ) */) { @@ -1116,6 +1127,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) exit( 0 ); } } +#endif server_do( globals.cGlobals.game.server ); diff --git a/xwords4/linux/gtkmain.c b/xwords4/linux/gtkmain.c index e10e54637..844813d88 100644 --- a/xwords4/linux/gtkmain.c +++ b/xwords4/linux/gtkmain.c @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */ /* - * Copyright 2000-2007 by Eric House (xwords@eehouse.org). All rights reserved. + * Copyright 2000-2008 by Eric House (xwords@eehouse.org). All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -58,7 +58,9 @@ #include "filestream.h" /* static guint gtkSetupClientSocket( GtkAppGlobals* globals, int sock ); */ +#ifndef XWFEATURE_STANDALONE_ONLY static void sendOnClose( XWStreamCtxt* stream, void* closure ); +#endif static XP_Bool file_exists( const char* fileName ); static void setCtrlsForTray( GtkAppGlobals* globals ); static void printFinalScores( GtkAppGlobals* globals ); @@ -292,8 +294,10 @@ createOrLoadObjects( GtkAppGlobals* globals ) XWStreamCtxt* stream = NULL; XP_Bool opened = XP_FALSE; +#ifndef XWFEATURE_STANDALONE_ONLY DeviceRole serverRole = globals->cGlobals.params->serverRole; XP_Bool isServer = serverRole != SERVER_ISCLIENT; +#endif LaunchParams* params = globals->cGlobals.params; globals->draw = (GtkDrawCtx*)gtkDrawCtxtMake( globals->drawing_area, @@ -308,7 +312,7 @@ createOrLoadObjects( GtkAppGlobals* globals ) params->dict, params->util, (DrawCtx*)globals->draw, &globals->cp, - linux_send, IF_CH(linux_reset) globals ); + LINUX_SEND, IF_CH(linux_reset) globals ); stream_destroy( stream ); } @@ -335,7 +339,7 @@ createOrLoadObjects( GtkAppGlobals* globals ) game_makeNewGame( MEMPOOL &globals->cGlobals.game, ¶ms->gi, params->util, (DrawCtx*)globals->draw, - gameID, &globals->cp, linux_send, + gameID, &globals->cp, LINUX_SEND, IF_CH(linux_reset) globals ); addr.conType = params->conType; @@ -364,11 +368,12 @@ createOrLoadObjects( GtkAppGlobals* globals ) #endif } +#ifndef XWFEATURE_STANDALONE_ONLY /* This may trigger network activity */ if ( !!globals->cGlobals.game.comms ) { comms_setAddr( globals->cGlobals.game.comms, &addr ); } - +#endif model_setDictionary( globals->cGlobals.game.model, params->dict ); /* params->gi.phoniesAction = PHONIES_DISALLOW; */ @@ -376,6 +381,7 @@ createOrLoadObjects( GtkAppGlobals* globals ) params->gi.allowHintRect = XP_TRUE; #endif +#ifndef XWFEATURE_STANDALONE_ONLY if ( !isServer ) { XWStreamCtxt* stream = mem_stream_make( MEMPOOL params->vtMgr, globals, CHANNEL_NONE, @@ -383,12 +389,14 @@ createOrLoadObjects( GtkAppGlobals* globals ) server_initClientConnection( globals->cGlobals.game.server, stream ); } +#endif } +#ifndef XWFEATURE_STANDALONE_ONLY if ( !!globals->cGlobals.game.comms ) { comms_start( globals->cGlobals.game.comms ); } - +#endif server_do( globals->cGlobals.game.server ); } /* createOrLoadObjects */ @@ -640,15 +648,18 @@ new_game( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals ) confirmed = newGameDialog( globals, XP_TRUE ); if ( confirmed ) { CurGameInfo* gi = &globals->cGlobals.params->gi; +#ifndef XWFEATURE_STANDALONE_ONLY XP_Bool isClient = gi->serverRole == SERVER_ISCLIENT; +#endif XP_U32 gameID = util_getCurSeconds( globals->cGlobals.params->util ); XP_STATUSF( "grabbed gameID: %ld\n", gameID ); game_reset( MEMPOOL &globals->cGlobals.game, gi, globals->cGlobals.params->util, - gameID, &globals->cp, linux_send, + gameID, &globals->cp, LINUX_SEND, IF_CH(linux_reset) globals ); +#ifndef XWFEATURE_STANDALONE_ONLY if ( isClient ) { XWStreamCtxt* stream = mem_stream_make( MEMPOOL @@ -659,7 +670,7 @@ new_game( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals ) server_initClientConnection( globals->cGlobals.game.server, stream ); } - +#endif (void)server_do( globals->cGlobals.game.server ); /* assign tiles, etc. */ board_invalAll( globals->cGlobals.game.board ); board_draw( globals->cGlobals.game.board ); @@ -726,6 +737,7 @@ handle_trayEditToggle_off( GtkWidget* widget, GtkAppGlobals* globals ) } #endif +#ifndef XWFEATURE_STANDALONE_ONLY static void handle_resend( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals ) { @@ -752,6 +764,7 @@ handle_commstats( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals ) } } /* handle_commstats */ #endif +#endif #ifdef MEM_DEBUG static void @@ -831,11 +844,13 @@ makeMenus( GtkAppGlobals* globals, int XP_UNUSED(argc), fileMenu = makeAddSubmenu( menubar, "Network" ); +#ifndef XWFEATURE_STANDALONE_ONLY (void)createAddItem( fileMenu, "Resend", GTK_SIGNAL_FUNC(handle_resend), globals ); -#ifdef DEBUG +# ifdef DEBUG (void)createAddItem( fileMenu, "Stats", GTK_SIGNAL_FUNC(handle_commstats), globals ); +# endif #endif #ifdef MEM_DEBUG (void)createAddItem( fileMenu, "Mem stats", @@ -1332,6 +1347,7 @@ gtk_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi, XP_U16 player, return result; } /* gtk_util_warnIllegalWord */ +#ifndef XWFEATURE_STANDALONE_ONLY static XWStreamCtxt* gtk_util_makeStreamFromAddr(XW_UtilCtxt* uc, XP_PlayerAddr channelNo ) { @@ -1343,6 +1359,7 @@ gtk_util_makeStreamFromAddr(XW_UtilCtxt* uc, XP_PlayerAddr channelNo ) sendOnClose ); return stream; } /* gtk_util_makeStreamFromAddr */ +#endif #ifdef XWFEATURE_SEARCHLIMIT static XP_Bool @@ -1558,9 +1575,9 @@ setupGtkUtilCallbacks( GtkAppGlobals* globals, XW_UtilCtxt* util ) util->vtable->m_util_setTimer = gtk_util_setTimer; util->vtable->m_util_requestTime = gtk_util_requestTime; util->vtable->m_util_warnIllegalWord = gtk_util_warnIllegalWord; - +#ifndef XWFEATURE_STANDALONE_ONLY util->vtable->m_util_makeStreamFromAddr = gtk_util_makeStreamFromAddr; - +#endif #ifdef XWFEATURE_SEARCHLIMIT util->vtable->m_util_getTraySearchLimits = gtk_util_getTraySearchLimits; #endif @@ -1568,6 +1585,7 @@ setupGtkUtilCallbacks( GtkAppGlobals* globals, XW_UtilCtxt* util ) util->closure = globals; } /* setupGtkUtilCallbacks */ +#ifndef XWFEATURE_STANDALONE_ONLY static gboolean newConnectionInput( GIOChannel *source, GIOCondition condition, @@ -1780,6 +1798,7 @@ drop_msg_toggle( GtkWidget* toggle, GtkAppGlobals* globals ) globals->dropIncommingMsgs = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(toggle) ); } /* drop_msg_toggle */ +#endif int gtkmain( LaunchParams* params, int argc, char *argv[] ) @@ -1792,19 +1811,23 @@ gtkmain( LaunchParams* params, int argc, char *argv[] ) GtkWidget* vbox; GtkWidget* hbox; GtkAppGlobals globals; +#ifndef XWFEATURE_STANDALONE_ONLY GtkWidget* dropCheck; +#endif memset( &globals, 0, sizeof(globals) ); globals.cGlobals.params = params; globals.cGlobals.lastNTilesToUse = MAX_TRAY_TILES; -#ifdef XWFEATURE_RELAY +#ifndef XWFEATURE_STANDALONE_ONLY +# ifdef XWFEATURE_RELAY globals.cGlobals.socket = -1; -#endif +# endif globals.cGlobals.socketChanged = gtk_socket_changed; globals.cGlobals.socketChangedClosure = &globals; globals.cGlobals.addAcceptor = gtk_socket_acceptor; +#endif globals.cp.showBoardArrow = XP_TRUE; globals.cp.showRobotScores = params->showRobotScores; @@ -1840,11 +1863,13 @@ gtkmain( LaunchParams* params, int argc, char *argv[] ) menubar = makeMenus( &globals, argc, argv ); gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, TRUE, 0); +#ifndef XWFEATURE_STANDALONE_ONLY dropCheck = gtk_check_button_new_with_label( "drop incoming messages" ); g_signal_connect( GTK_OBJECT(dropCheck), "toggled", G_CALLBACK(drop_msg_toggle), &globals ); gtk_box_pack_start( GTK_BOX(vbox), dropCheck, FALSE, TRUE, 0); gtk_widget_show( dropCheck ); +#endif buttonbar = makeButtons( &globals, argc, argv ); gtk_box_pack_start( GTK_BOX(vbox), buttonbar, FALSE, TRUE, 0); diff --git a/xwords4/linux/gtknewgame.c b/xwords4/linux/gtknewgame.c index d85daadc9..cce5be52c 100644 --- a/xwords4/linux/gtknewgame.c +++ b/xwords4/linux/gtknewgame.c @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */ /* - * Copyright 2001-2006 by Eric House (xwords@eehouse.org). All rights + * Copyright 2001-2008 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or @@ -37,6 +37,7 @@ typedef struct GtkNewGameState { #ifndef XWFEATURE_STANDALONE_ONLY GtkWidget* remoteChecks[MAX_NUM_PLAYERS]; + GtkWidget* roleCombo; #endif GtkWidget* robotChecks[MAX_NUM_PLAYERS]; GtkWidget* nameLabels[MAX_NUM_PLAYERS]; @@ -44,7 +45,6 @@ typedef struct GtkNewGameState { GtkWidget* passwdLabels[MAX_NUM_PLAYERS]; GtkWidget* passwdFields[MAX_NUM_PLAYERS]; GtkWidget* nPlayersCombo; - GtkWidget* roleCombo; GtkWidget* nPlayersLabel; GtkWidget* juggleButton; } GtkNewGameState; @@ -59,6 +59,7 @@ nplayers_menu_changed( GtkComboBox* combo, GtkNewGameState* state ) } } /* nplayers_menu_changed */ +#ifndef XWFEATURE_STANDALONE_ONLY static void role_combo_changed( GtkComboBox* combo, gpointer gp ) { @@ -70,6 +71,7 @@ role_combo_changed( GtkComboBox* combo, gpointer gp ) newg_attrChanged( state->newGameCtxt, NG_ATTR_ROLE, value ); } } /* role_combo_changed */ +#endif static void callChangedWithIndex( GtkNewGameState* state, GtkWidget* item, @@ -161,18 +163,21 @@ makeNewGameDialog( GtkNewGameState* state, XP_Bool isNewGame ) GtkWidget* dialog; GtkWidget* vbox; GtkWidget* hbox; +#ifndef XWFEATURE_STANDALONE_ONLY GtkWidget* roleCombo; + char* roles[] = { "Standalone", "Host", "Guest" }; +#endif GtkWidget* nPlayersCombo; GtkWidget* boardSizeCombo; CurGameInfo* gi; short i; - char* roles[] = { "Standalone", "Host", "Guest" }; dialog = gtk_dialog_new(); gtk_window_set_modal( GTK_WINDOW( dialog ), TRUE ); vbox = gtk_vbox_new( FALSE, 0 ); +#ifndef XWFEATURE_STANDALONE_ONLY hbox = gtk_hbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox), gtk_label_new("Role:"), FALSE, TRUE, 0 ); @@ -187,6 +192,7 @@ makeNewGameDialog( GtkNewGameState* state, XP_Bool isNewGame ) gtk_box_pack_start( GTK_BOX(hbox), roleCombo, FALSE, TRUE, 0 ); gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 ); +#endif /* NPlayers menu */ hbox = gtk_hbox_new( FALSE, 0 ); @@ -388,8 +394,10 @@ gtk_newgame_attr_enable( void* closure, NewGameAttr attr, XP_TriEnable enable ) GtkWidget* widget = NULL; if ( attr == NG_ATTR_NPLAYERS ) { widget = state->nPlayersCombo; +#ifndef XWFEATURE_STANDALONE_ONLY } else if ( attr == NG_ATTR_ROLE ) { widget = state->roleCombo; +#endif } else if ( attr == NG_ATTR_CANJUGGLE ) { widget = state->juggleButton; } @@ -456,11 +464,13 @@ gtk_newgame_attr_set( void* closure, NewGameAttr attr, NGValue value ) XP_U16 i = value.ng_u16; XP_LOGF( "%s: setting menu %d", __func__, i-1 ); gtk_combo_box_set_active( GTK_COMBO_BOX(state->nPlayersCombo), i-1 ); +#ifndef XWFEATURE_STANDALONE_ONLY } else if ( attr == NG_ATTR_ROLE ) { gtk_combo_box_set_active( GTK_COMBO_BOX(state->roleCombo), value.ng_role ); } else if ( attr == NG_ATTR_REMHEADER ) { /* ignored on GTK: no headers at all */ +#endif } else if ( attr == NG_ATTR_NPLAYHEADER ) { gtk_label_set_text( GTK_LABEL(state->nPlayersLabel), value.ng_cp ); } diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index 297b498a6..7035df94c 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */ /* - * Copyright 2000-2007 by Eric House (xwords@eehouse.org). All rights + * Copyright 2000-2008 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or @@ -349,6 +349,7 @@ linShiftFocus( CommonGlobals* cGlobals, XP_Key key, const BoardObjectType* order } /* linShiftFocus */ #endif +#ifndef XWFEATURE_STANDALONE_ONLY #ifdef XWFEATURE_RELAY static int linux_init_relay_socket( CommonGlobals* cGlobals ) @@ -546,7 +547,8 @@ linux_relay_receive( CommonGlobals* cGlobals, unsigned char* buf, int bufSize ) } return nRead; } /* linuxReceive */ -#endif +#endif /* XWFEATURE_RELAY */ +#endif /* XWFEATURE_STANDALONE_ONLY */ /* Create a stream for the incoming message buffer, and read in any information specific to our platform's comms layer (return address, say) diff --git a/xwords4/linux/linuxmain.h b/xwords4/linux/linuxmain.h index c42921eca..c8bd53ccf 100644 --- a/xwords4/linux/linuxmain.h +++ b/xwords4/linux/linuxmain.h @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make -k";-*- */ /* - * Copyright 1997-2000 by Eric House (xwords@eehouse.org). All rights reserved. + * Copyright 1997-2008 by Eric House (xwords@eehouse.org). All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -39,6 +39,12 @@ DictionaryCtxt* linux_dictionary_make( MPFORMAL const char* dictFileName ); int initListenerSocket( int port ); XP_S16 linux_send( const XP_U8* buf, XP_U16 buflen, const CommsAddrRec* addrRec, void* closure ); +#ifndef XWFEATURE_STANDALONE_ONLY +# define LINUX_SEND linux_send +#else +# define LINUX_SEND NULL +#endif + #ifdef COMMS_HEARTBEAT void linux_reset( void* closure ); #endif