Skip to content

Commit 0fbe0e9

Browse files
committed
net: Add reason in the exit message
This avoid "you been kicked" after leaving a game
1 parent 305ec2f commit 0fbe0e9

5 files changed

+20
-6
lines changed

Source/Network/CommonEvents.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,28 @@ struct terEventPing : netCommandGeneral
121121

122122
struct netCommand4G_Exit : netCommandGeneral
123123
{
124+
enum ExitReason {
125+
EXITREASON_NORMAL = 0,
126+
EXITREASON_DROPPED,
127+
EXITREASON_KICKED,
128+
};
129+
124130
NETID netid;
125-
explicit netCommand4G_Exit(NETID netid_) : netCommandGeneral(NETCOM_4G_ID_EXIT), netid(netid_) {
131+
ExitReason reason = EXITREASON_NORMAL;
132+
133+
explicit netCommand4G_Exit(NETID netid_, ExitReason reason_) : netCommandGeneral(NETCOM_4G_ID_EXIT), netid(netid_), reason(reason_) {
126134
}
127135

128136
explicit netCommand4G_Exit(XBuffer& in) : netCommandGeneral(NETCOM_4G_ID_EXIT) {
129137
in.read(&netid, sizeof(netid));
138+
uint32_t tmp = 0;
139+
in.read(&tmp, sizeof(tmp));
140+
reason = static_cast<ExitReason>(tmp);
130141
}
131142

132143
void Write(XBuffer& out) const override {
133144
out.write(&netid, sizeof(netid));
145+
out.write(&reason, sizeof(uint32_t));
134146
}
135147
};
136148

Source/Network/P2P_interface1Th.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,12 @@ void PNetCenter::HandlerInputNetCommand()
343343
netCommand4G_Exit nc4g_exit(in_ClientBuf);
344344
//Host already does this before relaying to itself
345345
if (!isHost()) {
346-
if (nc4g_exit.netid == m_localNETID) {
346+
if (nc4g_exit.netid == m_localNETID && nc4g_exit.reason == netCommand4G_Exit::EXITREASON_KICKED) {
347347
ExecuteInternalCommand(PNC_COMMAND__RESET, false);
348348
ExecuteInterfaceCommand(PNC_INTERFACE_COMMAND_KICKED);
349349
} else {
350-
ExitClient(nc4g_exit.netid);
350+
bool normal = nc4g_exit.reason == netCommand4G_Exit::EXITREASON_NORMAL;
351+
DeleteClient(nc4g_exit.netid, normal);
351352
}
352353
}
353354
break;

Source/Network/P2P_interface2Th.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void PNetCenter::SecondThreadQuant()
263263
}
264264

265265
//Send exit event to everyone connected (host or clients)
266-
netCommand4G_Exit ex(m_localNETID);
266+
netCommand4G_Exit ex(m_localNETID, netCommand4G_Exit::EXITREASON_NORMAL);
267267
SendEvent(ex, NETID_ALL);
268268
LogMsg("Sent Exit packets to NETID_ALL\n");
269269
}

Source/Network/P2P_interface2Th_Host.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,8 @@ void PNetCenter::hostProcessPlayerClientPackets(PClientData* client) {
901901
xassert(event.netid == netid);
902902
if (event.netid == netid) {
903903
SendEvent(event, NETID_ALL);
904-
ExitClient(netid);
904+
bool normal = event.reason == netCommand4G_Exit::EXITREASON_NORMAL;
905+
DeleteClient(netid, normal);
905906
}
906907
}
907908
break;

Source/Network/P2P_interface2Th_NetConn.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void PNetCenter::SetConnectionTimeout(int _ms) {
1515
void PNetCenter::KickPlayer(NETID netid) {
1616
fprintf(stdout, "KickPlayer: 0x%" PRIX64 "\n", netid);
1717

18-
netCommand4G_Exit ex(netid);
18+
netCommand4G_Exit ex(netid, netCommand4G_Exit::EXITREASON_KICKED);
1919
SendEvent(ex, netid);
2020

2121
RemovePlayer(netid);

0 commit comments

Comments
 (0)