Add error code to onError protocol event

master
Eduardo Bart 12 years ago
parent 59f75d996e
commit e7691b873b

@ -123,7 +123,7 @@ function onGameLoginError(message)
end
end
function onGameConnectionError(message)
function onGameConnectionError(code, message)
CharacterList.destroyLoadBox()
errorBox = displayErrorBox(tr("Login Error"), message)
errorBox.onOk = function()

@ -7,21 +7,14 @@ local motdButton
local enterGameButton
-- private functions
local function clearAccountFields()
enterGame:getChildById('accountNameTextEdit'):clearText()
enterGame:getChildById('accountPasswordTextEdit'):clearText()
enterGame:getChildById('accountNameTextEdit'):focus()
g_settings.remove('account')
g_settings.remove('password')
end
local function onError(protocol, message, connectionError)
local function onError(protocol, message, errorCode)
loadBox:destroy()
loadBox = nil
if not connectionError then
clearAccountFields()
if not errorCode then
EnterGame.clearAccountFields()
end
local errorBox = displayErrorBox(tr('Login Error'), message)
connect(errorBox, { onOk = EnterGame.show })
end
@ -38,7 +31,7 @@ local function onCharacterList(protocol, characters, premDays)
g_settings.set('password', g_crypt.encrypt(G.password))
g_settings.set('autologin', enterGame:getChildById('autoLoginBox'):isChecked())
else
clearAccountFields()
EnterGame.clearAccountFields()
end
loadBox:destroy()
@ -123,6 +116,15 @@ function EnterGame.openWindow()
end
end
function EnterGame.clearAccountFields()
enterGame:getChildById('accountNameTextEdit'):clearText()
enterGame:getChildById('accountPasswordTextEdit'):clearText()
enterGame:getChildById('accountNameTextEdit'):focus()
g_settings.remove('account')
g_settings.remove('password')
end
function EnterGame.doLogin()
G.account = enterGame:getChildById('accountNameTextEdit'):getText()
G.password = enterGame:getChildById('accountPasswordTextEdit'):getText()

@ -60,7 +60,7 @@ function ProtocolLogin:onRecv(msg)
elseif opcode == LoginServerMotd then
self:parseMotd(msg)
elseif opcode == LoginServerUpdateNeeded then
signalcall(self.onError, self, "Client needs update.", false)
signalcall(self.onError, self, "Client needs update.")
elseif opcode == LoginServerCharacterList then
self:parseCharacterList(msg)
else
@ -77,7 +77,7 @@ end
function ProtocolLogin:login(host, port, accountName, accountPassword)
if string.len(accountName) == 0 or string.len(accountPassword) == 0 then
signalcall(self.onError, self, "You must enter an account name and password.", false)
signalcall(self.onError, self, "You must enter an account name and password.")
return
end
@ -94,7 +94,7 @@ end
function ProtocolLogin:parseError(msg)
local errorMessage = msg:getString()
signalcall(self.onError, self, errorMessage, false)
signalcall(self.onError, self, errorMessage)
end
function ProtocolLogin:parseMotd(msg)

@ -34,9 +34,9 @@ SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
IF(USE_STATIC_LIBS)
SET(CMAKE_CXX_LINK_FLAGS "-static-libgcc -static-libstdc++")
MESSAGE("Link to static libraries: ON")
MESSAGE(STATUS "Link to static libraries: ON")
ELSE()
MESSAGE("Link to static libraries: OFF")
MESSAGE(STATUS "Link to static libraries: OFF")
ENDIF()
MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})

@ -242,6 +242,6 @@ void Protocol::onRecv(const InputMessagePtr& inputMessage)
void Protocol::onError(const boost::system::error_code& err)
{
callLuaField("onError", err.message(), true);
callLuaField("onError", err.message(), err.value());
disconnect();
}

@ -64,13 +64,13 @@ void Game::resetGameStates()
m_gmActions.clear();
}
void Game::processConnectionError(const boost::system::error_code& error)
void Game::processConnectionError(const boost::system::error_code& ec)
{
// connection errors only have meaning if we still have a protocol
if(m_protocolGame) {
// eof = end of file, a clean disconnect
if(error != asio::error::eof)
g_lua.callGlobalField("g_game", "onConnectionError", error.message());
if(ec != asio::error::eof)
g_lua.callGlobalField("g_game", "onConnectionError", ec.message(), ec.value());
processDisconnect();
}

@ -42,6 +42,8 @@ void ProtocolGame::login(const std::string& accountName, const std::string& acco
void ProtocolGame::onConnect()
{
Protocol::onConnect();
// must create local player before parsing anything
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
@ -56,12 +58,16 @@ void ProtocolGame::onConnect()
void ProtocolGame::onRecv(const InputMessagePtr& inputMessage)
{
//Protocol::onConnect(inputMessage);
parseMessage(inputMessage);
recv();
}
void ProtocolGame::onError(const boost::system::error_code& error)
{
Protocol::onError(error);
g_game.processConnectionError(error);
}

Loading…
Cancel
Save