mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 03:24:55 +02:00
protocol login working
This commit is contained in:
@@ -31,3 +31,36 @@ NorthEast = 4
|
||||
SouthEast = 5
|
||||
SouthWest = 6
|
||||
NorthWest = 7
|
||||
|
||||
ClientEnterAccount = 1
|
||||
ClientEnterGame = 10
|
||||
|
||||
LoginServerError = 10
|
||||
LoginServerMotd = 20
|
||||
LoginServerUpdateNeeded = 30
|
||||
LoginServerCharacterList = 100
|
||||
|
||||
GameExtendedOpcode = 0
|
||||
GameProtocolChecksum = 1
|
||||
GameAccountNames = 2
|
||||
GameChallangeOnLogin = 3
|
||||
GameStackposOnTileAddThing = 4
|
||||
GamePenalityOnDeath = 5
|
||||
GameNameOnNpcTrade = 6
|
||||
GameDoubleFreeCapacity = 7
|
||||
GameDoubleExperience = 8
|
||||
GameTotalCapacity = 9
|
||||
GameSkillsBase = 10
|
||||
GameAdditionalPlayerStats = 11
|
||||
GameIdOnCancelAttack = 12
|
||||
GameChannelPlayerList = 13
|
||||
GamePlayerMounts = 14
|
||||
GameEnvironmentEffect = 15
|
||||
GameCreatureType = 16
|
||||
GameCreatureAdditionalInfo = 17
|
||||
GameCreaturePassableInfo = 18
|
||||
GameItemAnimationPhase = 19
|
||||
GameTrucatedPingOpcode = 20
|
||||
GameReverseCreatureStack = 21
|
||||
|
||||
OTSERV_RSA = "109120132967399429278860960508995541528237502902798129123468757937266291492576446330739696001110603907230888610072655818825358503429057592827629436413108566029093628212635953836686562675849720620786279431090218017681061521755056710823876476444260558147179707119674283982419152118103759076030616683978566631413"
|
||||
|
@@ -38,6 +38,8 @@ Module
|
||||
|
||||
dofile 'const'
|
||||
|
||||
dofile 'protocollogin'
|
||||
|
||||
dofile 'widgets/uigamemap'
|
||||
dofile 'widgets/uiitem'
|
||||
dofile 'widgets/uiminiwindow'
|
||||
|
121
modules/game/protocollogin.lua
Normal file
121
modules/game/protocollogin.lua
Normal file
@@ -0,0 +1,121 @@
|
||||
ProtocolLogin = extends(Protocol)
|
||||
|
||||
-- private functions
|
||||
local function sendLoginPacket(protocol)
|
||||
local msg = OutputMessage.create()
|
||||
msg:addU8(ClientEnterAccount)
|
||||
msg:addU16(1) -- todo: ClientOs
|
||||
msg:addU16(g_game.getClientVersion())
|
||||
|
||||
msg:addU32(g_thingsType.getSignature())
|
||||
msg:addU32(g_sprites.getSignature())
|
||||
msg:addU32(0) -- todo: pic signature
|
||||
|
||||
local paddingBytes = 128
|
||||
msg:addU8(0) -- first RSA byte must be 0
|
||||
paddingBytes = paddingBytes - 1
|
||||
|
||||
-- xtea key
|
||||
protocol:generateXteaKey()
|
||||
local xteaKey = protocol:getXteaKey()
|
||||
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
|
||||
protocol:enableChecksum()
|
||||
end
|
||||
|
||||
if g_game.getFeature(GameAccountNames) then
|
||||
msg:addString(protocol.accountName)
|
||||
msg:addString(protocol.accountPassword)
|
||||
paddingBytes = paddingBytes - (4 + string.len(protocol.accountName) + string.len(protocol.accountPassword))
|
||||
else
|
||||
msg:addU32(tonumber(protocol.accountName))
|
||||
msg:addString(protocol.accountPassword)
|
||||
paddingBytes = paddingBytes - (6 + string.len(protocol.accountPassword))
|
||||
end
|
||||
|
||||
msg:addPaddingBytes(paddingBytes, 0)
|
||||
msg:encryptRSA(128, OTSERV_RSA) -- todo: check whether to use cip or ot rsa
|
||||
|
||||
protocol:send(msg)
|
||||
protocol:enableXteaEncryption()
|
||||
protocol:recv()
|
||||
end
|
||||
|
||||
-- events
|
||||
function ProtocolLogin:onConnect()
|
||||
self:connectCallback(self)
|
||||
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
|
||||
signalcall(self.onError, self, "Client needs update.", false)
|
||||
elseif opcode == LoginServerCharacterList then
|
||||
self:parseCharacterList(msg)
|
||||
else
|
||||
self:parseOpcode(opcode, msg)
|
||||
end
|
||||
end
|
||||
self:disconnect()
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function ProtocolLogin.create()
|
||||
return ProtocolLogin.internalCreate()
|
||||
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)
|
||||
return
|
||||
end
|
||||
|
||||
self.accountName = accountName
|
||||
self.accountPassword = accountPassword
|
||||
self.connectCallback = sendLoginPacket
|
||||
|
||||
self:connect(host, port)
|
||||
end
|
||||
|
||||
function ProtocolLogin:cancelLogin()
|
||||
self:disconnect()
|
||||
end
|
||||
|
||||
function ProtocolLogin:parseError(msg)
|
||||
local errorMessage = msg:getString()
|
||||
signalcall(self.onError, self, errorMessage, false)
|
||||
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 = {}
|
||||
character[1] = msg:getString()
|
||||
character[2] = msg:getString()
|
||||
character[3] = iptostring(msg:getU32())
|
||||
character[4] = msg:getU16()
|
||||
characters[i] = character
|
||||
end
|
||||
local premDays = msg:getU16()
|
||||
signalcall(self.onCharacterList, self, characters, premDays)
|
||||
end
|
||||
|
||||
function ProtocolLogin:parseOpcode(opcode, msg)
|
||||
signalcall(self.onOpcode, self, opcode, msg)
|
||||
end
|
Reference in New Issue
Block a user