Respond to disconnect error from comms with new error message then new

game dialog with conns already open on top.  It's opened as soon as
new game gets its first WM_PAINT message, which may not be best.
Tested only on win32 so far.
This commit is contained in:
ehouse 2009-12-04 09:09:07 +00:00
parent 9f7c0db09f
commit 07be694df6
10 changed files with 83 additions and 12 deletions

View file

@ -49,6 +49,7 @@ typedef struct _GameInfoState {
#endif
XP_Bool isNewGame; /* newGame or GameInfo */
XP_Bool popConnsDlg;
XP_Bool userCancelled; /* OUT param */
/* For tracking when to move stuff up/down */
@ -690,6 +691,13 @@ GameInfo( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
break;
#endif
case WM_PAINT:
if ( state->popConnsDlg ) {
state->popConnsDlg = XP_FALSE;
callConnsDlg( state );
}
break;
case WM_NOTIFY:
if ( !!state->newGameCtx ) {
checkUpdateCombo( state, LOWORD(wParam)-1 );
@ -791,9 +799,8 @@ GameInfo( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
return result;
} /* GameInfo */
XP_Bool
WrapGameInfoDialog( CEAppGlobals* globals, XP_Bool isNewGame,
WrapGameInfoDialog( CEAppGlobals* globals, GIShow showWhat,
CePrefsPrefs* prefsPrefs,
XP_UCHAR* dictName, XP_U16 dictNameLen,
GInfoResults* results )
@ -805,7 +812,8 @@ WrapGameInfoDialog( CEAppGlobals* globals, XP_Bool isNewGame,
state.dlgHdr.globals = globals;
state.dlgHdr.resIDs = resIDs;
state.dlgHdr.nResIDs = VSIZE(resIDs);
state.isNewGame = isNewGame;
state.isNewGame = showWhat != GI_INFO_ONLY;
state.popConnsDlg = showWhat == GI_GOTO_CONNS;
state.prefsPrefs = prefsPrefs;
state.newDictName = dictName;
state.dictNameLen = dictNameLen;
@ -819,4 +827,4 @@ WrapGameInfoDialog( CEAppGlobals* globals, XP_Bool isNewGame,
}
return !state.userCancelled;
}
} /* WrapGameInfoDialog */

View file

@ -35,7 +35,13 @@ typedef struct _GInfoResults {
XP_Bool addrChanged;
} GInfoResults;
XP_Bool WrapGameInfoDialog( CEAppGlobals* globals, XP_Bool isNewGame,
typedef enum {
GI_INFO_ONLY
,GI_NEW_GAME
,GI_GOTO_CONNS
} GIShow;
XP_Bool WrapGameInfoDialog( CEAppGlobals* globals, GIShow showWhat,
CePrefsPrefs* prefsPrefs,
XP_UCHAR* dictName, XP_U16 dictNameLen,
GInfoResults* results );

View file

@ -83,6 +83,8 @@ static XP_S16 ce_send_proc( const XP_U8* buf, XP_U16 len,
void* closure );
static void ce_relay_status( void* closure,
CommsRelayState newState );
static void ce_relay_error( void* closure, XWREASON relayErr );
# ifdef COMMS_HEARTBEAT
static void ce_reset_proc( void* closure );
@ -145,7 +147,7 @@ static XP_Bool ceMsgFromStream( CEAppGlobals* globals, XWStreamCtxt* stream,
const wchar_t* title, XP_U16 buttons,
XP_Bool destroy );
static void RECTtoXPR( XP_Rect* dest, const RECT* src );
static XP_Bool ceDoNewGame( CEAppGlobals* globals );
static XP_Bool ceDoNewGame( CEAppGlobals* globals, GIShow showWhat );
static XP_Bool ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave );
static void closeGame( CEAppGlobals* globals );
static void ceInitPrefs( CEAppGlobals* globals, CEAppPrefs* prefs );
@ -868,6 +870,7 @@ ceInitTProcs( CEAppGlobals* globals, TransportProcs* procs )
#endif
#ifdef XWFEATURE_RELAY
procs->rstatus = ce_relay_status;
procs->rerror = ce_relay_error;
#endif
procs->closure = globals;
}
@ -1492,7 +1495,8 @@ InitInstance(HINSTANCE hInstance, int nCmdShow
&globals->util, (DrawCtx*)globals->draw, 0,
&globals->appPrefs.cp, &procs );
newDone = ceDoNewGame( globals ); /* calls ceInitAndStartBoard */
/* calls ceInitAndStartBoard */
newDone = ceDoNewGame( globals, GI_NEW_GAME );
if ( !newDone ) {
result = FALSE;
}
@ -1648,6 +1652,7 @@ ceFlattenState( const CEAppGlobals* globals )
if ( socketState == CE_IPST_CONNECTED ) {
switch( relayState ) {
case COMMS_RELAYSTATE_UNCONNECTED:
case COMMS_RELAYSTATE_DENIED:
case COMMS_RELAYSTATE_CONNECT_PENDING:
state = CENSTATE_TRYING_RELAY;
break;
@ -1750,7 +1755,7 @@ ceWarnLangChange( CEAppGlobals* globals )
}
static XP_Bool
ceDoNewGame( CEAppGlobals* globals )
ceDoNewGame( CEAppGlobals* globals, GIShow showWhat )
{
CommsAddrRec* addr = NULL;
XP_Bool changed = XP_FALSE;
@ -1758,7 +1763,7 @@ ceDoNewGame( CEAppGlobals* globals )
XP_UCHAR newDictName[CE_MAX_PATH_LEN+1];
GInfoResults results;
if ( WrapGameInfoDialog( globals, XP_TRUE, &prefsPrefs, newDictName,
if ( WrapGameInfoDialog( globals, showWhat, &prefsPrefs, newDictName,
VSIZE(newDictName), &results )
#ifndef STUBBED_DICT
&& ( newDictName[0] != '\0' )
@ -2451,7 +2456,7 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
CePrefsPrefs prefsPrefs;
XP_UCHAR dictName[CE_MAX_PATH_LEN+1];
if ( WrapGameInfoDialog( globals, XP_FALSE, &prefsPrefs,
if ( WrapGameInfoDialog( globals, GI_INFO_ONLY, &prefsPrefs,
dictName, VSIZE(dictName),
&results ) ) {
if ( results.prefsChanged ) {
@ -2471,7 +2476,7 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|| queryBoxChar( globals, hWnd,
ceGetResString( globals,
IDS_OVERWRITE ) ) ) {
draw = ceDoNewGame( globals );
draw = ceDoNewGame( globals, GI_NEW_GAME );
}
break;
@ -2738,6 +2743,10 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
ceTilesLeft( globals );
break;
case XWWM_RELAY_REQ_NEW:
draw = ceDoNewGame( globals, GI_GOTO_CONNS );
break;
#ifndef XWFEATURE_STANDALONE_ONLY
case XWWM_HOSTNAME_ARRIVED:
/* drop it if we're standalone now */
@ -3072,6 +3081,13 @@ ce_relay_status( void* closure, CommsRelayState newState )
globals->relayState = newState;
InvalidateRect( globals->hWnd, &globals->relayStatusR, TRUE /* erase */ );
}
static void
ce_relay_error( void* closure, XWREASON XP_UNUSED(relayErr) )
{
CEAppGlobals* globals = (CEAppGlobals*)closure;
PostMessage( globals->hWnd, XWWM_RELAY_REQ_NEW, 0, 0 );
}
#endif
static XP_S16
@ -3205,6 +3221,14 @@ ce_util_userError( XW_UtilCtxt* uc, UtilErrID id )
case ERR_RELAY_BASE + XWRELAY_ERROR_OTHER_DISCON:
resID = IDS_XWRELAY_ERROR_HEART_OTHER;
break;
case ERR_RELAY_BASE + XWRELAY_ERROR_NO_ROOM:
resID = IDS_ERROR_NO_ROOM;
break;
case ERR_RELAY_BASE + XWRELAY_ERROR_DUP_ROOM:
resID = IDS_ERROR_DUP_ROOM;
break;
/* Same string as above for now */
/* resID = IDS_XWRELAY_ERROR_LOST_OTHER; */
/* break; */

View file

@ -205,6 +205,7 @@ enum {
XWWM_TIME_RQST = WM_APP
,XWWM_REM_SEL
,XWWM_HOSTNAME_ARRIVED
,XWWM_RELAY_REQ_NEW
,XWWM_SOCKET_EVT
};

View file

@ -1012,6 +1012,11 @@ BEGIN
IDS_XWRELAY_RELAY_INCOMPAT "This version of Crosswords does not match the "\
"relay. You probably need to upgrade to the "\
"latest version." /* translate */
IDS_ERROR_NO_ROOM "No such room. Has the host connected yet "\
"to reserve it?" /* translate */
IDS_ERROR_DUP_ROOM "That room is reserved by another host. "\
"Rename your room, become a guest, or try "\
"again in a few minutes." /* translate */
# endif
#endif

View file

@ -1012,6 +1012,15 @@ BEGIN
"jste se dlouho neukázal."
IDS_XWRELAY_ERROR_HEART_OTHER "Bylo ztraceno spojení s dalším zařízením ve hře."
/* IDS_XWRELAY_ERROR_LOST_OTHER "Bylo ztraceno spojení s dalším zařízením ve hře." */
IDS_XWRELAY_RELAY_INCOMPAT "This version of Crosswords does not match the "\
"relay. You probably need to upgrade to the "\
"latest version." /* translate */
IDS_ERROR_NO_ROOM "No such room. Has the host connected yet "\
"to reserve it?" /* translate */
IDS_ERROR_DUP_ROOM "That room is reserved by another host. "\
"Rename your room, become a guest, or try "\
"again in a few minutes." /* translate */
# endif
#endif

View file

@ -1015,6 +1015,11 @@ BEGIN
IDS_XWRELAY_RELAY_INCOMPAT "This version of Crosswords does not match the "\
"relay. You probably need to upgrade to the "\
"latest version."
IDS_ERROR_NO_ROOM "No such room. Has the host connected yet "\
"to reserve it?"
IDS_ERROR_DUP_ROOM "That room is reserved by another host. "\
"Rename your room, become a guest, or try "\
"again in a few minutes."
# endif
#endif

View file

@ -974,6 +974,11 @@ BEGIN
IDS_XWRELAY_RELAY_INCOMPAT "This version of Crosswords does not match the "\
"relay. You probably need to upgrade to the "\
"latest version." /* translate */
IDS_ERROR_NO_ROOM "No such room. Has the host connected yet "\
"to reserve it?" /* translate */
IDS_ERROR_DUP_ROOM "That room is reserved by another host. "\
"Rename your room, become a guest, or try "\
"again in a few minutes." /* translate */
# endif
#endif /* XWFEATURE_STANDALONE_ONLY */

View file

@ -987,6 +987,11 @@ BEGIN
IDS_XWRELAY_RELAY_INCOMPAT "This version of Crosswords does not match the "\
"relay. You probably need to upgrade to the "\
"latest version." /* translate */
IDS_ERROR_NO_ROOM "No such room. Has the host connected yet "\
"to reserve it?" /* translate */
IDS_ERROR_DUP_ROOM "That room is reserved by another host. "\
"Rename your room, become a guest, or try "\
"again in a few minutes." /* translate */
# endif
#endif

View file

@ -123,11 +123,14 @@
# define IDS_XWRELAY_ERROR_HEART_OTHER 40095
# define IDS_XWRELAY_ERROR_LOST_OTHER 40096
# define IDS_XWRELAY_RELAY_INCOMPAT 40097
# define IDS_ERROR_NO_ROOM 40098
# define IDS_ERROR_DUP_ROOM 40099
# endif
#endif
#if ! defined XWFEATURE_STANDALONE_ONLY
# define CE_LAST_RES_ID 40098
# define CE_LAST_RES_ID 40100
#else
# define CE_LAST_RES_ID 40082
#endif