commit 497a601c424e8e728ef0a8e61f049982f2d4af16 Author: Persson-dev <sim16.prib@gmail.com> Date: Sat Aug 12 10:32:52 2023 +0200 fix warning commit 1bfd019a1ea00dcdb6323d1f285e2cdd3ebb4020 Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 19:05:13 2023 +0200 refactor: update cast commit 5bbc23a7d37e53eb74a885685f18e714f9448fd9 Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 19:04:15 2023 +0200 moved GetImguiTeamColor commit fd0e2d2470ea5cca3553acf280aa371de5c06f4c Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 19:03:37 2023 +0200 packets forward declaration commit 06eb9b99a96731f4b9a2167c00ed0bcd03702e3b Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 18:30:55 2023 +0200 remove Protocol.h includes commit 165f63d2e8b468f3e38992baddc221270010f801 Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 18:30:30 2023 +0200 split packets into separate source files commit f247f146c6c1e804a44b86f65cf3059859c07c6c Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 17:45:24 2023 +0200 split packets into separate headers
85 lines
2.0 KiB
C++
85 lines
2.0 KiB
C++
#include "game/client/Client.h"
|
|
#include "misc/Format.h"
|
|
|
|
#include "protocol/packets/DisconnectPacket.h"
|
|
#include "protocol/packets/PlaceTowerPacket.h"
|
|
#include "protocol/packets/RemoveTowerPacket.h"
|
|
#include "protocol/packets/SelectTeamPacket.h"
|
|
#include "protocol/packets/UpgradeTowerPacket.h"
|
|
|
|
namespace td {
|
|
namespace client {
|
|
|
|
bool Client::Connect(const network::IPAddresses& addresses, std::uint16_t port) {
|
|
for (const network::IPAddress& address : addresses) {
|
|
if (address.IsValid() && m_Connexion.Connect(address.ToString(), port)) {
|
|
m_Connected = true;
|
|
return true;
|
|
}
|
|
}
|
|
utils::LOGE("Failed to connect !");
|
|
return false;
|
|
}
|
|
|
|
void Client::SelectTeam(game::TeamColor team) {
|
|
if (!m_Connected)
|
|
return;
|
|
|
|
protocol::SelectTeamPacket packet(team);
|
|
m_Connexion.SendPacket(&packet);
|
|
}
|
|
|
|
void Client::CloseConnection() {
|
|
if (!m_Connected)
|
|
return;
|
|
|
|
m_Connected = false;
|
|
|
|
protocol::DisconnectPacket packet;
|
|
m_Connexion.SendPacket(&packet);
|
|
}
|
|
|
|
void Client::Tick(std::uint64_t delta) {
|
|
if (!m_Connected)
|
|
return;
|
|
m_Connected = m_Connexion.UpdateSocket();
|
|
if (!m_Connected) {
|
|
utils::LOG(utils::format("Disconnected ! (Reason : %s)", m_Connexion.GetDisconnectReason().c_str()));
|
|
Reset();
|
|
} else {
|
|
m_Game->Tick(delta);
|
|
}
|
|
}
|
|
|
|
void Client::Render() {
|
|
m_Game->RenderWorld();
|
|
}
|
|
|
|
void Client::Reset() {
|
|
m_Game.reset(0);
|
|
m_Game = std::make_unique<ClientGame>(this);
|
|
}
|
|
|
|
void Client::SendMobs(const std::vector<protocol::MobSend>& mobSends) {
|
|
protocol::SendMobsPacket packet(mobSends);
|
|
m_Connexion.SendPacket(&packet);
|
|
}
|
|
|
|
void Client::PlaceTower(game::TowerType type, const Vec2f& position) {
|
|
protocol::PlaceTowerPacket packet(position.x, position.y, type);
|
|
m_Connexion.SendPacket(&packet);
|
|
}
|
|
|
|
void Client::UpgradeTower(game::TowerID tower, game::TowerLevel level) {
|
|
protocol::UpgradeTowerPacket packet(tower, level);
|
|
m_Connexion.SendPacket(&packet);
|
|
}
|
|
|
|
void Client::RemoveTower(game::TowerID tower) {
|
|
protocol::RemoveTowerPacket packet(tower);
|
|
m_Connexion.SendPacket(&packet);
|
|
}
|
|
|
|
} // namespace client
|
|
} // namespace td
|