Add/get table functions implemented on ext charlist
This commit is contained in:
parent
d98f6f7673
commit
c517f7b745
|
@ -182,9 +182,9 @@ function CharacterList.terminate()
|
||||||
CharacterList = nil
|
CharacterList = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function CharacterList.create(characters, premDays)
|
function CharacterList.create(characters, account)
|
||||||
G.characters = characters
|
G.characters = characters
|
||||||
G.premDays = premDays
|
G.premDays = account.premDays
|
||||||
|
|
||||||
characterList:destroyChildren()
|
characterList:destroyChildren()
|
||||||
local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel')
|
local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel')
|
||||||
|
@ -212,8 +212,8 @@ function CharacterList.create(characters, premDays)
|
||||||
|
|
||||||
characterList:focusChild(focusLabel, ActiveFocusReason)
|
characterList:focusChild(focusLabel, ActiveFocusReason)
|
||||||
|
|
||||||
if premDays > 0 then
|
if account.premDays > 0 then
|
||||||
accountStatusLabel:setText(tr("Account Status:\nPremium Account (%s) days left", premDays))
|
accountStatusLabel:setText(tr("Account Status:\nPremium Account (%s) days left", account.premDays))
|
||||||
else
|
else
|
||||||
accountStatusLabel:setText(tr('Account Status:\nFree Account'))
|
accountStatusLabel:setText(tr('Account Status:\nFree Account'))
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,7 +28,7 @@ local function onMotd(protocol, motd)
|
||||||
motdButton:show()
|
motdButton:show()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onCharacterList(protocol, characters, premDays)
|
local function onCharacterList(protocol, characters, account)
|
||||||
if enterGame:getChildById('rememberPasswordBox'):isChecked() then
|
if enterGame:getChildById('rememberPasswordBox'):isChecked() then
|
||||||
g_settings.set('account', g_crypt.encrypt(G.account))
|
g_settings.set('account', g_crypt.encrypt(G.account))
|
||||||
g_settings.set('password', g_crypt.encrypt(G.password))
|
g_settings.set('password', g_crypt.encrypt(G.password))
|
||||||
|
@ -40,7 +40,7 @@ local function onCharacterList(protocol, characters, premDays)
|
||||||
loadBox:destroy()
|
loadBox:destroy()
|
||||||
loadBox = nil
|
loadBox = nil
|
||||||
|
|
||||||
CharacterList.create(characters, premDays)
|
CharacterList.create(characters, account)
|
||||||
CharacterList.show()
|
CharacterList.show()
|
||||||
|
|
||||||
local lastMotdNumber = g_settings.getNumber("motd")
|
local lastMotdNumber = g_settings.getNumber("motd")
|
||||||
|
|
|
@ -295,3 +295,10 @@ KeyCodeDescs = {
|
||||||
[KeyNumpad8] = 'Numpad8',
|
[KeyNumpad8] = 'Numpad8',
|
||||||
[KeyNumpad9] = 'Numpad9'
|
[KeyNumpad9] = 'Numpad9'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NetworkMessageTypes = {
|
||||||
|
Boolean = 1,
|
||||||
|
Number = 2,
|
||||||
|
String = 3,
|
||||||
|
Table = 4
|
||||||
|
}
|
||||||
|
|
|
@ -19,3 +19,6 @@ Module
|
||||||
dofile 'mouse'
|
dofile 'mouse'
|
||||||
|
|
||||||
dofiles 'ui'
|
dofiles 'ui'
|
||||||
|
|
||||||
|
dofile 'inputmessage'
|
||||||
|
dofile 'outputmessage'
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
function InputMessage:getData()
|
||||||
|
local dataType = self:getU8()
|
||||||
|
if dataType == NetworkMessageTypes.Boolean then
|
||||||
|
return numbertoboolean(self:getU8())
|
||||||
|
elseif dataType == NetworkMessageTypes.Number then
|
||||||
|
return self:getU64()
|
||||||
|
elseif dataType == NetworkMessageTypes.String then
|
||||||
|
return self:getString()
|
||||||
|
elseif dataType == NetworkMessageTypes.Table then
|
||||||
|
return self:getTable()
|
||||||
|
else
|
||||||
|
perror('Unknown data type ' .. dataType)
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function InputMessage:getTable()
|
||||||
|
local ret = {}
|
||||||
|
local size = self:getU32()
|
||||||
|
for i=1,size do
|
||||||
|
local index = self:getData()
|
||||||
|
local value = self:getData()
|
||||||
|
ret[index] = value
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
|
@ -0,0 +1,42 @@
|
||||||
|
function OutputMessage:addData(data)
|
||||||
|
if type(data) == 'boolean' then
|
||||||
|
self:addU8(NetworkMessageTypes.Boolean)
|
||||||
|
self:addU8(booleantonumber(data))
|
||||||
|
elseif type(data) == 'number' then
|
||||||
|
self:addU8(NetworkMessageTypes.Number)
|
||||||
|
self:addU64(data)
|
||||||
|
elseif type(data) == 'string' then
|
||||||
|
self:addU8(NetworkMessageTypes.String)
|
||||||
|
self:addString(data)
|
||||||
|
elseif type(data) == 'table' then
|
||||||
|
self:addU8(NetworkMessageTypes.Table)
|
||||||
|
self:addTable(data)
|
||||||
|
else
|
||||||
|
perror('Invalid data type ' .. type(data))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function OutputMessage:addTable(data)
|
||||||
|
local size = 0
|
||||||
|
|
||||||
|
-- reserve for size
|
||||||
|
local sizePos = self:getWritePos()
|
||||||
|
self:addU32(size)
|
||||||
|
local sizeSize = self:getWritePos() - sizePos
|
||||||
|
|
||||||
|
-- add values
|
||||||
|
for key,value in pairs(data) do
|
||||||
|
self:addData(key)
|
||||||
|
self:addData(value)
|
||||||
|
size = size + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- write size
|
||||||
|
local currentPos = self:getWritePos()
|
||||||
|
self:setWritePos(sizePos)
|
||||||
|
self:addU32(size)
|
||||||
|
|
||||||
|
-- fix msg size and go back to end
|
||||||
|
self:setMessageSize(self:getMessageSize() - sizeSize)
|
||||||
|
self:setWritePos(currentPos)
|
||||||
|
end
|
|
@ -244,6 +244,22 @@ function fromboolean(boolean)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function booleantonumber(boolean)
|
||||||
|
if boolean then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function numbertoboolean(number)
|
||||||
|
if number ~= 0 then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function signalcall(param, ...)
|
function signalcall(param, ...)
|
||||||
if type(param) == 'function' then
|
if type(param) == 'function' then
|
||||||
local status, ret = pcall(param, ...)
|
local status, ret = pcall(param, ...)
|
||||||
|
|
|
@ -5,6 +5,7 @@ LoginServerError = 10
|
||||||
LoginServerMotd = 20
|
LoginServerMotd = 20
|
||||||
LoginServerUpdateNeeded = 30
|
LoginServerUpdateNeeded = 30
|
||||||
LoginServerCharacterList = 100
|
LoginServerCharacterList = 100
|
||||||
|
LoginServerExtendedCharacterList = 101
|
||||||
|
|
||||||
function ProtocolLogin:login(host, port, accountName, accountPassword)
|
function ProtocolLogin:login(host, port, accountName, accountPassword)
|
||||||
if string.len(host) == 0 or port == nil or port == 0 then
|
if string.len(host) == 0 or port == nil or port == 0 then
|
||||||
|
@ -83,6 +84,8 @@ function ProtocolLogin:onRecv(msg)
|
||||||
signalcall(self.onError, self, tr("Client needs update. Verify your spr/dat/pic versions."))
|
signalcall(self.onError, self, tr("Client needs update. Verify your spr/dat/pic versions."))
|
||||||
elseif opcode == LoginServerCharacterList then
|
elseif opcode == LoginServerCharacterList then
|
||||||
self:parseCharacterList(msg)
|
self:parseCharacterList(msg)
|
||||||
|
elseif opcode == LoginServerExtendedCharacterList then
|
||||||
|
self:parseExtendedCharacterList(msg)
|
||||||
else
|
else
|
||||||
self:parseOpcode(opcode, msg)
|
self:parseOpcode(opcode, msg)
|
||||||
end
|
end
|
||||||
|
@ -111,8 +114,16 @@ function ProtocolLogin:parseCharacterList(msg)
|
||||||
character.worldPort = msg:getU16()
|
character.worldPort = msg:getU16()
|
||||||
characters[i] = character
|
characters[i] = character
|
||||||
end
|
end
|
||||||
local premDays = msg:getU16()
|
|
||||||
signalcall(self.onCharacterList, self, characters, premDays)
|
local account = {}
|
||||||
|
account.premDays = msg:getU16()
|
||||||
|
signalcall(self.onCharacterList, self, characters, account)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ProtocolLogin:parseExtendedCharacterList(msg)
|
||||||
|
local characters = msg:getTable()
|
||||||
|
local account = msg:getTable()
|
||||||
|
signalcall(self.onCharacterList, self, characters, account)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ProtocolLogin:parseOpcode(opcode, msg)
|
function ProtocolLogin:parseOpcode(opcode, msg)
|
||||||
|
|
|
@ -725,6 +725,9 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<OutputMessage>("addPaddingBytes", &OutputMessage::addPaddingBytes);
|
g_lua.bindClassMemberFunction<OutputMessage>("addPaddingBytes", &OutputMessage::addPaddingBytes);
|
||||||
g_lua.bindClassMemberFunction<OutputMessage>("encryptRsa", &OutputMessage::encryptRsa);
|
g_lua.bindClassMemberFunction<OutputMessage>("encryptRsa", &OutputMessage::encryptRsa);
|
||||||
g_lua.bindClassMemberFunction<OutputMessage>("getMessageSize", &OutputMessage::getMessageSize);
|
g_lua.bindClassMemberFunction<OutputMessage>("getMessageSize", &OutputMessage::getMessageSize);
|
||||||
|
g_lua.bindClassMemberFunction<OutputMessage>("setMessageSize", &OutputMessage::setMessageSize);
|
||||||
|
g_lua.bindClassMemberFunction<OutputMessage>("getWritePos", &OutputMessage::getWritePos);
|
||||||
|
g_lua.bindClassMemberFunction<OutputMessage>("setWritePos", &OutputMessage::setWritePos);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FW_SOUND
|
#ifdef FW_SOUND
|
||||||
|
|
|
@ -51,8 +51,12 @@ public:
|
||||||
|
|
||||||
void encryptRsa(int size);
|
void encryptRsa(int size);
|
||||||
|
|
||||||
|
uint16 getWritePos() { return m_writePos; }
|
||||||
uint16 getMessageSize() { return m_messageSize; }
|
uint16 getMessageSize() { return m_messageSize; }
|
||||||
|
|
||||||
|
void setWritePos(uint16 writePos) { m_writePos = writePos; }
|
||||||
|
void setMessageSize(uint16 messageSize) { m_messageSize = messageSize; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8* getWriteBuffer() { return m_buffer + m_writePos; }
|
uint8* getWriteBuffer() { return m_buffer + m_writePos; }
|
||||||
uint8* getHeaderBuffer() { return m_buffer + m_headerPos; }
|
uint8* getHeaderBuffer() { return m_buffer + m_headerPos; }
|
||||||
|
|
Loading…
Reference in New Issue