summaryrefslogtreecommitdiffstats
path: root/src/gamestate/GameState.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gamestate/GameState.cpp')
-rw-r--r--src/gamestate/GameState.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/gamestate/GameState.cpp b/src/gamestate/GameState.cpp
index 7b6734f..5c5b9c4 100644
--- a/src/gamestate/GameState.cpp
+++ b/src/gamestate/GameState.cpp
@@ -1,13 +1,10 @@
#include "GameState.hpp"
-#include <nlohmann/json.hpp>
-#include "../packet/PacketParser.hpp"
-#include "../packet/PacketBuilder.hpp"
GameState::GameState(NetworkClient *Net) : nc(Net) {
Packet *response = nc->GetPacket();
if (response->GetId() != 0x02) {
- std::cout << response->GetId() << std::endl;
- throw 127;
+ LOG(ERROR) << "Response id is " << response->GetId();
+ throw std::runtime_error("Response id is not 0x02");
}
PacketParser::Parse(*response, Login);
g_PlayerUuid = response->GetField(0).GetString();
@@ -18,14 +15,20 @@ GameState::GameState(NetworkClient *Net) : nc(Net) {
}
void GameState::Update() {
- Packet &packet = *nc->GetPacket();
- if (&packet == nullptr)
- return;
+ Packet *packetPtr;
+ try {
+ packetPtr = nc->GetPacket();
+ if (packetPtr == nullptr)
+ return;
+ PacketParser::Parse(*packetPtr, m_networkState);
+ } catch (std::exception &e) {
+ LOG(ERROR) << "Catched exception during packet pulling: " << e.what();
+ return;
+ }
+ Packet &packet = *packetPtr;
nlohmann::json json;
- PacketParser::Parse(packet, m_networkState);
-
switch (packet.GetId()) {
case 0x23:
g_PlayerEid = packet.GetField(0).GetInt();
@@ -97,7 +100,7 @@ void GameState::Update() {
break;
case 0x1A:
json = nlohmann::json::parse(packet.GetField(0).GetString());
- std::cout << "Disconnect reason: " << json["text"].get<std::string>() << std::endl;
+ LOG(INFO) << "Disconnect reason: " << json["text"].get<std::string>();
throw 119;
break;
case 0x20:
@@ -124,5 +127,5 @@ void GameState::Update() {
}
}
- delete &packet;
+ delete packetPtr;
}