masterserver ok
This commit is contained in:
parent
b0c4341c04
commit
cce23b2d65
@ -54,7 +54,7 @@ add_executable(
|
|||||||
add_custom_target(script_pb_protocol ALL)
|
add_custom_target(script_pb_protocol ALL)
|
||||||
add_custom_command(TARGET script_pb_protocol
|
add_custom_command(TARGET script_pb_protocol
|
||||||
PRE_BUILD
|
PRE_BUILD
|
||||||
COMMAND python ../../third_party/tools/scripts/construct/build_pb.py --cpp_out=. --pb_files=cs_proto,cs_msgid,ss_proto,ss_msgid,metatable --python_out=../tools/robot/virtualclient
|
COMMAND python ../../third_party/tools/scripts/construct/build_pb.py --cpp_out=. --pb_files=ss_proto,ss_msgid
|
||||||
)
|
)
|
||||||
add_dependencies(masterserver script_pb_protocol)
|
add_dependencies(masterserver script_pb_protocol)
|
||||||
|
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "GGListener.h"
|
#include "GGListener.h"
|
||||||
#include "jsondatamgr.h"
|
#include "jsondatamgr.h"
|
||||||
#include "cs_proto.pb.h"
|
|
||||||
#include "cs_msgid.pb.h"
|
|
||||||
#include "handlermgr.h"
|
#include "handlermgr.h"
|
||||||
|
|
||||||
class GCClientSession: public a8::MixedSession
|
class GCClientSession: public a8::MixedSession
|
||||||
|
@ -18,8 +18,9 @@ void GSMgr::UnInit()
|
|||||||
void GSMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg)
|
void GSMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg)
|
||||||
{
|
{
|
||||||
ss::SS_MS_ResponseTargetServer respmsg;
|
ss::SS_MS_ResponseTargetServer respmsg;
|
||||||
|
respmsg.set_context_id(msg.context_id());
|
||||||
GSNode* node = GetNodeByTeamId(msg.team_id());
|
GSNode* node = GetNodeByTeamId(msg.team_id());
|
||||||
if (!node) {
|
if (node) {
|
||||||
respmsg.set_host(node->ip);
|
respmsg.set_host(node->ip);
|
||||||
respmsg.set_port(node->port);
|
respmsg.set_port(node->port);
|
||||||
} else {
|
} else {
|
||||||
@ -42,8 +43,8 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
|
|||||||
int room_num = request->request.Get("room_num");
|
int room_num = request->request.Get("room_num");
|
||||||
std::string key = ip + a8::XValue(port).GetString();
|
std::string key = ip + a8::XValue(port).GetString();
|
||||||
|
|
||||||
auto itr = node_hash_.find(key);
|
auto itr = node_key_hash_.find(key);
|
||||||
if (itr != node_hash_.end()) {
|
if (itr != node_key_hash_.end()) {
|
||||||
itr->second.online_num = online_num;
|
itr->second.online_num = online_num;
|
||||||
itr->second.room_num = room_num;
|
itr->second.room_num = room_num;
|
||||||
} else {
|
} else {
|
||||||
@ -53,7 +54,7 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
|
|||||||
gs.room_num = room_num;
|
gs.room_num = room_num;
|
||||||
gs.ip = ip;
|
gs.ip = ip;
|
||||||
gs.port = port;
|
gs.port = port;
|
||||||
node_hash_[key] = gs;
|
node_key_hash_[key] = gs;
|
||||||
}
|
}
|
||||||
|
|
||||||
request->resp_xobj->SetVal("errcode", 0);
|
request->resp_xobj->SetVal("errcode", 0);
|
||||||
@ -68,5 +69,17 @@ GSNode* GSMgr::GetNodeByTeamId(const std::string& team_id)
|
|||||||
|
|
||||||
GSNode* GSMgr::AllocNode()
|
GSNode* GSMgr::AllocNode()
|
||||||
{
|
{
|
||||||
|
std::array<GSNode*, 5> nodes = {};
|
||||||
|
size_t i = 0;
|
||||||
|
for (auto& pair : node_desc_hash_) {
|
||||||
|
nodes[i] = &pair.second;
|
||||||
|
++i;
|
||||||
|
if (i >= nodes.size()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i <= 0) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return nodes[rand() % i];
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
struct GSNode
|
struct GSNode
|
||||||
{
|
{
|
||||||
std::string key;
|
std::string key;
|
||||||
|
unsigned short node_idx = 0;
|
||||||
int room_num = 0;
|
int room_num = 0;
|
||||||
int online_num = 0;
|
int online_num = 0;
|
||||||
std::string ip;
|
std::string ip;
|
||||||
@ -36,5 +37,6 @@ class GSMgr : public a8::Singleton<GSMgr>
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
std::map<std::string, GSNode*> team_hash_;
|
std::map<std::string, GSNode*> team_hash_;
|
||||||
std::map<std::string, GSNode> node_hash_;
|
std::map<std::string, GSNode> node_key_hash_;
|
||||||
|
std::map<int, GSNode> node_desc_hash_;
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include "GGListener.h"
|
#include "GGListener.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "cs_proto.pb.h"
|
|
||||||
#include "gsmgr.h"
|
#include "gsmgr.h"
|
||||||
|
|
||||||
static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
|
static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
#include "cs_proto.pb.h"
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user