跳到主要内容

gm_client

简介

gm客户端

使用方法

  • import pkg.gm_client;
  • 自行启动httpserver即可
  • 调用 gm_client.load_all_entry("/cmds"); 初始化native层的gm命令回调接口,该目录下存放具体gm命令文件
  • 在gm命令文件中处理详细gm指令业务逻辑,return相应的原始数据即可,数据格式如下
"data" : [
// 第一行为表头
{"id" : "玩家ID", "name" : "玩家名", "property" : "属性", "detail1" : "详情1", "detail2" : "详情2"},

// 后面为表字段内容
{"id" : 2, "name" : "暗夜白虎宝箱", "property" : "二阶", "detail1" : "detail1", "detail2" : "detail2"},
{"id" : 3, "name" : "暗夜白虎宝箱", "property" : "三阶", "detail1" : "detail1", "detail2" : "detail2"},
{"id" : 4, "name" : "暗夜白虎宝箱", "property" : "四阶", "detail1" : "detail1", "detail2" : "detail2"},
{"id" : 5, "name" : "暗夜白虎宝箱", "property" : "五阶", "detail1" : "detail1", "detail2" : "detail2"},
{"id" : 6, "name" : "暗夜白虎宝箱", "property" : "六阶", "detail1" : "detail1", "detail2" : "detail2"},
{"id" : 7, "name" : "暗夜白虎宝箱", "property" : "七阶", "detail1" : "detail1", "detail2" : "detail2"}
]

例子:

#pragma parallel

import gs.lang.*;
import gs.util.*;
import pkg.gtest;
import pkg.httpclient;
import pkg.httpserver;
import pkg.httpserver.http_const;
import pkg.httpserver.request;
import pkg.httpserver.response;

import pkg.gm_client;

void create()
{
httpserver.start("GM_Client", "/test/http_server.json");
load_static(pkg.gm_client, this_domain());
}

void destruct()
{

}

public mixed search_account(mixed data)
{
mixed ret = httpclient.post("http://127.0.0.1:8888/gm_cmd", data);
if (ret.code == 200)
{
mixed d = json.parse(ret.data.to_string());
return d.data.data;
}
else
{
return {
"code" : 4004,
"data" : "",
"msg" : "请求数据失败",
};
}
}

public void test_run()
{
gtest.test_func((: search_account, {"cmd" : "test_search_account"} :), [
{"id" : "aaa2", "name" : "bbb2", "lv" : 10},
{"id" : "aaa3", "name" : "bbb3", "lv" : 10},
{"id" : "aaa4", "name" : "bbb4", "lv" : 10}
]);
}

组件接口

函数原型函数作用
void gm_cmd(request req, response res)该接口用来回调gmserver的请求,转发gm命令到相应模块
map gen_response_table(array data)该接口用来生成回调数据的格式
mixed gen_response(mixed data = nil)该接口用来返回处理好的gm命令到gmserver