logout improvments

This commit is contained in:
Eduardo Bart 2011-08-29 20:20:30 -03:00
parent 94324e3e88
commit 67d8112ed0
8 changed files with 55 additions and 46 deletions

View File

@ -1,6 +1,3 @@
-- private variables
local showCharacterListOnLogout = true
-- private functions
local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
if keyboardModifiers == KeyboardCtrlModifier then
@ -8,7 +5,7 @@ local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
CharacterList.show()
return true
elseif keyCode == KeyQ then
Game.logout()
Game.logout(false)
return true
end
end
@ -35,21 +32,20 @@ function Game.onLogin()
createMainInterface()
end
function Game.onLoginError(message)
CharacterList.destroyLoadBox()
local errorBox = displayErrorBox("Login Error", "Login error: " .. message)
errorBox.onOk = CharacterList.show
end
function Game.onConnectionError(message)
CharacterList.destroyLoadBox()
local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
errorBox.onOk = CharacterList.show
showCharacterListOnLogout = false
end
function Game.onLogout()
MainMenu.show()
if showCharacterListOnLogout then
CharacterList.show()
else
showCharacterListOnLogout = true
end
destroyMainInterface()
end

View File

@ -10,4 +10,4 @@ UIWidget
anchors.left: gameMap.right
anchors.top: parent.top
text: Logout
onClick: Game.logout()
onClick: Game.logout(false)

View File

@ -17,15 +17,26 @@ local function onCharactersWindowKeyPress(self, keyCode, keyChar, keyboardModifi
return false
end
local function tryLogin(charInfo)
CharacterList.hide()
local function tryLogin(charInfo, tries)
tries = tries or 1
if Game.isOnline() then
Game.logout()
scheduleEvent(function() tryLogin(charInfo) end, 250)
if tries > 4 then
CharacterList.destroyLoadBox()
displayErrorBox('Error', 'Could not logout.')
return
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)
loadBox = displayCancelBox('Please wait', 'Connecting to game server...')
@ -79,9 +90,11 @@ function CharacterList.hide()
end
function CharacterList.show()
if not loadBox then
charactersWindow:show()
charactersWindow:lock()
end
end
function CharacterList.doLogin()
local selected = charactersWindow:getChildById('characterList'):getFocusedChild()
@ -89,6 +102,7 @@ function CharacterList.doLogin()
local charInfo = { worldHost = selected.worldHost,
worldPort = selected.worldPort,
characterName = selected.characterName }
CharacterList.hide()
tryLogin(charInfo)
else
displayErrorBox('Error', 'You must select a character to login!')

View File

@ -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)
@ -45,19 +45,22 @@ void Game::loginWorld(const std::string& account, const std::string& password, c
void Game::cancelLogin()
{
if(m_protocolGame) {
if(m_protocolGame->isConnected()) {
logout();
} else if(m_protocolGame->isConnecting()) {
m_protocolGame->disconnect();
m_protocolGame.reset();
processLogout();
}
void Game::logout(bool force)
{
if(m_protocolGame) {
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();
}
}
}
@ -86,21 +84,21 @@ void Game::processLogin(const LocalPlayerPtr& localPlayer)
void Game::processLogout()
{
if(m_online) {
g_lua.callGlobalField("Game", "onLogout", m_localPlayer);
if(m_protocolGame) {
m_protocolGame->disconnect();
m_protocolGame.reset();
}
m_localPlayer.reset();
m_online = false;
}
if(m_protocolGame) {
m_protocolGame->disconnect();
m_protocolGame.reset();
}
}
void Game::walk(Otc::Direction direction)
{
if(!m_online)
return;
// TODO: check if we can walk.

View File

@ -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();

View File

@ -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)

View File

@ -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();

View File

@ -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));