Skip to content

Commit 1102ff0

Browse files
committed
networkthreading: fix it up
1 parent 1984022 commit 1102ff0

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

source/modules/networkthreading.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ struct QueuedPacket {
9090
pBytes = nullptr;
9191
}
9292

93-
ConDMsg(PROJECT_NAME " - networkthreading: Freeing %i bytes after packet was now processed (%p)\n", pPacket.size, this);
93+
if (g_pNetworkThreadingModule.InDebug() == 1)
94+
Msg(PROJECT_NAME " - networkthreading: Freeing %i bytes after packet was now processed (%p)\n", pPacket.size, this);
9495
}
9596

9697
netpacket_s pPacket;
@@ -117,9 +118,11 @@ static void AddPacketToQueueForMainThread(netpacket_s* pPacket, bool bIsConnecti
117118
memcpy(pQueue->pBytes, pPacket->data, pPacket->size);
118119

119120
pQueue->pPacket.data = pQueue->pBytes; // Update the pointer for later access
120-
pQueue->pPacket.message.StartReading( pQueue->pPacket.data, pQueue->pPacket.size ); // also needs updating
121+
pQueue->pPacket.message.StartReading( pQueue->pPacket.data, pQueue->pPacket.size, pPacket->message.GetNumBitsRead() ); // also needs updating
122+
pQueue->pPacket.pNext = NULL;
121123

122-
ConDMsg(PROJECT_NAME " - networkthreading: Added %i bytes packet to queue (%p)\n", pPacket->size, pQueue);
124+
if (g_pNetworkThreadingModule.InDebug() == 1)
125+
Msg(PROJECT_NAME " - networkthreading: Added %i bytes packet to queue (%p)\n", pPacket->size, pQueue);
123126

124127
AUTO_LOCK(g_pQueuePacketsMutex);
125128
g_pQueuedPackets.push_back(pQueue);
@@ -145,7 +148,9 @@ static HandleStatus ShouldHandlePacket(netpacket_s* pPacket, bool isConnectionle
145148
if (networkthreading_parallelprocessing.GetBool())
146149
{
147150
if (c == A2S_GETCHALLENGE || c == A2S_SERVERQUERY_GETCHALLENGE || c == A2S_INFO || c == A2S_PLAYER || c == A2S_RULES)
151+
{
148152
return HandleStatus::HANDLE_NOW;
153+
}
149154
}
150155
}
151156

@@ -225,7 +230,7 @@ static SIMPLETHREAD_RETURNVALUE NetworkThread(void* pThreadData)
225230
CNetChan* netchan = func_NET_FindNetChannel(nSocket, packet->from);
226231
if (netchan)
227232
{
228-
HandleStatus pStatus = ShouldHandlePacket(packet, true);
233+
HandleStatus pStatus = ShouldHandlePacket(packet, false);
229234
if (pStatus == HandleStatus::HANDLE_NOW) {
230235
netchan->ProcessPacket(packet, true);
231236
} else {
@@ -234,7 +239,8 @@ static SIMPLETHREAD_RETURNVALUE NetworkThread(void* pThreadData)
234239
} else {
235240
char pNetAddr[64]; // Needed since else .ToString is not threadsafe!
236241
(*(netadrnew_s*)&packet->from).ToString(pNetAddr, sizeof(pNetAddr), false);
237-
ConDMsg(PROJECT_NAME " - networkthreading: Discarding of %i bytes since there is no channel for %s!\n", packet->size, pNetAddr);
242+
if (g_pNetworkThreadingModule.InDebug() == 1)
243+
Msg(PROJECT_NAME " - networkthreading: Discarding of %i bytes since there is no channel for %s!\n", packet->size, pNetAddr);
238244
}
239245
}
240246

@@ -273,8 +279,14 @@ static void hook_NET_ProcessSocket(int nSocket, IConnectionlessPacketHandler* pH
273279
for (QueuedPacket* pQueuePacket : g_pQueuedPackets)
274280
{
275281
if (pQueuePacket->bIsConnectionless) {
282+
if (g_pNetworkThreadingModule.InDebug() == 1)
283+
Msg(PROJECT_NAME " - networkthreading: Processed %i bytes as connectionless! (%p)\n", pQueuePacket->pPacket.size, pQueuePacket);
284+
276285
Util::server->ProcessConnectionlessPacket(&pQueuePacket->pPacket);
277286
} else {
287+
if (g_pNetworkThreadingModule.InDebug() == 1)
288+
Msg(PROJECT_NAME " - networkthreading: Processed %i bytes as net channel! (%p)\n", pQueuePacket->pPacket.size, pQueuePacket);
289+
278290
CNetChan* netchan = func_NET_FindNetChannel(nSocket, pQueuePacket->pPacket.from);
279291
if (netchan)
280292
netchan->ProcessPacket(&pQueuePacket->pPacket, true);

0 commit comments

Comments
 (0)