2011-08-29 16:14:21 +02:00
|
|
|
EnterGame = { }
|
2011-08-26 20:00:22 +02:00
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
-- private variables
|
|
|
|
local loadBox
|
2011-11-02 04:02:56 +01:00
|
|
|
local enterGame
|
2011-11-02 02:55:36 +01:00
|
|
|
local motdNumber
|
|
|
|
local motdMessage
|
2011-08-29 16:14:21 +02:00
|
|
|
|
|
|
|
-- private functions
|
|
|
|
local function onError(protocol, error)
|
|
|
|
loadBox:destroy()
|
|
|
|
local errorBox = displayErrorBox('Login Error', error)
|
2011-11-16 19:59:55 +01:00
|
|
|
errorBox.onOk = EnterGame.show
|
2011-08-26 20:00:22 +02:00
|
|
|
end
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
local function onMotd(protocol, motd)
|
2011-11-02 02:55:36 +01:00
|
|
|
motdNumber = tonumber(string.sub(motd, 0, string.find(motd, "\n")))
|
|
|
|
motdMessage = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd))
|
2011-11-16 19:08:42 +01:00
|
|
|
TopMenu.getButton('motdButton'):show()
|
2011-08-26 20:44:18 +02:00
|
|
|
end
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
local function onCharacterList(protocol, characters, premDays)
|
2011-11-16 19:59:55 +01:00
|
|
|
if enterGame:getChildById('rememberPasswordBox'):isChecked() then
|
|
|
|
Configs.set('account', EnterGame.account)
|
|
|
|
Configs.set('password', EnterGame.password)
|
|
|
|
Configs.set('autologin', tostring(enterGame:getChildById('autoLoginBox'):isChecked()))
|
|
|
|
else
|
|
|
|
Configs.set('account', nil)
|
|
|
|
Configs.set('password', nil)
|
|
|
|
enterGame:getChildById('accountNameLineEdit'):clearText()
|
|
|
|
enterGame:getChildById('accountPasswordLineEdit'):clearText()
|
|
|
|
end
|
|
|
|
|
2011-11-02 02:55:36 +01:00
|
|
|
loadBox:destroy()
|
2011-08-29 16:14:21 +02:00
|
|
|
CharacterList.create(characters, premDays)
|
2011-11-02 02:55:36 +01:00
|
|
|
|
|
|
|
local lastMotdNumber = tonumber(Configs.get("motd"))
|
|
|
|
if motdNumber and motdNumber ~= lastMotdNumber then
|
|
|
|
Configs.set("motd", motdNumber)
|
|
|
|
local motdBox = displayInfoBox("Message of the day", motdMessage)
|
|
|
|
motdBox.onOk = CharacterList.show
|
2011-10-31 18:56:00 +01:00
|
|
|
CharacterList.hide()
|
|
|
|
end
|
2011-08-29 16:14:21 +02:00
|
|
|
end
|
2011-08-26 23:20:53 +02:00
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
-- public functions
|
2011-11-02 04:02:56 +01:00
|
|
|
function EnterGame.create()
|
|
|
|
enterGame = UI.loadAndDisplay('/entergame/entergame.otui')
|
2011-11-16 19:59:55 +01:00
|
|
|
|
|
|
|
local account = Configs.get('account')
|
|
|
|
local password = Configs.get('password')
|
2011-11-16 21:07:52 +01:00
|
|
|
local host = Configs.get('host')
|
|
|
|
local port = tonumber(Configs.get('port'))
|
2011-11-16 19:59:55 +01:00
|
|
|
local autologin = toboolean(Configs.get('autologin'))
|
|
|
|
|
|
|
|
enterGame:getChildById('accountNameLineEdit'):setText(account)
|
|
|
|
enterGame:getChildById('accountPasswordLineEdit'):setText(password)
|
2011-11-16 21:07:52 +01:00
|
|
|
enterGame:getChildById('serverHostLineEdit'):setText(host)
|
|
|
|
enterGame:getChildById('serverPortLineEdit'):setText(port)
|
|
|
|
enterGame:getChildById('autoLoginBox'):setChecked(autologin)
|
|
|
|
enterGame:getChildById('rememberPasswordBox'):setChecked(#account > 0)
|
2011-11-16 19:59:55 +01:00
|
|
|
|
2011-11-16 21:07:52 +01:00
|
|
|
if #account > 0 and autologin then
|
|
|
|
addEvent(EnterGame.doLogin)
|
2011-11-16 19:59:55 +01:00
|
|
|
end
|
2011-11-02 02:55:36 +01:00
|
|
|
end
|
|
|
|
|
2011-11-02 04:02:56 +01:00
|
|
|
function EnterGame.destroy()
|
|
|
|
enterGame:destroy()
|
|
|
|
enterGame = nil
|
2011-08-26 20:44:18 +02:00
|
|
|
end
|
2011-08-26 20:00:22 +02:00
|
|
|
|
2011-11-02 04:02:56 +01:00
|
|
|
function EnterGame.show()
|
|
|
|
enterGame:show()
|
2011-11-03 10:59:11 +01:00
|
|
|
enterGame:focus()
|
2011-11-02 04:02:56 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function EnterGame.hide()
|
|
|
|
enterGame:hide()
|
2011-08-29 16:14:21 +02:00
|
|
|
end
|
2011-07-17 08:56:57 +02:00
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
function EnterGame.doLogin()
|
2011-11-02 04:02:56 +01:00
|
|
|
EnterGame.account = enterGame:getChildById('accountNameLineEdit'):getText()
|
|
|
|
EnterGame.password = enterGame:getChildById('accountPasswordLineEdit'):getText()
|
2011-11-16 21:07:52 +01:00
|
|
|
EnterGame.host = enterGame:getChildById('serverHostLineEdit'):getText()
|
|
|
|
EnterGame.port = enterGame:getChildById('serverPortLineEdit'):getText()
|
2011-11-02 02:55:36 +01:00
|
|
|
EnterGame.hide()
|
2011-07-17 08:56:57 +02:00
|
|
|
|
2011-11-16 21:07:52 +01:00
|
|
|
Configs.set('host', EnterGame.host)
|
|
|
|
Configs.set('port', EnterGame.port)
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
local protocolLogin = ProtocolLogin.create()
|
|
|
|
protocolLogin.onError = onError
|
|
|
|
protocolLogin.onMotd = onMotd
|
|
|
|
protocolLogin.onCharacterList = onCharacterList
|
2011-07-17 08:56:57 +02:00
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
loadBox = displayCancelBox('Please wait', 'Connecting to login server...')
|
2011-07-27 01:55:39 +02:00
|
|
|
loadBox.onCancel = function(msgbox)
|
2011-08-16 06:24:20 +02:00
|
|
|
protocolLogin:cancelLogin()
|
2011-11-02 02:55:36 +01:00
|
|
|
EnterGame.show()
|
2011-07-17 08:56:57 +02:00
|
|
|
end
|
|
|
|
|
2011-11-16 21:07:52 +01:00
|
|
|
protocolLogin:login(EnterGame.host, EnterGame.port, EnterGame.account, EnterGame.password)
|
2011-07-17 08:56:57 +02:00
|
|
|
end
|
2011-11-16 19:08:42 +01:00
|
|
|
|
|
|
|
function EnterGame.displayMotd()
|
|
|
|
displayInfoBox("Message of the day", motdMessage)
|
|
|
|
end
|