1
This commit is contained in:
parent
4e702143ef
commit
fd49464d7c
@ -1,5 +1,7 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include <google/protobuf/message.h>
|
||||
#include <a8/mixedsession.h>
|
||||
#include <a8/tcplistener.h>
|
||||
@ -132,6 +134,19 @@ public:
|
||||
.SetParam1(1));
|
||||
}
|
||||
|
||||
void SetKey(unsigned char* data, int len)
|
||||
{
|
||||
send_i_ = 0;
|
||||
send_j_ = 0;
|
||||
recv_i_ = 0;
|
||||
recv_j_ = 0;
|
||||
initialized_ = true;
|
||||
key_.clear();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
key_.push_back(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual void SendBuff(const char* buff, unsigned int bufflen) override
|
||||
@ -197,6 +212,25 @@ void GCListener::MarkClient(int sockhandle, bool is_active)
|
||||
tcp_listener_->MarkClient(sockhandle, is_active);
|
||||
}
|
||||
|
||||
void GCListener::SetKey(int sockhandle, const std::string& key)
|
||||
{
|
||||
tcp_listener_->LockClients();
|
||||
GCClientSession* session = (GCClientSession*)tcp_listener_->GetClientSession(sockhandle);
|
||||
if (session) {
|
||||
bignum_st* bn = BN_new();
|
||||
BN_hex2bn(&bn, key.c_str());
|
||||
{
|
||||
int length = BN_num_bytes(bn);
|
||||
unsigned char* _array = new unsigned char[length];
|
||||
BN_bn2bin(bn, (unsigned char*)_array);
|
||||
std::reverse(_array, _array + length);
|
||||
session->SetKey(_array, 40);
|
||||
}
|
||||
BN_free(bn);
|
||||
}
|
||||
tcp_listener_->UnLockClients();
|
||||
}
|
||||
|
||||
void GCListener::InternalSendMsg(int socket_handle, int msgid, google::protobuf::Message& msg)
|
||||
{
|
||||
unsigned short packlen = 2 + CustomPbSerializeSize(&msg);
|
||||
|
@ -44,6 +44,7 @@ class GCListener : public a8::Singleton<GCListener>
|
||||
|
||||
void ForceCloseClient(int sockhandle);
|
||||
void MarkClient(int sockhandle, bool is_active);
|
||||
void SetKey(int sockhandle, const std::string& key);
|
||||
|
||||
private:
|
||||
void InternalSendMsg(int socket_handle, int msgid, google::protobuf::Message& msg);
|
||||
|
@ -24,6 +24,8 @@ void PlayerMgr::_CMAuthSession(f8::MsgHdr& hdr, const cs::CMAuthSession& msg)
|
||||
msg.account()
|
||||
});
|
||||
assert(ret > 0);
|
||||
GCListener::Instance()->SetKey(hdr.socket_handle,
|
||||
DBEngine::Instance()->GetValue(2).GetString());
|
||||
cs::SMAuthResponse respmsg;
|
||||
respmsg.set_errcode(AUTH_OK);
|
||||
GCListener::Instance()->SendMsg(hdr.socket_handle, respmsg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user