protocol compability fixes

This commit is contained in:
Eduardo Bart 2012-05-12 17:16:33 -03:00
parent ffa94f10b6
commit b7a70dd1e3
3 changed files with 66 additions and 49 deletions

View File

@ -81,6 +81,12 @@ namespace Proto {
LoginServerCharacterList = 100 LoginServerCharacterList = 100
}; };
enum CreatureOpcode {
UnknownCreature = 97,
OutdatedCreature = 98,
Creature = 99
};
enum GameServerOpcodes { enum GameServerOpcodes {
GameServerInitGame = 10, GameServerInitGame = 10,
GameServerGMActions = 11, GameServerGMActions = 11,

View File

@ -162,7 +162,6 @@ private:
void parseCreatureSkulls(InputMessage& msg); void parseCreatureSkulls(InputMessage& msg);
void parseCreatureShields(InputMessage& msg); void parseCreatureShields(InputMessage& msg);
void parseCreatureUnpass(InputMessage& msg); void parseCreatureUnpass(InputMessage& msg);
void parseCreatureTurn(InputMessage& msg);
void parseEditText(InputMessage& msg); void parseEditText(InputMessage& msg);
void parseEditList(InputMessage& msg); void parseEditList(InputMessage& msg);
void parsePlayerInfo(InputMessage& msg); void parsePlayerInfo(InputMessage& msg);
@ -209,6 +208,7 @@ private:
void setTileDescription(InputMessage& msg, Position position); void setTileDescription(InputMessage& msg, Position position);
Outfit internalGetOutfit(InputMessage& msg); Outfit internalGetOutfit(InputMessage& msg);
CreaturePtr internalGetCreature(InputMessage& msg, int type = 0);
ThingPtr internalGetThing(InputMessage& msg); ThingPtr internalGetThing(InputMessage& msg);
ItemPtr internalGetItem(InputMessage& msg, int id = 0); ItemPtr internalGetItem(InputMessage& msg, int id = 0);

View File

@ -455,11 +455,8 @@ void ProtocolGame::parseTileTransformThing(InputMessage& msg)
Position pos = parsePosition(msg); Position pos = parsePosition(msg);
int stackPos = msg.getU8(); int stackPos = msg.getU8();
int thingId = msg.getU16(); ThingPtr thing = internalGetThing(msg);
if(thingId == 0x0061 || thingId == 0x0062 || thingId == 0x0063) { if(thing) {
parseCreatureTurn(msg);
} else {
ThingPtr thing = internalGetItem(msg, thingId);
if(!g_map.removeThingByPos(pos, stackPos)) if(!g_map.removeThingByPos(pos, stackPos))
logTraceError("could not remove thing"); logTraceError("could not remove thing");
g_map.addThing(thing, pos, stackPos); g_map.addThing(thing, pos, stackPos);
@ -502,11 +499,7 @@ void ProtocolGame::parseCreatureMove(InputMessage& msg)
void ProtocolGame::parseOpenContainer(InputMessage& msg) void ProtocolGame::parseOpenContainer(InputMessage& msg)
{ {
int containerId = msg.getU8(); int containerId = msg.getU8();
#if PROTOCOL>=920
ItemPtr containerItem = internalGetItem(msg); ItemPtr containerItem = internalGetItem(msg);
#else
ItemPtr containerItem = Item::create(msg.getU16());
#endif
std::string name = msg.getString(); std::string name = msg.getString();
int capacity = msg.getU8(); int capacity = msg.getU8();
bool hasParent = (msg.getU8() != 0); bool hasParent = (msg.getU8() != 0);
@ -796,18 +789,6 @@ void ProtocolGame::parseCreatureUnpass(InputMessage& msg)
logTraceError("could not get creature"); logTraceError("could not get creature");
} }
void ProtocolGame::parseCreatureTurn(InputMessage& msg)
{
uint id = msg.getU32();
Otc::Direction direction = (Otc::Direction)msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->turn(direction);
else
logTraceError("could not get creature");
}
void ProtocolGame::parseEditText(InputMessage& msg) void ProtocolGame::parseEditText(InputMessage& msg)
{ {
uint id = msg.getU32(); uint id = msg.getU32();
@ -998,6 +979,15 @@ void ProtocolGame::parseOpenChannel(InputMessage& msg)
int channelId = msg.getU16(); int channelId = msg.getU16();
std::string name = msg.getString(); std::string name = msg.getString();
#if PROTOCOL>=944
int joinedPlayers = msg.getU16();
for(int i=0;i<joinedPlayers;++i)
msg.getString(); // player name
int invitedPlayers = msg.getU16();
for(int i=0;i<invitedPlayers;++i)
msg.getString(); // player name
#endif
g_game.processOpenChannel(channelId, name); g_game.processOpenChannel(channelId, name);
} }
@ -1285,7 +1275,6 @@ void ProtocolGame::setTileDescription(InputMessage& msg, Position position)
logTraceError("too many things, stackpos=", stackPos, " pos=", position); logTraceError("too many things, stackpos=", stackPos, " pos=", position);
ThingPtr thing = internalGetThing(msg); ThingPtr thing = internalGetThing(msg);
if(thing)
g_map.addThing(thing, position, -1); g_map.addThing(thing, position, -1);
} }
stackPos++; stackPos++;
@ -1304,9 +1293,6 @@ Outfit ProtocolGame::internalGetOutfit(InputMessage& msg)
int legs = msg.getU8(); int legs = msg.getU8();
int feet = msg.getU8(); int feet = msg.getU8();
int addons = msg.getU8(); int addons = msg.getU8();
#if PROTOCOL>=870
msg.getU16(); // mount
#endif
outfit.setId(lookType); outfit.setId(lookType);
outfit.setHead(head); outfit.setHead(head);
@ -1327,6 +1313,10 @@ Outfit ProtocolGame::internalGetOutfit(InputMessage& msg)
} }
} }
#if PROTOCOL>=870
msg.getU16(); // mount
#endif
return outfit; return outfit;
} }
@ -1334,23 +1324,36 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
{ {
ThingPtr thing; ThingPtr thing;
int thingId = msg.getU16(); int id = msg.getU16();
if(thingId == 0)
Fw::throwException("thingId == 0"); if(id == 0)
Fw::throwException("invalid thing id");
else if(id == Proto::UnknownCreature || id == Proto::OutdatedCreature || id == Proto::Creature)
thing = internalGetCreature(msg, id);
else // item
thing = internalGetItem(msg, id);
return thing;
}
CreaturePtr ProtocolGame::internalGetCreature(InputMessage& msg, int type)
{
if(type == 0)
type = msg.getU16();
if(thingId == 0x0061 || thingId == 0x0062) { // add new creature
CreaturePtr creature; CreaturePtr creature;
bool known = (type != Proto::UnknownCreature);
if(thingId == 0x0062) { //creature is known if(type == Proto::OutdatedCreature || type == Proto::UnknownCreature) {
if(known) {
uint id = msg.getU32(); uint id = msg.getU32();
creature = g_map.getCreatureById(id);
CreaturePtr knownCreature = g_map.getCreatureById(id); if(!creature)
if(knownCreature)
creature = knownCreature;
else
logTraceError("server said that a creature is known, but it's not"); logTraceError("server said that a creature is known, but it's not");
} else if(thingId == 0x0061) { //creature is not known } else {
uint removeId = msg.getU32(); uint removeId = msg.getU32();
g_map.removeCreatureById(removeId);
uint id = msg.getU32(); uint id = msg.getU32();
int creatureType; int creatureType;
@ -1364,13 +1367,13 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
else else
creatureType = Proto::CreatureTypeNpc; creatureType = Proto::CreatureTypeNpc;
#endif #endif
std::string name = msg.getString(); std::string name = msg.getString();
if(name.length() > 0) // every creature name must start with a capital letter // every creature name must start with a capital letter
if(name.length() > 0)
name[0] = toupper(name[0]); name[0] = toupper(name[0]);
g_map.removeCreatureById(removeId);
if(id == m_localPlayer->getId()) if(id == m_localPlayer->getId())
creature = m_localPlayer; creature = m_localPlayer;
else if(creatureType == Proto::CreatureTypePlayer) else if(creatureType == Proto::CreatureTypePlayer)
@ -1407,7 +1410,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
bool passable = false; bool passable = false;
#if PROTOCOL>=854 #if PROTOCOL>=854
if(thingId == 0x0061) if(!known)
emblem = msg.getU8(); emblem = msg.getU8();
passable = (msg.getU8() == 0); passable = (msg.getU8() == 0);
@ -1428,15 +1431,23 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
if(creature == m_localPlayer && !m_localPlayer->isKnown()) if(creature == m_localPlayer && !m_localPlayer->isKnown())
m_localPlayer->setKnown(true); m_localPlayer->setKnown(true);
} }
} else if(type == Proto::Creature) {
uint id = msg.getU32();
Otc::Direction direction = (Otc::Direction)msg.getU8();
#if PROTOCOL>=953
msg.getU8(); // passable
#endif
thing = creature; creature = g_map.getCreatureById(id);
} else if(thingId == 0x0063) { // creature turn if(creature)
parseCreatureTurn(msg); creature->turn(direction);
} else { // item else
thing = internalGetItem(msg, thingId); logTraceError("invalid creature");
} else {
Fw::throwException("invalid creature opcode");
} }
return thing; return creature;
} }
ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, int id) ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, int id)