gm_client.gm_cmd
声明
public void gm_cmd(request req, response res)
参数
参数名 | 描述 |
---|---|
req | http请求数据,包含url,get参数,post内容等数据 |
res | http返回数据,可以设置返回数据格式,Content_Type.rep_json, Content_Type.string, Content_Type.buffer等数据格式 |
作用
该接口用来回调gmserver的请求,转发gm命令到相应模块
使用方式
GmD.gs
httpserver.add_handler("/gm_cmd", (: gm_cmd :));
public void gm_cmd(request req, response res)
{
mixed cmds = req.get_content();
if (!cmds)
return;
cmds = cmds.to_string();
if (cmds == "")
return;
cmds = json.parse(cmds);
if (!is_map(cmds))
return;
object handler = _handlers[cmds["cmd"]];
if (!handler)
{
trace_warn("Can not find cmd handler(%M)", cmds["cmd"]);
return;
}
mixed ret = handler.main(cmds);
mixed data = gen_response(ret);
res.set_content(data, Content_Type.rep_json);
}