diff --git a/.luacheckrc b/.luacheckrc index 6ffdf425..56186448 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -14,24 +14,20 @@ max_cyclomatic_complexity = 13 max_code_line_length = 160 max_comment_line_length = 160 exclude_files = { - "script/luabt/*.*", - "script/luaoop/*.*", - "script/luabt/luaoop/*.*", - "script/luabt/LICENSE", - "script/luaoop/LICENSE", - "script/luabt/luaoop/LICENSE", - "server/robot/accord/page/*", - "extend/lmake/share.lua" + "extend/lmake/share.lua", + "server/robot/accord/page/*" } include_files = { - "script/*", - "server/*", - "worker/*", - "bin/proto/*.lua", - "tools/encrypt/*", - "tools/excel2lua/*", + "script/*.lua", + "server/*.lua", + "script/*/*.lua", + "server/*/*.lua", + "script/*/*/*.lua", + "server/*/*/*.lua", + "script/*/*/*/*.lua", + "server/*/*/*/*.lua", "extend/lmake/*.lua", - "extend/lmake/ltemplate/*.lua", + "tools/*/*.lua", } ignore = {"212", "213", "512"} diff --git a/bin/database.conf b/bin/database.conf index 2c7dd418..3ca8bf7f 100644 --- a/bin/database.conf +++ b/bin/database.conf @@ -19,7 +19,7 @@ set_env("QUANTA_MONGO_URLS", [[ ]]) --redis set_env("QUANTA_REDIS_URLS", [[ - redis://root:123456@127.0.0.1:6379; + redis://root:123456@10.96.8.100:6379; ]]) --mysql set_env("QUANTA_MYSQL_URLS", [[ diff --git a/extend/lmake/ltemplate.lua b/extend/lmake/ltemplate.lua index d4082680..4a9b82ab 100644 --- a/extend/lmake/ltemplate.lua +++ b/extend/lmake/ltemplate.lua @@ -164,12 +164,11 @@ local function render(content, env) return nil, chunk end ---导出文件模板 +--根据配置导出文件模板 --tpl_f: 文件模板 --tpl_out_f: 输出文件 --tpl_env: 环境变量 ---tpl_var_f: 环境变量文件 -local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f) +local function render_file(tpl_f, tpl_out_f, tpl_env) if not tpl_f or not tpl_out_f or not tpl_env then error("render template file params error!") return @@ -182,19 +181,6 @@ local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f) tpl_env.NAME = tpl_f local content = template_file:read("*all") template_file:close() - if tpl_var_f then - setmetatable(tpl_env, { __index = function(t, k) return _G[k] end }) - local func, err = loadfile(tpl_var_f, "bt", tpl_env) - if not func then - error(sformat("open template variable file %s failed :%s", tpl_var_f, err)) - return - end - local ok, res = pcall(func) - if not ok then - error(sformat("load template variable file %s failed :%s", tpl_var_f, res)) - return - end - end local out_file = iopen(tpl_out_f, "w") if not out_file then error(sformat("open template out file %s failed!", tpl_out_f)) @@ -214,13 +200,52 @@ local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f) print(sformat("render template file %s to %s success!", tpl_f, tpl_out_f)) end +--输入参数 +local arg_num = select("#", ...) + --工具用法 --tpl_f: 模板文件路径 --tpl_out_f:输出文件路径 --tpl_var_f:环境变量配置文件 -if select("#", ...) == 3 then +if arg_num == 3 then + local tpl_env = {} local tpl_f, tpl_out_f, tpl_var_f = select(1, ...) - render_file(tpl_f, tpl_out_f, {}, tpl_var_f) + if tpl_var_f then + setmetatable(tpl_env, { __index = function(t, k) return _G[k] end }) + local func, err = loadfile(tpl_var_f, "bt", tpl_env) + if not func then + error(sformat("open template variable file %s failed :%s", tpl_var_f, err)) + return + end + local ok, res = pcall(func) + if not ok then + error(sformat("load template variable file %s failed :%s", tpl_var_f, res)) + return + end + end + render_file(tpl_f, tpl_out_f, tpl_env) +end + +--工具用法 +--tpl_f: 模板文件路径 +--tpl_out_f:输出文件路径 +--key:文件索引, filename:文件名, ... +if arg_num > 3 then + local tpl_env = {} + local args = { ... } + local filenum = (arg_num - 2) // 2 + for i = 1, filenum do + local key = args[2 + i * 2 - 1] + local filename = args[2 + i * 2] + local args_file = iopen(filename, "r") + if not args_file then + error(sformat("open args file %s failed!", filename)) + return + end + tpl_env[key] = args_file:read("*all") + args_file:close() + end + render_file(args[1], args[2], tpl_env) end return { diff --git a/server/center/gm_page.lua b/server/center/gm_page.lua index 9ad5e84e..4878b737 100644 --- a/server/center/gm_page.lua +++ b/server/center/gm_page.lua @@ -12,64 +12,64 @@ return [[
@@ -81,11 +81,6 @@ return [[ - - - - -
@@ -118,179 +113,217 @@ return [[ ]] diff --git a/server/center/page/gm.css b/server/center/page/gm.css new file mode 100644 index 00000000..317d206b --- /dev/null +++ b/server/center/page/gm.css @@ -0,0 +1,58 @@ +html,body,div,h1,h2,h3,h4,h5,h6,p,span{ + padding: 0; + margin: 0; +} +body{ + padding-top: 10px; + overflow: auto; +} +.gmDumpContainer { + float: left; + border: 1px solid black; + height: 800px; + width: 30%; + margin-top:30px; + overflow: auto; +} +.gmContainer { + padding: 2px; + border: 1px solid black; + margin-top:30px; + height: 800px; + width: 70%; + overflow: auto; +} +.historyMsg{ + top: 5px; + border: 1px solid black; + height: 660px; + padding: 3px; + overflow: auto; +} +.newMsg{ + text-align: left; + margin-top: 5px; +} +.myMsg{ + background-color: grey; + color: white; + text-align: left; + margin-top: 5px; +} +.control{ + border: 1px solid black; + height: 130px; +} +.control-row{ + margin-top: 10px; +} +.inputMsg{ + height: 110px !important; + resize: none; +} +.sendBtn{ + height: 100px; +} +footer{ + text-align: center; +} \ No newline at end of file diff --git a/server/center/page/gm.html b/server/center/page/gm.html new file mode 100644 index 00000000..4e32e7a5 --- /dev/null +++ b/server/center/page/gm.html @@ -0,0 +1,61 @@ +-- luacheck: ignore +return [[ + + + + + + + + + GM Console + + + + +
+ +
+ +
+ 服务器: + + + + +
+
+
    +
  • 请选择服务器
  • +
+
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+ + + + + + +]] diff --git a/server/center/page/gm.js b/server/center/page/gm.js new file mode 100644 index 00000000..34545763 --- /dev/null +++ b/server/center/page/gm.js @@ -0,0 +1,212 @@ + +function changeServer(){ + var tx = document.getElementById("curServer").value; + window.open(tx, "_self"); +} + +function onfocusServer(){ + document.getElementById("curServer").value = ""; +} + +window.onload = function(){ + var host = window.location.host ; + var selectDiv = document.getElementById("curServer"); + selectDiv.value = host + var gmconsole = new GMConsole(); + gmconsole.init(); +}; + +var GMConsole = function(){ +}; + +GMConsole.prototype = { + init: function(){ + var that = this; + var cmd_index = 0; + var historyCmds = []; + var treeNodes = [{}]; + //获取服务器列表 + var fusion_url = "http://183.66.202.114:18080/server_mgr/query"; + + // 加载命令列表 + $.ajax({ + url: "/gmlist", + type: "GET", + dataType: "json", + contentType: "utf-8", + success: function (res) { + treeNodes[0] = res; + that._showConsole(treeNodes); + }, + error: function(status) { + document.write(JSON.stringify(status)); + } + }); + + // 加载命令列表 + $.ajax({ + url: fusion_url, + type: "GET", + dataType: "json", + contentType: "utf-8", + success: function (res) { + console.log(JSON.stringify(res)); + that._showServers(res); + }, + error: function(status) { + document.write(JSON.stringify(status)); + } + }); + + //sendMsg事件 + document.getElementById('send').addEventListener('click', function(){ + that._sendCommand(historyCmds); + cmd_index = historyCmds.length + }, false); + + //inputMsg事件 + document.getElementById('inputMsg').addEventListener('keyup', function(e){ + if (e.keyCode == 13 && e.ctrlKey){ + that._sendCommand(historyCmds); + cmd_index = historyCmds.length + } else if (e.keyCode == 38){ + if (cmd_index > 0) cmd_index = cmd_index - 1 + that._showCommand(historyCmds[cmd_index]) + } else if (e.keyCode == 40){ + if (cmd_index < historyCmds.length - 1) cmd_index = cmd_index + 1 + that._showCommand(historyCmds[cmd_index]) + } + }, false); + }, + + _showCommand: function(cmd) { + var inputMsg = document.getElementById('inputMsg'); + inputMsg.value = cmd; + inputMsg.focus(); + }, + + _showConsole: function(treeNodes) { + var that = this; + $('#consoleTree').treeview({data: treeNodes}); + //consoleTree事件 + $('#consoleTree').on('nodeSelected', function(event, data) { + if (data.tag == "gm") { + //参数数组 + var arg_arr = ["
命令: ", data.text,"  参数: ", data.command];
+                if (data.example) {
+                    arg_arr.push("
示例:"); + arg_arr.push(data.example); + } + if (data.tip) { + arg_arr.push("
说明:"); + arg_arr.push(data.tip); + } + arg_arr.push("
"); + var msg = arg_arr.join("") + that._displayNewMsg("historyMsg", msg, "myMsg"); + that._showCommand(data.name + " ") + } else if (data.tag == "log") { + window.open("http://" + data.text); + } + }); + }, + + _isJson(data){ + try{ + JSON.parse(data); + } + catch(err){ + return false; + } + return true; + }, + + _showServers: function(res){ + var curServerList = document.getElementById('curServerList'); + curServerList.value = ""; + + var host = window.location.host ; + var selectDiv = document.getElementById("curServer"); + selectDiv.value = host + + for (i = 0; i < res.data.length; i++) { + var option = new Option(); + option.innerHTML = res.data[i].name; + option.value = res.data[i].web; + + curServerList.appendChild(option); + console.log(option.value) + } + }, + + _inputMsgTrim(historyCmds){ + var that = this; + var inputMsg = document.getElementById('inputMsg'); + var msg = inputMsg.value.replace('\n', ''); + if (msg == ''){ + inputMsg.focus(); + return null; + } + historyCmds.push(msg); + var result = { cmdType : "cmd", data : {} }; + that._displayNewMsg("historyMsg", msg, "myMsg"); + if(that._isJson(msg)){ + result.cmdType = "json"; + result.data = JSON.stringify({ data : JSON.parse(msg) }); + return result; + } + result.data = JSON.stringify({ data : msg }) + return result; + }, + + _sendCommand: function(historyCmds) { + var that = this; + var result = that._inputMsgTrim(historyCmds); + if(!result){ + that._displayNewMsg("historyMsg", "error", "newMsg"); + return; + } + var url = result.cmdType == "cmd" ? "/command" : "/message"; + $.ajax({ + url: url, + type: "POST", + dataType: "json", + contentType: "application/json", + data: result.data, + success: function (res) { + var result = res.msg + if (res.code != 0) { + var data = "
" + result + "
"; + that._displayNewMsg("historyMsg", data, "newMsg"); + return + } + if (typeof(result) == "object") { + var data = JSON.stringify(result, null, " "); + data = "
" + data + "
"; + that._displayNewMsg("historyMsg", data, "newMsg"); + } else { + var data = "
" + result + "
"; + that._displayNewMsg("historyMsg", data, "newMsg"); + } + }, + error: function(status) { + var data = status.responseText; + data = data.replace(new RegExp("\n",'g'),"
"); + that._displayNewMsg("historyMsg", data, "newMsg"); + } + }); + inputMsg.value = ""; + inputMsg.focus(); + }, + + _displayNewMsg: function(container_id, msg, type){ + var container = document.getElementById(container_id); + var p = document.createElement('p'); + var text = document.createElement("span"); + text.innerHTML = msg; + p.setAttribute('class', type); + p.appendChild(text); + container.appendChild(p); + container.scrollTop = container.scrollHeight; + }, +}; \ No newline at end of file diff --git a/server/login/login_servlet.lua b/server/login/login_servlet.lua index 2ca0c416..20dd236e 100644 --- a/server/login/login_servlet.lua +++ b/server/login/login_servlet.lua @@ -64,6 +64,7 @@ function LoginServlet:on_account_login_req(session, cmd_id, body, session_id) local account_params = {} if platform >= PLATFORM_PASSWORD then --登录验证 + body.ip = session.ip local result = event_mgr:notify_listener("on_platform_login", platform, open_id, access_token, body, account_params) local ok, code, sdk_open_id, sdk_device_id = tunpack(result) local login_failed, login_code = qfailed(code, ok) diff --git a/tools/accord.bat b/tools/accord.bat deleted file mode 100644 index b18e8b63..00000000 --- a/tools/accord.bat +++ /dev/null @@ -1,12 +0,0 @@ -@echo off - -chcp 65001 - -:: 解析xlsm文件为lua - -set LUA_PATH=!/../tools/accord/?.lua;!/../script/?.lua;; - -..\bin\quanta.exe --entry=accord --proto=../bin/proto/ --input=./accord/ --output=../server/robot/accord/ - -pause - diff --git a/tools/accord/accord.lua b/tools/accord/accord.lua deleted file mode 100644 index f864eca4..00000000 --- a/tools/accord/accord.lua +++ /dev/null @@ -1,145 +0,0 @@ ---accord.lua - -local ldir = stdfs.dir -local lstem = stdfs.stem -local lmkdir = stdfs.mkdir -local lappend = stdfs.append -local lfilename = stdfs.filename -local lextension = stdfs.extension -local lcurdir = stdfs.current_path -local serialize = luakit.serialize -local pb_enum_id = protobuf.enum -local json_encode = json.encode -local tunpack = table.unpack -local sformat = string.format -local supper = string.upper -local ogetenv = os.getenv - -local pb_indexs = {} - -local function ssplit(str, token) - local t = {} - while #str > 0 do - local pos = str:find(token) - if not pos then - t[#t + 1] = str - break - end - if pos > 1 then - t[#t + 1] = str:sub(1, pos - 1) - end - str = str:sub(pos + 1, #str) - end - return t -end - -local function sends_with(str, ending) - return str:sub(-#ending) == ending -end - -local function parse_message(full_name, proto_name) - local proto_isreq = sends_with(proto_name, "_req") - if proto_isreq then - local package_name = tunpack(ssplit(full_name, ".")) - local enum_type = package_name .. ".NCmdId" - local msg_name = "NID_" .. supper(proto_name) - local msg_id = pb_enum_id(enum_type, msg_name) - if msg_id then - local fields = {} - for name, _, typ in protobuf.fields(full_name) do - fields[name] = (typ == "string") and "xxx" or 0 - end - pb_indexs[msg_name] = { - msg_id = msg_id, - name = msg_name, - fields = fields, - } - end - end - return pb_indexs -end - ---加载pb文件 -local function load_pbfiles(proto_dir, proto_file) - local full_name = lappend(proto_dir, proto_file) - --加载PB文件 - protobuf.loadfile(full_name) - --注册CMDID和PB的映射 - for name, basename, typ in protobuf.types() do - if typ == "message" then - parse_message(name, basename) - end - end -end - ---加载pb文件 -local function load_protocol(proto_path) - local dir_files = ldir(proto_path) - for _, file in pairs(dir_files) do - if lextension(file.name) == ".pb" then - load_pbfiles(proto_path, lfilename(file.name)) - end - end -end - ---加载case文件 -local function load_cases(tool_dir, case_dir) - local tcases = {} - local case_path = lappend(tool_dir, case_dir) - local dir_files = ldir(case_path) - for _, file in pairs(dir_files or {}) do - if lextension(file.name) == ".lua" then - local name = lstem(file.name) - tcases[name] = require(sformat("%s.%s", case_dir, name)) - end - end - return tcases -end - -local function export_json(input, output) - local configs = {} - configs.accord = pb_indexs - configs.servers = require("server") - configs.cases = load_cases(input, "cases") - --export - local jdata = json_encode(configs) - local ldata = serialize(configs) - local jsonname = lappend(input, "accord_conf.json") - local json_file = io.open(jsonname, "w") - json_file:write(jdata) - json_file:close() - local confname = lappend(output, "accord_conf.lua") - local conf_file = io.open(confname, "w") - conf_file:write("--luacheck: ignore 631\n") - conf_file:write(sformat("return {\n lua = %s,\n json = [[%s]]\n}\n", ldata, jdata)) - conf_file:close() - print("export accord config success!") -end - -local proto = lcurdir() -local input = lcurdir() -local output = lcurdir() -local env_proto = ogetenv("QUANTA_PROTO") -if not env_proto or #env_proto == 0 then - print("proto dir not config!") -else - proto = lappend(proto, env_proto) -end -local env_input = ogetenv("QUANTA_INPUT") -if not env_input or #env_input == 0 then - print("input dir not config!") -else - input = lappend(input, env_input) -end -local env_output = ogetenv("QUANTA_OUTPUT") -if not env_output or #env_output == 0 then - print("output dir not config!") -else - output = lappend(output, env_output) - lmkdir(output) -end - -load_protocol(proto) -export_json(input, output) - -os.exit() diff --git a/tools/accord/accord_conf.json b/tools/accord/accord_conf.json deleted file mode 100644 index 175f322b..00000000 --- a/tools/accord/accord_conf.json +++ /dev/null @@ -1 +0,0 @@ -{"servers":["127.0.0.1:20013"],"cases":{"login":{"protocols":[{"id":10009,"name":"NID_LOGIN_ROLE_CHOOSE_REQ","args":{"role_id":0,"user_id":0}},{"id":10011,"name":"NID_LOGIN_ROLE_DELETE_REQ","args":{"role_id":0,"user_id":0}}],"name":"login","openid":"test001","password":"123456","server":"127.0.0.1:20013"}},"accord":{"NID_LOGIN_ROLE_LOGOUT_REQ":{"msg_id":10015,"name":"NID_LOGIN_ROLE_LOGOUT_REQ","fields":{"role_id":0}},"NID_LOGIN_ROLE_RELOAD_REQ":{"msg_id":10017,"name":"NID_LOGIN_ROLE_RELOAD_REQ","fields":{"role_id":0,"token":0,"lobby":0,"user_id":0}},"NID_HEARTBEAT_REQ":{"msg_id":1001,"name":"NID_HEARTBEAT_REQ","fields":{"time":0,"serial":0}},"NID_LOGIN_RANDOM_NAME_REQ":{"msg_id":10005,"name":"NID_LOGIN_RANDOM_NAME_REQ","fields":{}},"NID_LOGIN_ACCOUNT_RELOAD_REQ":{"msg_id":10003,"name":"NID_LOGIN_ACCOUNT_RELOAD_REQ","fields":{"openid":"xxx","account_token":0}},"NID_LOGIN_ROLE_CHOOSE_REQ":{"msg_id":10009,"name":"NID_LOGIN_ROLE_CHOOSE_REQ","fields":{"role_id":0,"user_id":0}},"NID_LOGIN_ROLE_CREATE_REQ":{"msg_id":10007,"name":"NID_LOGIN_ROLE_CREATE_REQ","fields":{"model":0,"gender":0,"name":"xxx","user_id":0}},"NID_LOGIN_ACCOUNT_LOGIN_REQ":{"msg_id":10001,"name":"NID_LOGIN_ACCOUNT_LOGIN_REQ","fields":{"platform":0,"openid":"xxx","session":"xxx"}},"NID_LOGIN_ROLE_LOGIN_REQ":{"msg_id":10013,"name":"NID_LOGIN_ROLE_LOGIN_REQ","fields":{"role_id":0,"token":0,"lobby":0,"user_id":0}},"NID_LOGIN_ROLE_DELETE_REQ":{"msg_id":10011,"name":"NID_LOGIN_ROLE_DELETE_REQ","fields":{"role_id":0,"user_id":0}}}} \ No newline at end of file diff --git a/tools/accord/cases/login.lua b/tools/accord/cases/login.lua deleted file mode 100644 index d716dc9e..00000000 --- a/tools/accord/cases/login.lua +++ /dev/null @@ -1,20 +0,0 @@ ---login.lua - -return { - name = "login", - openid = "test001", - password = "123456", - server = "127.0.0.1:20013", - protocols = { - { - id = 10009, - name = "NID_LOGIN_ROLE_CHOOSE_REQ", - args = { user_id = 0, role_id = 0 } - }, - { - id = 10011, - name = "NID_LOGIN_ROLE_DELETE_REQ", - args = { user_id = 0, role_id = 0 } - } - } -} \ No newline at end of file diff --git a/tools/accord/server.lua b/tools/accord/server.lua deleted file mode 100644 index 09c77a23..00000000 --- a/tools/accord/server.lua +++ /dev/null @@ -1,5 +0,0 @@ ---server.lua - -return { - "127.0.0.1:20013" -} diff --git a/tools/gmbuild.bat b/tools/gmbuild.bat new file mode 100644 index 00000000..a1169661 --- /dev/null +++ b/tools/gmbuild.bat @@ -0,0 +1,12 @@ +@echo off + +set JS=../server/center/page/gm.js +set CSS=../server/center/page/gm.css +set TPL=../server/center/page/gm.html +set OUT=../server/center/gm_page.lua +set SCRIPT=../extend/lmake/ltemplate.lua + +..\bin\lua.exe %SCRIPT% %TPL% %OUT% GM_CSS %CSS% GM_SCRIPT %JS% + +pause + diff --git a/tools/mongo/index.lua b/tools/mongo/index.lua index ef416f90..19d57e24 100644 --- a/tools/mongo/index.lua +++ b/tools/mongo/index.lua @@ -51,7 +51,7 @@ local function generate_js(input_path, ouput_path) --创建索引,默认升序 idx_file:write(sformat("db.getCollection(\"%s\").createIndex({%s: 1}, {name: \"%s\",unique: true});\n", sheet, key, key)) if key2 then - idx_file:write(sformat("db.getCollection(\"%s\").createIndex({%s: 1}, {name: \"%s\",unique: true});\n", sheet, key2, key2)) + idx_file:write(sformat("db.getCollection(\"%s\").createIndex({%s: 1}, {name: \"%s\",unique: true});\n", sheet, key2, key2)) end idx_file:write("//------------------------------------------------------------------------\n\n") end