From 8272a37aeac9c97a1760ba8bf948bf8615fcbc1e Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 25 Sep 2020 06:47:11 +0200 Subject: [PATCH] Add connection state and player state enums --- 3rdParty/Storm/Source/storm.h | 7 +++++++ Source/monster.cpp | 2 +- Source/msg.cpp | 2 +- Source/multi.cpp | 18 +++++++++--------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/3rdParty/Storm/Source/storm.h b/3rdParty/Storm/Source/storm.h index 61d68175d..ef2a6cc54 100644 --- a/3rdParty/Storm/Source/storm.h +++ b/3rdParty/Storm/Source/storm.h @@ -86,6 +86,13 @@ struct CCritSect { #define GAMESTATE_STARTED 0x08 #define GAMESTATE_REPLAY 0x80 +#define PS_CONNECTED 0x10000 +#define PS_TURN_ARRIVED 0x20000 +#define PS_ACTIVE 0x40000 + +#define LEAVE_ENDING 0x40000004 +#define LEAVE_DROP 0x40000006 + #if defined(__GNUC__) || defined(__cplusplus) extern "C" { #endif diff --git a/Source/monster.cpp b/Source/monster.cpp index 2f1aae308..430476f87 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -2534,7 +2534,7 @@ void DoEnding() int musicVolume; if (gbMaxPlayers > 1) { - SNetLeaveGame(0x40000004); + SNetLeaveGame(LEAVE_ENDING); } music_stop(); diff --git a/Source/msg.cpp b/Source/msg.cpp index c77692929..b3bfc6938 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -1135,7 +1135,7 @@ DWORD ParseCmd(int pnum, TCmd *pCmd) } if (pCmd->bCmd < CMD_DLEVEL_0 || pCmd->bCmd > CMD_DLEVEL_END) { - SNetDropPlayer(pnum, 0x40000006); + SNetDropPlayer(pnum, LEAVE_DROP); return 0; } diff --git a/Source/multi.cpp b/Source/multi.cpp index ab98f8657..394a77e94 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -215,7 +215,7 @@ void multi_msg_countdown() int i; for (i = 0; i < MAX_PLRS; i++) { - if (player_state[i] & 0x20000) { + if (player_state[i] & PS_TURN_ARRIVED) { if (gdwMsgLenTbl[i] == 4) multi_parse_turn(i, *(DWORD *)glpMsgTbl[i]); } @@ -242,7 +242,7 @@ void multi_handle_turn_upper_bit(int pnum) int i; for (i = 0; i < MAX_PLRS; i++) { - if (player_state[i] & 0x10000 && i != pnum) + if (player_state[i] & PS_CONNECTED && i != pnum) break; } @@ -290,11 +290,11 @@ void multi_player_left_msg(int pnum, int left) if (left) { pszFmt = "Player '%s' just left the game"; switch (sgdwPlayerLeftReasonTbl[pnum]) { - case 0x40000004: + case LEAVE_ENDING: pszFmt = "Player '%s' killed Diablo and left the game!"; gbSomebodyWonGameKludge = TRUE; break; - case 0x40000006: + case LEAVE_DROP: pszFmt = "Player '%s' dropped due to timeout"; break; } @@ -397,11 +397,11 @@ void multi_begin_timeout() bGroupCount = 0; for (i = 0; i < MAX_PLRS; i++) { nState = player_state[i]; - if (nState & 0x10000) { + if (nState & PS_CONNECTED) { if (nLowestPlayer == -1) { nLowestPlayer = i; } - if (nState & 0x40000) { + if (nState & PS_ACTIVE) { bGroupPlayers++; if (nLowestActive == -1) { nLowestActive = i; @@ -444,8 +444,8 @@ void multi_check_drop_player() int i; for (i = 0; i < MAX_PLRS; i++) { - if (!(player_state[i] & 0x40000) && player_state[i] & 0x10000) { - SNetDropPlayer(i, 0x40000006); + if (!(player_state[i] & PS_ACTIVE) && player_state[i] & PS_CONNECTED) { + SNetDropPlayer(i, LEAVE_DROP); } } } @@ -665,7 +665,7 @@ void __stdcall multi_handle_events(_SNETEVENT *pEvt) if (data && (DWORD)pEvt->databytes >= 4) LeftReason = data[0]; sgdwPlayerLeftReasonTbl[pEvt->playerid] = LeftReason; - if (LeftReason == 0x40000004) + if (LeftReason == LEAVE_ENDING) gbSomebodyWonGameKludge = TRUE; sgbSendDeltaTbl[pEvt->playerid] = FALSE; dthread_remove_player(pEvt->playerid);