From 411687b41ce893d4cb02c95349acbe1f29a02182 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 10 Sep 2014 17:35:12 +1000 Subject: [PATCH] Added a proper disconnection message by hacking the config --- client/scenes/clean_up.cpp | 4 +++- client/scenes/in_world.cpp | 9 +++++++-- client/scenes/in_world.hpp | 1 + todo.txt | 1 - 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/client/scenes/clean_up.cpp b/client/scenes/clean_up.cpp index c602014..54ced25 100644 --- a/client/scenes/clean_up.cpp +++ b/client/scenes/clean_up.cpp @@ -90,8 +90,10 @@ void CleanUp::Update() { } void CleanUp::Render(SDL_Surface* const screen) { + ConfigUtility& config = ConfigUtility::GetSingleton(); + backButton.DrawTo(screen); - font.DrawStringTo("You have been disconnected.", screen, 50, 30); + font.DrawStringTo(config["client.disconnectMessage"], screen, 50, 30); } //------------------------- diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index a79f3b3..78cb8d8 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -152,7 +152,9 @@ void InWorld::Update() { //check the connection if (Clock::now() - lastBeat > std::chrono::seconds(3)) { if (attemptedBeats > 2) { - throw(std::runtime_error("Connection lost")); + RequestDisconnect(); + SetNextScene(SceneList::CLEANUP); + ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server"; } ServerPacket newPacket; @@ -341,6 +343,7 @@ void InWorld::HandlePong(ServerPacket* const argPacket) { void InWorld::HandleDisconnect(ClientPacket* const argPacket) { //TODO: More needed in the disconnection SetNextScene(SceneList::CLEANUP); + ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been disconnected"; } void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) { @@ -415,9 +418,11 @@ void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) { } void InWorld::HandleCharacterRejection(TextPacket* const argPacket) { - std::cerr << "Error: " << argPacket->text << std::endl; RequestDisconnect(); SetNextScene(SceneList::CLEANUP); + ConfigUtility& config = ConfigUtility::GetSingleton(); + config["client.disconnectMessage"] = "Error: "; + config["client.disconnectMessage"] += argPacket->text; } void InWorld::HandleRegionContent(RegionPacket* const argPacket) { diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 010bea8..d80659d 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -127,6 +127,7 @@ protected: Character* localCharacter = nullptr; //connections + //TODO: This needs it's own utility, for both InWorld and InCombat typedef std::chrono::steady_clock Clock; Clock::time_point lastBeat = Clock::now(); int attemptedBeats = 0; diff --git a/todo.txt b/todo.txt index 1583f88..bef95f3 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,3 @@ -TODO: The error handling is terrible TODO: Get the rooms working, even if only via hotkeys TODO: Fix shoddy movement TODO: Move the statistics into their own SQL table, instead of duplicating the structure a dozen times