znote_login.lua

main 69 lines · 3 KB Raw
Alex Alex Commit Initial commit 01/10/2026 09:20
1-- Znote LoginWebService (version 1) for protocol 11, 12+
2-- Move file to this location: data/scripts/znote_login.lua
3-- And restart OT server, it should auto load script.
4-- Requires updated version of Znote AAC. (18. June 2020)
5-- This script will help Znote AAC connect players to this game server.
6
7local znote_loginWebService = GlobalEvent("znote_loginWebService")
8function znote_loginWebService.onStartup()
9 print(" ")
10 print("=============================")
11 print("= Znote AAC loginWebService =")
12 print("=============================")
13 local configLua = {
14 ["SERVER_NAME"] = configManager.getString(configKeys.SERVER_NAME),
15 ["IP"] = configManager.getString(configKeys.IP),
16 ["GAME_PORT"] = configManager.getNumber(configKeys.GAME_PORT)
17 }
18 local configSQL = {
19 ["SERVER_NAME"] = false,
20 ["IP"] = false,
21 ["GAME_PORT"] = false
22 }
23 local webStorage = db.storeQuery([[
24 SELECT
25 `key`,
26 `value`
27 FROM `znote_global_storage`
28 WHERE `key` IN('SERVER_NAME', 'IP', 'GAME_PORT')
29 ]])
30 if webStorage ~= false then
31 repeat
32 local key = result.getString(webStorage, 'key')
33 local value = result.getString(webStorage, 'value')
34 configSQL[key] = value
35 until not result.next(webStorage)
36 result.free(webStorage)
37 end
38 local inserts = {}
39 if configSQL.SERVER_NAME == false then
40 table.insert(inserts, "('SERVER_NAME',".. db.escapeString(configLua.SERVER_NAME) ..")")
41 elseif configSQL.SERVER_NAME ~= configLua.SERVER_NAME then
42 db.query("UPDATE `znote_global_storage` SET `value`=".. db.escapeString(configLua.SERVER_NAME) .." WHERE `key`='SERVER_NAME';")
43 print("= Updated [SERVER_NAME] FROM [" .. configSQL.SERVER_NAME .. "] to [" .. configLua.SERVER_NAME .. "]")
44 end
45 if configSQL.IP == false then
46 table.insert(inserts, "('IP',".. db.escapeString(configLua.IP) ..")")
47 elseif configSQL.IP ~= configLua.IP then
48 db.query("UPDATE `znote_global_storage` SET `value`=".. db.escapeString(configLua.IP) .." WHERE `key`='IP';")
49 print("= Updated [IP] FROM [" .. configSQL.IP .. "] to [" .. configLua.IP .. "]")
50 end
51 if configSQL.GAME_PORT == false then
52 table.insert(inserts, "('GAME_PORT',".. db.escapeString(configLua.GAME_PORT) ..")")
53 elseif configSQL.GAME_PORT ~= tostring(configLua.GAME_PORT) then
54 db.query("UPDATE `znote_global_storage` SET `value`=".. db.escapeString(configLua.GAME_PORT) .." WHERE `key`='GAME_PORT';")
55 print("= Updated [GAME_PORT] FROM [" .. configSQL.GAME_PORT .. "] to [" .. configLua.GAME_PORT .. "]")
56 end
57 if #inserts > 0 then
58 db.query("INSERT INTO `znote_global_storage` (`key`,`value`) VALUES "..table.concat(inserts,',')..";")
59 print("= Fixed " .. #inserts .. " missing configurations.")
60 end
61 print("=============================")
62 print("= SERVER_NAME: " .. configLua.SERVER_NAME)
63 print("= IP: " .. configLua.IP)
64 print("= GAME_PORT: " .. configLua.GAME_PORT)
65 print("=============================")
66 print(" ")
67end
68znote_loginWebService:register()
69
Top