From 35f068e05ce668f11cc9722033c3ba6c411dd476 Mon Sep 17 00:00:00 2001 From: ehouse Date: Mon, 14 Dec 2009 04:06:26 +0000 Subject: [PATCH] Implement new callback giving progress connecting with relay. --- xwords4/linux/cursesmain.c | 19 ++++++++++++------ xwords4/linux/gtkmain.c | 41 ++++++++++++++++++++++++++++++++++++++ xwords4/linux/linuxutl.c | 4 ++++ 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/xwords4/linux/cursesmain.c b/xwords4/linux/cursesmain.c index b2a8d1ca5..5fd40a61a 100644 --- a/xwords4/linux/cursesmain.c +++ b/xwords4/linux/cursesmain.c @@ -1185,13 +1185,13 @@ initClientSocket( CursesAppGlobals* globals, char* serverName ) struct hostent* hostinfo; hostinfo = gethostbyname( serverName ); if ( !hostinfo ) { - userError( globals, "unable to get host info for %s\n", serverName ); + userError( globals, "unable to get host info for %s\n", serverName ); } else { - char* hostName = inet_ntoa( *(struct in_addr*)hostinfo->h_addr ); - XP_LOGF( "gethostbyname returned %s", hostName ); - globals->csInfo.client.serverAddr = inet_addr(hostName); - XP_LOGF( "inet_addr returned %lu", - globals->csInfo.client.serverAddr ); + char* hostName = inet_ntoa( *(struct in_addr*)hostinfo->h_addr ); + XP_LOGF( "gethostbyname returned %s", hostName ); + globals->csInfo.client.serverAddr = inet_addr(hostName); + XP_LOGF( "inet_addr returned %lu", + globals->csInfo.client.serverAddr ); } } /* initClientSocket */ #endif @@ -1406,6 +1406,12 @@ relay_status_curses( void* XP_UNUSED(closure), CommsRelayState state ) XP_LOGF( "%s got status: %s", __func__, CommsRelayState2Str(state) ); } +static void +relay_connd_curses( void* XP_UNUSED(closure), XP_Bool allHere, XP_U16 nMissing ) +{ + XP_LOGF( "%s got allHere: %d; nMissing: %d", __func__, allHere, nMissing ); +} + static void relay_error_curses( void* XP_UNUSED(closure), XWREASON XP_UNUSED(relayErr) ) { @@ -1478,6 +1484,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) #endif #ifdef XWFEATURE_RELAY .rstatus = relay_status_curses, + .rconnd = relay_connd_curses, .rerror = relay_error_curses, #endif }; diff --git a/xwords4/linux/gtkmain.c b/xwords4/linux/gtkmain.c index 58f4ceef9..8f80448cf 100644 --- a/xwords4/linux/gtkmain.c +++ b/xwords4/linux/gtkmain.c @@ -303,8 +303,45 @@ relay_status_gtk( void* closure, CommsRelayState state ) draw_gtk_status( globals->draw, globals->stateChar ); } +static void +relay_connd_gtk( void* closure, XP_Bool allHere, XP_U16 nMissing ) +{ + XP_Bool skip = XP_FALSE; + char buf[256]; + + if ( allHere ) { + snprintf( buf, sizeof(buf), "All expected players have joined. Play!" ); + } else { + GtkAppGlobals* globals = (GtkAppGlobals*)closure; + DeviceRole role = globals->cGlobals.params->serverRole; + if ( role == SERVER_ISSERVER ) { + snprintf( buf, sizeof(buf), "Connected to relay as host; waiting " + "for %d player[s].", nMissing ); + } else if ( nMissing > 0 ) { + snprintf( buf, sizeof(buf), "Connected to relay as guest. Still waiting " + "for %d player[s].", nMissing ); + } else { + /* an allHere message should be coming immediately, so no + notification now. */ + skip = XP_TRUE; + } + } + + if ( !skip ) { + (void)gtkask( buf, GTK_BUTTONS_OK ); + } +} + static gint invoke_new_game( gpointer data ) +{ + GtkAppGlobals* globals = (GtkAppGlobals*)data; + new_game_impl( globals, XP_FALSE ); + return 0; +} + +static gint +invoke_new_game_conns( gpointer data ) { GtkAppGlobals* globals = (GtkAppGlobals*)data; new_game_impl( globals, XP_TRUE ); @@ -321,6 +358,9 @@ relay_error_gtk( void* closure, XWREASON relayErr ) switch( relayErr ) { case XWRELAY_ERROR_NO_ROOM: case XWRELAY_ERROR_DUP_ROOM: + proc = invoke_new_game_conns; + break; + case XWRELAY_ERROR_TOO_MANY: proc = invoke_new_game; break; default: @@ -354,6 +394,7 @@ createOrLoadObjects( GtkAppGlobals* globals ) #endif #ifdef XWFEATURE_RELAY .rstatus = relay_status_gtk, + .rconnd = relay_connd_gtk, .rerror = relay_error_gtk, #endif }; diff --git a/xwords4/linux/linuxutl.c b/xwords4/linux/linuxutl.c index 2da7a5893..354c6511f 100644 --- a/xwords4/linux/linuxutl.c +++ b/xwords4/linux/linuxutl.c @@ -305,6 +305,10 @@ linux_getErrString( UtilErrID id, XP_Bool* silent ) "become a guest, or try again in a few minutes."; break; + case ERR_RELAY_BASE + XWRELAY_ERROR_TOO_MANY: + message = "You tried to supply more players than the host expected."; + break; + default: XP_LOGF( "no code for error: %d", id ); message = "";