-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandDispatch.js
More file actions
41 lines (36 loc) · 1.02 KB
/
Copy pathCommandDispatch.js
File metadata and controls
41 lines (36 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
if (typeof module !== "undefined") {
JsBase = require("../JsBase/jsbase");
}
function CmdDispatcher() {
}
var GetCmdDispatcher = JsBase.GenSingletonInst(CmdDispatcher);
/**
* Dispatch Cmd On RecvMsg
* @param {string} con 控制器
* @param {string} act 操作
* @param {object} param 参数
*/
CmdDispatcher.prototype.DispatchCmd = function (param) {
var cmdName = param.C;
var param = param.D;
global.EvEmitter.Emit("Cmd_" + cmdName + "_Execute", param);
}
/**
* SendMsg To Call Server Cmd
* @param {string | number} cmdName string to identify which cmd you want to call
* @param {object} param arguments you pass to cmd
*/
CmdDispatcher.prototype.SendCmd = function (cmdName, param) {
var sendParam = {};
if (!cmdName) {
console.error("[CmdDispatcher.SendCmd] Wrong cmdName: " + cmdName);
return;
}
sendParam.C = cmdName; //C: Cmd
sendParam.D = param; //D: Data
global.EvEmitter.Emit("Msger_SendMsg", sendParam);
}
var Cmder = GetCmdDispatcher();
if (typeof module !== "undefined") {
module.exports = Cmder;
}