fix login crash

This commit is contained in:
2023-08-15 19:32:44 +02:00
parent a36716d8e4
commit 7b8c13612c
3 changed files with 10 additions and 2 deletions

View File

@@ -2,6 +2,9 @@
#include <cstdint>
#define SAFE_CHECK(expr) if(!(expr)) return
namespace td {
static constexpr float PI = 3.141592653f;

View File

@@ -77,6 +77,9 @@ void ClientGame::HandlePacket(const protocol::PlayerListPacket* packet) {
void ClientGame::HandlePacket(const protocol::UpdatePlayerTeamPacket* packet) {
game::Player* player = &m_Players[packet->GetPlayerID()];
SAFE_CHECK(player);
if (player->GetTeamColor() == game::TeamColor::None) { //join a team
GetTeam(packet->GetSelectedTeam()).AddPlayer(player);
} else if (packet->GetSelectedTeam() == game::TeamColor::None) { // leave a team
@@ -101,10 +104,14 @@ void ClientGame::HandlePacket(const protocol::UpdateLobbyTimePacket* packet) {
}
void ClientGame::HandlePacket(const protocol::UpdateMoneyPacket* packet) {
SAFE_CHECK(m_Player);
m_Player->SetGold(packet->GetGold());
}
void ClientGame::HandlePacket(const protocol::UpdateExpPacket* packet) {
SAFE_CHECK(m_Player);
m_Player->SetExp(packet->GetExp());
}

View File

@@ -28,8 +28,6 @@
#define KEEP_ALIVE_TIMEOUT 10 * 1000 // 10s
#define SAFE_CHECK(expr) if(!(expr)) return
namespace td {
namespace server {