Skip to content

Commit

Permalink
合并主干代码
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed Mar 12, 2024
2 parents affb62f + 8cefdfe commit 988ccee
Show file tree
Hide file tree
Showing 66 changed files with 15,147 additions and 700 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ bin/configs
.gitignore
.DS_Store
/.idea/
*.mdb
*.lock
*.mdb-lock
4 changes: 2 additions & 2 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ stds.quanta = {
globals = {
--common
"coroutine", "qtable", "qstring", "qmath", "ncmd_cs",
"quanta", "environ", "signal", "luabt", "service", "logger",
"quanta", "environ", "signal", "service", "logger",
"import", "class", "enum", "mixin", "property", "singleton", "super", "implemented",
"logfeature", "db_property", "classof", "is_class", "is_subclass", "instanceof", "conv_class", "class_review",
"codec", "crypt", "stdfs", "luabus", "luakit", "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", "lmdb"
}
}
std = "max+quanta"
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ luaext:
cd extend/lcurl; make SOLUTION_DIR=$(CUR_DIR) -f lcurl.mak;
cd extend/ldetour; make SOLUTION_DIR=$(CUR_DIR) -f ldetour.mak;
cd extend/ljson; make SOLUTION_DIR=$(CUR_DIR) -f ljson.mak;
cd extend/lmdb; make SOLUTION_DIR=$(CUR_DIR) -f lmdb.mak;
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;
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ quanta.bat
# 依赖
- lua
- lbson
- luabt
- lcurl
- ljson
- luabus
Expand Down Expand Up @@ -96,7 +95,7 @@ quanta.bat
- tcp服务器/客户端支持
- rpc调用机制支持
- 协议加密和压缩功能支持
- 行为树ai功能支持
- ai功能支持
- 文件系统支持
- 异步日志功能支持
- lua面向对象机制支持
Expand Down
3 changes: 3 additions & 0 deletions bin/template/monitor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ set_env("QUANTA_SERVICE", "monitor")
--服务模式
set_env("QUANTA_MODE", "3")

--监控开关
set_env("QUANTA_MONITOR", "0")

--DB连接池大小
set_env("QUANTA_DB_POOL_COUNT", "{{%= QUANTA_DB_POOL_COUNT or 2 %}}")

Expand Down
4 changes: 4 additions & 0 deletions bin/template/share.conf
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ set_env("QUANTA_HOTFIX", "{{%= QUANTA_HOTFIX or 1 %}}")
set_env("QUANTA_GM_SERVER", "{{%= QUANTA_GM_SERVER or 1 %}}")
--客户端GM开关
set_env("QUANTA_GM_CLIENT", "{{%= QUANTA_GM_CLIENT or 1 %}}")
--监控开关
set_env("QUANTA_MONITOR", "{{%= QUANTA_MONITOR or 1 %}}")


--webhook日志等级
Expand Down Expand Up @@ -131,6 +133,8 @@ set_env("QUANTA_LARK_URL", "{{%= QUANTA_LARK_URL %}}")
set_env("QUANTA_SANDBOX", "sandbox")
--定义协议文件路径,多个路径使用";"隔开
set_env("QUANTA_PROTO_PATH", "./proto/")
--定义LMDB路径
set_env("QUANTA_LMDB_PATH", "./lmdb/")

