2012-06-26 00:13:30 +02:00
|
|
|
-- @docclass
|
2012-06-05 23:27:37 +02:00
|
|
|
ProtocolLogin = extends(Protocol)
|
|
|
|
|
2012-07-18 01:49:21 +02:00
|
|
|
LoginServerError = 10
|
|
|
|
LoginServerMotd = 20
|
|
|
|
LoginServerUpdateNeeded = 30
|
|
|
|
LoginServerCharacterList = 100
|
2012-08-30 07:59:10 +02:00
|
|
|
LoginServerExtendedCharacterList = 101
|
2012-07-18 01:49:21 +02:00
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
function ProtocolLogin:login(host, port, accountName, accountPassword)
|
|
|
|
if string.len(host) == 0 or port == nil or port == 0 then
|
|
|
|
signalcall(self.onError, self, tr("You must enter a valid server address and port."))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
self.accountName = accountName
|
|
|
|
self.accountPassword = accountPassword
|
|
|
|
self.connectCallback = sendLoginPacket
|
|
|
|
|
|
|
|
self:connect(host, port)
|
|
|
|
end
|
2012-07-18 01:49:21 +02:00
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
function ProtocolLogin:cancelLogin()
|
|
|
|
self:disconnect()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ProtocolLogin:sendLoginPacket()
|
2012-06-05 23:27:37 +02:00
|
|
|
local msg = OutputMessage.create()
|
2012-07-17 16:36:27 +02:00
|
|
|
msg:addU8(ClientOpcodes.ClientEnterAccount)
|
2012-07-18 01:49:21 +02:00
|
|
|
msg:addU16(g_game.getOsType())
|
2012-07-26 08:10:28 +02:00
|
|
|
msg:addU16(g_game.getClientVersion())
|
2012-06-05 23:27:37 +02:00
|
|
|
|
2012-06-21 19:54:20 +02:00
|
|
|
msg:addU32(g_things.getDatSignature())
|
|
|
|
msg:addU32(g_sprites.getSprSignature())
|
2012-07-18 01:49:21 +02:00
|
|
|
msg:addU32(PIC_SIGNATURE)
|
2012-06-05 23:27:37 +02:00
|
|
|
|
|
|
|
local paddingBytes = 128
|
|
|
|
msg:addU8(0) -- first RSA byte must be 0
|
|
|
|
paddingBytes = paddingBytes - 1
|
|
|
|
|
|
|
|
-- xtea key
|
2012-07-26 08:10:28 +02:00
|
|
|
self:generateXteaKey()
|
|
|
|
local xteaKey = self:getXteaKey()
|
2012-06-05 23:27:37 +02:00
|
|
|
msg:addU32(xteaKey[1])
|
|
|
|
msg:addU32(xteaKey[2])
|
|
|
|
msg:addU32(xteaKey[3])
|
|
|
|
msg:addU32(xteaKey[4])
|
|
|
|
paddingBytes = paddingBytes - 16
|
|
|
|
|
|
|
|
if g_game.getFeature(GameProtocolChecksum) then
|
2012-07-26 08:10:28 +02:00
|
|
|
self:enableChecksum()
|
2012-06-05 23:27:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if g_game.getFeature(GameAccountNames) then
|
2012-07-26 08:10:28 +02:00
|
|
|
msg:addString(self.accountName)
|
|
|
|
msg:addString(self.accountPassword)
|
|
|
|
paddingBytes = paddingBytes - (4 + string.len(self.accountName) + string.len(self.accountPassword))
|
2012-06-05 23:27:37 +02:00
|
|
|
else
|
2012-07-26 08:10:28 +02:00
|
|
|
msg:addU32(tonumber(self.accountName))
|
|
|
|
msg:addString(self.accountPassword)
|
|
|
|
paddingBytes = paddingBytes - (6 + string.len(self.accountPassword))
|
2012-06-05 23:27:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
msg:addPaddingBytes(paddingBytes, 0)
|
2012-08-04 15:54:35 +02:00
|
|
|
msg:encryptRsa(128)
|
2012-06-05 23:27:37 +02:00
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
self:send(msg)
|
|
|
|
self:enableXteaEncryption()
|
|
|
|
self:recv()
|
2012-06-05 23:27:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ProtocolLogin:onConnect()
|
2012-07-26 08:10:28 +02:00
|
|
|
self:sendLoginPacket()
|
2012-06-05 23:27:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ProtocolLogin:onRecv(msg)
|
|
|
|
while not msg:eof() do
|
|
|
|
local opcode = msg:getU8()
|
|
|
|
if opcode == LoginServerError then
|
|
|
|
self:parseError(msg)
|
|
|
|
elseif opcode == LoginServerMotd then
|
|
|
|
self:parseMotd(msg)
|
|
|
|
elseif opcode == LoginServerUpdateNeeded then
|
2012-08-27 09:47:08 +02:00
|
|
|
signalcall(self.onError, self, tr("Client needs update. Verify your spr/dat/pic versions."))
|
2012-06-05 23:27:37 +02:00
|
|
|
elseif opcode == LoginServerCharacterList then
|
|
|
|
self:parseCharacterList(msg)
|
2012-08-30 07:59:10 +02:00
|
|
|
elseif opcode == LoginServerExtendedCharacterList then
|
|
|
|
self:parseExtendedCharacterList(msg)
|
2012-06-05 23:27:37 +02:00
|
|
|
else
|
|
|
|
self:parseOpcode(opcode, msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self:disconnect()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ProtocolLogin:parseError(msg)
|
|
|
|
local errorMessage = msg:getString()
|
2012-07-10 00:45:34 +02:00
|
|
|
signalcall(self.onError, self, errorMessage)
|
2012-06-05 23:27:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ProtocolLogin:parseMotd(msg)
|
|
|
|
local motd = msg:getString()
|
|
|
|
signalcall(self.onMotd, self, motd)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ProtocolLogin:parseCharacterList(msg)
|
|
|
|
local characters = {}
|
|
|
|
local charactersCount = msg:getU8()
|
|
|
|
for i=1,charactersCount do
|
|
|
|
local character = {}
|
2012-08-07 22:55:05 +02:00
|
|
|
character.name = msg:getString()
|
|
|
|
character.worldName = msg:getString()
|
|
|
|
character.worldIp = iptostring(msg:getU32())
|
|
|
|
character.worldPort = msg:getU16()
|
2012-06-05 23:27:37 +02:00
|
|
|
characters[i] = character
|
|
|
|
end
|
2012-08-30 07:59:10 +02:00
|
|
|
|
|
|
|
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()
|
2012-08-31 06:56:10 +02:00
|
|
|
local otui = msg:getString()
|
|
|
|
signalcall(self.onCharacterList, self, characters, account, otui)
|
2012-06-05 23:27:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ProtocolLogin:parseOpcode(opcode, msg)
|
|
|
|
signalcall(self.onOpcode, self, opcode, msg)
|
|
|
|
end
|