diff --git a/bin/accord.conf b/bin/accord.conf index 775edc55..398d4931 100644 --- a/bin/accord.conf +++ b/bin/accord.conf @@ -28,3 +28,6 @@ set_env("QUANTA_MODE", "3") --协议测试 set_env("QUANTA_ACCORD_HTTP", "127.0.0.1:10401") + +--服务器列表API +set_env("QUANTA_SRVLIST_API", "http://10.98.8.100:18080/server_mgr/query") diff --git a/server/robot/accord/src/bundle.lua b/server/robot/accord/src/bundle.lua index b8dc20df..f2892a2c 100644 --- a/server/robot/accord/src/bundle.lua +++ b/server/robot/accord/src/bundle.lua @@ -283,88 +283,6 @@ return [[ - - -
-
-
- - - -
-
-
- -
-
-
-
-
-
-
-
    -
  • - {{ server.name }} - {{ server.address }}:{{ server.port }} - - -
  • -
-
-
-
-
-
-
-
-
-
- - -
-
-
- - - -
-
-
-
-
-
-
-
-
- - - - - - -

-
- -
-
- -
-
-
-
-
-
-
-
-
-
-
@@ -407,8 +325,6 @@ return [[ -
@@ -582,7 +498,7 @@ var DataUtils = { this.http = http }, post: function (name, args, callback) { - this.http.post('/'+name, args).then(function (response) { + this.http.post(name, args).then(function (response) { var data = response.data || {} if(response.status == 200){ if(callback){ @@ -593,12 +509,12 @@ var DataUtils = { console.error("[Request][post] fail name(%s) args(%s) status(%s)", name, args, response.status) } }, function (response) { - callback(false, data) + callback(false, null) console.error("[Request][post] fail name(%s) args(%s) status(%s)", name, args, response.status) }); }, get: function(name, args, callback){ - this.http.get('/'+name, args).then(function(response){ + this.http.get(name, args).then(function(response){ var data = response.data || {} if(response.status == 200){ if(callback){ @@ -609,7 +525,7 @@ var DataUtils = { console.error("[Request][get] fail name(%s) args(%s) status(%s)", name, args, response.status) } }, function (response) { - callback(false, data) + callback(false, null) console.error("[Request][get] fail name(%s) args(%s) status(%s)", name, args, response.status) }); } @@ -643,10 +559,9 @@ var DataUtils = { ////////////////////////////////////////////////////////////////// //服务信息 - $scope.svrListShow = false //服务列表弹框 - $scope.svrAdEdShow = false //添加服务弹框 $scope.serverAddr = null //服务器地址 $scope.robotStatus = "未启动" //机器状态 + $scope.srvListApi = "" //服务列表api $scope.serverList = {} //服务列表 $scope.serverSort = [] //服务列表排序 $scope.serverEdit = null //编辑服务 @@ -715,7 +630,7 @@ var DataUtils = { //初始化数据 $scope.loadData = function () { - NetUtils.post("accord_group", {}, function (ok, data) { + NetUtils.post("/accord_group", {}, function (ok, data) { if (!ok) { return } @@ -737,21 +652,42 @@ var DataUtils = { $scope.refreshServer() $scope.refreshAccordGroup() }) - NetUtils.post("case_group", {}, function (ok, data) { + NetUtils.post("/case_group", {}, function (ok, data) { if (!ok) { return } $scope.caseGroupMap = data.case_group $scope.refreshCaseGroup() }) - NetUtils.post("server_list", {}, function (ok, data) { + + NetUtils.post("/get_config", {}, function (ok, data) { if (!ok) { return } - $scope.serverList = data.server_list - $scope.refreshServer() + $scope.srvListApi = data.srvlist_api + console.log("srvListApi=%s", $scope.srvListApi) + NetUtils.get($scope.srvListApi, {}, function (ok, data) { + if (!ok) { + return + } + for(var i=0; i match.substring(1, match.length - 1)); var ipInfo = connections[0].split(":"); - NetUtils.post("create", { + NetUtils.post("/create", { "ip": ipInfo[0], "port": Number(ipInfo[1]), "open_id": $scope.openid, @@ -1627,7 +1482,7 @@ var DataUtils = { alert("尚未启动"); return; } - NetUtils.post("destory", { + NetUtils.post("/destory", { "open_id": $scope.openid }, function (ok, data) { if (!ok) { @@ -1655,7 +1510,7 @@ var DataUtils = { } } $scope.removeItem = function (cmd) { - NetUtils.post("proto_del", { + NetUtils.post("/proto_del", { "data": { id: $scope.curCase.id, proto_id: cmd.id, diff --git a/server/robot/accord/src/index.html b/server/robot/accord/src/index.html index d796d269..8c65e1cc 100644 --- a/server/robot/accord/src/index.html +++ b/server/robot/accord/src/index.html @@ -282,88 +282,6 @@

- - -
-
-
- - - -
-
-
- -
-
-
-
-
-
-
-
    -
  • - {{ server.name }} - {{ server.address }}:{{ server.port }} - - -
  • -
-
-
-
-
-
-
-
-
-
- - -
-
-
- - - -
-
-
-
-
-
-
-
-
- - - - - - -

-
- -
-
- -
-
-
-
-
-
-
-
-
-
-
@@ -406,8 +324,6 @@

-
@@ -480,10 +396,9 @@

////////////////////////////////////////////////////////////////// //服务信息 - $scope.svrListShow = false //服务列表弹框 - $scope.svrAdEdShow = false //添加服务弹框 $scope.serverAddr = null //服务器地址 $scope.robotStatus = "未启动" //机器状态 + $scope.srvListApi = "" //服务列表api $scope.serverList = {} //服务列表 $scope.serverSort = [] //服务列表排序 $scope.serverEdit = null //编辑服务 @@ -552,7 +467,7 @@

//初始化数据 $scope.loadData = function () { - NetUtils.post("accord_group", {}, function (ok, data) { + NetUtils.post("/accord_group", {}, function (ok, data) { if (!ok) { return } @@ -574,21 +489,42 @@

$scope.refreshServer() $scope.refreshAccordGroup() }) - NetUtils.post("case_group", {}, function (ok, data) { + NetUtils.post("/case_group", {}, function (ok, data) { if (!ok) { return } $scope.caseGroupMap = data.case_group $scope.refreshCaseGroup() }) - NetUtils.post("server_list", {}, function (ok, data) { + + NetUtils.post("/get_config", {}, function (ok, data) { if (!ok) { return } - $scope.serverList = data.server_list - $scope.refreshServer() + $scope.srvListApi = data.srvlist_api + console.log("srvListApi=%s", $scope.srvListApi) + NetUtils.get($scope.srvListApi, {}, function (ok, data) { + if (!ok) { + return + } + for(var i=0; i } } - NetUtils.post("case_group_edit", { + NetUtils.post("/case_group_edit", { "data": { case_group: $scope.caseGroupEditItem } @@ -843,7 +779,7 @@

} //编辑分组 $scope.editCaseGroup = function (group) { - console.log("editServer group(%s)", group) + console.log("editCaseGroup group(%s)", group) this.showCaseGroupEdit(true) //拷贝配置 $scope.caseGroupEditItem = group @@ -857,7 +793,7 @@

return } } - NetUtils.post("case_group_del", { + NetUtils.post("/case_group_del", { "data": group }, function (ok, data) { if (!ok) { @@ -870,87 +806,6 @@

$scope.refreshCaseGroup() }) } - //显示服务器列表 - $scope.showServerList = function (value) { - if (value) { - $scope.caseShow = false - } else { - $scope.caseShow = true - } - $scope.svrListShow = value - } - //显示添加/编辑框 - $scope.showServerEdit = function (value, back) { - $scope.svrAdEdShow = value - if (back) { - this.showServerList(true) - console.log("显示列表...") - } - if (value) { - $scope.serverEdit = { - id: DataUtils.generateUUID(), - name: "", - address: "", - port: null, - time: DataUtils.getNowSecond() - } - } - } - //保存服务 - $scope.saveServer = function () { - if (!$scope.serverEdit) { - alert("数据不正确,请重新配置"); - return - } - - //配置验证 - if (!$scope.serverEdit.name) { - alert("名称不正确,请检查!"); - return - } - - if (!$scope.serverEdit.address || !DataUtils.isValidIP($scope.serverEdit.address)) { - alert("地址不正确,请检查!"); - return - } - - if (!$scope.serverEdit.port || $scope.serverEdit.port <= 0) { - alert("端口不正确,请检查!"); - return - } - - NetUtils.post("server_edit", { - "data": $scope.serverEdit - }, function (ok, data) { - if (!ok) { - alert("保存失败") - return - } - $scope.serverList[$scope.serverEdit.id] = $scope.serverEdit - $scope.showServerEdit(false, true) - $scope.refreshServer() - }) - } - //编辑服务 - $scope.editServer = function (server) { - console.log("editServer server(%s)", server) - this.showServerEdit(true) - $scope.serverEdit = server - } - //删除服务 - $scope.delServer = function (server) { - NetUtils.post("server_del", { - "data": server - }, function (ok, data) { - if (!ok) { - alert("删除失败") - return - } - delete $scope.serverList[server.id] - $scope.refreshServer() - $scope.showServerEdit(false, true) - }) - } //刷新服务 $scope.refreshServer = function () { $scope.serverSort = [] @@ -1034,7 +889,7 @@

accord.id = DataUtils.generateUUID() } - NetUtils.post("accord_edit", { + NetUtils.post("/accord_edit", { "data": { id: accord.id, name: accord.name, @@ -1119,7 +974,7 @@

time: DataUtils.getNowSecond() } - NetUtils.post("accord_edit", { + NetUtils.post("/accord_edit", { "data": { id: accord.id, name: accord.name, @@ -1166,7 +1021,7 @@

if (!$scope.curCase) { return } - NetUtils.post("accord_del", { + NetUtils.post("/accord_del", { "data": { id: $scope.curCase.id } @@ -1280,7 +1135,7 @@

alert("数据异常,请刷新网页再尝试") return } - NetUtils.post("proto_edit", JSON.stringify({ + NetUtils.post("/proto_edit", JSON.stringify({ "data": { id: $scope.curCase.id, data: $scope.curProtocol @@ -1353,7 +1208,7 @@

heartArgs.time = 0 cmd.id = 1001; cmd.args = heartArgs; - NetUtils.post("run", { + NetUtils.post("/run", { "open_id": $scope.openid, "cmd_id": cmd.id, "data": cmd.args @@ -1373,7 +1228,7 @@

var args_log = `{\n "id":${cmd.cmd_id},\n "name":${cmd.name},\n "args":${cmd.args}\n}` $scope.messages += "\n\n[" + new Date().Format("yyyy-MM-dd hh:mm:ss S") + "]发送:\n" + FormatUtils.prettyFormat(args_log) document.getElementById('jsonShow').innerHTML = $scope.messages - NetUtils.post("run", { + NetUtils.post("/run", { "open_id": $scope.openid, "cmd_id": cmd.cmd_id, "data": cmd.args @@ -1413,7 +1268,7 @@

var args_log = `{\n "id":${req.cmd_id},\n "name":${req.name},\n "args":${req.args}\n}` $scope.messages += "\n[" + new Date().Format("yyyy-MM-dd hh:mm:ss S") + "]请求:\n" + FormatUtils.prettyFormat(args_log) document.getElementById('jsonShow').innerHTML = $scope.messages - NetUtils.post("run", { + NetUtils.post("/run", { "open_id": $scope.openid, "cmd_id": req.cmd_id, "data": req.args @@ -1445,7 +1300,7 @@

const matches = $scope.serverAddr.match(regex); const connections = matches.map(match => match.substring(1, match.length - 1)); var ipInfo = connections[0].split(":"); - NetUtils.post("create", { + NetUtils.post("/create", { "ip": ipInfo[0], "port": Number(ipInfo[1]), "open_id": $scope.openid, @@ -1464,7 +1319,7 @@

alert("尚未启动"); return; } - NetUtils.post("destory", { + NetUtils.post("/destory", { "open_id": $scope.openid }, function (ok, data) { if (!ok) { @@ -1492,7 +1347,7 @@

} } $scope.removeItem = function (cmd) { - NetUtils.post("proto_del", { + NetUtils.post("/proto_del", { "data": { id: $scope.curCase.id, proto_id: cmd.id, diff --git a/server/robot/accord/src/net_utils.js b/server/robot/accord/src/net_utils.js index c9d53d3f..dba4edd4 100644 --- a/server/robot/accord/src/net_utils.js +++ b/server/robot/accord/src/net_utils.js @@ -4,7 +4,7 @@ var NetUtils = { this.http = http }, post: function (name, args, callback) { - this.http.post('/'+name, args).then(function (response) { + this.http.post(name, args).then(function (response) { var data = response.data || {} if(response.status == 200){ if(callback){ @@ -15,12 +15,12 @@ var NetUtils = { console.error("[Request][post] fail name(%s) args(%s) status(%s)", name, args, response.status) } }, function (response) { - callback(false, data) + callback(false, null) console.error("[Request][post] fail name(%s) args(%s) status(%s)", name, args, response.status) }); }, get: function(name, args, callback){ - this.http.get('/'+name, args).then(function(response){ + this.http.get(name, args).then(function(response){ var data = response.data || {} if(response.status == 200){ if(callback){ @@ -31,7 +31,7 @@ var NetUtils = { console.error("[Request][get] fail name(%s) args(%s) status(%s)", name, args, response.status) } }, function (response) { - callback(false, data) + callback(false, null) console.error("[Request][get] fail name(%s) args(%s) status(%s)", name, args, response.status) }); } diff --git a/server/robot/module/login.lua b/server/robot/module/login.lua index 3c73be33..896ba4a8 100644 --- a/server/robot/module/login.lua +++ b/server/robot/module/login.lua @@ -170,7 +170,7 @@ function LoginModule:choose_role_req() } local ok, res = self:call("NID_LOGIN_ROLE_CHOOSE_REQ", req_data) if self:check_callback(ok, res) then - log_warn("[LoginModule][choose_role_req] robot:{}, ok={}, res={}", self:get_title(), ok, res) + log_warn("[LoginModule][choose_role_req] robot:{}, ok={}, res={} req_data={}", self:get_title(), ok, res, req_data) return false end self.lobby = res.lobby diff --git a/server/robot/module/session.lua b/server/robot/module/session.lua index f4ad9d94..e1fee869 100644 --- a/server/robot/module/session.lua +++ b/server/robot/module/session.lua @@ -88,6 +88,7 @@ function SessionModule:call(cmdid, data) if self.client then local srv_type = self:conv_type(cmdid) local ok, resp = self.client:call(cmdid, data, srv_type) + log_debug("call cmdid:{} data:{} srv_type:{} ok:{} resp:{}",cmdid, data, srv_type, ok, resp) if srv_type == 0 and cmdid ~= 1001 then if resp then resp.req_cmd_id = cmdid diff --git a/server/robot/msg_mgr.lua b/server/robot/msg_mgr.lua index 1d84e4a1..81c60618 100644 --- a/server/robot/msg_mgr.lua +++ b/server/robot/msg_mgr.lua @@ -5,6 +5,7 @@ local log_debug = logger.debug local pb_enum_id = protobuf.enum local supper = string.upper local tunpack = table.unpack +local tcopy = qtable.copy local protobuf_mgr = quanta.get("protobuf_mgr") @@ -99,12 +100,14 @@ function MsgMgr:args_convert(cmd_id, data) if cmd_id == 1001 then return end + local c_data = tcopy(data) -- 获取协议结构 local struct = self:msg_struct(cmd_id) -- 转换参数字段 if struct then - self:convert_fields(struct, data) + self:convert_fields(struct, c_data) end + return c_data end quanta.msg_mgr = MsgMgr() diff --git a/server/robot/robot.lua b/server/robot/robot.lua index dd9cbc72..c8529f74 100644 --- a/server/robot/robot.lua +++ b/server/robot/robot.lua @@ -48,8 +48,8 @@ end function Robot:push_message(cmd_id, msg) log_debug("recv server msg:{} {}",cmd_id, msg) msg.cmd_id = cmd_id - msg_mgr:args_convert(cmd_id, msg) - self.messages:push(msg) + local c_msg = msg_mgr:args_convert(cmd_id, msg) + self.messages:push(c_msg) end function Robot:get_messages()