logout improvments
This commit is contained in:
parent
94324e3e88
commit
67d8112ed0
|
@ -1,6 +1,3 @@
|
||||||
-- private variables
|
|
||||||
local showCharacterListOnLogout = true
|
|
||||||
|
|
||||||
-- private functions
|
-- private functions
|
||||||
local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
|
local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
|
||||||
if keyboardModifiers == KeyboardCtrlModifier then
|
if keyboardModifiers == KeyboardCtrlModifier then
|
||||||
|
@ -8,7 +5,7 @@ local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
|
||||||
CharacterList.show()
|
CharacterList.show()
|
||||||
return true
|
return true
|
||||||
elseif keyCode == KeyQ then
|
elseif keyCode == KeyQ then
|
||||||
Game.logout()
|
Game.logout(false)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -35,21 +32,20 @@ function Game.onLogin()
|
||||||
createMainInterface()
|
createMainInterface()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Game.onLoginError(message)
|
||||||
|
CharacterList.destroyLoadBox()
|
||||||
|
local errorBox = displayErrorBox("Login Error", "Login error: " .. message)
|
||||||
|
errorBox.onOk = CharacterList.show
|
||||||
|
end
|
||||||
|
|
||||||
function Game.onConnectionError(message)
|
function Game.onConnectionError(message)
|
||||||
CharacterList.destroyLoadBox()
|
CharacterList.destroyLoadBox()
|
||||||
local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
|
local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
|
||||||
errorBox.onOk = CharacterList.show
|
errorBox.onOk = CharacterList.show
|
||||||
showCharacterListOnLogout = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Game.onLogout()
|
function Game.onLogout()
|
||||||
MainMenu.show()
|
MainMenu.show()
|
||||||
|
CharacterList.show()
|
||||||
if showCharacterListOnLogout then
|
|
||||||
CharacterList.show()
|
|
||||||
else
|
|
||||||
showCharacterListOnLogout = true
|
|
||||||
end
|
|
||||||
|
|
||||||
destroyMainInterface()
|
destroyMainInterface()
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,4 +10,4 @@ UIWidget
|
||||||
anchors.left: gameMap.right
|
anchors.left: gameMap.right
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
text: Logout
|
text: Logout
|
||||||
onClick: Game.logout()
|
onClick: Game.logout(false)
|
|
@ -17,15 +17,26 @@ local function onCharactersWindowKeyPress(self, keyCode, keyChar, keyboardModifi
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tryLogin(charInfo)
|
local function tryLogin(charInfo, tries)
|
||||||
CharacterList.hide()
|
tries = tries or 1
|
||||||
|
|
||||||
if Game.isOnline() then
|
if tries > 4 then
|
||||||
Game.logout()
|
CharacterList.destroyLoadBox()
|
||||||
scheduleEvent(function() tryLogin(charInfo) end, 250)
|
displayErrorBox('Error', 'Could not logout.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Game.isOnline() then
|
||||||
|
Game.logout(false)
|
||||||
|
if tries == 1 then
|
||||||
|
loadBox = displayCancelBox('Please wait', 'Loggin out...')
|
||||||
|
end
|
||||||
|
scheduleEvent(function() tryLogin(charInfo, tries+1) end, 250)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
CharacterList.destroyLoadBox()
|
||||||
|
|
||||||
Game.loginWorld(EnterGame.account, EnterGame.password, charInfo.worldHost, charInfo.worldPort, charInfo.characterName)
|
Game.loginWorld(EnterGame.account, EnterGame.password, charInfo.worldHost, charInfo.worldPort, charInfo.characterName)
|
||||||
|
|
||||||
loadBox = displayCancelBox('Please wait', 'Connecting to game server...')
|
loadBox = displayCancelBox('Please wait', 'Connecting to game server...')
|
||||||
|
@ -79,8 +90,10 @@ function CharacterList.hide()
|
||||||
end
|
end
|
||||||
|
|
||||||
function CharacterList.show()
|
function CharacterList.show()
|
||||||
charactersWindow:show()
|
if not loadBox then
|
||||||
charactersWindow:lock()
|
charactersWindow:show()
|
||||||
|
charactersWindow:lock()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function CharacterList.doLogin()
|
function CharacterList.doLogin()
|
||||||
|
@ -89,6 +102,7 @@ function CharacterList.doLogin()
|
||||||
local charInfo = { worldHost = selected.worldHost,
|
local charInfo = { worldHost = selected.worldHost,
|
||||||
worldPort = selected.worldPort,
|
worldPort = selected.worldPort,
|
||||||
characterName = selected.characterName }
|
characterName = selected.characterName }
|
||||||
|
CharacterList.hide()
|
||||||
tryLogin(charInfo)
|
tryLogin(charInfo)
|
||||||
else
|
else
|
||||||
displayErrorBox('Error', 'You must select a character to login!')
|
displayErrorBox('Error', 'You must select a character to login!')
|
||||||
|
|
|
@ -34,7 +34,7 @@ void Game::init()
|
||||||
void Game::terminate()
|
void Game::terminate()
|
||||||
{
|
{
|
||||||
if(m_online)
|
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)
|
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()
|
void Game::cancelLogin()
|
||||||
|
{
|
||||||
|
processLogout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::logout(bool force)
|
||||||
{
|
{
|
||||||
if(m_protocolGame) {
|
if(m_protocolGame) {
|
||||||
if(m_protocolGame->isConnected()) {
|
m_protocolGame->sendLogout();
|
||||||
logout();
|
|
||||||
} else if(m_protocolGame->isConnecting()) {
|
if(force)
|
||||||
m_protocolGame->disconnect();
|
processLogout();
|
||||||
m_protocolGame.reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
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)
|
if(error != asio::error::eof)
|
||||||
g_lua.callGlobalField("Game", "onConnectionError", error.message());
|
g_lua.callGlobalField("Game", "onConnectionError", error.message());
|
||||||
|
|
||||||
if(m_online) {
|
processLogout();
|
||||||
processLogout();
|
|
||||||
} else {
|
|
||||||
m_protocolGame->disconnect();
|
|
||||||
m_protocolGame.reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,21 +84,21 @@ void Game::processLogin(const LocalPlayerPtr& localPlayer)
|
||||||
|
|
||||||
void Game::processLogout()
|
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) {
|
if(m_protocolGame) {
|
||||||
m_protocolGame->disconnect();
|
m_protocolGame->disconnect();
|
||||||
m_protocolGame.reset();
|
m_protocolGame.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_localPlayer.reset();
|
|
||||||
m_online = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::walk(Otc::Direction direction)
|
void Game::walk(Otc::Direction direction)
|
||||||
{
|
{
|
||||||
if(!m_online)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// TODO: check if we can walk.
|
// TODO: check if we can walk.
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,9 @@ public:
|
||||||
const std::string& worldHost, int worldPort,
|
const std::string& worldHost, int worldPort,
|
||||||
const std::string& characterName);
|
const std::string& characterName);
|
||||||
void cancelLogin();
|
void cancelLogin();
|
||||||
void logout();
|
void logout(bool force);
|
||||||
|
|
||||||
|
void processLoginError(const std::string& error);
|
||||||
void processConnectionError(const boost::system::error_code& error);
|
void processConnectionError(const boost::system::error_code& error);
|
||||||
void processLogin(const LocalPlayerPtr& localPlayer);
|
void processLogin(const LocalPlayerPtr& localPlayer);
|
||||||
void processLogout();
|
void processLogout();
|
||||||
|
|
|
@ -275,7 +275,7 @@ void ProtocolGame::parseGMActions(InputMessage& msg)
|
||||||
void ProtocolGame::parseErrorMessage(InputMessage& msg)
|
void ProtocolGame::parseErrorMessage(InputMessage& msg)
|
||||||
{
|
{
|
||||||
std::string error = msg.getString();
|
std::string error = msg.getString();
|
||||||
callLuaField("onError", error);
|
g_game.processLoginError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolGame::parseFYIMessage(InputMessage& msg)
|
void ProtocolGame::parseFYIMessage(InputMessage& msg)
|
||||||
|
|
|
@ -170,11 +170,11 @@ void OTClient::terminate()
|
||||||
// hide the window because there is no render anymore
|
// hide the window because there is no render anymore
|
||||||
g_platform.hideWindow();
|
g_platform.hideWindow();
|
||||||
|
|
||||||
|
g_game.terminate();
|
||||||
|
|
||||||
// run modules unload event
|
// run modules unload event
|
||||||
g_modules.unloadModules();
|
g_modules.unloadModules();
|
||||||
|
|
||||||
g_game.terminate();
|
|
||||||
|
|
||||||
// terminate ui
|
// terminate ui
|
||||||
g_ui.terminate();
|
g_ui.terminate();
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ void OTClient::registerLuaFunctions()
|
||||||
|
|
||||||
g_lua.registerClass<Game>();
|
g_lua.registerClass<Game>();
|
||||||
g_lua.bindClassStaticFunction<Game>("loginWorld", std::bind(&Game::loginWorld, &g_game, _1, _2, _3, _4, _5));
|
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>("cancelLogin", std::bind(&Game::cancelLogin, &g_game));
|
||||||
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
|
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue