From d93c2073896e63aca5a859fe7182ba24dbe84cd3 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 28 May 2017 19:16:05 +0500 Subject: 2017-05-28 --- src/gamestate/GameState.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/gamestate/GameState.cpp') 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 -#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::endl; + LOG(INFO) << "Disconnect reason: " << json["text"].get(); throw 119; break; case 0x20: @@ -124,5 +127,5 @@ void GameState::Update() { } } - delete &packet; + delete packetPtr; } -- cgit v1.2.3