Skip to content

Commit

Permalink
合并主支
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaobangyu committed Oct 18, 2023
2 parents 1440943 + 259be05 commit 88d0b79
Show file tree
Hide file tree
Showing 236 changed files with 7,856 additions and 3,524 deletions.
28 changes: 12 additions & 16 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,28 @@ stds.quanta = {
"quanta", "environ", "signal", "luabt", "service", "logger",
"import", "class", "enum", "mixin", "property", "singleton", "super", "implemented",
"logfeature", "db_property", "classof", "is_class", "is_subclass", "instanceof", "conv_class",
"codec", "crypt", "stdfs", "luabus", "json", "protobuf", "curl", "timer", "aoi", "log", "worker", "http", "bson", "detour"
"codec", "crypt", "stdfs", "luabus", "luakit", "json", "protobuf", "curl", "timer", "aoi", "log", "worker", "http", "bson", "detour"
}
}
std = "max+quanta"
max_cyclomatic_complexity = 13
max_code_line_length = 160
max_comment_line_length = 160
exclude_files = {
"script/luabt/*.*",
"script/luaoop/*.*",
"script/luabt/luaoop/*.*",
"script/luabt/LICENSE",
"script/luaoop/LICENSE",
"script/luabt/luaoop/LICENSE",
"server/robot/accord/page/*",
"extend/lmake/share.lua"
"extend/lmake/share.lua",
"server/robot/accord/page/*"
}
include_files = {
"script/*",
"server/*",
"worker/*",
"bin/proto/*.lua",
"tools/encrypt/*",
"tools/excel2lua/*",
"script/*.lua",
"server/*.lua",
"script/*/*.lua",
"server/*/*.lua",
"script/*/*/*.lua",
"server/*/*/*.lua",
"script/*/*/*/*.lua",
"server/*/*/*/*.lua",
"extend/lmake/*.lua",
"extend/lmake/ltemplate/*.lua",
"tools/*/*.lua",
}
ignore = {"212", "213", "512"}

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ luaext:
cd extend/lstdfs; make SOLUTION_DIR=$(CUR_DIR) -f lstdfs.mak;
cd extend/ltimer; make SOLUTION_DIR=$(CUR_DIR) -f ltimer.mak;
cd extend/lualog; make SOLUTION_DIR=$(CUR_DIR) -f lualog.mak;
cd extend/luapb; make SOLUTION_DIR=$(CUR_DIR) -f luapb.mak;
cd extend/luaxlsx; make SOLUTION_DIR=$(CUR_DIR) -f luaxlsx.mak;
cd extend/lworker; make SOLUTION_DIR=$(CUR_DIR) -f lworker.mak;
cd extend/protobuf; make SOLUTION_DIR=$(CUR_DIR) -f lua-protobuf.mak;

share:
cd extend/mimalloc; make SOLUTION_DIR=$(CUR_DIR) -f mimalloc.mak;
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ cd bin

# 依赖
- lua
- bson
- mongo
- lbson
- luabt
- lhttp
- lcurl
- ljson
- luabus
- lcrypt
- lcjson
- lstdfs
- luakit
- lualog
- lbuffer
- lcodec
- luaxlsx
- lua-protobuf

Expand Down
3 changes: 3 additions & 0 deletions bin/accord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ set_env("QUANTA_MODE", "3")

--协议测试
set_env("QUANTA_ACCORD_HTTP", "127.0.0.1:10401")

--服务器列表API
set_env("QUANTA_SRVLIST_API", "http://10.98.8.100:18080/server_mgr/query")
8 changes: 4 additions & 4 deletions bin/database.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ set_env("QUANTA_MONGO_URLS", [[
]])
--redis
set_env("QUANTA_REDIS_URLS", [[
redis://root:123456@127.0.0.1:6379;
redis://root:123456@10.96.8.100:6379;
]])
--mysql
--set_env("QUANTA_MYSQL_URLS", [[
-- mysql://root:[email protected]:6379/quanta;
--]])
set_env("QUANTA_MYSQL_URLS", [[
mysql://root:[email protected]:3306/quanta;
]])
9 changes: 6 additions & 3 deletions bin/share.conf
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,15 @@ set_env("QUANTA_DB_CACHE_MAX", "4096")
--每帧落地最大数量
set_env("QUANTA_DB_CACHE_FLUSH", "10")

--webhook日志等级
--webhook设置
-----------------------------------------------------
set_env("QUANTA_WEBHOOK_LVL", "6")
--log: 日志采集
--http:http发送
set_env("QUANTA_WEBHOOK_MODE", "log")
--webhook地址设置
--set_env("QUANTA_LARK_URL", "https://open.feishu.cn/open-apis/bot/v2/hook/9a6565bf-51b4-48ab-80f0-64caf4d58ab8")
--set_env("QUANTA_DING_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a4c64781-adad-4ddc-a615-6bc232ce71ef")
--set_env("QUANTA_WECHAT_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ee6d97c5-477d-436f-83db-dd5361a5e8bd")
set_env("QUANTA_WECHAT_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d7cd918c-f608-4762-87af-bb8c7fc51074")

--graylog配置
-----------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions core/luabus/luabus.mak
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MYCFLAGS += -Wsign-compare
MYCFLAGS += -Wno-sign-compare
MYCFLAGS += -Wno-unused-variable
MYCFLAGS += -Wno-unused-parameter
MYCFLAGS += -Wno-unused-but-set-variable
MYCFLAGS += -Wno-unused-but-set-parameter
MYCFLAGS += -Wno-unknown-pragmas

Expand Down
2 changes: 1 addition & 1 deletion core/luabus/luabus.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Develop|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<Optimization>MaxSpeed</Optimization>
<AdditionalIncludeDirectories>..\..\extend\lua\lua;..\..\extend\ltimer\ltimer;..\..\extend\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
Expand Down
60 changes: 51 additions & 9 deletions core/luabus/src/lua_socket_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
bool lua_socket_mgr::setup(lua_State* L, int max_fd) {
m_lvm = L;
m_mgr = std::make_shared<socket_mgr>();
m_codec = std::make_shared<luacodec>();
m_router = std::make_shared<socket_router>(m_mgr);
return m_mgr->setup(max_fd);
}
Expand All @@ -14,31 +13,35 @@ int lua_socket_mgr::listen(lua_State* L, const char* ip, int port) {
if (ip == nullptr || port <= 0) {
return luakit::variadic_return(L, nullptr, "invalid param");
}

std::string err;
int token = m_mgr->listen(err, ip, port);
if (token == 0) {
return luakit::variadic_return(L, nullptr, err);
}

auto listener = new lua_socket_node(token, L, m_mgr, m_router, true);
listener->set_codec(m_codec.get());
eproto_type proto_type = (eproto_type)luaL_optinteger(L, 3, (int)eproto_type::proto_rpc);
auto listener = new lua_socket_node(token, L, m_mgr, m_router, proto_type);
if (proto_type == eproto_type::proto_rpc) {
listener->create_codec();
}
return luakit::variadic_return(L, listener, "ok");
}

int lua_socket_mgr::connect(lua_State* L, const char* ip, const char* port, int timeout) {
if (ip == nullptr || port == nullptr) {
return luakit::variadic_return(L, nullptr, "invalid param");
}

std::string err;
int token = m_mgr->connect(err, ip, port, timeout);
if (token == 0) {
return luakit::variadic_return(L, nullptr, err);
}

auto socket_node = new lua_socket_node(token, L, m_mgr, m_router, false);
socket_node->set_codec(m_codec.get());
eproto_type proto_type = (eproto_type)luaL_optinteger(L, 4, (int)eproto_type::proto_rpc);
auto socket_node = new lua_socket_node(token, L, m_mgr, m_router, proto_type);
if (proto_type == eproto_type::proto_rpc) {
socket_node->create_codec();
}
return luakit::variadic_return(L, socket_node, "ok");
}

Expand All @@ -50,10 +53,49 @@ int lua_socket_mgr::get_recvbuf_size(uint32_t token) {
return m_mgr->get_recvbuf_size(token);
}

void lua_socket_mgr::set_proto_type(uint32_t token, eproto_type type) {
return m_mgr->set_proto_type(token, type);
void lua_socket_mgr::set_codec(uint32_t token, codec_base* codec) {
return m_mgr->set_codec(token, codec);
}

int lua_socket_mgr::map_token(uint32_t node_id, uint32_t token) {
return m_router->map_token(node_id, token);
}

int lua_socket_mgr::broadcast(lua_State* L, codec_base* codec, uint32_t kind) {
size_t data_len = 0;
char* data = (char*)codec->encode(L, 3, &data_len);
socket_header* header = (socket_header*)data;
if (data_len <= USHRT_MAX) {
//组装数据
header->len = data_len;
header->session_id = 0;
//发送数据
m_mgr->broadcast(kind, data, data_len);
lua_pushboolean(L, true);
return 1;
}
lua_pushboolean(L, false);
return 1;
}

int lua_socket_mgr::broadgroup(lua_State* L, codec_base* codec) {
size_t data_len = 0;
std::vector<uint32_t> groups;
if (!lua_to_native(L, 2, groups)) {
lua_pushboolean(L, false);
return 1;
}
char* data = (char*)codec->encode(L, 3, &data_len);
socket_header* header = (socket_header*)data;
if (data_len <= USHRT_MAX) {
//组装数据
header->len = data_len;
header->session_id = 0;
//发送数据
m_mgr->broadgroup(groups, data, data_len);
lua_pushboolean(L, true);
return 1;
}
lua_pushboolean(L, false);
return 1;
}
15 changes: 7 additions & 8 deletions core/luabus/src/lua_socket_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ struct lua_socket_mgr final
public:
~lua_socket_mgr(){}
bool setup(lua_State* L, int max_fd);
int wait(int64_t now, int timeout) { return m_mgr->wait(now, timeout); }
int get_sendbuf_size(uint32_t token);
int get_recvbuf_size(uint32_t token);
int map_token(uint32_t node_id, uint32_t token);
int listen(lua_State* L, const char* ip, int port);
int connect(lua_State* L, const char* ip, const char* port, int timeout);
void set_proto_type(uint32_t token, eproto_type type);

std::shared_ptr<socket_router> get_router() { return m_router; }
int wait(int64_t now, int timeout) { return m_mgr->wait(now, timeout); }
int broadcast(lua_State* L, codec_base* codec, uint32_t kind);
int broadgroup(lua_State* L, codec_base* codec);
void set_codec(uint32_t token, codec_base* codec);

private:
lua_State* m_lvm = nullptr;
std::shared_ptr<luacodec> m_codec;
std::shared_ptr<socket_mgr> m_mgr;
std::shared_ptr<socket_router> m_router;
lua_State* m_lvm;
stdsptr<socket_mgr> m_mgr;
stdsptr<socket_router> m_router;
};

Loading

0 comments on commit 88d0b79

Please sign in to comment.