diff --git a/server/gameserver/GCListener.cc b/server/gameserver/GCListener.cc index 08a5664..35ed4cd 100644 --- a/server/gameserver/GCListener.cc +++ b/server/gameserver/GCListener.cc @@ -11,10 +11,58 @@ #include "jsondatamgr.h" #include "handlermgr.h" +const static size_t CRYPTED_SEND_LEN = 4; +const static size_t CRYPTED_RECV_LEN = 6; + class GGClientSession: public a8::MixedSession { public: + virtual void Reset() override + { + a8::MixedSession::Reset(); + send_i_ = 0; + send_j_ = 0; + recv_i_ = 0; + recv_j_ = 0; + initialized_ = false; + } + + void DecryptRecv(unsigned char* data, size_t len) + { + if (!initialized_) { + return; + } + if (len < CRYPTED_RECV_LEN) { + return; + } + for (size_t t = 0; t < CRYPTED_RECV_LEN; t++) { + recv_i_ %= key_.size(); + unsigned char x = (data[t] - recv_j_) ^ key_[recv_i_]; + ++recv_i_; + recv_j_ = data[t]; + data[t] = x; + } + } + + void EncryptSend(unsigned char* data, size_t len) + { + if (!initialized_) { + return; + } + + if (len < CRYPTED_SEND_LEN) { + return; + } + + for (size_t t = 0; t < CRYPTED_SEND_LEN; t++) { + send_i_ %= key_.size(); + unsigned char x = (data[t] ^ key_[send_i_]) + send_j_; + ++send_i_; + data[t] = send_j_ = x; + } + } + virtual void DecodeUserPacket(char* buf, int& offset, unsigned int buflen) override { #if 1 @@ -67,6 +115,13 @@ public: .SetParam1(1)); } +private: + std::vector key_; + unsigned char send_i_ = 0; + unsigned char send_j_ = 0; + unsigned char recv_i_ = 0; + unsigned char recv_j_ = 0; + bool initialized_ = false; }; static void CreateGameClientSocket(a8::TcpSession **p)