Added a proper disconnection message by hacking the config
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user