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
|
2012-01-07 18:36:58 +01:00
|
|
|
local motdButton
|
|
|
|
local enterGameButton
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
-- private functions
|
2011-11-16 22:00:40 +01:00
|
|
|
local function clearAccountFields()
|
2012-03-31 15:43:01 +02:00
|
|
|
enterGame:getChildById('accountNameTextEdit'):clearText()
|
|
|
|
enterGame:getChildById('accountPasswordTextEdit'):clearText()
|
|
|
|
enterGame:getChildById('accountNameTextEdit'):focus()
|
2012-01-06 10:35:48 +01:00
|
|
|
Settings.remove('account')
|
|
|
|
Settings.remove('password')
|
2011-11-16 22:00:40 +01:00
|
|
|
end
|
|
|
|
|
2012-01-07 23:25:35 +01:00
|
|
|
local function onError(protocol, message, connectionError)
|
2011-08-29 16:14:21 +02:00
|
|
|
loadBox:destroy()
|
2012-02-06 20:19:47 +01:00
|
|
|
loadBox = nil
|
|
|
|
|
2012-01-07 23:25:35 +01:00
|
|
|
if not connectionError then
|
|
|
|
clearAccountFields()
|
|
|
|
end
|
2012-04-26 21:54:16 +02:00
|
|
|
local errorBox = displayErrorBox(tr('Login Error'), message)
|
2012-02-06 20:19:47 +01:00
|
|
|
connect(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)
|
2012-06-04 14:38:15 +02:00
|
|
|
G.motdNumber = tonumber(motd:sub(0, motd:find("\n")))
|
|
|
|
G.motdMessage = motd:sub(motd:find("\n") + 1, #motd)
|
2012-01-07 18:36:58 +01:00
|
|
|
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
|
2012-06-04 14:38:15 +02:00
|
|
|
Settings.set('account', g_crypt.encrypt(G.account))
|
|
|
|
Settings.set('password', g_crypt.encrypt(G.password))
|
2012-01-06 10:35:48 +01:00
|
|
|
Settings.set('autologin', enterGame:getChildById('autoLoginBox'):isChecked())
|
2011-11-16 19:59:55 +01:00
|
|
|
else
|
2011-11-16 22:00:40 +01:00
|
|
|
clearAccountFields()
|
2011-11-16 19:59:55 +01:00
|
|
|
end
|
|
|
|
|
2011-11-02 02:55:36 +01:00
|
|
|
loadBox:destroy()
|
2012-02-06 20:19:47 +01:00
|
|
|
loadBox = nil
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
CharacterList.create(characters, premDays)
|
2012-06-04 14:38:15 +02:00
|
|
|
CharacterList.show()
|
2011-11-02 02:55:36 +01:00
|
|
|
|
2012-01-06 10:35:48 +01:00
|
|
|
local lastMotdNumber = Settings.getNumber("motd")
|
2012-06-04 14:38:15 +02:00
|
|
|
if G.motdNumber and G.motdNumber ~= lastMotdNumber then
|
2012-01-06 10:35:48 +01:00
|
|
|
Settings.set("motd", motdNumber)
|
2012-06-04 14:38:15 +02:00
|
|
|
local motdBox = displayInfoBox(tr('Message of the day'), G.motdMessage)
|
2012-02-06 20:19:47 +01:00
|
|
|
connect(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
|
2012-01-07 18:36:58 +01:00
|
|
|
function EnterGame.init()
|
2012-01-03 01:42:53 +01:00
|
|
|
enterGame = displayUI('entergame.otui')
|
2012-04-26 21:54:16 +02:00
|
|
|
enterGameButton = TopMenu.addLeftButton('enterGameButton', tr('Login') .. ' (Ctrl + G)', 'login.png', EnterGame.openWindow)
|
|
|
|
motdButton = TopMenu.addLeftButton('motdButton', tr('Message of the day'), 'motd.png', EnterGame.displayMotd)
|
2012-02-20 03:27:08 +01:00
|
|
|
motdButton:hide()
|
|
|
|
Keyboard.bindKeyDown('Ctrl+G', EnterGame.openWindow)
|
2011-11-16 19:59:55 +01:00
|
|
|
|
2012-06-04 14:38:15 +02:00
|
|
|
if G.motdNumber then
|
|
|
|
motdButton:show()
|
|
|
|
end
|
|
|
|
|
|
|
|
local account = g_crypt.decrypt(Settings.get('account'))
|
|
|
|
local password = g_crypt.decrypt(Settings.get('password'))
|
2012-01-06 10:35:48 +01:00
|
|
|
local host = Settings.get('host')
|
2012-01-07 01:34:40 +01:00
|
|
|
local port = Settings.get('port')
|
2012-01-07 01:18:08 +01:00
|
|
|
local autologin = Settings.getBoolean('autologin')
|
2011-11-16 19:59:55 +01:00
|
|
|
|
2012-03-31 15:43:01 +02:00
|
|
|
enterGame:getChildById('accountNameTextEdit'):setText(account)
|
|
|
|
enterGame:getChildById('accountPasswordTextEdit'):setText(password)
|
|
|
|
enterGame:getChildById('serverHostTextEdit'):setText(host)
|
|
|
|
enterGame:getChildById('serverPortTextEdit'):setText(port)
|
2011-11-16 21:07:52 +01:00
|
|
|
enterGame:getChildById('autoLoginBox'):setChecked(autologin)
|
|
|
|
enterGame:getChildById('rememberPasswordBox'):setChecked(#account > 0)
|
2012-03-31 15:43:01 +02:00
|
|
|
enterGame:getChildById('accountNameTextEdit'):focus()
|
2011-11-16 19:59:55 +01:00
|
|
|
|
2012-02-06 20:19:47 +01:00
|
|
|
-- only open entergame when app starts
|
|
|
|
if not g_app.isRunning() then
|
|
|
|
if #account > 0 and autologin then
|
|
|
|
addEvent(EnterGame.doLogin)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
enterGame:hide()
|
2011-11-16 19:59:55 +01:00
|
|
|
end
|
2011-11-02 02:55:36 +01:00
|
|
|
end
|
|
|
|
|
2012-01-07 18:36:58 +01:00
|
|
|
function EnterGame.terminate()
|
2012-02-06 05:39:52 +01:00
|
|
|
Keyboard.unbindKeyDown('Ctrl+G')
|
2011-11-02 04:02:56 +01:00
|
|
|
enterGame:destroy()
|
|
|
|
enterGame = nil
|
2012-01-07 18:36:58 +01:00
|
|
|
enterGameButton:destroy()
|
|
|
|
enterGameButton = nil
|
|
|
|
motdButton:destroy()
|
|
|
|
motdButton = nil
|
2012-02-07 01:41:53 +01:00
|
|
|
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()
|
2012-02-20 03:27:08 +01:00
|
|
|
enterGame:raise()
|
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
|
|
|
|
2012-01-07 18:36:58 +01:00
|
|
|
function EnterGame.openWindow()
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.isOnline() then
|
2012-01-07 18:36:58 +01:00
|
|
|
CharacterList.show()
|
|
|
|
elseif not CharacterList.isVisible() then
|
|
|
|
EnterGame.show()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
function EnterGame.doLogin()
|
2012-06-04 14:38:15 +02:00
|
|
|
G.account = enterGame:getChildById('accountNameTextEdit'):getText()
|
|
|
|
G.password = enterGame:getChildById('accountPasswordTextEdit'):getText()
|
|
|
|
G.host = enterGame:getChildById('serverHostTextEdit'):getText()
|
|
|
|
G.port = tonumber(enterGame:getChildById('serverPortTextEdit'):getText())
|
2011-11-02 02:55:36 +01:00
|
|
|
EnterGame.hide()
|
2011-07-17 08:56:57 +02:00
|
|
|
|
2012-06-04 14:38:15 +02:00
|
|
|
Settings.set('host', G.host)
|
|
|
|
Settings.set('port', G.port)
|
2011-11-16 21:07:52 +01:00
|
|
|
|
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
|
|
|
|
2012-04-26 21:54:16 +02:00
|
|
|
loadBox = displayCancelBox(tr('Please wait'), tr('Connecting to login server...'))
|
2012-02-06 20:19:47 +01:00
|
|
|
connect(loadBox, { onCancel = function(msgbox)
|
|
|
|
loadBox = nil
|
|
|
|
protocolLogin:cancelLogin()
|
|
|
|
EnterGame.show()
|
|
|
|
end })
|
2011-07-17 08:56:57 +02:00
|
|
|
|
2012-06-04 14:38:15 +02:00
|
|
|
protocolLogin:login(G.host, G.port, G.account, G.password)
|
2011-07-17 08:56:57 +02:00
|
|
|
end
|
2011-11-16 19:08:42 +01:00
|
|
|
|
|
|
|
function EnterGame.displayMotd()
|
2012-06-04 14:38:15 +02:00
|
|
|
displayInfoBox(tr('Message of the day'), G.motdMessage)
|
2011-11-16 19:08:42 +01:00
|
|
|
end
|