mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
logout improvments
This commit is contained in:
@@ -34,7 +34,7 @@ void Game::init()
|
||||
void Game::terminate()
|
||||
{
|
||||
if(m_online)
|
||||
logout();
|
||||
logout(true);
|
||||
}
|
||||
|
||||
void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldHost, int worldPort, const std::string& characterName)
|
||||
@@ -44,20 +44,23 @@ void Game::loginWorld(const std::string& account, const std::string& password, c
|
||||
}
|
||||
|
||||
void Game::cancelLogin()
|
||||
{
|
||||
processLogout();
|
||||
}
|
||||
|
||||
void Game::logout(bool force)
|
||||
{
|
||||
if(m_protocolGame) {
|
||||
if(m_protocolGame->isConnected()) {
|
||||
logout();
|
||||
} else if(m_protocolGame->isConnecting()) {
|
||||
m_protocolGame->disconnect();
|
||||
m_protocolGame.reset();
|
||||
}
|
||||
m_protocolGame->sendLogout();
|
||||
|
||||
if(force)
|
||||
processLogout();
|
||||
}
|
||||
}
|
||||
|
||||
void Game::logout()
|
||||
void Game::processLoginError(const std::string& error)
|
||||
{
|
||||
m_protocolGame->sendLogout();
|
||||
g_lua.callGlobalField("Game", "onLoginError", error);
|
||||
}
|
||||
|
||||
void Game::processConnectionError(const boost::system::error_code& error)
|
||||
@@ -67,12 +70,7 @@ void Game::processConnectionError(const boost::system::error_code& error)
|
||||
if(error != asio::error::eof)
|
||||
g_lua.callGlobalField("Game", "onConnectionError", error.message());
|
||||
|
||||
if(m_online) {
|
||||
processLogout();
|
||||
} else {
|
||||
m_protocolGame->disconnect();
|
||||
m_protocolGame.reset();
|
||||
}
|
||||
processLogout();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,21 +84,21 @@ void Game::processLogin(const LocalPlayerPtr& localPlayer)
|
||||
|
||||
void Game::processLogout()
|
||||
{
|
||||
g_lua.callGlobalField("Game", "onLogout", m_localPlayer);
|
||||
if(m_online) {
|
||||
g_lua.callGlobalField("Game", "onLogout", m_localPlayer);
|
||||
|
||||
m_localPlayer.reset();
|
||||
m_online = false;
|
||||
}
|
||||
|
||||
if(m_protocolGame) {
|
||||
m_protocolGame->disconnect();
|
||||
m_protocolGame.reset();
|
||||
}
|
||||
|
||||
m_localPlayer.reset();
|
||||
m_online = false;
|
||||
}
|
||||
|
||||
void Game::walk(Otc::Direction direction)
|
||||
{
|
||||
if(!m_online)
|
||||
return;
|
||||
|
||||
// TODO: check if we can walk.
|
||||
|
||||
|
@@ -37,8 +37,9 @@ public:
|
||||
const std::string& worldHost, int worldPort,
|
||||
const std::string& characterName);
|
||||
void cancelLogin();
|
||||
void logout();
|
||||
void logout(bool force);
|
||||
|
||||
void processLoginError(const std::string& error);
|
||||
void processConnectionError(const boost::system::error_code& error);
|
||||
void processLogin(const LocalPlayerPtr& localPlayer);
|
||||
void processLogout();
|
||||
|
@@ -275,7 +275,7 @@ void ProtocolGame::parseGMActions(InputMessage& msg)
|
||||
void ProtocolGame::parseErrorMessage(InputMessage& msg)
|
||||
{
|
||||
std::string error = msg.getString();
|
||||
callLuaField("onError", error);
|
||||
g_game.processLoginError(error);
|
||||
}
|
||||
|
||||
void ProtocolGame::parseFYIMessage(InputMessage& msg)
|
||||
|
@@ -170,11 +170,11 @@ void OTClient::terminate()
|
||||
// hide the window because there is no render anymore
|
||||
g_platform.hideWindow();
|
||||
|
||||
g_game.terminate();
|
||||
|
||||
// run modules unload event
|
||||
g_modules.unloadModules();
|
||||
|
||||
g_game.terminate();
|
||||
|
||||
// terminate ui
|
||||
g_ui.terminate();
|
||||
|
||||
|
@@ -60,7 +60,7 @@ void OTClient::registerLuaFunctions()
|
||||
|
||||
g_lua.registerClass<Game>();
|
||||
g_lua.bindClassStaticFunction<Game>("loginWorld", std::bind(&Game::loginWorld, &g_game, _1, _2, _3, _4, _5));
|
||||
g_lua.bindClassStaticFunction<Game>("logout", std::bind(&Game::logout, &g_game));
|
||||
g_lua.bindClassStaticFunction<Game>("logout", std::bind(&Game::logout, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction<Game>("cancelLogin", std::bind(&Game::cancelLogin, &g_game));
|
||||
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
|
||||
|
||||
|
Reference in New Issue
Block a user