415 lines
8.5 KiB
C++
415 lines
8.5 KiB
C++
/*
|
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include "protocolgame.h"
|
|
#include <framework/net/rsa.h>
|
|
|
|
void ProtocolGame::sendLoginPacket(uint32 timestamp, uint8 unknown)
|
|
{
|
|
OutputMessage oMsg;
|
|
|
|
oMsg.addU8(Otc::ClientEnterGame);
|
|
oMsg.addU16(Otc::OsLinux);
|
|
oMsg.addU16(Otc::ClientVersion);
|
|
|
|
oMsg.addU8(0); // first RSA byte must be 0
|
|
|
|
// xtea key
|
|
generateXteaKey();
|
|
oMsg.addU32(m_xteaKey[0]);
|
|
oMsg.addU32(m_xteaKey[1]);
|
|
oMsg.addU32(m_xteaKey[2]);
|
|
oMsg.addU32(m_xteaKey[3]);
|
|
|
|
oMsg.addU8(0); // is gm set?
|
|
oMsg.addString(m_accountName);
|
|
oMsg.addString(m_characterName);
|
|
oMsg.addString(m_accountPassword);
|
|
|
|
oMsg.addU32(timestamp);
|
|
oMsg.addU8(unknown);
|
|
|
|
// complete the 128 bytes for rsa encryption with zeros
|
|
oMsg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length()));
|
|
|
|
// encrypt with RSA
|
|
Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, Otc::OtservPublicRSA);
|
|
|
|
send(oMsg);
|
|
|
|
enableXteaEncryption();
|
|
}
|
|
|
|
void ProtocolGame::sendLogout()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientQuitGame);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendPing()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientPingBack);
|
|
send(oMsg);
|
|
}
|
|
|
|
// autowalk
|
|
|
|
void ProtocolGame::sendWalkNorth()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientGoNorth);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendWalkEast()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientGoEast);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendWalkSouth()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientGoSouth);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendWalkWest()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientGoWest);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendStopAutowalk()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientStop);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendWalkNorthEast()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientGoNorthEast);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendWalkSouthEast()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientGoSouthEast);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendWalkSouthWest()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientGoSouthWest);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendWalkNorthWest()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientGoNorthWest);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendTurnNorth()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientRotateNorth);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendTurnEast()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientRotateEast);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendTurnSouth()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientRotateSouth);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendTurnWest()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientRotateWest);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendThrow(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count)
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientMoveObject);
|
|
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(Otc::ClientInspectNpcTrade);
|
|
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(Otc::ClientBuyObject);
|
|
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(Otc::ClientSellObject);
|
|
oMsg.addU16(thingId);
|
|
oMsg.addU8(count);
|
|
oMsg.addU8(amount);
|
|
oMsg.addU8(ignoreEquipped ? 0x01 : 0x00);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendCloseShop()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientCloseNpcTrade);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendRequestTrade(const Position& pos, int thingId, int stackpos, int playerId)
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientTradeObject);
|
|
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(Otc::ClientInspectTrade);
|
|
oMsg.addU8(counterOffer ? 0x01 : 0x00);
|
|
oMsg.addU8(index);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendAcceptTrade()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientAcceptTrade);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendRejectTrade()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientRejectTrade);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendUseItem(const Position& position, int itemId, int stackpos, int index)
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientUseObject);
|
|
addPosition(oMsg, position);
|
|
oMsg.addU16(itemId);
|
|
oMsg.addU8(stackpos);
|
|
oMsg.addU8(index);
|
|
send(oMsg);
|
|
}
|
|
|
|
// use item ex
|
|
|
|
// battle window
|
|
|
|
// rotate item
|
|
|
|
// close container
|
|
|
|
// up arrow container
|
|
|
|
// text window
|
|
|
|
// house window
|
|
|
|
void ProtocolGame::sendLookAt(const Position& position, int thingId, int stackpos)
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientLook);
|
|
addPosition(oMsg, position);
|
|
oMsg.addU16(thingId);
|
|
oMsg.addU8(stackpos);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message)
|
|
{
|
|
if(message.length() > 255 || message.length() <= 0)
|
|
return;
|
|
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientTalk);
|
|
|
|
assert(channelType >= 0);
|
|
oMsg.addU8(channelType);
|
|
|
|
switch(channelType) {
|
|
case Otc::SpeakPrivate:
|
|
case Otc::SpeakPrivateRed:
|
|
oMsg.addString(receiver);
|
|
break;
|
|
case Otc::SpeakChannelYellow:
|
|
case Otc::SpeakChannelRed:
|
|
oMsg.addU16(channelId);
|
|
break;
|
|
}
|
|
|
|
oMsg.addString(message);
|
|
send(oMsg);
|
|
}
|
|
|
|
// get channels
|
|
|
|
// open channels
|
|
|
|
// close channel
|
|
|
|
// open priv
|
|
|
|
// process report
|
|
|
|
// gm closes report
|
|
|
|
// cancel report
|
|
|
|
// close npc
|
|
|
|
// fight modes
|
|
|
|
// attack
|
|
|
|
// follow
|
|
|
|
// invite to party
|
|
|
|
// join party
|
|
|
|
// revoke party invitation
|
|
|
|
// pass party leadership
|
|
|
|
// leave party
|
|
|
|
// enable shared exp
|
|
|
|
// create private channel
|
|
|
|
// channel invite
|
|
|
|
// channel exclude
|
|
|
|
// cancel move
|
|
|
|
// update tile
|
|
|
|
// update container
|
|
|
|
void ProtocolGame::sendGetOutfit()
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientGetOutfit);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendSetOutfit(const Outfit& outfit)
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientSetOutfit);
|
|
|
|
oMsg.addU16(outfit.getType());
|
|
oMsg.addU8(outfit.getHead());
|
|
oMsg.addU8(outfit.getBody());
|
|
oMsg.addU8(outfit.getLegs());
|
|
oMsg.addU8(outfit.getFeet());
|
|
oMsg.addU8(outfit.getAddons());
|
|
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendAddVip(const std::string& name)
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientAddBuddy);
|
|
oMsg.addString(name);
|
|
send(oMsg);
|
|
}
|
|
|
|
void ProtocolGame::sendRemoveVip(int id)
|
|
{
|
|
OutputMessage oMsg;
|
|
oMsg.addU8(Otc::ClientRemoveBuddy);
|
|
oMsg.addU32(id);
|
|
send(oMsg);
|
|
}
|
|
|
|
// bug report
|
|
|
|
// violation window
|
|
|
|
// debug assert
|
|
|
|
// quest log
|
|
|
|
// quest line
|
|
|
|
void ProtocolGame::addPosition(OutputMessage& msg, const Position& position)
|
|
{
|
|
msg.addU16(position.x);
|
|
msg.addU16(position.y);
|
|
msg.addU8(position.z);
|
|
}
|