server side safe checks
This commit is contained in:
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#define KEEP_ALIVE_TIMEOUT 10 * 1000 // 10s
|
#define KEEP_ALIVE_TIMEOUT 10 * 1000 // 10s
|
||||||
|
|
||||||
|
#define SAFE_CHECK(expr) if(expr) return
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace server {
|
namespace server {
|
||||||
|
|
||||||
@@ -97,8 +99,8 @@ void ServerConnexion::HandlePacket(const protocol::PlayerLoginPacket* packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServerConnexion::HandlePacket(const protocol::SelectTeamPacket* packet) {
|
void ServerConnexion::HandlePacket(const protocol::SelectTeamPacket* packet) {
|
||||||
if (m_Server->GetGame().GetGameState() != game::GameState::Lobby)
|
SAFE_CHECK(m_Server->GetGame().GetGameState() != game::GameState::Lobby);
|
||||||
return;
|
|
||||||
if (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
|
if (m_Player->GetTeamColor() == game::TeamColor::None) { // join a team
|
||||||
m_Server->GetGame().GetTeam(packet->GetSelectedTeam()).AddPlayer(m_Player);
|
m_Server->GetGame().GetTeam(packet->GetSelectedTeam()).AddPlayer(m_Player);
|
||||||
@@ -138,12 +140,12 @@ void ServerConnexion::InitConnection() {
|
|||||||
protocol::ConnexionInfoPacket conPacket(m_ID);
|
protocol::ConnexionInfoPacket conPacket(m_ID);
|
||||||
SendPacket(&conPacket);
|
SendPacket(&conPacket);
|
||||||
|
|
||||||
if (m_Server->GetGame().GetGameState() == game::GameState::Game) {
|
SAFE_CHECK(m_Server->GetGame().GetGameState() != game::GameState::Game);
|
||||||
protocol::WorldBeginDataPacket headerDataPacket(m_Server->GetGame().GetWorld());
|
|
||||||
protocol::WorldBeginDataPacket dataPacket(m_Server->GetGame().GetWorld());
|
protocol::WorldBeginDataPacket headerDataPacket(m_Server->GetGame().GetWorld());
|
||||||
SendPacket(&headerDataPacket);
|
protocol::WorldBeginDataPacket dataPacket(m_Server->GetGame().GetWorld());
|
||||||
SendPacket(&dataPacket);
|
SendPacket(&headerDataPacket);
|
||||||
}
|
SendPacket(&dataPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConnexion::HandlePacket(const protocol::PlaceTowerPacket* packet) {
|
void ServerConnexion::HandlePacket(const protocol::PlaceTowerPacket* packet) {
|
||||||
@@ -153,12 +155,10 @@ void ServerConnexion::HandlePacket(const protocol::PlaceTowerPacket* packet) {
|
|||||||
|
|
||||||
Vec2f towerPos = { static_cast<float>(packet->GetTowerX()), static_cast<float>(packet->GetTowerY()) };
|
Vec2f towerPos = { static_cast<float>(packet->GetTowerX()), static_cast<float>(packet->GetTowerY()) };
|
||||||
|
|
||||||
if (!world->CanPlaceLittleTower(towerPos, m_ID))
|
SAFE_CHECK(!world->CanPlaceLittleTower(towerPos, m_ID));
|
||||||
return;
|
|
||||||
|
|
||||||
if (towerInfo.IsBigTower())
|
if (towerInfo.IsBigTower())
|
||||||
if (!world->CanPlaceBigTower(towerPos, m_ID))
|
SAFE_CHECK(!world->CanPlaceBigTower(towerPos, m_ID));
|
||||||
return;
|
|
||||||
|
|
||||||
game::TowerPtr tower = world->PlaceTowerAt(towerType, packet->GetTowerX(), packet->GetTowerY(), m_ID);
|
game::TowerPtr tower = world->PlaceTowerAt(towerType, packet->GetTowerX(), packet->GetTowerY(), m_ID);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user