From ebcf23a5bf6ae6a19a358f9757eb4e74d210606f Mon Sep 17 00:00:00 2001 From: meep-eep Date: Thu, 7 Dec 2006 04:21:26 +0000 Subject: [PATCH] Corrected abort feedback. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2577 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/melee.c | 28 ++++++++++++++---------- sc2/src/sc2code/netplay/netmelee.c | 34 +++++++++++++++++------------- sc2/src/sc2code/netplay/netmisc.c | 16 +++++++++----- 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/sc2/src/sc2code/melee.c b/sc2/src/sc2code/melee.c index 658f6f654..e89fc8c0d 100644 --- a/sc2/src/sc2code/melee.c +++ b/sc2/src/sc2code/melee.c @@ -3205,12 +3205,12 @@ confirmationCancelled(PMELEE_STATE pMS, COUNT side) } static void -connectionFeedback (NetConnection *conn, const char *str) { +connectionFeedback (NetConnection *conn, const char *str, bool forcePopup) { struct battlestate_struct *bs = NetMelee_getBattleState (conn); - if (bs == NULL) + if (bs == NULL && !forcePopup) { - // bs == NULL means the game has started. + // bs == NULL means the game has not started yet. LockMutex (GraphicsLock); DrawMeleeStatusMessage (str); UnlockMutex (GraphicsLock); @@ -3224,10 +3224,12 @@ connectionFeedback (NetConnection *conn, const char *str) { void connectedFeedback (NetConnection *conn) { if (NetConnection_getPlayerNr(conn) == 0) - connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 8)); + connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 8), + false); // "Bottom player is connected." else - connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 9)); + connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 9), + false); // "Top player is connected." PlayMenuSound (MENU_SOUND_INVOKED); @@ -3261,7 +3263,7 @@ abortFeedback (NetConnection *conn, NetplayAbortReason reason) msg = abortReasonString (reason); if (msg != NULL) - connectionFeedback (conn, msg); + connectionFeedback (conn, msg, true); } const char * @@ -3305,17 +3307,19 @@ resetFeedback (NetConnection *conn, NetplayResetReason reason, msg = resetReasonString (reason); if (msg != NULL) - connectionFeedback (conn, msg); + connectionFeedback (conn, msg, false); } void errorFeedback (NetConnection *conn) { if (NetConnection_getPlayerNr(conn) == 0) - connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 10)); + connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 10), + false); // "Bottom player: connection failed." else - connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 11)); + connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 11), + false); // "Top player: connection failed." } @@ -3323,10 +3327,12 @@ void closeFeedback (NetConnection *conn) { if (NetConnection_getPlayerNr(conn) == 0) - connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 12)); + connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 12), + false); // "Bottom player: connection closed." else - connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 13)); + connectionFeedback (conn, GAME_STRING (NETMELEE_STRING_BASE + 13), + false); // "Top player: connection closed." } diff --git a/sc2/src/sc2code/netplay/netmelee.c b/sc2/src/sc2code/netplay/netmelee.c index 942f4f2c8..2b1a2e723 100644 --- a/sc2/src/sc2code/netplay/netmelee.c +++ b/sc2/src/sc2code/netplay/netmelee.c @@ -120,18 +120,28 @@ NetMelee_getBattleState(NetConnection *conn) { //////////////////////////////////////////////////////////////////////////// +static inline +void +netInputAux(uint32 timeoutMs) { + NetManager_process(&timeoutMs); + // This may cause more packets to be queued, hence the + // flushPacketQueues(). + Alarm_process(); + Callback_process(); + flushPacketQueues(); + // During the flush, a disconnect may be noticed, which triggers + // another callback. It must be handled immediately, before + // another flushPacketQueue() can occur, which would not know + // that the socket is no longer valid. + // TODO: modify the close handling so this order isn't + // necessary. + Callback_process(); +} // Check the network connections for input. void netInput(void) { - uint32 timeoutMs = 0; - NetManager_process(&timeoutMs); - // This may cause more packets to be queued, hence the - // flushPacketQueues(). - flushPacketQueues(); - - Alarm_process(); - Callback_process(); + netInputAux(0); } void @@ -142,13 +152,7 @@ netInputBlocking(uint32 timeoutMs) { if (nextAlarmMs < timeoutMs) timeoutMs = nextAlarmMs; - NetManager_process(&timeoutMs); - // This may cause more packets to be queued, hence the - // flushPacketQueues(). - flushPacketQueues(); - - Alarm_process(); - Callback_process(); + netInputAux(timeoutMs); } diff --git a/sc2/src/sc2code/netplay/netmisc.c b/sc2/src/sc2code/netplay/netmisc.c index aeb207028..bbbaaf9ad 100644 --- a/sc2/src/sc2code/netplay/netmisc.c +++ b/sc2/src/sc2code/netplay/netmisc.c @@ -75,6 +75,14 @@ static void NetMelee_enterState_inSetup(NetConnection *conn, void *arg); // Called when a connection has been established. void NetMelee_connectCallback(NetConnection *conn) { + BattleStateData *battleStateData; + struct melee_state *meleeState; + + meleeState = (struct melee_state *) NetConnection_getExtra(conn); + battleStateData = BattleStateData_new(meleeState, NULL, NULL); + NetConnection_setStateData(conn, (void *) battleStateData); + NetConnection_setExtra(conn, NULL); + sendInit(conn); Netplay_localReady (conn, NetMelee_enterState_inSetup, NULL, false); } @@ -102,12 +110,10 @@ NetMelee_enterState_inSetup(NetConnection *conn, void *arg) { int player; NetConnection_setState(conn, NetState_inSetup); + + battleStateData = (BattleStateData *) NetConnection_getStateData(conn); + meleeState = battleStateData->meleeState; - meleeState = (struct melee_state *) NetConnection_getExtra(conn); - battleStateData = BattleStateData_new(meleeState, NULL, NULL); - NetConnection_setStateData(conn, (void *) battleStateData); - NetConnection_setExtra(conn, NULL); - player = NetConnection_getPlayerNr(conn); connectedFeedback(conn);