Merge branch 'master' of github.com:edubart/otclient

master
Henrique 13 years ago
commit 99d677913a

@ -1,55 +1,36 @@
function EnterGame_connectToLoginServer() function EnterGame_connectToLoginServer()
-- create login protocol
local protocolLogin = ProtocolLogin.create() local protocolLogin = ProtocolLogin.create()
-- used to recreate enter game window
local recreateEnterGame = function() local recreateEnterGame = function()
loadUI("/mainmenu/ui/entergamewindow.otui") rootWidget:addChild(loadUI("/mainmenu/ui/entergamewindow.otui"))
end end
-- display loading message box
local loadBox = displayCancelBox("Please wait", "Connecting..") local loadBox = displayCancelBox("Please wait", "Connecting..")
-- cancel loading callback
loadBox.onCancel = function(msgbox) loadBox.onCancel = function(msgbox)
-- cancel protocol and reacreate enter game window -- cancel protocol and reacreate enter game window
protocolLogin:cancel() protocolLogin:cancelLogin()
recreateEnterGame() recreateEnterGame()
end end
-- error callback
protocolLogin.onError = function(protocol, error) protocolLogin.onError = function(protocol, error)
-- destroy loading message box
loadBox:destroy() loadBox:destroy()
-- display error message
local errorBox = displayErrorBox("Login Error", error) local errorBox = displayErrorBox("Login Error", error)
-- cancel protocol and reacreate enter game window
protocol:cancel()
errorBox.onOk = recreateEnterGame errorBox.onOk = recreateEnterGame
end end
-- motd callback
protocolLogin.onMotd = function(protocol, motd) protocolLogin.onMotd = function(protocol, motd)
-- destroy loading message box
loadBox:destroy() loadBox:destroy()
-- display motd
local motdNumber = string.sub(motd, 0, string.find(motd, "\n")) local motdNumber = string.sub(motd, 0, string.find(motd, "\n"))
local motdText = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd)) local motdText = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd))
local motdBox = displayInfoBox("Message of the day", motdText) displayInfoBox("Message of the day", motdText)
-- hide main menu
mainMenu.visible = false mainMenu.visible = false
end end
-- get account and password then login
local enterGameWindow = rootWidget:getChild("enterGameWindow") local enterGameWindow = rootWidget:getChild("enterGameWindow")
local account = enterGameWindow:getChild("accountNameLineEdit").text local account = enterGameWindow:getChild("accountNameLineEdit").text
local password = enterGameWindow:getChild("accountPasswordLineEdit").text local password = enterGameWindow:getChild("accountPasswordLineEdit").text
protocolLogin:login(account, password) protocolLogin:login(account, password)
-- destroy enter game window
enterGameWindow:destroy() enterGameWindow:destroy()
end end

