1
This commit is contained in:
parent
962766cc20
commit
9f44a2e85f
@ -27,6 +27,7 @@
|
|||||||
#include "GGListener.h"
|
#include "GGListener.h"
|
||||||
#include "selfchecker.h"
|
#include "selfchecker.h"
|
||||||
#include "httpproxy.h"
|
#include "httpproxy.h"
|
||||||
|
#include "playermgr.h"
|
||||||
|
|
||||||
#include "mt/MetaMgr.h"
|
#include "mt/MetaMgr.h"
|
||||||
|
|
||||||
@ -96,6 +97,7 @@ bool App::Init(int argc, char* argv[])
|
|||||||
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
|
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
|
||||||
GGListener::Instance()->Init();
|
GGListener::Instance()->Init();
|
||||||
HttpProxy::Instance()->Init();
|
HttpProxy::Instance()->Init();
|
||||||
|
PlayerMgr::Instance()->Init();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
f8::UdpLog::Instance()->Info("imserver starting instance_id:%d pid:%d debug_mode:%d channel:%d",
|
f8::UdpLog::Instance()->Info("imserver starting instance_id:%d pid:%d debug_mode:%d channel:%d",
|
||||||
@ -134,6 +136,7 @@ bool App::Init(int argc, char* argv[])
|
|||||||
|
|
||||||
void App::UnInit()
|
void App::UnInit()
|
||||||
{
|
{
|
||||||
|
PlayerMgr::Instance()->UnInit();
|
||||||
HttpProxy::Instance()->UnInit();
|
HttpProxy::Instance()->UnInit();
|
||||||
GGListener::Instance()->UnInit();
|
GGListener::Instance()->UnInit();
|
||||||
SelfChecker::UnInit();
|
SelfChecker::UnInit();
|
||||||
|
1
server/imserver/player.cc
Normal file
1
server/imserver/player.cc
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "precompile.h"
|
8
server/imserver/player.h
Normal file
8
server/imserver/player.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Player
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int socket_handle = 0;
|
||||||
|
|
||||||
|
};
|
117
server/imserver/playermgr.cc
Normal file
117
server/imserver/playermgr.cc
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include <f8/udplog.h>
|
||||||
|
|
||||||
|
#include "playermgr.h"
|
||||||
|
#include "player.h"
|
||||||
|
|
||||||
|
#include <f8/utils.h>
|
||||||
|
#include <f8/msgqueue.h>
|
||||||
|
|
||||||
|
void PlayerMgr::Init()
|
||||||
|
{
|
||||||
|
f8::MsgQueue::Instance()->RegisterCallBack
|
||||||
|
(
|
||||||
|
IM_ClientSocketDisconnect,
|
||||||
|
[this] (const a8::Args& args)
|
||||||
|
{
|
||||||
|
int gg_socket = args.Get<int>(0);
|
||||||
|
OnClientDisconnect(gg_socket);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerMgr::UnInit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int PlayerMgr::OnlineNum()
|
||||||
|
{
|
||||||
|
return socket_hash_.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
Player* PlayerMgr::GetPlayerBySocket(int socket)
|
||||||
|
{
|
||||||
|
auto itr = socket_hash_.find(socket);
|
||||||
|
return itr != socket_hash_.end() ? itr->second : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerMgr::OnClientDisconnect(int gg_socket)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::vector<int> socket_list;
|
||||||
|
for (auto& pair : socket_hash_) {
|
||||||
|
unsigned short parent_socket_handle = (pair.first >> 16) & 0xFFFF;
|
||||||
|
if (parent_socket_handle == gg_socket) {
|
||||||
|
socket_list.push_back(pair.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int socket_handle : socket_list) {
|
||||||
|
Player* hum = GetPlayerBySocket(socket_handle);
|
||||||
|
if (hum) {
|
||||||
|
RemovePlayerBySocket(socket_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerMgr::RemovePlayerBySocket(int socket_handle)
|
||||||
|
{
|
||||||
|
auto itr = socket_hash_.find(socket_handle);
|
||||||
|
if (itr != socket_hash_.end()) {
|
||||||
|
itr->second->socket_handle = 0;
|
||||||
|
socket_hash_.erase(itr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerMgr::IncAccountNum(const std::string& account_id)
|
||||||
|
{
|
||||||
|
auto itr = account_num_hash_.find(account_id);
|
||||||
|
if (itr != account_num_hash_.end()) {
|
||||||
|
++(itr->second);
|
||||||
|
if (itr->second > 3) {
|
||||||
|
f8::UdpLog::Instance()->Warning
|
||||||
|
(
|
||||||
|
"IncAccountNum account_id:%s num:%d > 3",
|
||||||
|
{
|
||||||
|
account_id,
|
||||||
|
itr->second
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
account_num_hash_[account_id] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerMgr::DecAccountNum(const std::string& account_id)
|
||||||
|
{
|
||||||
|
auto itr = account_num_hash_.find(account_id);
|
||||||
|
if (itr != account_num_hash_.end()) {
|
||||||
|
--(itr->second);
|
||||||
|
if (itr->second < 0) {
|
||||||
|
f8::UdpLog::Instance()->Warning
|
||||||
|
(
|
||||||
|
"DecAccountNum account_id:%s num:%d < 0",
|
||||||
|
{
|
||||||
|
account_id,
|
||||||
|
itr->second
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (itr->second <= 0) {
|
||||||
|
account_num_hash_.erase(itr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f8::UdpLog::Instance()->Warning
|
||||||
|
(
|
||||||
|
"DecAccountNum account_id:%s not exits",
|
||||||
|
{
|
||||||
|
account_id
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerMgr::ReBindSocket(Player* hum)
|
||||||
|
{
|
||||||
|
socket_hash_[hum->socket_handle] = hum;
|
||||||
|
}
|
47
server/imserver/playermgr.h
Normal file
47
server/imserver/playermgr.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <a8/singleton.h>
|
||||||
|
|
||||||
|
namespace cs
|
||||||
|
{
|
||||||
|
class CMJoin;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ss
|
||||||
|
{
|
||||||
|
class SS_WSP_SocketDisconnect;
|
||||||
|
class SS_Ping;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Player;
|
||||||
|
class PlayerMgr : public a8::Singleton<PlayerMgr>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum { HID = HID_PlayerMgr };
|
||||||
|
|
||||||
|
private:
|
||||||
|
PlayerMgr() {};
|
||||||
|
friend class a8::Singleton<PlayerMgr>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void Init();
|
||||||
|
void UnInit();
|
||||||
|
|
||||||
|
void _SS_WSP_SocketDisconnect(f8::MsgHdr& hdr, const ss::SS_WSP_SocketDisconnect& msg);
|
||||||
|
void _SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg);
|
||||||
|
|
||||||
|
int OnlineNum();
|
||||||
|
Player* GetPlayerBySocket(int socket);
|
||||||
|
Player* CreatePlayerByCMJoin(Player* hum, long ip_saddr, int socket, const cs::CMJoin& msg);
|
||||||
|
void RemovePlayerBySocket(int socket_handle);
|
||||||
|
size_t GetAccountNum() { return account_num_hash_.size(); }
|
||||||
|
void IncAccountNum(const std::string& account_id);
|
||||||
|
void DecAccountNum(const std::string& account_id);
|
||||||
|
void ReBindSocket(Player* hum);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void OnClientDisconnect(int gg_socket);
|
||||||
|
private:
|
||||||
|
std::map<int, Player*> socket_hash_;
|
||||||
|
std::map<std::string, int> account_num_hash_;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user