MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / HandleEvents

Function HandleEvents

Source/multi.cpp:385–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383}
384
385void HandleEvents(_SNETEVENT *pEvt)
386{
387 const uint32_t playerId = pEvt->playerid;
388 switch (pEvt->eventid) {
389 case EVENT_TYPE_PLAYER_CREATE_GAME: {
390 GameData gameData;
391 if (pEvt->databytes < sizeof(GameData))
392 app_fatal(StrCat("Invalid packet size (<sizeof(GameData)): ", pEvt->databytes));
393 std::memcpy(&gameData, pEvt->data, sizeof(gameData));
394 gameData.swapLE();
395 if (gameData.size != sizeof(GameData))
396 app_fatal(StrCat("Invalid size of game data: ", gameData.size));
397 sgGameInitInfo = gameData;
398 sgbPlayerTurnBitTbl[playerId] = true;
399 } break;
400 case EVENT_TYPE_PLAYER_LEAVE_GAME: {
401 sgbPlayerLeftGameTbl[playerId] = true;
402 sgbPlayerTurnBitTbl[playerId] = false;
403
404 int32_t leftReason = 0;
405 if (pEvt->data != nullptr && pEvt->databytes >= sizeof(leftReason)) {
406 std::memcpy(&leftReason, pEvt->data, sizeof(leftReason));
407 leftReason = SDL_SwapLE32(leftReason);
408 }
409 sgdwPlayerLeftReasonTbl[playerId] = leftReason;
410 if (leftReason == LEAVE_ENDING)
411 gbSomebodyWonGameKludge = true;
412
413 sgbSendDeltaTbl[playerId] = false;
414
415 if (gbDeltaSender == playerId)
416 gbDeltaSender = MAX_PLRS;
417 } break;
418 case EVENT_TYPE_PLAYER_MESSAGE: {
419 string_view data(static_cast<const char *>(pEvt->data), pEvt->databytes);
420 if (const size_t nullPos = data.find('\0'); nullPos != string_view::npos) {
421 data.remove_suffix(data.size() - nullPos);
422 }
423 EventPlrMsg(data);
424 } break;
425 }
426}
427
428void RegisterNetEventHandlers()
429{

Callers

nothing calls this directly

Calls 5

app_fatalFunction · 0.85
StrCatFunction · 0.85
EventPlrMsgFunction · 0.85
swapLEMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected