Skip to content

Commit

Permalink
Update: Move the Node type defines to proto file
Browse files Browse the repository at this point in the history
  • Loading branch information
i0gan committed Apr 27, 2024
1 parent dbb9ee4 commit a6814e4
Show file tree
Hide file tree
Showing 30 changed files with 151 additions and 176 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

**Unreal SDK**: [squick-unreal-sdk](https://github.com/pwnsky/squick-unreal-sdk)

**Web Admin**: [squick-web](https://github.com/pwnsky/squick-web)

**QQ Group:739065686**

**Version:** 1.1.1
Expand Down
16 changes: 0 additions & 16 deletions src/lua/common/base.lua
Original file line number Diff line number Diff line change
@@ -1,16 +0,0 @@
ServerType =
{
ST_NONE = 0,
ST_MASTER = 1,
ST_LOGIN = 2,
ST_WORLD = 3,
ST_DB_PROXY = 4,
ST_PROXY = 5,
ST_PLAYER = 6,
ST_GAME_MGR = 7,
ST_GAME = 8,
ST_MICRO = 9,
ST_CDN = 10,
ST_ROBOT = 11,
ST_MAX = 12,
};
6 changes: 3 additions & 3 deletions src/lua/lib/db/clickhouse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ local DbClickhouseID = 0;
Clickhouse = Clickhouse and Clickhouse or Object(QueryAsync).new()

function Clickhouse:Bind()
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckClickhouseExecute, self, self.AckExecute)
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckClickhouseSelect, self, self.AckSelect)
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckClickhouseInsert, self, self.AckInsert)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckClickhouseExecute, self, self.AckExecute)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckClickhouseSelect, self, self.AckSelect)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckClickhouseInsert, self, self.AckInsert)
DbClickhouseID = GetDbProxyID()
end

Expand Down
10 changes: 5 additions & 5 deletions src/lua/lib/db/mongo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ local DbProxyID = 0;
Mongo = Mongo and Mongo or Object(QueryAsync).new()

function Mongo:Bind()
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckMongoInsert, self, self.AckInsert)
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckMongoFind, self, self.AckFind)
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckMongoUpdate, self, self.AckUpdate)
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckMongoDelete, self, self.AckDelete)
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckMongoCreateIndex, self, self.AckCreateIndex)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckMongoInsert, self, self.AckInsert)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckMongoFind, self, self.AckFind)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckMongoUpdate, self, self.AckUpdate)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckMongoDelete, self, self.AckDelete)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckMongoCreateIndex, self, self.AckCreateIndex)
DbProxyID = GetDbProxyID()
end

Expand Down
8 changes: 4 additions & 4 deletions src/lua/lib/db/mysql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ local DbMysqlID = 0;
Mysql = Mysql and Mysql or Object(QueryAsync).new()

function Mysql:Bind()
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckMysqlExecute, self, self.AckExecute)
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckMysqlSelect, self, self.AckSelect)
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckMysqlInsert, self, self.AckInsert)
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckMysqlUpdate, self, self.AckUpdate)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckMysqlExecute, self, self.AckExecute)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckMysqlSelect, self, self.AckSelect)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckMysqlInsert, self, self.AckInsert)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckMysqlUpdate, self, self.AckUpdate)
DbMysqlID = GetDbProxyID()
end

Expand Down
4 changes: 2 additions & 2 deletions src/lua/lib/db/redis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ local DbProxyID = 0;
Redis = Redis and Redis or Object(QueryAsync).new()

function Redis:Bind()
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckRedisGet, self, self.AckGetString)
Net:ClientRegister(ServerType.ST_DB_PROXY, NMsgId.IdNAckRedisSet, self, self.AckSetString)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckRedisGet, self, self.AckGetString)
Net:ClientRegister(NodeType.ST_DB_PROXY, NMsgId.IdNAckRedisSet, self, self.AckSetString)
DbProxyID = GetDbProxyID()
end

Expand Down
4 changes: 2 additions & 2 deletions src/lua/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ function Load()
Require("lib.init")

local node_init = {
[ServerType.ST_GAME ] = function()
[NodeType.ST_GAME ] = function()
Require("node.game.init")
end,
[ServerType.ST_PLAYER] = function ()
[NodeType.ST_PLAYER] = function ()
Require("node.player.init")
-- Require("test.init")
end
Expand Down
2 changes: 1 addition & 1 deletion src/node/ds_mgr/logic/logic_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bool LogicModule::AfterStart() {
}*/

// 来自Game 服务器
m_net_client_->AddReceiveCallBack(ServerType::ST_GAME, rpc::REQ_GAMEPLAY_CREATE, this, &LogicModule::OnReqPvpInstanceCreate);
m_net_client_->AddReceiveCallBack(rpc::ST_GAME, rpc::REQ_GAMEPLAY_CREATE, this, &LogicModule::OnReqPvpInstanceCreate);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/node/global/logic/logic_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace global::logic {
bool LogicModule::Start() {
m_node_ = pm_->FindModule<INodeModule>();
vector<int> node_types = {ServerType::ST_DB_PROXY};
vector<int> node_types = {rpc::ST_DB_PROXY};
m_node_->AddSubscribeNode(node_types);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/node/login/logic/logic_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool LogicModule::AfterStart() {
m_net_->AddReceiveCallBack(rpc::IdNReqConnectProxyVerify, this, &LogicModule::OnConnectProxyVerify);
m_http_server_->StartServer(pm_->GetArg("http_port=", 80));

vector<int> node_types = {ServerType::ST_DB_PROXY};
vector<int> node_types = {rpc::ST_DB_PROXY};
m_node_->AddSubscribeNode(node_types);
return true;
}
Expand Down Expand Up @@ -63,7 +63,7 @@ Coroutine<bool> LogicModule::OnLogin(std::shared_ptr<HttpRequest> request) {

// find min work load proxy
rpc::NReqMinWorkloadNodeInfo pbreq;
pbreq.add_type_list(ST_PROXY);
pbreq.add_type_list(rpc::ST_PROXY);
auto data = co_await m_net_client_->RequestPB(DEFAULT_MASTER_ID, rpc::IdNReqMinWorkloadNodeInfo, pbreq, rpc::IdNAckMinWorkloadNodeInfo);
if (data.error) {
ack.code = IResponse::SERVER_ERROR;
Expand Down
4 changes: 2 additions & 2 deletions src/node/master/logic/logic_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void LogicModule::OnNReqMinWorkNodeInfo(const socket_t sock, const int msg_id, c
return;
}
for (auto type : req.type_list()) {
int id = GetLoadBanlanceNode((ServerType)type);
int id = GetLoadBanlanceNode(type);
if (id == -1)
continue;
auto p = ack.add_list();
Expand All @@ -216,7 +216,7 @@ void LogicModule::OnNReqMinWorkNodeInfo(const socket_t sock, const int msg_id, c
m_net_->SendPBToNode(rpc::IdNAckMinWorkloadNodeInfo, ack, sock, 0, req_id);
}

int LogicModule::GetLoadBanlanceNode(ServerType type) {
int LogicModule::GetLoadBanlanceNode(int type) {
int node_id = -1;
int min_workload = 0x7fffffff;
for (auto &iter : node_map_) {
Expand Down
2 changes: 1 addition & 1 deletion src/node/master/logic/logic_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LogicModule : public ILogicModule {
void OnNNtfNodeMsgForward(const socket_t sock, const int msg_id, const char *msg, const uint32_t len);
void OnNReqAllNodesInfo(const socket_t sock, const int msg_id, const char *msg, const uint32_t len);

int GetLoadBanlanceNode(ServerType type);
int GetLoadBanlanceNode(int type);

void AddSubscribeNode(int new_node_id, vector<int> types);
void NtfSubscribNode(int new_node_id);
Expand Down
2 changes: 1 addition & 1 deletion src/node/player/logic/logic_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace player::logic {
bool LogicModule::Start() {
m_lua_script_ = pm_->FindModule<ILuaScriptModule>();
m_node_ = pm_->FindModule<INodeModule>();
vector<int> node_types = {ServerType::ST_WORLD, ServerType::ST_DB_PROXY, ServerType::ST_PLAYER};
vector<int> node_types = {rpc::ST_WORLD, rpc::ST_DB_PROXY, rpc::ST_PLAYER};
m_node_->AddSubscribeNode(node_types);

LuaBind();
Expand Down
18 changes: 9 additions & 9 deletions src/node/proxy/logic/logic_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ bool LogicModule::AfterStart() {
m_ws_->AddReceiveCallBack(rpc::IdReqPlayerLeave, this, &LogicModule::OnReqPlayerLeave);

// Master
m_net_client_->AddReceiveCallBack(ServerType::ST_MASTER, this, &LogicModule::OnNAckMinWorkloadNodeInfo);
m_net_client_->AddReceiveCallBack(rpc::ST_MASTER, this, &LogicModule::OnNAckMinWorkloadNodeInfo);

// Lobby
m_net_client_->AddReceiveCallBack(ServerType::ST_PLAYER, this, &LogicModule::OnRecivedPlayerNodeMsg);
m_net_client_->AddReceiveCallBack(ServerType::ST_LOGIN, rpc::IdNAckConnectProxyVerify, this, &LogicModule::OnNAckConnectVerify);
m_net_client_->AddReceiveCallBack(ServerType::ST_PLAYER, rpc::IdAckPlayerEnter, this, &LogicModule::OnAckPlayerEnter);
m_net_client_->AddReceiveCallBack(rpc::ST_PLAYER, this, &LogicModule::OnRecivedPlayerNodeMsg);
m_net_client_->AddReceiveCallBack(rpc::ST_LOGIN, rpc::IdNAckConnectProxyVerify, this, &LogicModule::OnNAckConnectVerify);
m_net_client_->AddReceiveCallBack(rpc::ST_PLAYER, rpc::IdAckPlayerEnter, this, &LogicModule::OnAckPlayerEnter);

auto &node_info = m_node_->GetNodeInfo();
node_info.info->set_ws_port(pm_->GetArg("ws_port=", 10502));
Expand All @@ -58,7 +58,7 @@ bool LogicModule::AfterStart() {
m_ws_->AddEventCallBack(this, &LogicModule::OnSocketEvent);
m_net_->AddEventCallBack(this, &LogicModule::OnSocketEvent);

vector<int> node_types = {ServerType::ST_WORLD, ServerType::ST_LOGIN, ServerType::ST_PLAYER};
vector<int> node_types = {rpc::ST_WORLD, rpc::ST_LOGIN, rpc::ST_PLAYER};
m_node_->AddSubscribeNode(node_types);

return true;
Expand All @@ -80,8 +80,8 @@ void LogicModule::OnSocketEvent(socket_t sock, const SQUICK_NET_EVENT eEvent, IN
void LogicModule::NReqMinWorkloadNodeInfo() {
// find min work load proxy
rpc::NReqMinWorkloadNodeInfo pbreq;
pbreq.add_type_list(ST_PLAYER);
pbreq.add_type_list(ST_WORLD);
pbreq.add_type_list(rpc::ST_PLAYER);
pbreq.add_type_list(rpc::ST_WORLD);
m_net_client_->SendPBByID(DEFAULT_MASTER_ID, rpc::IdNReqMinWorkloadNodeInfo, pbreq);
}

Expand All @@ -105,7 +105,7 @@ void LogicModule::OnReqPlayerEnter(const socket_t sock, const int msg_id, const
return;
}

int player_node = GetLoadBanlanceNode(ST_PLAYER);
int player_node = GetLoadBanlanceNode(rpc::ST_PLAYER);
if (player_node <= 0 || pInfo->player_node > 0) {
LOG_WARN("No player node find: %v ", player_node);
return;
Expand Down Expand Up @@ -171,7 +171,7 @@ void LogicModule::OnAckPlayerEnter(const socket_t sock, const int msg_id, const
}
}

int LogicModule::GetLoadBanlanceNode(ServerType type) {
int LogicModule::GetLoadBanlanceNode(int type) {
auto iter = min_workload_nodes_.find(type);
if (iter == min_workload_nodes_.end()) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/node/proxy/logic/logic_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class LogicModule : public ILogicModule {
void OnWS(const socket_t sock, const int msg_id, const char *msg, const uint32_t len);
void OnSocketEvent(socket_t sock, const SQUICK_NET_EVENT eEvent, INet *pNet);

int GetLoadBanlanceNode(ServerType type);
int GetLoadBanlanceNode(int type);
PlayerConnInfo *GetPlayerConnInfoByUID(const uint64_t uid);
PlayerConnInfo *GetPlayerConnInfo(const socket_t player_sock);
bool RemovePlayerConnInfo(const socket_t player_sock);
Expand Down
2 changes: 1 addition & 1 deletion src/node/web/logic/logic_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool LogicModule::AfterStart() {
m_http_server_->AddRequestHandler(WEB_BASE_PATH "/auth_check", HttpType::SQUICK_HTTP_REQ_GET, this, &LogicModule::OnAuthCheck);
m_http_server_->StartServer(pm_->GetArg("http_port=", ARG_DEFAULT_HTTP_PORT));

vector<int> node_types = {ServerType::ST_GLOBAL, ServerType::ST_DB_PROXY, ServerType::ST_PLAYER};
vector<int> node_types = {rpc::ST_GLOBAL, rpc::ST_DB_PROXY, rpc::ST_PLAYER};
m_node_->AddSubscribeNode(node_types);

LoadConfig();
Expand Down
2 changes: 1 addition & 1 deletion src/node/world/logic/logic_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace world::logic {
bool LogicModule::Start() {
m_node_ = pm_->FindModule<INodeModule>();
vector<int> node_types = {ServerType::ST_DB_PROXY};
vector<int> node_types = {rpc::ST_DB_PROXY};
m_node_->AddSubscribeNode(node_types);
return true;
}
Expand Down
50 changes: 35 additions & 15 deletions src/proto/n_master.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,41 @@
syntax = "proto3";
package rpc;

enum ServerState {
ServerCrash = 0;
ServerNormal = 1;
ServerBusy = 2;
ServerFrie = 3;
enum NodeState {
NodeStateCrash = 0;
NodeStateNormal = 1;
NodeStateBusy = 2;
NodeStateFrie = 3;
}

message Server {
enum NodeType {
ST_NONE = 0; // NONE
ST_MASTER = 1; //
ST_LOGIN = 2; //
ST_WORLD = 3; //
ST_DB_PROXY = 4; //
ST_PROXY = 5; //
ST_PLAYER = 6;
ST_GAME_MGR = 7; //
ST_GAME = 8; //
ST_MICRO = 9; // Micro
ST_CDN = 10; // CDN
ST_WEB = 11; // Web
ST_GLOBAL = 12; // Global
ST_ROOM = 13; // Room
ST_MATCH = 14; // Match
ST_GM = 15; // GM
ST_MAX = 16;
}

message Node {
int32 id = 1;
bytes name = 2;
bytes ip = 3;
int32 port = 4;
int32 max_online = 5;
int32 cpu_count = 6;
ServerState state = 7;
NodeState state = 7;
int32 type = 8;
int32 area = 9;
int32 connections = 10;
Expand All @@ -33,12 +53,12 @@ message Server {

message NReqNodeRegister { // msg_id=500;
repeated int32 listen_type_list = 1; // set bind type, When new same type node connect to master, it will ntf self node.
Server node = 2;
Node node = 2;
}

message NAckNodeRegister { // msg_id=501;
int32 code = 1;
repeated Server node_add_list = 2;
repeated Node node_add_list = 2;
}

message NReqNodeUnregister { // msg_id=502;
Expand All @@ -54,28 +74,28 @@ message NReqMinWorkloadNodeInfo { // msg_id=504;
}

message NAckMinWorkloadNodeInfo { // msg_id=505;
repeated Server list = 1;
repeated Node list = 1;
}

message NReqNodeInfo { // msg_id=506;
repeated int32 id_list = 1;
}

message NAckNodeInfo { // msg_id=507;
repeated Server list = 1;
repeated Node list = 1;
}

message NNtfNodeReport { // msg_id=508; desc=Report current node status;
int32 id = 1;
repeated Server list = 2;
repeated Node list = 2;
}

message NNtfNodeAdd { // msg_id=509;
repeated Server node_list = 1;
repeated Node node_list = 1;
}

message NNtfNodeRemove { // msg_id=510;
repeated Server node_list = 1;
repeated Node node_list = 1;
}

message NNtfNodeMsgForward { // msg_id=511;
Expand All @@ -86,5 +106,5 @@ message NReqAllNodesInfo { // msg_id=512;
}

message NAckAllNodesInfo { // msg_id=513;
repeated Server node_list = 1;
repeated Node node_list = 1;
}
20 changes: 0 additions & 20 deletions src/squick/core/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,6 @@
#define SQUICK_VERSION "1.1.1"
#define SERVER_NAME "Squick/" SQUICK_VERSION

enum ServerType {
ST_NONE = 0, // NONE
ST_MASTER = 1, //
ST_LOGIN = 2, //
ST_WORLD = 3, //
ST_DB_PROXY = 4, //
ST_PROXY = 5, //
ST_PLAYER = 6,
ST_GAME_MGR = 7, //
ST_GAME = 8, //
ST_MICRO = 9, // Micro
ST_CDN = 10, // CDN
ST_WEB = 11, // Web
ST_GLOBAL = 12, // Global
ST_ROOM = 12, // Room
ST_MATCH = 13, // Match
ST_GM = 14, // GM
ST_MAX = 15,
};

// 线程池 每一帧睡眠时间,单位毫秒
#define THREAD_POOL_SLEEP_TIME 100
// 主线程 每一帧睡眠时间,单位毫秒
Expand Down
Loading

0 comments on commit a6814e4

Please sign in to comment.