SequencedPacket

This commit is contained in:
rajkosto 2009-08-12 19:55:32 +00:00
parent ff1a136ad7
commit 5ef3d99787
21 changed files with 386 additions and 536 deletions

View file

@ -21,11 +21,11 @@
#include "LocalSocket.h"
#include "RemoteSocket.h"
#include <Utility.h>
#include <Sockets/Utility.h>
#include "Util.h"
#include <iostream>
#include "EncryptedPacket.h"
#include "WorldPacket.h"
#include "SequencedPacket.h"
#include "Logging.h"
extern RemoteSocket *worldRemote;
@ -37,15 +37,15 @@ LocalSocket *globalLocalSocket = NULL;
extern CryptoPP::CBC_Mode<CryptoPP::Twofish>::Decryption *TFDecryptCTW;
extern CryptoPP::CBC_Mode<CryptoPP::Twofish>::Encryption *TFEncryptCTW;
extern uint16 CTW_client_sequence;
extern uint16 CTW_server_sequence;
extern uint16 CTW_remoteSeq;
extern uint16 CTW_localSeq;
extern uint8 CTW_flags;
LocalSocket::LocalSocket(ISocketHandler& h)
:UdpSocket(h)
{
CTW_client_sequence = 0;
CTW_server_sequence = 0;
CTW_remoteSeq = 0;
CTW_localSeq = 0;
CTW_flags = 0;
InitializeCriticalSection(&CriticalSection);
@ -53,8 +53,8 @@ LocalSocket::LocalSocket(ISocketHandler& h)
LocalSocket::~LocalSocket()
{
CTW_client_sequence = 0;
CTW_server_sequence = 0;
CTW_remoteSeq = 0;
CTW_localSeq = 0;
CTW_flags = 0;
DeleteCriticalSection(&CriticalSection);
@ -70,12 +70,12 @@ void LocalSocket::Replay( const char *p,size_t l)
EnterCriticalSection(&CriticalSection);
CTW_client_sequence++;
CTW_remoteSeq++;
if (CTW_client_sequence >= 4096)
CTW_client_sequence=0;
if (CTW_remoteSeq >= 4096)
CTW_remoteSeq=0;
WorldPacket replayMePacket(CTW_server_sequence,CTW_client_sequence,CTW_flags,string(p,l));
SequencedPacket replayMePacket(CTW_localSeq,CTW_remoteSeq,CTW_flags,string(p,l));
ByteBuffer replayMePlain = replayMePacket.getDataWithHeader();
EncryptedPacket replayMeCryptor;
replayMeCryptor.append((const byte*)replayMePlain.contents(),replayMePlain.size());

View file

@ -22,7 +22,7 @@
#ifndef LOCALSOCKET_H
#define LOCALSOCKET_H
#include <UdpSocket.h>
#include <Sockets/UdpSocket.h>
class LocalSocket : public UdpSocket

View file

@ -2,7 +2,7 @@
#include "Util.h"
#include "TCPVariableLengthPacket.h"
#include "EncryptedPacket.h"
#include "WorldPacket.h"
#include "SequencedPacket.h"
#pragma pack(1)
@ -67,10 +67,10 @@ void LogPacket(const char *pData,size_t pSize,PacketDirection direction,string c
File.close();
}
void LogWorldPacket(const char *pData,size_t pSize,PacketDirection direction,uint16 sSeq,uint16 cSeq,uint8 flags)
void LogWorldPacket(const char *pData,size_t pSize,PacketDirection direction,uint16 localSeq,uint16 remoteSeq,uint8 flags)
{
stringstream comment;
comment << "PSS: " << hex << (int)flags << " LocalSeq: " << dec << sSeq << " RemoteSeq: " << dec << cSeq;
comment << "PSS: " << hex << (int)flags << " LocalSeq: " << dec << localSeq << " RemoteSeq: " << dec << remoteSeq;
LogPacket(pData,pSize,direction,comment.str());
}
@ -1326,12 +1326,12 @@ string MarginToClient( const char* pData,size_t pSize )
}
}
uint16 CTW_client_sequence = 0;
uint16 CTW_server_sequence = 0;
uint16 CTW_remoteSeq = 0;
uint16 CTW_localSeq = 0;
uint8 CTW_flags = 0;
uint16 WTC_client_sequence = 0;
uint16 WTC_server_sequence = 0;
uint16 WTC_remoteSeq = 0;
uint16 WTC_localSeq = 0;
uint8 WTC_flags = 0;
string ClientToWorld( const char* pData,size_t pSize )
@ -1350,13 +1350,13 @@ string ClientToWorld( const char* pData,size_t pSize )
ByteBuffer encryptedContents;
encryptedContents.append((const byte*)&pData[1],pSize-1); //skip the first byte
EncryptedPacket encryptionless(encryptedContents,TFDecryptCTW);
WorldPacket headerless(encryptionless);
SequencedPacket headerless(encryptionless);
CTW_client_sequence = headerless.getClientSeq();
CTW_server_sequence = headerless.getServerSeq();
CTW_remoteSeq = headerless.getRemoteSeq();
CTW_localSeq = headerless.getLocalSeq();
CTW_flags = headerless.getPSS();
LogWorldPacket(headerless.contents(),headerless.size(),CLIENT_TO_WORLD,CTW_server_sequence,CTW_client_sequence,CTW_flags);
LogWorldPacket(headerless.contents(),headerless.size(),CLIENT_TO_WORLD,CTW_localSeq,CTW_remoteSeq,CTW_flags);
//reencrypt
ByteBuffer reencrypted = encryptionless.toCipherText(TFEncryptCTW);
@ -1384,13 +1384,13 @@ string WorldToClient( const char* pData,size_t pSize )
ByteBuffer encryptedContents;
encryptedContents.append((const byte*)&pData[1],pSize-1); //skip the first byte
EncryptedPacket encryptionless(encryptedContents,TFDecryptWTC);
WorldPacket headerless(encryptionless);
SequencedPacket headerless(encryptionless);
WTC_client_sequence = headerless.getClientSeq();
WTC_server_sequence = headerless.getServerSeq();
WTC_remoteSeq = headerless.getRemoteSeq();
WTC_localSeq = headerless.getLocalSeq();
WTC_flags = headerless.getPSS();
LogWorldPacket(headerless.contents(),headerless.size(),WORLD_TO_CLIENT,WTC_server_sequence,WTC_client_sequence,WTC_flags);
LogWorldPacket(headerless.contents(),headerless.size(),WORLD_TO_CLIENT,WTC_localSeq,WTC_remoteSeq,WTC_flags);
//reencrypt
ByteBuffer reencrypted = encryptionless.toCipherText(TFEncryptWTC);

