更新HttpServer类以支持服务ID管理,添加MD5类的hex_encode函数和改进base64_encode函数,修改A.nut文件以增加注释和功能

This commit is contained in:
lenheart
2026-01-03 14:38:50 +08:00
parent 6589ff93c4
commit a162ecee48
5 changed files with 194 additions and 12 deletions

View File

@@ -116,8 +116,40 @@ Gm_InputFunc_Handle["test"] <- function(SUser, CmdString) {
}
Timer.SetTimeOut(function() {
// // Sq_Rsa_GenerateKey();
// local str = format("%08x010101010101010101010101010101010101010101010101010101010101010155914510010403030101", 1);
// local Byte = Sq_Rsa_Private_Encrypt(str);
// local EnStr = _base64_encode(Byte);
// print(EnStr);
}, 1);
local passwd = "1";
}, 1);
// //玩家新增道具时
// Cb_wdzsdfge_Enter_Func <- {};
// Cb_wdzsdfge_Leave_Func <- {};
// _Hook_Register_Currency_Func_("0x81E8C78", ["pointer", "pointer", "pointer", "int"], Cb_wdzsdfge_Enter_Func, Cb_wdzsdfge_Leave_Func);
// Cb_wdzsdfge_Leave_Func["11"] <- function(args) {
// local Ret = Sq_CallFunc(S_Ptr("0x816EE1E"), "pointer", ["pointer"], args[1]);
// print("登录请求: ");
// print("GarenaAuthData: " + Ret);
// print("args[0]: " + args[0] + " args[1]: " + args[1]);
// print("args[2]: ");
// NativePointer(args[2]).Output(512);
// }

View File

@@ -0,0 +1,91 @@
class _DPS_Login_Gateway_ {
//数据库连接
MysqlObject = null;
PackHandleMap = null;
constructor() {
PackHandleMap = {};
MysqlObject = Mysql(Str_Ptr("127.0.0.1"), 3306, Str_Ptr("taiwan_cain"), Str_Ptr("game"), Str_Ptr("uu5!^%jg"));
MysqlObject.Exec_Sql(format("SET NAMES %s", "latin1"));
//创建一个Http Server
try {
local HS = HttpServer("0.0.0.0", "41817");
HS.Listen(function(SocketObject, Header, Msg) {
getroottable()._DPS_Login_Gateway_Object_._HttpServer_Event_DPS_(SocketObject, Header, Msg);
});
} catch (exception) {
}
PackHandleMap["/GetConfig"] <- function(SocketObject, Header, Msg) {
local Config = sq_ReadJsonFile("/dp_s/OfficialConfig/登录器配置.json");
//读取DPS登录器的配置并发送
SocketObject.Write(Config);
}
PackHandleMap["/Login"] <- function(SocketObject, Header, Msg) {
local Jso = Json.Decode(Msg);
local account = Jso.account;
local passwd = Jso.passwd;
local passwd_hash = MD5_Hash(passwd);
local sql = format("select UID from d_taiwan.accounts where accountname='%s' and password='%s';", account, passwd_hash);
local Ret = MysqlObject.Select(sql, ["int"]);
if (Ret && Ret.len() > 0) {
local Uid = Ret[0][0];
local str = format("%08x010101010101010101010101010101010101010101010101010101010101010155914510010403030101", Uid);
local Byte = Sq_Rsa_Private_Encrypt(str);
local EnStr = _base64_encode(Byte);
//发送登录Token
SocketObject.Write({
token = EnStr
});
} else {
SocketObject.Write({
error = 1
});
}
}.bindenv(this);
}
function _HttpServer_Event_DPS_(SocketObject, Header, Msg) {
if (PackHandleMap.rawin(Header.path)) {
PackHandleMap[Header.path](SocketObject, Header, Msg);
} else {
SocketObject.Write({
error = "error url"
});
}
}
function MD5_Hash(str) {
local Ctx = Memory.alloc(0x100);
MD5.MD5_Init(Ctx.C_Object);
MD5.MD5_Update(Ctx.C_Object, Memory.allocUtf8String(str).C_Object, str.len());
local Result = Memory.alloc(16);
MD5.MD5_Final(Result.C_Object, Ctx.C_Object);
return MD5.hex_encode(Result.readUtf8String(16));
}
}
Timer.SetTimeOut(function() {
getroottable()._DPS_Login_Gateway_Object_ <- _DPS_Login_Gateway_();
}, 1);