--定义lua代码查询路径/扩展库查询路径
if platform == "windows" then
Expand Down
1 change: 1 addition & 0 deletions core/luabus/src/luabus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace luabus {

lluabus.set_function("udp", create_udp);
lluabus.set_function("tcp", create_tcp);
lluabus.set_function("host", gethostip);
lluabus.set_function("dns", gethostbydomain);
lluabus.set_function("create_socket_mgr", create_socket_mgr);
lluabus.new_enum("eproto_type",
Expand Down
23 changes: 23 additions & 0 deletions core/luabus/src/socket_dns.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
#pragma once
#include "socket_helper.h"

#ifndef WIN32
#include <netdb.h>
#endif

inline int gethostip(lua_State* L) {
int sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
struct sockaddr_in remote_addr;
struct sockaddr_in local_addr;
remote_addr.sin_family = AF_INET;
remote_addr.sin_port = htons(53);
remote_addr.sin_addr.s_addr = inet_addr("1.1.1.1");
if (connect(sock_fd, (struct sockaddr*)&remote_addr, sizeof(struct sockaddr_in)) != 0) {
closesocket(sock_fd);
return 0;
}
socklen_t len = sizeof(struct sockaddr_in);
getsockname(sock_fd, (struct sockaddr*)&local_addr, &len);
char* local_ip = inet_ntoa(local_addr.sin_addr);
closesocket(sock_fd);
if (local_ip) {
lua_pushstring(L, local_ip);
return 1;
}
return 0;
}

inline int gethostbydomain(lua_State* L, std::string domain) {
struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo));
Expand Down
8 changes: 1 addition & 7 deletions core/quanta/src/quanta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ const char* quanta_app::get_env(const char* key) {
int quanta_app::set_env(lua_State* L) {
const char* key = lua_tostring(L, 1);
const char* value = lua_tostring(L, 2);
if (getenv(key)){
int overwrite = luaL_optinteger(L, 3, 0);
if (overwrite || m_environs.find(key) != m_environs.end()) {
setenv(key, value, 1);
}
return 0;
}
m_environs[key] = value;
setenv(key, value, 1);
return 0;
Expand Down Expand Up @@ -153,6 +146,7 @@ void quanta_app::run() {
quanta.set_function("default_signal", [](int n) { signal(n, SIG_DFL); });
quanta.set_function("register_signal", [](int n) { signal(n, on_signal); });
quanta.set_function("getenv", [&](const char* key) { return get_env(key); });
quanta.set_function("setenv", [&](lua_State* L) { return set_env(L); });

const char* env_log_path = get_env("QUANTA_LOG_PATH");
if (env_log_path) {
Expand Down
12 changes: 10 additions & 2 deletions extend/laoi/src/aoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ namespace laoi {
marker = 1, //被观察者
};

class aoi;
#pragma pack(2)
struct aoi_obj
{
uint64_t eid;
aoi_type type;
uint64_t eid = 0;
uint16_t grid_x = 0;
uint16_t grid_z = 0;
aoi* aoi_inst = nullptr;
void set_grid(uint16_t x, uint16_t z) {
grid_x = x;
grid_z = z;
}
aoi_obj(uint64_t id, aoi_type typ) : eid(id), type(typ) {}
aoi_obj(uint64_t id, aoi_type typ) : type(typ), eid(id){}
};
#pragma pack()

Expand Down Expand Up @@ -158,6 +160,10 @@ namespace laoi {
if ((nxgrid >= m_xgrid_num) || (nzgrid >= m_zgrid_num)) {
return false;
}
if (obj->aoi_inst) {
obj->aoi_inst->detach(L, obj);
}
obj->aoi_inst = this;
//查询节点
object_set objs;
kit_state kit_state(L);
Expand Down Expand Up @@ -197,6 +203,8 @@ namespace laoi {
object_set objs;
kit_state kit_state(L);
get_rect_objects(objs, obj->grid_x - m_aoi_radius, obj->grid_x + m_aoi_radius, obj->grid_z - m_aoi_radius, obj->grid_z + m_aoi_radius);
//清空aoi_inst
obj->aoi_inst = nullptr;
//移除
remove(obj);
//消息通知
Expand Down
5 changes: 3 additions & 2 deletions extend/ljson/src/ljson.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,11 @@ namespace ljson {
}

yyjson_mut_val* array_encode(lua_State* L, yyjson_mut_doc* doc, bool emy_as_arr, int index, int depth) {
lua_pushnil(L);
int asize = lua_rawlen(L, index);
yyjson_mut_val* array = yyjson_mut_arr(doc);
if (!array) throw invalid_argument("json encode memory not enough!");
while (lua_next(L, index) != 0) {
for (int i = 1; i <= asize; ++i){
lua_geti(L, index, i);
auto value = encode_one(L, doc, emy_as_arr, -1, depth);
if (!value) throw invalid_argument("json encode memory not enough!");
yyjson_mut_arr_append(array, value);
Expand Down
38 changes: 38 additions & 0 deletions extend/lmdb/lmdb.lmak
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--工程名字
PROJECT_NAME = "lmdb"

--目标名字
TARGET_NAME = "lmdb"

----工程类型: static/dynamic/exe
PROJECT_TYPE = "dynamic"

EX_FLAGS = {
"Wno-implicit-fallthrough"
}

--需要的include目录
INCLUDES = {
"../lua/lua",
"../luakit/include"
}

MIMALLOC = false

--需要连接的库文件
LIBS = {
"lua"
}

--WINDOWS需要定义的选项
WINDOWS_DEFINES = {
"LUA_BUILD_AS_DLL"
}

--依赖项目
DEPS = {
"lualib"
}

--分组定义
GROUP = "luaext"
130 changes: 130 additions & 0 deletions extend/lmdb/lmdb.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#工程名字
PROJECT_NAME = lmdb

#目标名字
TARGET_NAME = lmdb

#系统环境
UNAME_S = $(shell uname -s)

#伪目标
.PHONY: clean all target pre_build post_build
all : pre_build target post_build

#CFLAG
MYCFLAGS =

#需要定义的FLAG
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
MYCFLAGS += -Wno-implicit-fallthrough

#c标准库版本
#gnu99/gnu11/gnu17
STDC = -std=gnu99

#c++标准库版本
#c++11/c++14/c++17/c++20
STDCPP = -std=c++17

#需要的include目录
MYCFLAGS += -I../lua/lua
MYCFLAGS += -I../luakit/include

#需要定义的选项

#LDFLAGS
LDFLAGS =


#源文件路径
SRC_DIR = src

#需要排除的源文件,目录基于$(SRC_DIR)
EXCLUDE =

#需要连接的库文件
LIBS =
#自定义库
LIBS += -llua
#系统库
LIBS += -lm -ldl -lstdc++ -lpthread

#定义基础的编译选项
ifndef CC
CC = gcc
endif
ifndef CX
CX = c++
endif
CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS)
CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS)

#项目目录
ifndef SOLUTION_DIR
SOLUTION_DIR=./
endif

#临时文件目录
INT_DIR = $(SOLUTION_DIR)temp/$(PROJECT_NAME)

#目标文件前缀,定义则.so和.a加lib前缀,否则不加
PROJECT_PREFIX =

#目标定义
MYCFLAGS += -fPIC
TARGET_DIR = $(SOLUTION_DIR)bin
TARGET_DYNAMIC = $(TARGET_DIR)/$(PROJECT_PREFIX)$(TARGET_NAME).so
#soname
ifeq ($(UNAME_S), Linux)
LDFLAGS += -Wl,-soname,$(PROJECT_PREFIX)$(TARGET_NAME).so
endif
#install_name
ifeq ($(UNAME_S), Darwin)
LDFLAGS += -Wl,-install_name,$(PROJECT_PREFIX)$(TARGET_NAME).so
endif

#link添加.so目录
LDFLAGS += -L$(SOLUTION_DIR)bin
LDFLAGS += -L$(SOLUTION_DIR)library

#自动生成目标
OBJS =
#根目录
OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c)))
OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m)))
OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc)))
OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp)))

# 编译所有源文件
$(INT_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(INT_DIR)/%.o : $(SRC_DIR)/%.m
$(CC) $(CFLAGS) -c $< -o $@
$(INT_DIR)/%.o : $(SRC_DIR)/%.cc
$(CX) $(CXXFLAGS) -c $< -o $@
$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp
$(CX) $(CXXFLAGS) -c $< -o $@

$(TARGET_DYNAMIC) : $(OBJS)
$(CC) -o $@ -shared $(OBJS) $(LDFLAGS) $(LIBS)

#target伪目标
target : $(TARGET_DYNAMIC)

#clean伪目标
clean :
rm -rf $(INT_DIR)

#预编译
pre_build:
mkdir -p $(INT_DIR)
mkdir -p $(TARGET_DIR)

#后编译
post_build:
Loading

0 comments on commit 988ccee

Please sign in to comment.