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);