tibia-client/src/otclient/net/protocolgamesend.cpp

592 lines
13 KiB
C++
Raw Normal View History

2011-08-28 15:17:58 +02:00
/*
2012-01-02 17:58:37 +01:00
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
2011-08-28 15:17:58 +02:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
2011-08-15 16:11:24 +02:00
#include "protocolgame.h"
2011-08-16 02:30:31 +02:00
#include <framework/net/rsa.h>
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendLoginPacket(uint timestamp, uint8 unknown)
2011-08-16 02:30:31 +02:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientEnterGame);
oMsg.addU16(Proto::OsLinux);
oMsg.addU16(Proto::ClientVersion);
2011-08-16 02:30:31 +02:00
2011-08-16 05:27:46 +02:00
oMsg.addU8(0); // first RSA byte must be 0
2011-08-16 02:30:31 +02:00
2011-08-16 05:27:46 +02:00
// xtea key
generateXteaKey();
oMsg.addU32(m_xteaKey[0]);
oMsg.addU32(m_xteaKey[1]);
oMsg.addU32(m_xteaKey[2]);
oMsg.addU32(m_xteaKey[3]);
2011-08-16 02:30:31 +02:00
oMsg.addU8(0); // is gm set?
2011-08-16 05:27:46 +02:00
oMsg.addString(m_accountName);
oMsg.addString(m_characterName);
oMsg.addString(m_accountPassword);
2011-08-16 02:30:31 +02:00
2011-08-16 05:27:46 +02:00
oMsg.addU32(timestamp);
oMsg.addU8(unknown);
2011-08-16 02:30:31 +02:00
2011-08-16 06:24:20 +02:00
// complete the 128 bytes for rsa encryption with zeros
2011-08-16 02:30:31 +02:00
oMsg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length()));
2011-08-16 05:27:46 +02:00
// encrypt with RSA
Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, Proto::RSA);
2011-08-16 02:30:31 +02:00
send(oMsg);
2011-08-16 05:27:46 +02:00
enableXteaEncryption();
2011-08-16 02:30:31 +02:00
}
2011-08-15 16:11:24 +02:00
void ProtocolGame::sendLogout()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientQuitGame);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
void ProtocolGame::sendPing()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientPingBack);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
2012-01-02 23:23:54 +01:00
// autowalk
2011-08-15 16:11:24 +02:00
void ProtocolGame::sendWalkNorth()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoNorth);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkEast()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoEast);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkSouth()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoSouth);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkWest()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoWest);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
2012-01-02 23:23:54 +01:00
void ProtocolGame::sendStopAutowalk()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientStop);
2012-01-02 23:23:54 +01:00
send(oMsg);
}
2011-08-29 07:54:28 +02:00
void ProtocolGame::sendWalkNorthEast()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoNorthEast);
2011-08-29 07:54:28 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkSouthEast()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoSouthEast);
2011-08-29 07:54:28 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkSouthWest()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoSouthWest);
2011-08-29 07:54:28 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkNorthWest()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGoNorthWest);
2011-08-29 07:54:28 +02:00
send(oMsg);
}
void ProtocolGame::sendTurnNorth()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRotateNorth);
send(oMsg);
}
void ProtocolGame::sendTurnEast()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRotateEast);
send(oMsg);
}
void ProtocolGame::sendTurnSouth()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRotateSouth);
send(oMsg);
}
void ProtocolGame::sendTurnWest()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRotateWest);
send(oMsg);
}
2011-09-03 00:52:40 +02:00
2012-01-02 23:23:54 +01:00
void ProtocolGame::sendThrow(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientMoveObject);
2012-01-02 23:23:54 +01:00
addPosition(oMsg, fromPos);
oMsg.addU16(thingId);
oMsg.addU8(stackpos);
addPosition(oMsg, toPos);
oMsg.addU8(count);
send(oMsg);
}
void ProtocolGame::sendLookInShop(int thingId, int count)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientInspectNpcTrade);
2012-01-02 23:23:54 +01:00
oMsg.addU16(thingId);
oMsg.addU8(count);
send(oMsg);
}
void ProtocolGame::sendPlayerPurchase(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientBuyObject);
2012-01-02 23:23:54 +01:00
oMsg.addU16(thingId);
oMsg.addU8(count);
oMsg.addU8(amount);
oMsg.addU8(ignoreCapacity ? 0x01 : 0x00);
oMsg.addU8(buyWithBackpack ? 0x01 : 0x00);
send(oMsg);
}
void ProtocolGame::sendPlayerSale(int thingId, int count, int amount, bool ignoreEquipped)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientSellObject);
2012-01-02 23:23:54 +01:00
oMsg.addU16(thingId);
oMsg.addU8(count);
oMsg.addU8(amount);
oMsg.addU8(ignoreEquipped ? 0x01 : 0x00);
send(oMsg);
}
void ProtocolGame::sendCloseShop()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientCloseNpcTrade);
2012-01-02 23:23:54 +01:00
send(oMsg);
}
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId)
2012-01-02 23:23:54 +01:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientTradeObject);
2012-01-02 23:23:54 +01:00
addPosition(oMsg, pos);
oMsg.addU16(thingId);
oMsg.addU8(stackpos);
oMsg.addU32(playerId);
send(oMsg);
}
void ProtocolGame::sendLookInTrade(bool counterOffer, int index)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientInspectTrade);
2012-01-02 23:23:54 +01:00
oMsg.addU8(counterOffer ? 0x01 : 0x00);
oMsg.addU8(index);
send(oMsg);
}
void ProtocolGame::sendAcceptTrade()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientAcceptTrade);
2012-01-02 23:23:54 +01:00
send(oMsg);
}
void ProtocolGame::sendRejectTrade()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRejectTrade);
2012-01-02 23:23:54 +01:00
send(oMsg);
}
void ProtocolGame::sendUseItem(const Position& position, int itemId, int stackpos, int index)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientUseObject);
addPosition(oMsg, position);
oMsg.addU16(itemId);
oMsg.addU8(stackpos);
oMsg.addU8(index);
send(oMsg);
}
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendUseItemEx(const Position& fromPos, int fromThingId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientUseTwoObjects);
2012-01-03 14:13:54 +01:00
addPosition(oMsg, fromPos);
oMsg.addU16(fromThingId);
oMsg.addU8(fromStackpos);
addPosition(oMsg, toPos);
oMsg.addU16(toThingId);
oMsg.addU8(toStackpos);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendUseItemCreature(const Position& pos, int thingId, int stackpos, uint creatureId)
2012-01-03 14:13:54 +01:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientUseOnCreature);
2012-01-03 14:13:54 +01:00
addPosition(oMsg, pos);
oMsg.addU16(thingId);
oMsg.addU8(stackpos);
oMsg.addU32(creatureId);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendRotateItem(const Position& pos, int thingId, int stackpos)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientTurnObject);
2012-01-03 14:13:54 +01:00
addPosition(oMsg, pos);
oMsg.addU16(thingId);
oMsg.addU8(stackpos);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendCloseContainer(int containerId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientCloseContainer);
2012-01-03 14:13:54 +01:00
oMsg.addU8(containerId);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendUpContainer(int containerId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientUpContainer);
2012-01-03 14:13:54 +01:00
oMsg.addU8(containerId);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendTextWindow(uint windowTextId, const std::string& text)
2012-01-03 14:13:54 +01:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientEditText);
2012-01-03 14:13:54 +01:00
oMsg.addU32(windowTextId);
oMsg.addString(text);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendHouseWindow(int doorId, uint id, const std::string& text)
2012-01-03 14:13:54 +01:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientEditList);
2012-01-03 14:13:54 +01:00
oMsg.addU8(doorId);
oMsg.addU32(id);
oMsg.addString(text);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
void ProtocolGame::sendLookAt(const Position& position, int thingId, int stackpos)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientLook);
addPosition(oMsg, position);
oMsg.addU16(thingId);
oMsg.addU8(stackpos);
send(oMsg);
}
2012-01-14 02:37:15 +01:00
void ProtocolGame::sendTalk(const std::string& speakTypeDesc, int channelId, const std::string& receiver, const std::string& message)
2011-11-03 17:07:51 +01:00
{
2011-11-03 17:26:17 +01:00
if(message.length() > 255 || message.length() <= 0)
2011-11-03 17:07:51 +01:00
return;
2012-01-14 02:37:15 +01:00
int speakType = Proto::translateSpeakTypeDesc(speakTypeDesc);
2011-11-03 17:07:51 +01:00
OutputMessage oMsg;
oMsg.addU8(Proto::ClientTalk);
2012-01-14 02:37:15 +01:00
oMsg.addU8(speakType);
2011-11-03 17:07:51 +01:00
2012-01-14 02:37:15 +01:00
switch(speakType) {
case Proto::SpeakPrivate:
case Proto::SpeakPrivateRed:
2011-11-03 17:07:51 +01:00
oMsg.addString(receiver);
break;
case Proto::SpeakChannelYellow:
case Proto::SpeakChannelRed:
2011-11-03 17:07:51 +01:00
oMsg.addU16(channelId);
break;
}
oMsg.addString(message);
send(oMsg);
}
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendGetChannels()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGetChannels);
2012-01-03 14:13:54 +01:00
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendJoinChannel(int channelId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientJoinChannel);
2012-01-03 14:13:54 +01:00
oMsg.addU16(channelId);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendLeaveChannel(int channelId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientLeaveChannel);
2012-01-03 14:13:54 +01:00
oMsg.addU16(channelId);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendPrivateChannel(const std::string& receiver)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientPrivateChannel);
2012-01-03 14:13:54 +01:00
oMsg.addString(receiver);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
// removed from game
2012-01-02 23:23:54 +01:00
// process report
// gm closes report
// cancel report
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendCloseNpcChannel()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientCloseNpcChannel);
2012-01-03 14:13:54 +01:00
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendFightTatics(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientSetTactics);
2012-01-03 14:13:54 +01:00
oMsg.addU8(fightMode);
oMsg.addU8(chaseMode);
oMsg.addU8(safeFight ? 0x01: 0x00);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendAttack(uint creatureId)
2012-01-03 14:13:54 +01:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientAttack);
2012-01-03 14:13:54 +01:00
oMsg.addU32(creatureId);
oMsg.addU32(0);
oMsg.addU32(0);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendFollow(uint creatureId)
2012-01-03 14:13:54 +01:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientFollow);
2012-01-03 14:13:54 +01:00
oMsg.addU32(creatureId);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendInviteToParty(uint creatureId)
2012-01-03 14:13:54 +01:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientInviteToParty);
2012-01-03 14:13:54 +01:00
oMsg.addU32(creatureId);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendJoinParty(uint creatureId)
2012-01-03 14:13:54 +01:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientJoinParty);
2012-01-03 14:13:54 +01:00
oMsg.addU32(creatureId);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendRevokeInvitation(uint creatureId)
2012-01-03 14:13:54 +01:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRevokeInvitation);
2012-01-03 14:13:54 +01:00
oMsg.addU32(creatureId);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendPassLeadership(uint creatureId)
2012-01-03 14:13:54 +01:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientPassLeadership);
2012-01-03 14:13:54 +01:00
oMsg.addU32(creatureId);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendLeaveParty()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientLeaveParty);
2012-01-03 14:13:54 +01:00
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendShareExperience(bool active, int unknown)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientShareExperience);
2012-01-03 14:13:54 +01:00
oMsg.addU8(active ? 0x01 : 0x00);
oMsg.addU8(unknown);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-14 02:37:15 +01:00
void ProtocolGame::sendOpenChannel(int channelId)
2012-01-03 14:13:54 +01:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientOpenChannel);
2012-01-14 02:37:15 +01:00
oMsg.addU16(channelId);
2012-01-03 14:13:54 +01:00
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendInviteToChannel(const std::string& name)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientInviteToChannel);
2012-01-03 14:13:54 +01:00
oMsg.addString(name);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendExcludeFromChannel(const std::string& name)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientExcludeFromChannel);
2012-01-03 14:13:54 +01:00
oMsg.addString(name);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendCancel()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientCancel);
2012-01-03 14:13:54 +01:00
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
// update tile (not used)
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendUpdateContainer()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRefreshContainer);
2012-01-03 14:13:54 +01:00
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2011-11-14 23:32:55 +01:00
void ProtocolGame::sendGetOutfit()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGetOutfit);
2011-11-14 23:32:55 +01:00
send(oMsg);
}
2011-11-14 23:47:36 +01:00
void ProtocolGame::sendSetOutfit(const Outfit& outfit)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientSetOutfit);
2011-11-14 23:47:36 +01:00
2012-01-10 01:36:18 +01:00
oMsg.addU16(outfit.getId());
2011-11-14 23:47:36 +01:00
oMsg.addU8(outfit.getHead());
oMsg.addU8(outfit.getBody());
oMsg.addU8(outfit.getLegs());
oMsg.addU8(outfit.getFeet());
oMsg.addU8(outfit.getAddons());
send(oMsg);
}
2011-09-03 00:52:40 +02:00
void ProtocolGame::sendAddVip(const std::string& name)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientAddBuddy);
2011-09-03 00:52:40 +02:00
oMsg.addString(name);
send(oMsg);
}
2012-01-12 20:20:18 +01:00
void ProtocolGame::sendRemoveVip(uint playerId)
2011-09-03 00:52:40 +02:00
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientRemoveBuddy);
2012-01-04 15:30:28 +01:00
oMsg.addU32(playerId);
2011-09-03 00:52:40 +02:00
send(oMsg);
}
2012-01-02 23:23:54 +01:00
// bug report
// violation window
// debug assert
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendGetQuestLog()
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGetQuestLog);
2012-01-03 14:13:54 +01:00
send(oMsg);
}
2012-01-02 23:23:54 +01:00
2012-01-03 14:13:54 +01:00
void ProtocolGame::sendGetQuestLine(int questId)
{
OutputMessage oMsg;
oMsg.addU8(Proto::ClientGetQuestLine);
2012-01-03 14:13:54 +01:00
oMsg.addU16(questId);
send(oMsg);
}
2012-01-02 23:23:54 +01:00
void ProtocolGame::addPosition(OutputMessage& msg, const Position& position)
{
msg.addU16(position.x);
msg.addU16(position.y);
msg.addU8(position.z);
}