use of SAFE_CHECK
This commit is contained in:
@@ -50,7 +50,9 @@ void WorldClient::HandlePacket(const protocol::SpawnMobPacket* packet) {
|
||||
|
||||
void WorldClient::HandlePacket(const protocol::UpgradeTowerPacket* packet) {
|
||||
game::TowerPtr tower = GetTowerById(packet->GetTowerID());
|
||||
if (tower == nullptr) return; // this should not happen but who knows ?
|
||||
|
||||
SAFE_CHECK(tower);
|
||||
|
||||
tower->Upgrade(packet->GetTowerLevel().GetLevel(), packet->GetTowerLevel().GetPath());
|
||||
}
|
||||
|
||||
@@ -63,9 +65,9 @@ void WorldClient::HandlePacket(const protocol::WorldAddTowerPacket* packet) {
|
||||
void WorldClient::HandlePacket(const protocol::RemoveTowerPacket* packet) {
|
||||
game::TowerPtr tower = RemoveTower(packet->GetTowerID());
|
||||
|
||||
if (tower != nullptr) {
|
||||
SAFE_CHECK(tower);
|
||||
|
||||
GetWorldNotifier().NotifyListeners(&WorldListener::OnTowerRemove, tower);
|
||||
}
|
||||
}
|
||||
|
||||
void WorldClient::HandlePacket(const protocol::UpdateMobStatesPacket* packet) {
|
||||
|
||||
@@ -92,7 +92,11 @@ void ServerConnexion::SendKeepAlive() {
|
||||
}
|
||||
|
||||
void ServerConnexion::HandlePacket(const protocol::PlayerLoginPacket* packet) {
|
||||
if (m_Player->GetName().empty() && !packet->GetPlayerName().empty()) {
|
||||
|
||||
SAFE_CHECK(m_Player->GetName().empty() && !packet->GetPlayerName().empty());
|
||||
|
||||
|
||||
|
||||
m_Player->SetName(packet->GetPlayerName());
|
||||
|
||||
utils::LOG(utils::format("\t[%s] joined !", m_Player->GetName().c_str()));
|
||||
@@ -123,13 +127,14 @@ void ServerConnexion::HandlePacket(const protocol::PlayerLoginPacket* packet) {
|
||||
protocol::WorldDataPacket dataPacket(m_Server->GetGame().GetWorld());
|
||||
SendPacket(&headerDataPacket);
|
||||
SendPacket(&dataPacket);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ServerConnexion::HandlePacket(const protocol::SelectTeamPacket* packet) {
|
||||
SAFE_CHECK(m_Server->GetGame().GetGameState() == game::GameState::Lobby);
|
||||
SAFE_CHECK(static_cast<std::int8_t>(packet->GetSelectedTeam()) >= -1 ||
|
||||
static_cast<std::int8_t>(packet->GetSelectedTeam()) <= 1);
|
||||
|
||||
if (static_cast<std::int8_t>(packet->GetSelectedTeam()) >= -1 || static_cast<std::int8_t>(packet->GetSelectedTeam()) <= 1) {
|
||||
if (m_Player->GetTeamColor() == game::TeamColor::None) { // join a team
|
||||
m_Server->GetGame().GetTeam(packet->GetSelectedTeam()).AddPlayer(m_Player);
|
||||
} else if (packet->GetSelectedTeam() == game::TeamColor::None) { // leave a team
|
||||
@@ -142,11 +147,11 @@ void ServerConnexion::HandlePacket(const protocol::SelectTeamPacket* packet) {
|
||||
m_Player->SetTeamColor(packet->GetSelectedTeam());
|
||||
protocol::UpdatePlayerTeamPacket updateTeamPacket(m_ID, packet->GetSelectedTeam());
|
||||
m_Server->BroadcastPacket(&updateTeamPacket);
|
||||
}
|
||||
}
|
||||
|
||||
void ServerConnexion::HandlePacket(const protocol::KeepAlivePacket* packet) {
|
||||
if (packet->GetAliveID() == m_KeepAlive.keepAliveID)
|
||||
SAFE_CHECK(packet->GetAliveID() == m_KeepAlive.keepAliveID);
|
||||
|
||||
m_KeepAlive.recievedResponse = true;
|
||||
}
|
||||
|
||||
@@ -209,7 +214,8 @@ void ServerConnexion::HandlePacket(const protocol::RemoveTowerPacket* packet) {
|
||||
}
|
||||
|
||||
ServerConnexion::~ServerConnexion() {
|
||||
if (GetDispatcher() != nullptr)
|
||||
SAFE_CHECK(GetDispatcher() != nullptr);
|
||||
|
||||
GetDispatcher()->UnregisterHandler(this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user