From 529abad19cfd96895b909866931b136951e00a43 Mon Sep 17 00:00:00 2001 From: Znote Date: Wed, 17 Jun 2020 03:18:35 +0200 Subject: [PATCH] Lua file: RevScriptSys LoginWebService for protocol 11, 12+ Move file to this location: data/scripts/znote_login.lua And restart OT server, it should auto load script. This script will help Znote AAC connect players to your game server. --- LUA/TFS_10/revscriptsys/znote_login.lua | 68 +++++++++++++++++++++++++ login.php | 25 ++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 LUA/TFS_10/revscriptsys/znote_login.lua diff --git a/LUA/TFS_10/revscriptsys/znote_login.lua b/LUA/TFS_10/revscriptsys/znote_login.lua new file mode 100644 index 0000000..53e5cea --- /dev/null +++ b/LUA/TFS_10/revscriptsys/znote_login.lua @@ -0,0 +1,68 @@ +-- Znote LoginWebService (version 1) for protocol 11, 12+ +-- Move file to this location: data/scripts/znote_login.lua +-- And restart OT server, it should auto load script. +-- Requires updated version of Znote AAC. (18. June 2020) +-- This script will help Znote AAC connect players to this game server. + +local znote_loginWebService = GlobalEvent("znote_loginWebService") +function znote_loginWebService.onStartup() + print(" ") + print("=============================") + print("= Znote AAC loginWebService =") + print("=============================") + local configLua = { + ["SERVER_NAME"] = configManager.getString(configKeys.SERVER_NAME), + ["IP"] = configManager.getString(configKeys.IP), + ["GAME_PORT"] = configManager.getNumber(configKeys.GAME_PORT) + } + local configSQL = { + ["SERVER_NAME"] = false, + ["IP"] = false, + ["GAME_PORT"] = false + } + local webStorage = db.storeQuery([[ + SELECT + `key`, + `value` + FROM `znote_global_storage` + WHERE `key` IN('SERVER_NAME', 'IP', 'GAME_PORT') + ]]) + if webStorage ~= false then + repeat + local key = result.getString(webStorage, 'key') + local value = result.getString(webStorage, 'value') + configSQL[key] = value + until not result.next(webStorage) + result.free(webStorage) + end + local inserts = {} + if configSQL.SERVER_NAME == false then + table.insert(inserts, "('SERVER_NAME',".. db.escapeString(configLua.SERVER_NAME) ..")") + elseif configSQL.SERVER_NAME ~= configLua.SERVER_NAME then + db.query("UPDATE `znote_global_storage` SET `value`=".. db.escapeString(configLua.SERVER_NAME) .." WHERE `key`='SERVER_NAME';") + print("= Updated [SERVER_NAME] FROM [" .. configSQL.SERVER_NAME .. "] to [" .. configLua.SERVER_NAME .. "]") + end + if configSQL.IP == false then + table.insert(inserts, "('IP',".. db.escapeString(configLua.IP) ..")") + elseif configSQL.IP ~= configLua.IP then + db.query("UPDATE `znote_global_storage` SET `value`=".. db.escapeString(configLua.IP) .." WHERE `key`='IP';") + print("= Updated [IP] FROM [" .. configSQL.IP .. "] to [" .. configLua.IP .. "]") + end + if configSQL.GAME_PORT == false then + table.insert(inserts, "('GAME_PORT',".. db.escapeString(configLua.GAME_PORT) ..")") + elseif configSQL.GAME_PORT ~= tostring(configLua.GAME_PORT) then + db.query("UPDATE `znote_global_storage` SET `value`=".. db.escapeString(configLua.GAME_PORT) .." WHERE `key`='GAME_PORT';") + print("= Updated [GAME_PORT] FROM [" .. configSQL.GAME_PORT .. "] to [" .. configLua.GAME_PORT .. "]") + end + if #inserts > 0 then + db.query("INSERT INTO `znote_global_storage` (`key`,`value`) VALUES "..table.concat(inserts,',')..";") + print("= Fixed " .. #inserts .. " missing configurations.") + end + print("=============================") + print("= SERVER_NAME: " .. configLua.SERVER_NAME) + print("= IP: " .. configLua.IP) + print("= GAME_PORT: " .. configLua.GAME_PORT) + print("=============================") + print(" ") +end +znote_loginWebService:register() diff --git a/login.php b/login.php index 44eaade..9d13181 100644 --- a/login.php +++ b/login.php @@ -139,7 +139,30 @@ if($_SERVER['HTTP_USER_AGENT'] == "Mozilla/5.0" && $config['ServerEngine'] === ' if ($players !== false) { $gameserver = $config['gameserver']; - // todo: Fix dynamic desition to pass along token. (and verify that it works). Hostname: otx11.lan + // Override $config['gameserver'] if server has installed Lua script for loginWebService + $sql_elements = mysql_select_multi(" + SELECT + `key`, + `value` + FROM `znote_global_storage` + WHERE `key` IN('SERVER_NAME', 'IP', 'GAME_PORT') + "); + if ($sql_elements !== false) { + foreach ($sql_elements AS $element) { + switch ($element['key']) { + case 'SERVER_NAME': + $gameserver['name'] = $element['value']; + break; + case 'IP': + $gameserver['ip'] = $element['value']; + break; + case 'GAME_PORT': + $gameserver['port'] = (int)$element['value']; + break; + } + } + } + $sessionKey = $username."\n".$client->password; if (isset($account['secret']) && strlen($account['secret']) > 5) $sessionKey .= "\n".$token."\n".floor(time() / 30);