Skip to content

Commit

Permalink
Merge pull request #23 from pwnsky/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
i0gan authored Sep 30, 2023
2 parents 84435bd + 7b959c1 commit 6b97194
Show file tree
Hide file tree
Showing 28 changed files with 198 additions and 219 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ i0gan/squick-runtime # squick程序运行容器,版本 1.0

#### 2. 源码编译第三方库(不推荐)

不推荐采用源码编译第三方库,需要搭建boost环境,也需下载依赖包,并安装到Windows中。
不推荐采用源码编译第三方库,部分依赖库,需要搭建boost环境,也需下载依赖包,并安装到Windows中。

**Win64 OpenSSL v3.0.7**

[EXE](http://slproweb.com/download/Win64OpenSSL-3_0_7.exe) | [MSI](http://slproweb.com/download/Win64OpenSSL-3_0_7.msi)
https://slproweb.com/products/Win32OpenSSL.html

在编译Lua库的时候,虽然MinGW能编译Lua出dll,但由于vc与gcc某些函数不兼容,导致squick程序的lua插件不能链接到该dll,需暂时借助第三方编译好的lua.lib来完成链接。

Expand Down
22 changes: 1 addition & 21 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,34 +96,14 @@ else()
)
endif()


#message("Build Version:"${BUILD_VERSION} ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_STANDARD 17)
#if( BUILD_VERSION STREQUAL "debug" )
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -g -ggdb -DDEBUG -fPIC") # -O0 -Wall -Wendif-labels
#else()
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -fPIC")# -Wendif-labels
#endif()
#set(LDFLAGS "$ENV{LDFLAGS} -stdlib=libc++")



#if( BUILD_VERSION STREQUAL "debug" )
# set(ThirdPartyLibPath ${SolutionDir}/third_party/build/lib ${SolutionDir}/build/debug/lib )
#else()
# set(ThirdPartyLibPath ${SolutionDir}/third_party/build/lib ${SolutionDir}/build/release/lib)
#endif()

if( MODE STREQUAL "dev" )
# -DDEBUG
add_definitions(-D_X64 -D_CONSOLE -DSQUICK_DEV )
endif()


link_directories(${ThirdPartyLibPath} ${SquickLibPath})
add_definitions(-D_X64 -D_CONSOLE -DSQUICK_DYNAMIC_PLUGIN)
add_definitions(-D_X64 -D_CONSOLE -DSQUICK_DYNAMIC_PLUGIN -DSQUICK_ENABLE_SSL)

add_subdirectory(struct)
add_subdirectory(squick)
Expand Down
2 changes: 0 additions & 2 deletions src/lua/lib/db/mongo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ end

function Mongo:AckFind(guid, msg_data, msg_id, fd)
local data = Squick:Decode("rpc.AckMongoFind", msg_data);
print("Find ack")
PrintTable(data)
self:QueryResume(data.query_id, data)
end

Expand Down
13 changes: 10 additions & 3 deletions src/lua/node/lobby/player_mgr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ function PlayerMgr:GetPlayerDataFromMongo(account_id, account)
account = account, account_id = account_id, player_id = Env.area .. "-" .. account_id, name = "none",
age = 0, level = 0, proxy_id = 0, last_login_time = os.time(), created_time = os.time(),
online = false, platform = "none", extra = {},
area = Env.area, mail = {}, itmes = {},
area = Env.area, mail = {}, itmes = {}, ip = "", ip_address = "",
real = {
id_card = "",
name = "",
address = "",
},
node = {
proxy_id = 0, proxy_fd = 0,
lobby_id = 0, db_proxy_id = 0,
login_id = Env.app_id, world_id = 0,
lobby_id = Env.app_id, db_proxy_id = 0,
login_id = 0, world_id = 0,
master_id = 0,
}
}
Expand Down Expand Up @@ -75,7 +80,9 @@ function PlayerMgr:OnEnter(player_id, msg_data, msg_id, fd)
player_data.node.proxy_fd = fd
player_data.node.proxy_id = req.proxy_id
player_data.online = true
player_data.ip = req.ip

PrintTable(player_data)
self:CachePlayerData(player_id, player_data)
Net:SendByFD(fd, PlayerEventRPC.PLAYER_BIND_EVENT, Squick:Encode("rpc.PlayerBindEvent", ack))
end)
Expand Down
2 changes: 1 addition & 1 deletion src/node/db_proxy/clickhouse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include_directories( ${SolutionDir}/third_party/clickhouse-cpp/contrib/absl )
if (APPLE)

