some protocol changes for more compatibility

This commit is contained in:
Eduardo Bart 2012-05-11 16:25:29 -03:00
parent 5584bfdd99
commit d586bb5e93
9 changed files with 44 additions and 62 deletions

View File

@ -41,7 +41,7 @@
Creature::Creature() : Thing() Creature::Creature() : Thing()
{ {
m_id = 0; m_id = 1;
m_healthPercent = 100; m_healthPercent = 100;
m_speed = 200; m_speed = 200;
m_direction = Otc::South; m_direction = Otc::South;

View File

@ -49,6 +49,7 @@ void Game::resetGameStates()
m_safeFight = true; m_safeFight = true;
m_followingCreature = nullptr; m_followingCreature = nullptr;
m_attackingCreature = nullptr; m_attackingCreature = nullptr;
m_localPlayer = nullptr;
for(auto& it : m_containers) { for(auto& it : m_containers) {
const ContainerPtr& container = it.second; const ContainerPtr& container = it.second;
@ -76,11 +77,8 @@ void Game::processConnectionError(const boost::system::error_code& error)
void Game::processDisconnect() void Game::processDisconnect()
{ {
if(isOnline()) { if(isOnline())
m_localPlayer = nullptr;
processGameEnd(); processGameEnd();
}
if(m_protocolGame) { if(m_protocolGame) {
m_protocolGame->disconnect(); m_protocolGame->disconnect();
@ -144,28 +142,6 @@ void Game::processGMActions(const std::vector<uint8>& actions)
g_lua.callGlobalField("g_game", "onGMActions", actions); g_lua.callGlobalField("g_game", "onGMActions", actions);
} }
void Game::processPlayerStats(double health, double maxHealth,
double freeCapacity, double experience,
double level, double levelPercent,
double mana, double maxMana,
double magicLevel, double magicLevelPercent,
double soul, double stamina)
{
if(!m_localPlayer) {
logTraceError("there is no local player");
return;
}
m_localPlayer->setHealth(health, maxHealth);
m_localPlayer->setFreeCapacity(freeCapacity);
m_localPlayer->setExperience(experience);
m_localPlayer->setLevel(level, levelPercent);
m_localPlayer->setMana(mana, maxMana);
m_localPlayer->setMagicLevel(magicLevel, magicLevelPercent);
m_localPlayer->setStamina(stamina);
m_localPlayer->setSoul(soul);
}
void Game::processPing() void Game::processPing()
{ {
g_lua.callGlobalField("g_game", "onPing"); g_lua.callGlobalField("g_game", "onPing");

View File

@ -53,13 +53,6 @@ protected:
void processDeath(int penality); void processDeath(int penality);
void processGMActions(const std::vector<uint8>& actions); void processGMActions(const std::vector<uint8>& actions);
void processPlayerStats(double health, double maxHealth,
double freeCapacity, double experience,
double level, double levelPercent,
double mana, double maxMana,
double magicLevel, double magicLevelPercent,
double soul, double stamina);
void processInventoryChange(int slot, const ItemPtr& item); void processInventoryChange(int slot, const ItemPtr& item);
void processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos); void processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos);
void processCreatureTeleport(const CreaturePtr& creature); void processCreatureTeleport(const CreaturePtr& creature);

View File

@ -52,6 +52,20 @@ namespace Proto {
constexpr int ClientVersion = PROTOCOL; constexpr int ClientVersion = PROTOCOL;
constexpr int PicSignature = 0x4E119CBF; constexpr int PicSignature = 0x4E119CBF;
enum OsTypes {
OsWindows = 1,
OsLinux = 2,
OsMac = 3
};
#ifdef OSTYPE
constexpr int ClientOs = OSTYPE;
#elif defined WIN32
constexpr int ClientOs = OsWindows;
#else
constexpr int ClientOs = OsLinux;
#endif
#if PROTOCOL>=860 #if PROTOCOL>=860
constexpr int NumViolationReasons = 20; constexpr int NumViolationReasons = 20;
#elif PROTOCOL>=854 #elif PROTOCOL>=854
@ -60,13 +74,6 @@ namespace Proto {
constexpr int NumViolationReasons = 32; constexpr int NumViolationReasons = 32;
#endif #endif
enum OsTypes {
OsWindows = 1,
OsLinux = 2,
OsMac = 3,
OsBrowser = 4
};
enum LoginServerOpts { enum LoginServerOpts {
LoginServerError = 10, LoginServerError = 10,
LoginServerMotd = 20, LoginServerMotd = 20,

View File

@ -24,6 +24,7 @@
#include <otclient/core/game.h> #include <otclient/core/game.h>
#include <otclient/core/player.h> #include <otclient/core/player.h>
#include <otclient/core/item.h> #include <otclient/core/item.h>
#include <otclient/core/localplayer.h>
void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, const std::string& host, uint16 port, const std::string& characterName) void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, const std::string& host, uint16 port, const std::string& characterName)
{ {
@ -43,6 +44,9 @@ void ProtocolGame::onConnect()
{ {
recv(); recv();
// must create local player before parsing anything
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
#if PROTOCOL>=854 #if PROTOCOL>=854
m_waitingLoginPacket = true; m_waitingLoginPacket = true;
#else #else

View File

@ -196,6 +196,7 @@ private:
private: private:
Boolean<false> m_waitingLoginPacket; Boolean<false> m_waitingLoginPacket;
Boolean<true> m_firstPacket;
std::string m_accountName; std::string m_accountName;
std::string m_accountPassword; std::string m_accountPassword;
std::string m_characterName; std::string m_characterName;

View File

@ -42,6 +42,12 @@ void ProtocolGame::parseMessage(InputMessage& msg)
while(!msg.eof()) { while(!msg.eof()) {
opcode = msg.getU8(); opcode = msg.getU8();
if(m_firstPacket) {
if(opcode != Proto::GameServerInitGame)
logWarning("first server network opcode is not GameServerInitGame");
m_firstPacket = false;
}
switch(opcode) { switch(opcode) {
case Proto::GameServerInitGame: case Proto::GameServerInitGame:
parseInitGame(msg); parseInitGame(msg);
@ -271,7 +277,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
parseExtendedOpcode(msg); parseExtendedOpcode(msg);
break; break;
default: default:
Fw::throwException("unknown opcode ", opcode, ", previous opcode is ", prevOpcode); Fw::throwException("unknown opcode");
break; break;
} }
prevOpcode = opcode; prevOpcode = opcode;
@ -287,9 +293,7 @@ void ProtocolGame::parseInitGame(InputMessage& msg)
int serverBeat = msg.getU16(); int serverBeat = msg.getU16();
bool canReportBugs = msg.getU8(); bool canReportBugs = msg.getU8();
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
m_localPlayer->setId(playerId); m_localPlayer->setId(playerId);
g_game.processGameStart(m_localPlayer, serverBeat, canReportBugs); g_game.processGameStart(m_localPlayer, serverBeat, canReportBugs);
} }
@ -595,7 +599,12 @@ void ProtocolGame::parseWorldLight(InputMessage& msg)
void ProtocolGame::parseMagicEffect(InputMessage& msg) void ProtocolGame::parseMagicEffect(InputMessage& msg)
{ {
Position pos = parsePosition(msg); Position pos = parsePosition(msg);
#if PROTOCOL>=854
// newer tibia decreased the max effects number, why???
int effectId = msg.getU8(); int effectId = msg.getU8();
#else
int effectId = msg.getU16();
#endif
EffectPtr effect = EffectPtr(new Effect()); EffectPtr effect = EffectPtr(new Effect());
effect->setId(effectId); effect->setId(effectId);
@ -781,12 +790,14 @@ void ProtocolGame::parsePlayerStats(InputMessage& msg)
double soul = msg.getU8(); double soul = msg.getU8();
double stamina = msg.getU16(); double stamina = msg.getU16();
g_game.processPlayerStats(health, maxHealth, m_localPlayer->setHealth(health, maxHealth);
freeCapacity, experience, m_localPlayer->setFreeCapacity(freeCapacity);
level, levelPercent, m_localPlayer->setExperience(experience);
mana, maxMana, m_localPlayer->setLevel(level, levelPercent);
magicLevel, magicLevelPercent, m_localPlayer->setMana(mana, maxMana);
soul, stamina); m_localPlayer->setMagicLevel(magicLevel, magicLevelPercent);
m_localPlayer->setStamina(stamina);
m_localPlayer->setSoul(soul);
} }
void ProtocolGame::parsePlayerSkills(InputMessage& msg) void ProtocolGame::parsePlayerSkills(InputMessage& msg)

View File

@ -28,13 +28,7 @@ void ProtocolGame::sendLoginPacket(uint timestamp, uint8 unknown)
OutputMessage msg; OutputMessage msg;
msg.addU8(Proto::ClientEnterGame); msg.addU8(Proto::ClientEnterGame);
msg.addU16(Proto::ClientOs);
#ifdef WIN32
msg.addU16(Proto::OsWindows);
#else
msg.addU16(Proto::OsLinux);
#endif
msg.addU16(Proto::ClientVersion); msg.addU16(Proto::ClientVersion);
int paddingBytes = 128; int paddingBytes = 128;

View File

@ -86,11 +86,7 @@ void ProtocolLogin::sendLoginPacket()
OutputMessage msg; OutputMessage msg;
msg.addU8(Proto::ClientEnterAccount); msg.addU8(Proto::ClientEnterAccount);
#ifdef WIN32 msg.addU16(Proto::ClientOs);
msg.addU16(Proto::OsWindows);
#else
msg.addU16(Proto::OsLinux);
#endif
msg.addU16(Proto::ClientVersion); msg.addU16(Proto::ClientVersion);
msg.addU32(g_thingsType.getSignature()); // data signature msg.addU32(g_thingsType.getSignature()); // data signature