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

202 lines
4.7 KiB
C++
Raw Normal View History

2011-08-28 15:17:58 +02:00
/*
* Copyright (c) 2010-2011 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.
*/
2011-08-15 16:11:24 +02:00
#include "protocolgame.h"
2011-08-16 02:30:31 +02:00
#include <framework/net/rsa.h>
void ProtocolGame::sendLoginPacket(uint32 timestamp, uint8 unknown)
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientEnterGame);
2011-11-03 01:55:50 +01:00
oMsg.addU16(Otc::OsLinux);
2011-08-31 18:49:51 +02:00
oMsg.addU16(Otc::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
if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, Otc::OtservPublicRSA))
2011-08-16 02:30:31 +02:00
return;
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;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientQuitGame);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
void ProtocolGame::sendPing()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientPingBack);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkNorth()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientGoNorth);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkEast()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientGoEast);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkSouth()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientGoSouth);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkWest()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientGoWest);
2011-08-15 16:11:24 +02:00
send(oMsg);
}
2011-08-29 07:54:28 +02:00
void ProtocolGame::sendWalkNorthEast()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientGoNorthEast);
2011-08-29 07:54:28 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkSouthEast()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientGoSouthEast);
2011-08-29 07:54:28 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkSouthWest()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientGoSouthWest);
2011-08-29 07:54:28 +02:00
send(oMsg);
}
void ProtocolGame::sendWalkNorthWest()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientGoNorthWest);
2011-08-29 07:54:28 +02:00
send(oMsg);
}
void ProtocolGame::sendTurnNorth()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientRotateNorth);
send(oMsg);
}
void ProtocolGame::sendTurnEast()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientRotateEast);
send(oMsg);
}
void ProtocolGame::sendTurnSouth()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientRotateSouth);
send(oMsg);
}
void ProtocolGame::sendTurnWest()
{
OutputMessage oMsg;
2011-08-31 18:49:51 +02:00
oMsg.addU8(Otc::ClientRotateWest);
send(oMsg);
}
2011-09-03 00:52:40 +02:00
2011-11-03 17:26:17 +01:00
void ProtocolGame::sendTalk(int channelType, 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;
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);
}
2011-09-03 00:52:40 +02:00
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);
}