View file

@ -209,6 +209,14 @@
RelativePath=".\RemoteSocket.cpp"
>
</File>
<File
RelativePath=".\SequencedPacket.cpp"
>
</File>
<File
RelativePath=".\SequencedPacket.h"
>
</File>
<File
RelativePath=".\stprog.cpp"
>
@ -221,14 +229,6 @@
RelativePath=".\Util.cpp"
>
</File>
<File
RelativePath=".\WorldPacket.cpp"
>
</File>
<File
RelativePath=".\WorldPacket.h"
>
</File>
</Filter>
<Filter
Name="Header Files"

View file

@ -17,31 +17,31 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// *************************************************************************************************
#ifndef PROXYHANDLER_H
#define PROXYHANDLER_H
#include <SocketHandler.h>
#ifdef USE_SOLID_MAX
#define MAX_MINIONS 10
#endif
class ProxyHandler : public SocketHandler
{
public:
ProxyHandler();
~ProxyHandler();
void ViewSockets();
};
#endif // PROXYHANDLER_H
// *************************************************************************************************
#ifndef PROXYHANDLER_H
#define PROXYHANDLER_H
#include <Sockets/SocketHandler.h>
#ifdef USE_SOLID_MAX
#define MAX_MINIONS 10
#endif
class ProxyHandler : public SocketHandler
{
public:
ProxyHandler();
~ProxyHandler();
void ViewSockets();
};
#endif // PROXYHANDLER_H

View file

