summaryrefslogtreecommitdiffstats
path: root/src/gamestate/GameState.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-05-28 16:16:05 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-05-28 16:16:05 +0200
commitd93c2073896e63aca5a859fe7182ba24dbe84cd3 (patch)
tree6144aaf7e01854fe245011ca4f4735974366febb /src/gamestate/GameState.cpp
parent2017-05-26 (diff)
downloadAltCraft-d93c2073896e63aca5a859fe7182ba24dbe84cd3.tar
AltCraft-d93c2073896e63aca5a859fe7182ba24dbe84cd3.tar.gz
AltCraft-d93c2073896e63aca5a859fe7182ba24dbe84cd3.tar.bz2
AltCraft-d93c2073896e63aca5a859fe7182ba24dbe84cd3.tar.lz
AltCraft-d93c2073896e63aca5a859fe7182ba24dbe84cd3.tar.xz
AltCraft-d93c2073896e63aca5a859fe7182ba24dbe84cd3.tar.zst
AltCraft-d93c2073896e63aca5a859fe7182ba24dbe84cd3.zip
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;
}