feat: add server tower place detection

This commit is contained in:
2021-09-19 18:32:47 +02:00
parent 37f76a3e78
commit fee1ab6638

View File

@@ -51,7 +51,7 @@ void ServerConnexion::checkKeepAlive() {
if (time - m_KeepAlive.sendTime > KEEP_ALIVE_TIMEOUT) {
if (m_KeepAlive.recievedResponse) {
sendKeepAlive();
} else {
} else {
protocol::DisconnectPacket packet("Time out");
sendPacket(&packet);
closeConnection();
@@ -144,7 +144,16 @@ void ServerConnexion::initConnection() {
}
void ServerConnexion::HandlePacket(protocol::PlaceTowerPacket* packet) {
// process packet
game::TowerType towerType = packet->getTowerType();
const game::TowerInfo& towerInfo = game::getTowerInfo(towerType);
const game::World* world = m_Server->getGame().getWorld();
if (towerInfo.isBigTower()) {
if (!world->CanPlaceBigTower({ packet->getTowerX(), packet->getTowerY() }))
return;
} else {
if (!world->CanPlaceLittleTower({ packet->getTowerX(), packet->getTowerY() }))
return;
}
protocol::WorldAddTowerPacket addTowerPacket(packet->getTowerX(), packet->getTowerY(), packet->getTowerType(), m_ID);
m_Server->broadcastPacket(&addTowerPacket);
}