@ -23,7 +23,7 @@
#include "LocalSocket.h"
#include "Util.h"
#include <iostream>
#include "WorldPacket.h"
#include "SequencedPacket.h"
#include "Logging.h"
#include "EncryptedPacket.h"
@ -34,15 +34,15 @@ extern std::string GlobalIP;
RemoteSocket *globalRemoteSocket = NULL;
extern LocalSocket *globalLocalSocket;
extern uint16 WTC_server_sequence;
extern uint16 WTC_client_sequence;
extern uint16 WTC_localSeq;
extern uint16 WTC_remoteSeq;
extern uint8 WTC_flags;
RemoteSocket::RemoteSocket(ISocketHandler& h)
:UdpSocket(h)
{
WTC_server_sequence = 0;
WTC_client_sequence = 0;
WTC_localSeq = 0;
WTC_remoteSeq = 0;
WTC_flags = 0;
InitializeCriticalSection(&CriticalSection);
@ -50,8 +50,8 @@ RemoteSocket::RemoteSocket(ISocketHandler& h)
RemoteSocket::~RemoteSocket()
{
WTC_server_sequence = 0;
WTC_client_sequence = 0;
WTC_localSeq = 0;
WTC_remoteSeq = 0;
WTC_flags = 0;
DeleteCriticalSection(&CriticalSection);
@ -88,12 +88,12 @@ void RemoteSocket::Replay( const char *p,size_t l)
EnterCriticalSection(&CriticalSection);
WTC_server_sequence++;
WTC_localSeq++;
if (WTC_server_sequence >= 4096)
WTC_server_sequence=0;
if (WTC_localSeq >= 4096)
WTC_localSeq=0;
WorldPacket replayMePacket(WTC_server_sequence,WTC_client_sequence,WTC_flags,string(p,l));
SequencedPacket replayMePacket(WTC_localSeq,WTC_remoteSeq,WTC_flags,string(p,l));
ByteBuffer replayMePlain = replayMePacket.getDataWithHeader();
EncryptedPacket replayMeCryptor;
replayMeCryptor.append((const byte*)replayMePlain.contents(),replayMePlain.size());

View file

@ -1,7 +1,7 @@
#ifndef _REMOTESOCKET_H
#define _REMOTESOCKET_H
#include <UdpSocket.h>
#include <Sockets/UdpSocket.h>
class RemoteSocket : public UdpSocket

View file

@ -19,16 +19,9 @@
//
// *************************************************************************************************
#include "WorldPacket.h"
#include "SequencedPacket.h"
#pragma pack(1)
typedef struct
{
} worldPacketHeader_t;
WorldPacket::WorldPacket( ByteBuffer &withHeader )
SequencedPacket::SequencedPacket( ByteBuffer withHeader )
{
uint32 packedSeqs; //FL CC CS SS
@ -36,8 +29,8 @@ WorldPacket::WorldPacket( ByteBuffer &withHeader )
withHeader >> packedSeqs;
uint32 packed = swap32(packedSeqs);
serverSequence = packed&0xFFF;
clientSequence = (packed>>12)&0xFFF;
localSeq = packed&0xFFF;
remoteSeq = (packed>>12)&0xFFF;
playerSetupState = (packed>>24)&0xFF;
vector<byte> restOfPacket;
@ -46,21 +39,19 @@ WorldPacket::WorldPacket( ByteBuffer &withHeader )
this->clear();
this->append(&restOfPacket[0],restOfPacket.size());
withHeader.rpos(0);
}
WorldPacket::WorldPacket( string &withHeader )
SequencedPacket::SequencedPacket( const string &withHeader )
{
ByteBuffer simulation;
simulation.append((const byte*)withHeader.data(),withHeader.size());
WorldPacket::WorldPacket(simulation);
SequencedPacket::SequencedPacket(simulation);
}
ByteBuffer WorldPacket::getDataWithHeader()
ByteBuffer SequencedPacket::getDataWithHeader()
{
uint32 packedSeqs = swap32((playerSetupState << 24) | ((clientSequence & 0xFFF) << 12) | (serverSequence & 0xFFF)); // FL CC CS SS
uint32 packedSeqs = swap32((playerSetupState << 24) | ((remoteSeq & 0xFFF) << 12) | (localSeq & 0xFFF)); // FL CC CS SS
ByteBuffer returnMe;
returnMe << packedSeqs;

View file

@ -22,63 +22,68 @@
#include "Util.h"
#include "ByteBuffer.h"
class WorldPacket : public ByteBuffer
class SequencedPacket : public ByteBuffer
{
public:
WorldPacket()
SequencedPacket()
{
setSequences(0,0);
setPlayerSetupState(0);
this->clear();
}
WorldPacket(uint16 sSeq,uint16 cSeq,uint8 pss)
SequencedPacket(uint16 _localSeq,uint16 _remoteSeq,uint8 pss)
{
setSequences(sSeq,cSeq);
setSequences(_localSeq,_remoteSeq);
setPlayerSetupState(pss);
this->clear();
}
WorldPacket(uint16 sSeq,uint16 cSeq,uint8 pss,string &headerless)
SequencedPacket(uint16 _localSeq,uint16 _remoteSeq,uint8 pss,const string &headerless)
{
setSequences(sSeq,cSeq);
setSequences(_localSeq,_remoteSeq);
setPlayerSetupState(pss);
this->clear();
this->append((const byte*)headerless.data(),headerless.size());
}
WorldPacket(uint16 sSeq,uint16 cSeq,uint8 pss,ByteBuffer &headerless)
SequencedPacket(uint16 _localSeq,uint16 _remoteSeq,uint8 pss,const ByteBuffer &headerless)
{
setSequences(sSeq,cSeq);
setSequences(_localSeq,_remoteSeq);
setPlayerSetupState(pss);
this->clear();
this->append((const byte*)headerless.contents(),headerless.size());
}
WorldPacket(ByteBuffer &withHeader);
WorldPacket(string &withHeader);
~WorldPacket()
SequencedPacket(ByteBuffer withHeader);
SequencedPacket(const string &withHeader);
~SequencedPacket()
{
}
void setSequences(unsigned short sSeq,unsigned short cSeq)
void setSequences(uint16 _localSeq,uint16 _remoteSeq)
{
serverSequence = sSeq;
clientSequence = cSeq;
this->localSeq = _localSeq;
this->remoteSeq = _remoteSeq;
}
void setPlayerSetupState(byte pss)
{
playerSetupState = pss;
}
void setData(string &headerless)
void setData(const string &headerless)
{
this->clear();
this->append((const byte*)headerless.data(),headerless.size());
}
unsigned short getClientSeq()
void setData(const ByteBuffer &headerless)
{
return clientSequence;
this->clear();
this->append((const byte*)headerless.contents(),headerless.size());
}
unsigned short getServerSeq()
unsigned short getRemoteSeq()
{
return serverSequence;
return remoteSeq;
}
unsigned short getLocalSeq()
{
return localSeq;
}
byte getPSS()
{
@ -93,7 +98,7 @@ public:
}
ByteBuffer getDataWithHeader();
private:
uint16 serverSequence;
uint16 clientSequence;
uint16 localSeq;
uint16 remoteSeq;
uint8 playerSetupState;
};

View file

@ -23,10 +23,11 @@
#include "GameClient.h"
#include "Timer.h"
#include "InPacket.h"
#include "GameResponses.h"
#include "Util.h"
#include "MersenneTwister.h"
#include "EncryptedPacket.h"
#include "SequencedPacket.h"
uint8 twofishkeyz[16] = {0x6C, 0xAB, 0x8E, 0xCC, 0xE7, 0x3C, 0x22, 0x47, 0xDB, 0xEB, 0xDE, 0x1A, 0xA8, 0xE7, 0x5F, 0xB8};
@ -73,94 +74,103 @@ void GameClient::HandlePacket(char *pData, uint16 nLength)
{
if (pData[0] == 0x01)
{
std::string decrypted;
if (Decrypt(pData,nLength,decrypted))
SequencedPacket packetData=Decrypt(&pData[1],nLength-1);
client_sequence = packetData.getLocalSeq();
cout << "CSeq: " << packetData.getLocalSeq() << " SSeq: " << packetData.getRemoteSeq();
cout << " " << Bin2Hex(packetData) << endl;
string contents = string(packetData.contents(),packetData.size());
string::size_type loc = contents.find( "Spawnalot", 0 );
if( loc != std::string::npos )
{
client_sequence++;
if (client_sequence == 4096)
client_sequence=0;
IncomingPacket thepaxor(decrypted);
std::cout << "CSeq: " << thepaxor.client_sequence << " SSeq: " << thepaxor.server_sequence;
std::string contents = thepaxor.ToString();
std::cout << " " << Bin2Hex(contents) << std::endl;
std::string::size_type loc = contents.find( "Spawnalot", 0 );
if( loc != std::string::npos )
{
if (PlayerSetupState==0x7F)
Send(std::string((const char *)rawData,sizeof(rawData)));
else {} //WTF
}
loc = contents.find( "Spawnanother", 0 );
if( loc != std::string::npos )
{
if (PlayerSetupState==0x7F)
Send(std::string((const char *)rawData2,sizeof(rawData2)));
else {} //WTF
}
/*
loc = contents.find( "Move", 0 );
if( loc != std::string::npos )
{
if (PlayerSetupState==0x7F)
Send(std::string((const char *)move,sizeof(move)));
else {} //WTF
}*/
if (PlayerSetupState==0x7F)
Send(std::string((const char *)rawData,sizeof(rawData)));
else {} //WTF
}
loc = contents.find( "Spawnanother", 0 );
if( loc != std::string::npos )
{
if (PlayerSetupState==0x7F)
Send(std::string((const char *)rawData2,sizeof(rawData2)));
else {} //WTF
}
/*
loc = contents.find( "Move", 0 );
if( loc != std::string::npos )
{
if (PlayerSetupState==0x7F)
Send(std::string((const char *)move,sizeof(move)));
else {} //WTF
}*/
}
switch(numPackets)
{
case 1:
for (unsigned int i=0;i<5;i++)
{
int clientlen=sizeof(_address);
sendto(*_sock, (const char *)GAMEResponseTo1_1_2_3_4_5, sizeof(GAMEResponseTo1_1_2_3_4_5), 0, (struct sockaddr*)&_address, clientlen);
for (unsigned int i=0;i<5;i++)
{
int clientlen=sizeof(_address);
sendto(*_sock, (const char *)GAMEResponseTo1_1_2_3_4_5, sizeof(GAMEResponseTo1_1_2_3_4_5), 0, (struct sockaddr*)&_address, clientlen);
}
Send(ByteBuffer(GAMEResponseTo1_6,sizeof(GAMEResponseTo1_6)));
Send(ByteBuffer(GAMEResponseTo1_7,sizeof(GAMEResponseTo1_7)));
Send(ByteBuffer(GAMEResponseTo1_8,sizeof(GAMEResponseTo1_8)));
Send(ByteBuffer(GAMEResponseTo1_9,sizeof(GAMEResponseTo1_9)));
Send(ByteBuffer(GAMEResponseTo1_10,sizeof(GAMEResponseTo1_10)));
Send(ByteBuffer(GAMEResponseTo1_11,sizeof(GAMEResponseTo1_11)));
Send(ByteBuffer(GAMEResponseTo1_12,sizeof(GAMEResponseTo1_12)));
Send(ByteBuffer(GAMEResponseTo1_13,sizeof(GAMEResponseTo1_13)));
Send(ByteBuffer(GAMEResponseTo1_14,sizeof(GAMEResponseTo1_14)));
Send(ByteBuffer(GAMEResponseTo1_15,sizeof(GAMEResponseTo1_15)));
Send(ByteBuffer(GAMEResponseTo1_16,sizeof(GAMEResponseTo1_16)));
Send(ByteBuffer(GAMEResponseTo1_17,sizeof(GAMEResponseTo1_17)));
Send(ByteBuffer(GAMEResponseTo1_18,sizeof(GAMEResponseTo1_18)));
Send(ByteBuffer(GAMEResponseTo1_19,sizeof(GAMEResponseTo1_19)));
Send(ByteBuffer(GAMEResponseTo1_20,sizeof(GAMEResponseTo1_20)));
break;
}
Send(std::string((const char *)GAMEResponseTo1_6,sizeof(GAMEResponseTo1_6)));
Send(std::string((const char *)GAMEResponseTo1_7,sizeof(GAMEResponseTo1_7)));
Send(std::string((const char *)GAMEResponseTo1_8,sizeof(GAMEResponseTo1_8)));
Send(std::string((const char *)GAMEResponseTo1_9,sizeof(GAMEResponseTo1_9)));
Send(std::string((const char *)GAMEResponseTo1_10,sizeof(GAMEResponseTo1_10)));
Send(std::string((const char *)GAMEResponseTo1_11,sizeof(GAMEResponseTo1_11)));
Send(std::string((const char *)GAMEResponseTo1_12,sizeof(GAMEResponseTo1_12)));
Send(std::string((const char *)GAMEResponseTo1_13,sizeof(GAMEResponseTo1_13)));
Send(std::string((const char *)GAMEResponseTo1_14,sizeof(GAMEResponseTo1_14)));
Send(std::string((const char *)GAMEResponseTo1_15,sizeof(GAMEResponseTo1_15)));
Send(std::string((const char *)GAMEResponseTo1_16,sizeof(GAMEResponseTo1_16)));
Send(std::string((const char *)GAMEResponseTo1_17,sizeof(GAMEResponseTo1_17)));
Send(std::string((const char *)GAMEResponseTo1_18,sizeof(GAMEResponseTo1_18)));
Send(std::string((const char *)GAMEResponseTo1_19,sizeof(GAMEResponseTo1_19)));
Send(std::string((const char *)GAMEResponseTo1_20,sizeof(GAMEResponseTo1_20)));
break;
case 2:
PlayerSetupState = 1;
Send(std::string((const char *)GAMEResponseTo2,sizeof(GAMEResponseTo2)));
break;
{
PlayerSetupState = 1;
Send(ByteBuffer(GAMEResponseTo2,sizeof(GAMEResponseTo2)));
break;
}
case 5:
Send(std::string((const char *)GAMEResponseTo5,sizeof(GAMEResponseTo5)));
break;
{
Send(ByteBuffer(GAMEResponseTo5,sizeof(GAMEResponseTo5)));
break;
}
case 6:
PlayerSetupState = 0x1F;
Send(std::string((const char *)GAMEResponseTo6_1_header,sizeof(GAMEResponseTo6_1_header)) +
name + std::string((const char *)GAMEResponseTo6_1_footer,sizeof(GAMEResponseTo6_1_footer)));
Send(std::string((const char *)GAMEResponseTo6_2,sizeof(GAMEResponseTo6_2)));
Send(std::string((const char *)GAMEResponseTo6_4,sizeof(GAMEResponseTo6_4)));
Send(std::string((const char *)GAMEResponseTo6_6,sizeof(GAMEResponseTo6_6)));
break;
{
PlayerSetupState = 0x1F;
ByteBuffer response;
response.append(GAMEResponseTo6_1_header,sizeof(GAMEResponseTo6_1_header));
response.append(name);
response.append(GAMEResponseTo6_1_footer,sizeof(GAMEResponseTo6_1_footer));
Send(response);
Send(ByteBuffer(GAMEResponseTo6_2,sizeof(GAMEResponseTo6_2)));
Send(ByteBuffer(GAMEResponseTo6_4,sizeof(GAMEResponseTo6_4)));
Send(ByteBuffer(GAMEResponseTo6_6,sizeof(GAMEResponseTo6_6)));
break;
}
case 9:
PlayerSetupState = 0x7F;
/* sendme.FromString(std::string((const char *)GAMEResponseTo9_1_header,sizeof(GAMEResponseTo9_1_header)));
sendme.Append(name);
sendme.Append(std::string((const char *)GAMEResponseTo9_1_footer,sizeof(GAMEResponseTo9_1_footer)));
Send(sendme);*/
Send(std::string((const char *)GAMEResponseTo9_2,sizeof(GAMEResponseTo9_2)));
Handled_Session=true;
break;
{
PlayerSetupState = 0x7F;
/* sendme.FromString(std::string((const char *)GAMEResponseTo9_1_header,sizeof(GAMEResponseTo9_1_header)));
sendme.Append(name);
sendme.Append(std::string((const char *)GAMEResponseTo9_1_footer,sizeof(GAMEResponseTo9_1_footer)));
Send(sendme);*/
Send(std::string((const char *)GAMEResponseTo9_2,sizeof(GAMEResponseTo9_2)));
Handled_Session=true;
break;
}
}
if (Handled_Session)
@ -170,62 +180,25 @@ void GameClient::HandlePacket(char *pData, uint16 nLength)
}
}
bool GameClient::Decrypt(char *pData, uint16 nLength,std::string &output)
SequencedPacket GameClient::Decrypt(char *pData, uint16 nLength)
{
std::string vector(pData+1,16);
TFDecrypt->Resynchronize((const byte *)vector.data());
std::string input(pData+17,nLength-17);
output.clear();
CryptoPP::StringSource(input, true, new CryptoPP::StreamTransformationFilter(*TFDecrypt, new CryptoPP::StringSink(output)));
//output now contains crc len time data
std::string crc32 = std::string(output.data(),sizeof(uint32));
uint16 length;
memcpy(&length,output.data()+sizeof(uint32),sizeof(uint16));
std::string computedcrc;
CryptoPP::CRC32 hash;
CryptoPP::StringSource(std::string(output.data()+sizeof(uint32),length+sizeof(uint32)+sizeof(uint16)), true,new CryptoPP::HashFilter(hash,new CryptoPP::StringSink(computedcrc)));
if (memcmp(crc32.data(),computedcrc.data(),sizeof(uint32)))
return false;
output = std::string(output.data()+sizeof(uint32)+sizeof(uint16)+sizeof(uint32),length);
return true;
EncryptedPacket decryptedData(ByteBuffer(pData,nLength),TFDecrypt);
return SequencedPacket(decryptedData);
}
void GameClient::Send(const std::string &contents)
void GameClient::Send(const ByteBuffer &contents)
{
server_sequence++;
if (server_sequence == 4096)
server_sequence=0;
OutgoingPacket packet(PlayerSetupState,client_sequence,server_sequence);
packet.FromString(contents);
std::string buffer = packet.ToString();
uint16 lenght = (uint16)buffer.size();
uint32 time = getTime();
std::string input = std::string((const char*)&lenght,sizeof(lenght)) + std::string((const char*)&time,sizeof(time)) + buffer; //len+time+data
std::string crc32;
std::string output;
CryptoPP::CRC32 hash;
CryptoPP::StringSource(input, true,new CryptoPP::HashFilter(hash,new CryptoPP::StringSink(crc32))); //output2 now has crc
output = crc32 + input; //add the rest onto the crc,output now contains crc len time data
byte vector[16];
for (uint32 i=0;i < sizeof(vector); i++)
{
vector[i] = rand()%255;
}
TFEncrypt->Resynchronize(vector);
input.clear();
CryptoPP::StringSource(output, true, new CryptoPP::StreamTransformationFilter(*TFEncrypt, new CryptoPP::StringSink(input))); // output now has encrypted shit
input = char(0x01) + std::string((const char*)vector,sizeof(vector)) + input; // input has whole packet now
SequencedPacket withSequences(server_sequence,client_sequence,PlayerSetupState,contents);
EncryptedPacket withEncryption(withSequences.getDataWithHeader());
ByteBuffer sendMe;
sendMe << uint8(1);
sendMe.append(withEncryption.toCipherText(TFEncrypt));
int clientlen=sizeof(_address);
sendto(*_sock, input.data(), (int)input.size(), 0, (struct sockaddr*)&_address,clientlen);
sendto(*_sock, sendMe.contents(), (int)sendMe.size(), 0, (struct sockaddr*)&_address,clientlen);
}

View file

@ -22,8 +22,8 @@
#ifndef MXOSIM_GAMECLIENT_H
#define MXOSIM_GAMECLIENT_H
#include "OutPacket.h"
#include "Crypto.h"
#include "SequencedPacket.h"
class GameClient
{
@ -32,7 +32,7 @@ class GameClient
bool Valid_Client;
bool Handled_Session;
// Master Sock handle, client's address structure, last recieved packet
// Master Sock handle, client's address structure, last received packet
SOCKET *_sock;
struct sockaddr_in _address;
uint32 _last_activity;
@ -46,10 +46,9 @@ class GameClient
uint16 client_sequence;
// Client tick count
uint16 tick;
uint32 tick;
//Player name lol
std::string name;
CryptoPP::CBC_Mode<CryptoPP::Twofish>::Decryption *TFDecrypt;
@ -57,7 +56,7 @@ class GameClient
public:
GameClient(sockaddr_in, SOCKET*);
GameClient(sockaddr_in address, SOCKET *sock);
~GameClient();
inline uint32 LastActive() { return _last_activity; }
@ -65,8 +64,8 @@ class GameClient
char *Address() { return inet_ntoa(_address.sin_addr); }
void HandlePacket(char *pData, uint16 Length);
bool Decrypt(char *pData, uint16 nLength,std::string &output);
void Send(const std::string &contents);
SequencedPacket Decrypt(char *pData, uint16 nLength);
void Send(const ByteBuffer &contents);
};
#endif

View file

@ -24,6 +24,7 @@
#include "Log.h"
#include "Timer.h"
#include "Config.h"
#include "Sockets.h"
initialiseSingleton( GameServer );

View file

@ -1,37 +0,0 @@
// *************************************************************************************************
// --------------------------------------
// Copyright (C) 2006-2010 Rajko Stojadinovic
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// *************************************************************************************************
#include "InPacket.h"
IncomingPacket::IncomingPacket(std::string &source)
{
uint32 packed;
memcpy(&packed,source.data(),sizeof(packed));
packed= ntohl(packed);
client_sequence = uint16(packed&0xFFF);
server_sequence = uint16((packed>>12)&0xFFF);
flags = uint8((packed>>24)&0xFF);
contents << std::string(source.data()+sizeof(packed),source.size()-sizeof(packed));
}
IncomingPacket::~IncomingPacket()
{
}

View file

@ -1,39 +0,0 @@
// *************************************************************************************************
// --------------------------------------
// Copyright (C) 2006-2010 Rajko Stojadinovic
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// *************************************************************************************************
#ifndef MXOSIM_INPACKET_H
#define MXOSIM_INPACKET_H
#include "Packet.h"
class IncomingPacket : public Packet
{
public:
IncomingPacket(std::string &source);
~IncomingPacket();
uint8 flags;
uint16 server_sequence;
uint16 client_sequence;
};
#endif

View file

@ -1,50 +0,0 @@
// *************************************************************************************************
// --------------------------------------
// Copyright (C) 2006-2010 Rajko Stojadinovic
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// *************************************************************************************************
#include "OutPacket.h"
#include "Util.h"
OutgoingPacket::OutgoingPacket(uint8 flagz,uint16 client_sequencez,uint16 server_sequencez)
{
flags = flagz;
client_sequence = client_sequencez;
server_sequence = server_sequencez;
}
OutgoingPacket::~OutgoingPacket()
{}
void OutgoingPacket::PreSave()
{
contents.clear();
uint32 storage = htonl((flags << 24) | ((client_sequence & 0xFFF) << 12) | (server_sequence & 0xFFF)); // FL CC CS SS
contents << storage;
/*
std::string nub;
ConvertBytesintoHex((const byte*)&storage,nub,sizeof(storage));
std::cout << nub << std::endl;*/
}
void OutgoingPacket::FromString(const std::string &string)
{
PreSave();
contents.append(string);
}

View file

@ -1,42 +0,0 @@
// *************************************************************************************************
// --------------------------------------
// Copyright (C) 2006-2010 Rajko Stojadinovic
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// *************************************************************************************************
#ifndef MXOSIM_OUTPACKET_H
#define MXOSIM_OUTPACKET_H
#include "Packet.h"
class OutgoingPacket : public Packet
{
public:
OutgoingPacket(uint8 flagz,uint16 client_sequencez,uint16 server_sequencez);
~OutgoingPacket();
uint8 flags;
uint16 client_sequence;
uint16 server_sequence;
void PreSave();
// virtual void Save() = 0;
void FromString(const std::string &string);
};
#endif

View file

@ -1,61 +0,0 @@
// *************************************************************************************************
// --------------------------------------
// Copyright (C) 2006-2010 Rajko Stojadinovic
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// *************************************************************************************************
#include "Packet.h"
Packet::Packet()
{
}
Packet::~Packet()
{
}
void Packet::Clear()
{
contents.clear();
}
uint16 Packet::Size()
{
return contents.size();
}
void Packet::FromString(std::string &string)
{
contents.clear();
contents.append(string);
}
std::string Packet::ToString()
{
uint8 *data=new uint8[contents.size()];
contents.rpos(0);
contents.read(data,contents.size());
std::string hax = std::string((const char *)data,contents.size());
delete[] data;
return hax;
}
void Packet::Append(std::string &string)
{
contents.append(string);
}

View file

@ -1,44 +0,0 @@
// *************************************************************************************************
// --------------------------------------
// Copyright (C) 2006-2010 Rajko Stojadinovic
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// *************************************************************************************************
#ifndef MXOSIM_PACKET_H
#define MXOSIM_PACKET_H
#include "Common.h"
#include "ByteBuffer.h"
#include "Sockets.h"
class Packet
{
public:
Packet();
~Packet();
uint16 Size();
void Clear();
void FromString(std::string &string);
void Append(std::string &string);
std::string ToString();
protected:
ByteBuffer contents;
};
#endif

View file

@ -332,27 +332,11 @@
>
</File>
<File
RelativePath=".\InPacket.cpp"
RelativePath=".\SequencedPacket.cpp"
>
</File>
<File
RelativePath=".\InPacket.h"
>
</File>
<File
RelativePath=".\OutPacket.cpp"
>
</File>
<File
RelativePath=".\OutPacket.h"
>
</File>
<File
RelativePath=".\Packet.cpp"
>
</File>
<File
RelativePath=".\Packet.h"
RelativePath=".\SequencedPacket.h"
>
</File>
</Filter>

View file

@ -0,0 +1,61 @@
// *************************************************************************************************
// --------------------------------------
// Copyright (C) 2006-2010 Rajko Stojadinovic
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// *************************************************************************************************
#include "SequencedPacket.h"
SequencedPacket::SequencedPacket( ByteBuffer withHeader )
{
uint32 packedSeqs; //FL CC CS SS
withHeader.rpos(0);
withHeader >> packedSeqs;
uint32 packed = swap32(packedSeqs);
localSeq = packed&0xFFF;
remoteSeq = (packed>>12)&0xFFF;
playerSetupState = (packed>>24)&0xFF;
vector<byte> restOfPacket;
restOfPacket.resize(withHeader.size() - withHeader.rpos());
withHeader.read(&restOfPacket[0],restOfPacket.size());
this->clear();
this->append(&restOfPacket[0],restOfPacket.size());
}
SequencedPacket::SequencedPacket( const string &withHeader )
{
ByteBuffer simulation;
simulation.append((const byte*)withHeader.data(),withHeader.size());
SequencedPacket::SequencedPacket(simulation);
}
ByteBuffer SequencedPacket::getDataWithHeader()
{
uint32 packedSeqs = swap32((playerSetupState << 24) | ((remoteSeq & 0xFFF) << 12) | (localSeq & 0xFFF)); // FL CC CS SS
ByteBuffer returnMe;
returnMe << packedSeqs;
returnMe.append(this->contents(),this->size());
return returnMe;
}

View file

@ -0,0 +1,109 @@
// *************************************************************************************************
// --------------------------------------
// Copyright (C) 2006-2010 Rajko Stojadinovic
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// *************************************************************************************************
#ifndef SEQUENCEDPACKET_H
#define SEQUENCEDPACKET_H
#include "Util.h"
#include "ByteBuffer.h"
class SequencedPacket : public ByteBuffer
{
public:
SequencedPacket()
{
setSequences(0,0);
setPlayerSetupState(0);
this->clear();
}
SequencedPacket(uint16 _localSeq,uint16 _remoteSeq,uint8 pss)
{
setSequences(_localSeq,_remoteSeq);
setPlayerSetupState(pss);
this->clear();
}
SequencedPacket(uint16 _localSeq,uint16 _remoteSeq,uint8 pss,const string &headerless)
{
setSequences(_localSeq,_remoteSeq);
setPlayerSetupState(pss);
this->clear();
this->append((const byte*)headerless.data(),headerless.size());
}
SequencedPacket(uint16 _localSeq,uint16 _remoteSeq,uint8 pss,const ByteBuffer &headerless)
{
setSequences(_localSeq,_remoteSeq);
setPlayerSetupState(pss);
this->clear();
this->append((const byte*)headerless.contents(),headerless.size());
}
SequencedPacket(ByteBuffer withHeader);
SequencedPacket(const string &withHeader);
~SequencedPacket()
{
}
void setSequences(uint16 _localSeq,uint16 _remoteSeq)
{
this->localSeq = _localSeq;
this->remoteSeq = _remoteSeq;
}
void setPlayerSetupState(byte pss)
{
playerSetupState = pss;
}
void setData(const string &headerless)
{
this->clear();
this->append((const byte*)headerless.data(),headerless.size());
}
void setData(const ByteBuffer &headerless)
{
this->clear();
this->append((const byte*)headerless.contents(),headerless.size());
}
unsigned short getRemoteSeq()
{
return remoteSeq;
}
unsigned short getLocalSeq()
{
return localSeq;
}
byte getPSS()
{
return playerSetupState;
}
ByteBuffer getData()
{
ByteBuffer zeReturn;
zeReturn.append((const byte*)this->contents(),this->size());
zeReturn.rpos(0);
return zeReturn;
}
ByteBuffer getDataWithHeader();
private:
uint16 localSeq;
uint16 remoteSeq;
uint8 playerSetupState;
};
#endif