elseif(UNIX)
target_link_libraries(${ProjectName} clickhouse-cpp)
target_link_libraries(${ProjectName} clickhouse-cpp-lib)
else()
target_link_libraries(${ProjectName} clickhouse-cpp-lib)
target_link_libraries(${ProjectName} ws2_32)
Expand Down
39 changes: 22 additions & 17 deletions src/node/db_proxy/clickhouse/clickhouse_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,46 @@ bool ClickhouseModule::AfterStart() {
m_net_ = pm_->FindModule<INetModule>();
Connect();
m_net_->AddReceiveCallBack(rpc::DbProxyRPC::REQ_CLICKHOUSE_QUERY, this, &ClickhouseModule::OnReqQuery);
m_net_->AddReceiveCallBack(rpc::DbProxyRPC::REQ_CLICKHOUSE_EXECUTE, this, &ClickhouseModule::OnReqExecute);
m_net_->AddReceiveCallBack(rpc::DbProxyRPC::REQ_CLICKHOUSE_INSERT, this, &ClickhouseModule::OnReqInsert);
m_net_->AddReceiveCallBack(rpc::DbProxyRPC::REQ_CLICKHOUSE_SELECT, this, &ClickhouseModule::OnReqSelect);
return true;
}

bool ClickhouseModule::Update() { return true; }

bool ClickhouseModule::Destory() { return true; }

