aozhiwei da3c6ee96e 1
2020-08-22 21:24:35 +08:00

59 lines
1.4 KiB
C++

#pragma once
#include "ss_proto.pb.h"
struct GSNode
{
std::string key;
long long node_idx = 0;
int node_id = 0;
int instance_id = 0;
int room_num = 0;
int alive_count = 0;
int online_num = 0;
std::string ip;
int port = 0;
bool servicing = false;
int channel = 0;
long long last_active_tick = 0;
};
class GSMgr : public a8::Singleton<GSMgr>
{
public:
enum { HID = HID_GSMgr };
private:
GSMgr() {};
friend class a8::Singleton<GSMgr>;
public:
void Init();
void UnInit();
void _SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg);
void _SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg);
void ___GSReport(f8::JsonHttpRequest* request);
void ___GSList(f8::JsonHttpRequest* request);
private:
GSNode* GetNodeByTeamId(const std::string& team_id);
GSNode* GetNodeByNodeKey(const std::string& node_key);
GSNode* AllocNode(int channel);
void RearrangeNode();
void ClearTimeOutNode();
void AddNodeToSortedNodes(GSNode* node);
void RemoveNodeFromSortedNodes(GSNode* node);
std::vector<GSNode*>* GetSortedNodesByChannel(int channel);
void OnChannelChange(GSNode* node);
int GetTargetChannel(const ss::SS_WSP_RequestTargetServer& msg);
private:
std::map<std::string, GSNode*> team_hash_;
std::map<std::string, GSNode> node_key_hash_;
std::map<int, std::vector<GSNode*>> sorted_node_hash_;
};