diff --git a/MyProject/A.nut b/MyProject/A.nut index d7b68c0..3b3b50c 100644 --- a/MyProject/A.nut +++ b/MyProject/A.nut @@ -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); \ No newline at end of file + 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); +// } \ No newline at end of file diff --git a/MyProject/DPS登录器.nut b/MyProject/DPS登录器.nut new file mode 100644 index 0000000..df05348 --- /dev/null +++ b/MyProject/DPS登录器.nut @@ -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); \ No newline at end of file diff --git a/_DPS_/_Core/BaseClass/HttpClass/HttpClass.nut b/_DPS_/_Core/BaseClass/HttpClass/HttpClass.nut index 05d1e26..7445cac 100644 --- a/_DPS_/_Core/BaseClass/HttpClass/HttpClass.nut +++ b/_DPS_/_Core/BaseClass/HttpClass/HttpClass.nut @@ -262,12 +262,17 @@ class HttpServer { //处理函数 Handler = null; + //服务ID + ServerId = null; constructor(host, service = "80") { Host = host; Service = service; + if (getroottable().rawin("HttpServer_" + Host + "_" + Service)){ + throw "端口被占用"; + } getroottable()["HttpServer_" + Host + "_" + Service] <- this; } @@ -275,15 +280,20 @@ class HttpServer { //记录处理函数 Handler = Func; - local success = Sq_CreateHttpServer(Host, Service, this); - if (success) { + ServerId = Sq_CreateHttpServer(Host, Service, this); + if (ServerId) { ::print("Server started successfully."); } else { ::print("Failed to start server."); } } - function Event(SocketObject, Msg) { - Timer.SetTimeOut(Handler, 1, HttpResponse(SocketObject), Msg); + function Stop() + { + Sq_StopHttpServer(ServerId); + } + + function Event(SocketObject, Header, Msg) { + Timer.SetTimeOut(Handler, 1, HttpResponse(SocketObject), Header, Msg); } } \ No newline at end of file diff --git a/_DPS_/_Core/BaseClass/MD5Class/MD5Class.nut b/_DPS_/_Core/BaseClass/MD5Class/MD5Class.nut index 317b7e8..c94f2c3 100644 --- a/_DPS_/_Core/BaseClass/MD5Class/MD5Class.nut +++ b/_DPS_/_Core/BaseClass/MD5Class/MD5Class.nut @@ -21,31 +21,78 @@ class MD5 { Sq_CallFunc(MD5_Final_ptr, "void", ["pointer", "pointer"], Ctx, Result); } + // 16进制编码函数 + // 参数: input - 可以是字符串或字节数组或Memory对象 + // 返回: 32位16进制小写字符串(默认格式) + function hex_encode(input) { + local byteArray = []; + + // 如果输入是字符串,转换为字节数组 + if (typeof input == "string") { + for (local i = 0; i < input.len(); i++) { + byteArray.append(input[i].tointeger() & 0xFF); + } + } + // 如果输入是数组,直接使用 + else { + byteArray = input; + } + + local encoded = ""; + + for (local i = 0; i < byteArray.len(); i++) { + local byte = byteArray[i] & 0xFF; + encoded += format("%02x", byte); + } + + return encoded; + } + + // Base64 编码函数 + // 参数: input - 可以是字符串或字节数组 + // 返回: base64 编码后的字符串 function base64_encode(input) { local base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - local inputLength = input.len(); + + // 如果输入是字符串,转换为字节数组 + local byteArray = []; + if (typeof input == "string") { + for (local i = 0; i< input.len(); i++) { + byteArray.append(input[i].tointeger() & 0xFF); + } + } else { + // 假设是数组,直接使用 + byteArray = input; + } + + local inputLength = byteArray.len(); local i = 0; local j = 0; local charArray3 = array(3); local charArray4 = array(4); local encoded = ""; - while (inputLength--) { - charArray3[i++] = input[inputLength]; + // 处理每3个字节为一组 + local pos = 0; + while (pos< inputLength) { + charArray3[i++] = byteArray[pos++]; + if (i == 3) { + // 将3个字节转换为4个base64字符 charArray4[0] = (charArray3[0] & 0xfc) >> 2; charArray4[1] = ((charArray3[0] & 0x03) << 4) + ((charArray3[1] & 0xf0) >> 4); charArray4[2] = ((charArray3[1] & 0x0f) << 2) + ((charArray3[2] & 0xc0) >> 6); charArray4[3] = charArray3[2] & 0x3f; for (i = 0; i< 4; i++) { - encoded += base64_chars[charArray4[i]]; + encoded += base64_chars.slice(charArray4[i], charArray4[i] + 1); } i = 0; } } - if (i) { + // 处理剩余的字节(不足3个字节的情况) + if (i > 0) { for (j = i; j< 3; j++) { charArray3[j] = 0; } @@ -56,9 +103,10 @@ class MD5 { charArray4[3] = charArray3[2] & 0x3f; for (j = 0; j< i + 1; j++) { - encoded += base64_chars[charArray4[j]]; + encoded += base64_chars.slice(charArray4[j], charArray4[j] + 1); } + // 添加填充字符 '=' while (i++<3) { encoded += "="; } @@ -67,6 +115,7 @@ class MD5 { return encoded; } + function GetFile(FileName) { local Io = IO(FileName, "r+"); diff --git a/lib/libAurora.so b/lib/libAurora.so index 66dca66..83e7c14 100755 Binary files a/lib/libAurora.so and b/lib/libAurora.so differ