@ -11,45 +11,45 @@ void InputMessage::reset()
m_messageSize = 2; m_messageSize = 2;
} }
uint8 InputMessage::getU8(bool blockReadPos) uint8 InputMessage::getU8(bool peek)
{ {
assert(canRead(1)); assert(canRead(1));
uint8 v = m_buffer[m_readPos]; uint8 v = m_buffer[m_readPos];
if(!blockReadPos) if(!peek)
m_readPos += 1; m_readPos += 1;
return v; return v;
} }
uint16 InputMessage::getU16(bool blockReadPos) uint16 InputMessage::getU16(bool peek)
{ {
assert(canRead(2)); assert(canRead(2));
uint16 v = *(uint16_t*)(m_buffer + m_readPos); uint16 v = *(uint16_t*)(m_buffer + m_readPos);
if(!blockReadPos) if(!peek)
m_readPos += 2; m_readPos += 2;
return v; return v;
} }
uint32 InputMessage::getU32(bool blockReadPos) uint32 InputMessage::getU32(bool peek)
{ {
assert(canRead(4)); assert(canRead(4));
uint32 v = *(uint32*)(m_buffer + m_readPos); uint32 v = *(uint32*)(m_buffer + m_readPos);
if(!blockReadPos) if(!peek)
m_readPos += 4; m_readPos += 4;
return v; return v;
} }
uint64 InputMessage::getU64(bool blockReadPos) uint64 InputMessage::getU64(bool peek)
{ {
assert(canRead(8)); assert(canRead(8));
uint64 v = *(uint64*)(m_buffer + m_readPos); uint64 v = *(uint64*)(m_buffer + m_readPos);
if(!blockReadPos) if(!peek)
m_readPos += 8; m_readPos += 8;
return v; return v;

@ -20,17 +20,17 @@ public:
void reset(); void reset();
uint8 getU8(bool blockReadPos = false); uint8 getU8(bool peek = false);
uint16 getU16(bool blockReadPos = false); uint16 getU16(bool peek = false);
uint32 getU32(bool blockReadPos = false); uint32 getU32(bool peek = false);
uint64 getU64(bool blockReadPos = false); uint64 getU64(bool peek = false);
std::string getString(); std::string getString();
void skipBytes(uint16 bytes) { m_readPos += bytes; } void skipBytes(uint16 bytes) { m_readPos += bytes; }
uint8* getBuffer() { return m_buffer; } uint8* getBuffer() { return m_buffer; }
uint16 getMessageSize() { return m_messageSize; } uint16 getMessageSize() { return m_messageSize; }
void setMessageSize(uint16 messageSize) { m_messageSize = messageSize; } void setMessageSize(uint16 messageSize) { m_messageSize = messageSize; }
bool end() { return m_readPos == m_messageSize; } bool eof() { return m_readPos == m_messageSize; }
private: private:
bool canRead(int bytes); bool canRead(int bytes);

@ -8,7 +8,7 @@
void ProtocolGame::parseMessage(InputMessage& msg) void ProtocolGame::parseMessage(InputMessage& msg)
{ {
while(!msg.end()) { while(!msg.eof()) {
uint8 opt = msg.getU8(); uint8 opt = msg.getU8();
switch(opt) { switch(opt) {
case 0x0A: case 0x0A:

@ -26,7 +26,7 @@ void ProtocolGame::sendLoginPacket(uint32 timestamp, uint8 unknown)
oMsg.addU32(timestamp); oMsg.addU32(timestamp);
oMsg.addU8(unknown); oMsg.addU8(unknown);
// fill the rest with zeros // complete the 128 bytes for rsa encryption with zeros
oMsg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length())); oMsg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length()));
// encrypt with RSA // encrypt with RSA

@ -36,7 +36,7 @@ void ProtocolLogin::onConnect()
void ProtocolLogin::onRecv(InputMessage& inputMessage) void ProtocolLogin::onRecv(InputMessage& inputMessage)
{ {
while(!inputMessage.end()) { while(!inputMessage.eof()) {
uint8 opt = inputMessage.getU8(); uint8 opt = inputMessage.getU8();
switch(opt) { switch(opt) {
case 0x0A: case 0x0A:
@ -65,30 +65,29 @@ void ProtocolLogin::sendLoginPacket()
{ {
OutputMessage oMsg; OutputMessage oMsg;
oMsg.addU8(0x01); // Protocol id oMsg.addU8(0x01); // protocol id
oMsg.addU16(0x02); // OS oMsg.addU16(0x02); // os
oMsg.addU16(862); // Client version oMsg.addU16(862); // client version
oMsg.addU32(0x4E12DAFF); // Data Signature oMsg.addU32(0x4E12DAFF); // data signature
oMsg.addU32(0x4E12DB27); // Sprite Signature oMsg.addU32(0x4E12DB27); // sprite signature
oMsg.addU32(0x4E119CBF); // Picture Signature oMsg.addU32(0x4E119CBF); // pic signature
oMsg.addU8(0); // First RSA byte must be 0x00 // 1 oMsg.addU8(0); // first RSA byte must be 0
// Add xtea key // xtea key
generateXteaKey(); generateXteaKey();
oMsg.addU32(m_xteaKey[0]); // 5 oMsg.addU32(m_xteaKey[0]);
oMsg.addU32(m_xteaKey[1]); // 9 oMsg.addU32(m_xteaKey[1]);
oMsg.addU32(m_xteaKey[2]); // 13 oMsg.addU32(m_xteaKey[2]);
oMsg.addU32(m_xteaKey[3]); // 17 oMsg.addU32(m_xteaKey[3]);
oMsg.addString(m_accountName); // Account Name // 19 oMsg.addString(m_accountName);
oMsg.addString(m_accountPassword); // Password // 21 oMsg.addString(m_accountPassword);
// Packet data must have since byte 0, start, 128 bytes // complete the 128 bytes for rsa encryption with zeros
oMsg.addPaddingBytes(128 - (21 + m_accountName.length() + m_accountPassword.length())); oMsg.addPaddingBytes(128 - (21 + m_accountName.length() + m_accountPassword.length()));
// Encrypt msg with RSA
if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, OTSERV_PUBLIC_RSA)) if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, OTSERV_PUBLIC_RSA))
return; return;

Loading…
Cancel
Save