mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
Implement new callback giving progress connecting with relay.
This commit is contained in:
parent
8450c9da2b
commit
35f068e05c
3 changed files with 58 additions and 6 deletions
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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 = "<unrecognized error code reported>";
|
||||
|
|
Loading…
Reference in a new issue