void ClickhouseModule::OnReqQuery(const socket_t sock, const int msg_id, const char* msg, const uint32_t len) {
void ClickhouseModule::OnReqQuery(const socket_t sock, const int msg_id, const char* msg, const uint32_t len) {}

void ClickhouseModule::OnReqExecute(const socket_t sock, const int msg_id, const char* msg, const uint32_t len) {
int code = rpc::DbProxyCode::DB_PROXY_CODE_CLICKHOUSE_SUCCESS;
rpc::ReqClickhouseExecute req;
rpc::AckMongoInsert ack;
string tmp;
rpc::ReqClickhouseQuery req;
rpc::AckClickhouseQuery ack;
int code = 0;
if (!m_net_->ReceivePB(msg_id, msg, len, req, tmp)) {
return;
}
try {
switch (req.cmd()) {
case rpc::ClickhouseCMD::CLICKHOUSE_RAW: {
client_->Execute(req.raw_cmd());
} break;
case rpc::ClickhouseCMD::CLICKHOUSE_SELECT: {

} break;
}
client_->Execute(req.sql());
}
catch (exception e) {
code = 1;
catch (const std::exception& e) {
std::cout << "Exception: " << e.what() << std::endl;
code = rpc::DbProxyCode::DB_PROXY_CODE_CLICKHOUSE_EXCEPTION;
ack.set_msg(e.what());
}
ack.set_code(code);
ack.set_query_id(req.query_id());
m_net_->SendMsgPB(rpc::DbProxyRPC::ACK_CLICKHOUSE_QUERY, ack, sock);
m_net_->SendMsgPB(rpc::DbProxyRPC::ACK_CLICKHOUSE_EXECUTE, ack, sock);
}

void ClickhouseModule::OnReqInsert(const socket_t sock, const int msg_id, const char* msg, const uint32_t len) {

}

void ClickhouseModule::OnReqSelect(const socket_t sock, const int msg_id, const char* msg, const uint32_t len) {

}
bool ClickhouseModule::Connect() {
const string id = "ClickhouseLogDb_1";
string ip = m_element_->GetPropertyString(id, excel::DB::IP());
Expand All @@ -66,8 +73,6 @@ bool ClickhouseModule::Connect() {
/// Initialize client connection.
client_ = new Client(ClientOptions().SetHost(ip).SetPort(port).SetPassword(password));

dout << "Test clickhouse\n";

// Create a table.
client_->Execute("CREATE TABLE IF NOT EXISTS default.numbers (id UInt64, name String) ENGINE = Memory");

Expand Down
4 changes: 4 additions & 0 deletions src/node/db_proxy/clickhouse/clickhouse_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class ClickhouseModule : public IClickhouseModule {
virtual ~ClickhouseModule();

void OnReqQuery(const socket_t sock, const int msg_id, const char* msg, const uint32_t len);
void OnReqExecute(const socket_t sock, const int msg_id, const char* msg, const uint32_t len);
void OnReqInsert(const socket_t sock, const int msg_id, const char* msg, const uint32_t len);
void OnReqSelect(const socket_t sock, const int msg_id, const char* msg, const uint32_t len);


virtual bool Start();
virtual bool AfterStart();
Expand Down
25 changes: 11 additions & 14 deletions src/node/db_proxy/mongo/mongo_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ namespace db_proxy::mongo {
+ m_element_->GetPropertyString(id, excel::DB::IP()) + ":"
+ to_string(m_element_->GetPropertyInt(id, excel::DB::Port()));

//dout << "connect to : " << url << std::endl;

// Setup the connection and get a handle on the "admin" database.
client_ = new client{ uri {url} };

Expand All @@ -68,14 +66,14 @@ namespace db_proxy::mongo {
}

void MongoModule::OnReqInsert(const socket_t sock, const int msg_id, const char* msg, const uint32_t len) {
int code = 0;
int code = rpc::DbProxyCode::DB_PROXY_CODE_MONGO_SUCCESS;
rpc::ReqMongoInsert req;
rpc::AckMongoInsert ack;
string tmp;
if (!m_net_->ReceivePB(msg_id, msg, len, req, tmp)) {
return;
}

try {
string tmp;
assert(m_net_->ReceivePB(msg_id, msg, len, req, tmp));

mongocxx::database db = client_->database(req.db());
auto collection = db[req.collection()];
auto doc = bsoncxx::from_json(req.insert_json());
Expand All @@ -86,7 +84,7 @@ namespace db_proxy::mongo {
}
catch (const std::exception& e) {
std::cout << "Exception: " << e.what() << std::endl;
code = rpc::MongoCode::MONGO_CODE_EXCEPTION;
code = rpc::DbProxyCode::DB_PROXY_CODE_MONGO_EXCEPTION;
ack.set_msg(e.what());
}
ack.set_code(code);
Expand All @@ -95,14 +93,13 @@ namespace db_proxy::mongo {
}
// Ref: http://mongocxx.org/mongocxx-v3/tutorial/#specify-a-query-filter
void MongoModule::OnReqFind(const socket_t sock, const int msg_id, const char* msg, const uint32_t len) {
int code = 0;
int code = rpc::DbProxyCode::DB_PROXY_CODE_MONGO_SUCCESS;
rpc::ReqMongoFind req;
rpc::AckMongoFind ack;
string tmp;
if (!m_net_->ReceivePB(msg_id, msg, len, req, tmp)) {
return;
}
try {
string tmp;
assert(m_net_->ReceivePB(msg_id, msg, len, req, tmp));

mongocxx::database db = client_->database(req.db());
auto collection = db[req.collection()];
auto cond = bsoncxx::from_json(req.condition_json());
Expand All @@ -112,7 +109,7 @@ namespace db_proxy::mongo {
}
} catch (const std::exception& e) {
std::cout << "Exception: " << e.what() << std::endl;
code = rpc::MongoCode::MONGO_CODE_EXCEPTION;
code = rpc::DbProxyCode::DB_PROXY_CODE_MONGO_EXCEPTION;
ack.set_msg(e.what());
}
ack.set_code(code);
Expand Down
7 changes: 4 additions & 3 deletions src/node/db_proxy/redis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ add_library(${ProjectName} SHARED ${soruces} ${headers})
if (APPLE)

elseif(UNIX)
target_link_libraries(${ProjectName} hiredisd.so)
target_link_libraries(${ProjectName} hiredis)
target_link_libraries(${ProjectName} redis++)
else()
target_link_libraries(${ProjectName} hiredisd.lib)
target_link_libraries(${ProjectName} redis++.lib)
target_link_libraries(${ProjectName} hiredisd)
target_link_libraries(${ProjectName} redis++)
endif()

LinkSquick(${ProjectName})
Expand Down
48 changes: 22 additions & 26 deletions src/node/db_proxy/redis/redis_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,24 @@ namespace db_proxy::redis {
bool RedisModule::Destory() { return true; }

void RedisModule::OnReqRedisGet(const socket_t sock, const int msg_id, const char* msg, const uint32_t len) {
int code = 0;
int code = rpc::DbProxyCode::DB_PROXY_CODE_REDIS_SUCCESS;
rpc::ReqRedisGet req;
rpc::AckRedisGet ack;
string tmp;
if (!m_net_->ReceivePB(msg_id, msg, len, req, tmp)) {
return;
}

try {
string tmp;
assert(m_net_->ReceivePB(msg_id, msg, len, req, tmp));
auto val = client_->get(req.key());
if (val) {
// Dereference val to get the returned value of std::string type.
ack.set_value(val.value());
}
else {
// else key doesn't exist.
code = rpc::RedisCode::REDIS_CODE_NO_KEY;
code = rpc::DbProxyCode::DB_PROXY_CODE_REDIS_NO_KEY;
}
} catch (const Error& e) {
code = rpc::RedisCode::REDIS_CODE_EXCEPTION;
code = rpc::DbProxyCode::DB_PROXY_CODE_REDIS_EXCEPTION;
ack.set_msg(e.what());
}
ack.set_code(code);
Expand All @@ -71,43 +70,41 @@ namespace db_proxy::redis {
}

void RedisModule::OnReqRedisSet(const socket_t sock, const int msg_id, const char* msg, const uint32_t len) {
int code = 0;
int code = rpc::DbProxyCode::DB_PROXY_CODE_REDIS_SUCCESS;
rpc::ReqRedisSet req;
rpc::AckRedisSet ack;
string tmp;
if (!m_net_->ReceivePB(msg_id, msg, len, req, tmp)) {
return;
}
try {
string tmp;
assert(m_net_->ReceivePB(msg_id, msg, len, req, tmp));
client_->set(req.key(), req.value(), std::chrono::milliseconds(req.ttl()));
}
catch (const Error& e) {
code = rpc::RedisCode::REDIS_CODE_NO_KEY;
code = rpc::DbProxyCode::DB_PROXY_CODE_REDIS_EXCEPTION;
ack.set_msg(e.what());
}
ack.set_code(code);
ack.set_query_id(req.query_id());
m_net_->SendMsgPB(rpc::DbProxyRPC::ACK_REDIS_SET, ack, sock);
}

void RedisModule::OnReqRedisHGet(const socket_t sock, const int msg_id, const char* msg, const uint32_t len) {
int code = 0;
int code = rpc::DbProxyCode::DB_PROXY_CODE_REDIS_SUCCESS;
rpc::ReqRedisHGet req;
rpc::AckRedisHGet ack;
string tmp;
if (!m_net_->ReceivePB(msg_id, msg, len, req, tmp)) {
return;
}
try {
string tmp;
assert(m_net_->ReceivePB(msg_id, msg, len, req, tmp));
auto val = client_->hget(req.key(), req.field());
if (val) {
ack.set_value(val.value());
}
else {
code = rpc::RedisCode::REDIS_CODE_NO_KEY;
code = rpc::DbProxyCode::DB_PROXY_CODE_REDIS_NO_KEY;
}
}
catch (const Error& e) {
code = rpc::RedisCode::REDIS_CODE_NO_KEY;
code = rpc::DbProxyCode::DB_PROXY_CODE_REDIS_EXCEPTION;
ack.set_msg(e.what());
}

ack.set_code(code);
Expand All @@ -116,18 +113,17 @@ namespace db_proxy::redis {
}

void RedisModule::OnReqRedisHSet(const socket_t sock, const int msg_id, const char* msg, const uint32_t len) {
int code = 0;
int code = rpc::DbProxyCode::DB_PROXY_CODE_REDIS_SUCCESS;
rpc::ReqRedisHSet req;
rpc::AckRedisHSet ack;
string tmp;
if (!m_net_->ReceivePB(msg_id, msg, len, req, tmp)) {
return;
}
try {
string tmp;
assert(m_net_->ReceivePB(msg_id, msg, len, req, tmp));
client_->hset(req.key(), req.field(), req.value());
}
catch (const Error& e) {
code = rpc::RedisCode::REDIS_CODE_NO_KEY;
code = rpc::DbProxyCode::DB_PROXY_CODE_REDIS_EXCEPTION;
ack.set_msg(e.what());
}
ack.set_code(code);
ack.set_query_id(req.query_id());
Expand Down
2 changes: 1 addition & 1 deletion src/node/login/http/http_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ bool HttpModule::CheckAuth(const std::string& account_id, const std::string& use

string HttpModule::MakeToken(string account_id) {
string sum = "UserID: " + account_id + std::to_string(SquickGetTimeMS()) + SQUICK_HASH_SALT;
SHA256 sha256;
crypto::SHA256 sha256;
return sha256(sum);
}

Expand Down
Loading

0 comments on commit 6b97194

Please sign in to comment.