cgserver 7.10.2113 → 7.12.2113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/Framework/AI/AiObject.ts +0 -12
- package/src/Framework/AI/Astar.ts +0 -157
- package/src/Framework/AI/BehaviorAI.ts +0 -382
- package/src/Framework/AI/Entity.ts +0 -37
- package/src/Framework/AI/Point.ts +0 -84
- package/src/Framework/AI/TriggerMgr.ts +0 -280
- package/src/Framework/Config/Config.ts +0 -61
- package/src/Framework/Config/FrameworkConfig.ts +0 -286
- package/src/Framework/Config/IServerConfig.ts +0 -28
- package/src/Framework/Config/_error_.ts +0 -32
- package/src/Framework/Core/Core.ts +0 -810
- package/src/Framework/Core/Timer.ts +0 -147
- package/src/Framework/Database/Decorator/AutoIncrement.ts +0 -9
- package/src/Framework/Database/Decorator/DBCache.ts +0 -74
- package/src/Framework/Database/Decorator/NotNull.ts +0 -9
- package/src/Framework/Database/Decorator/PrimaryKey.ts +0 -9
- package/src/Framework/Database/Decorator/Property.ts +0 -64
- package/src/Framework/Database/Decorator/Table.ts +0 -13
- package/src/Framework/Database/Decorator/Type.ts +0 -21
- package/src/Framework/Database/MSSqlManager.ts +0 -52
- package/src/Framework/Database/MongoBaseService.ts +0 -136
- package/src/Framework/Database/MongoManager.ts +0 -501
- package/src/Framework/Database/MysqlBaseService.ts +0 -345
- package/src/Framework/Database/MysqlManager.ts +0 -212
- package/src/Framework/Database/RedisManager.ts +0 -544
- package/src/Framework/Logic/CacheTool.ts +0 -85
- package/src/Framework/Logic/EventTool.ts +0 -31
- package/src/Framework/Logic/HttpTool.ts +0 -82
- package/src/Framework/Logic/Log.ts +0 -171
- package/src/Framework/Logic/SyncQueueTool.ts +0 -51
- package/src/Framework/Service/AccountService.ts +0 -508
- package/src/Framework/Service/MongoAccountService.ts +0 -456
- package/src/Framework/Service/MongoCacheService.ts +0 -48
- package/src/Framework/Service/MongoUserService.ts +0 -103
- package/src/Framework/Service/UserService.ts +0 -168
- package/src/Framework/Service/ini.ts +0 -33
- package/src/Framework/SocketServer/IClientWebSocket.ts +0 -50
- package/src/Framework/SocketServer/IRpc.ts +0 -12
- package/src/Framework/SocketServer/IRpcClientWebSocket.ts +0 -75
- package/src/Framework/SocketServer/IRpcServerWebSocket.ts +0 -76
- package/src/Framework/SocketServer/IServerWebSocket.ts +0 -88
- package/src/Framework/SocketServer/ISocketServer.ts +0 -243
- package/src/Framework/SocketServer/IWebSocket.ts +0 -243
- package/src/Framework/SocketServer/ProtoFilter/GoogleProtoFilter.ts +0 -68
- package/src/Framework/SocketServer/ProtoFilter/IProtoFilter.ts +0 -11
- package/src/Framework/SocketServer/ProtoFilter/JsonProtoFilter.ts +0 -34
- package/src/Framework/SocketServer/ProtoFilter/ProtoFactory.ts +0 -34
- package/src/Framework/ThirdParty/AlipayTool.ts +0 -224
- package/src/Framework/ThirdParty/Alisms.ts +0 -53
- package/src/Framework/ThirdParty/AppleTool.ts +0 -252
- package/src/Framework/ThirdParty/CgMq.ts +0 -153
- package/src/Framework/ThirdParty/EmailTool.ts +0 -37
- package/src/Framework/ThirdParty/OpenSocial.ts +0 -36
- package/src/Framework/ThirdParty/QQTool.ts +0 -124
- package/src/Framework/ThirdParty/QiniuTool.ts +0 -23
- package/src/Framework/ThirdParty/Rpc.ts +0 -75
- package/src/Framework/ThirdParty/WechatOATool.ts +0 -61
- package/src/Framework/ThirdParty/WechatTool.ts +0 -80
- package/src/Framework/WebServer/Controller/BaseController.ts +0 -140
- package/src/Framework/WebServer/Controller/BaseUserController.ts +0 -209
- package/src/Framework/WebServer/Controller/MongoBaseUserController.ts +0 -209
- package/src/Framework/WebServer/Decorator/AdminValidate.ts +0 -19
- package/src/Framework/WebServer/Decorator/AuthorityValidate.ts +0 -25
- package/src/Framework/WebServer/Decorator/CreatorValidate.ts +0 -19
- package/src/Framework/WebServer/Decorator/JsonAdminValidate.ts +0 -16
- package/src/Framework/WebServer/Decorator/JsonAuthorityValidate.d.ts +0 -2
- package/src/Framework/WebServer/Decorator/JsonAuthorityValidate.ts +0 -23
- package/src/Framework/WebServer/Decorator/JsonCreatorValidate.ts +0 -19
- package/src/Framework/WebServer/Decorator/SyncCall.ts +0 -20
- package/src/Framework/WebServer/Decorator/SyncCallServer.ts +0 -45
- package/src/Framework/WebServer/Engine/ControllerManager.ts +0 -134
- package/src/Framework/WebServer/Engine/Engine.ts +0 -186
- package/src/Framework/WebServer/Engine/RazorJs.ts +0 -720
- package/src/Framework/WebServer/Engine/Request.ts +0 -267
- package/src/Framework/WebServer/Engine/Response.ts +0 -123
- package/src/Framework/WebServer/IWebServer.ts +0 -61
- package/src/Framework/cgserver.ts +0 -112
- package/src/Framework/index.ts +0 -92
- package/src/test/test.ts +0 -12
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import { GMysqlMgr } from '../Database/MysqlManager';
|
|
2
|
-
import { GRedisMgr } from '../Database/RedisManager';
|
|
3
|
-
import { IClientWebSocket } from './IClientWebSocket';
|
|
4
|
-
import * as ws from 'websocket';
|
|
5
|
-
import { GLog } from './../Logic/Log';
|
|
6
|
-
import * as fs from "fs";
|
|
7
|
-
import * as http from "http";
|
|
8
|
-
import * as https from "https";
|
|
9
|
-
import { GMongoMgr } from '../Database/MongoManager';
|
|
10
|
-
import { GMSSqlMgr } from '../Database/MSSqlManager';
|
|
11
|
-
import { GEventTool } from '../Logic/EventTool';
|
|
12
|
-
import { GServerCfg, IServerConfig } from '../Config/IServerConfig';
|
|
13
|
-
import { GCgServer } from '../cgserver';
|
|
14
|
-
import { BaseMsg } from './IWebSocket';
|
|
15
|
-
|
|
16
|
-
export class ISocketServer
|
|
17
|
-
{
|
|
18
|
-
protected _cfg:IServerConfig=null
|
|
19
|
-
//方便提示
|
|
20
|
-
get cfg()
|
|
21
|
-
{
|
|
22
|
-
return this._cfg
|
|
23
|
-
}
|
|
24
|
-
//服务器已被关闭
|
|
25
|
-
protected _is_closed=false
|
|
26
|
-
get isClosed()
|
|
27
|
-
{
|
|
28
|
-
return this._is_closed
|
|
29
|
-
}
|
|
30
|
-
get name()
|
|
31
|
-
{
|
|
32
|
-
return this._cfg.serverName
|
|
33
|
-
}
|
|
34
|
-
//监听websocket
|
|
35
|
-
private _listening_websocket:ws.server= null
|
|
36
|
-
get listeningWebSocket()
|
|
37
|
-
{
|
|
38
|
-
return this._listening_websocket
|
|
39
|
-
}
|
|
40
|
-
//来自于用户的链接
|
|
41
|
-
protected _ws_clients:{[socketid:number]:IClientWebSocket}={}
|
|
42
|
-
get listenPort()
|
|
43
|
-
{
|
|
44
|
-
return this._cfg.port
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* websocket can accepted protocol
|
|
48
|
-
*/
|
|
49
|
-
protected _accepted_protocol=null
|
|
50
|
-
//服务器管理相关
|
|
51
|
-
/*
|
|
52
|
-
item=servername:class
|
|
53
|
-
*/
|
|
54
|
-
protected _name_vs_class={}
|
|
55
|
-
registerWebSocketHandleClass(name:string,cls)
|
|
56
|
-
{
|
|
57
|
-
if(!name||name=="")
|
|
58
|
-
{
|
|
59
|
-
throw "registerWebSocketHandleClass name must be not null or empty!"
|
|
60
|
-
}
|
|
61
|
-
this._name_vs_class[name] = cls
|
|
62
|
-
}
|
|
63
|
-
constructor(cfg:IServerConfig)
|
|
64
|
-
{
|
|
65
|
-
this._cfg=cfg
|
|
66
|
-
}
|
|
67
|
-
removeServerWebSocketBySocketId(socketId:number)
|
|
68
|
-
{
|
|
69
|
-
this._ws_clients[socketId] = null
|
|
70
|
-
delete this._ws_clients[socketId]
|
|
71
|
-
}
|
|
72
|
-
async run()
|
|
73
|
-
{
|
|
74
|
-
GCgServer.addSocketServer(this)
|
|
75
|
-
await GMSSqlMgr.init()
|
|
76
|
-
await GMysqlMgr.init()
|
|
77
|
-
await GRedisMgr.init(GServerCfg.db?.redis)
|
|
78
|
-
await GMongoMgr.init(GServerCfg.db?.mongo)
|
|
79
|
-
this.initWebSocket()
|
|
80
|
-
}
|
|
81
|
-
stop()
|
|
82
|
-
{
|
|
83
|
-
this._is_closed=true
|
|
84
|
-
this._listening_websocket.closeAllConnections()
|
|
85
|
-
}
|
|
86
|
-
/*
|
|
87
|
-
把所有的客户端链接保存起来
|
|
88
|
-
方便统计,广播等
|
|
89
|
-
*/
|
|
90
|
-
addClient(ws_client:IClientWebSocket)
|
|
91
|
-
{
|
|
92
|
-
this._ws_clients[ws_client.socketId] = ws_client
|
|
93
|
-
}
|
|
94
|
-
isOriginAllowed(origin)
|
|
95
|
-
{
|
|
96
|
-
return true
|
|
97
|
-
}
|
|
98
|
-
initWebSocket(wss?)
|
|
99
|
-
{
|
|
100
|
-
let server = null
|
|
101
|
-
if(wss)
|
|
102
|
-
{
|
|
103
|
-
console.log("wss:---")
|
|
104
|
-
let options =
|
|
105
|
-
{
|
|
106
|
-
key:fs.readFileSync("ssl/ssl2.key"),
|
|
107
|
-
cert: fs.readFileSync("ssl/ssl2.crt"),
|
|
108
|
-
//passphrase:'1234'//如果秘钥文件有密码的话,用这个属性设置密码
|
|
109
|
-
}
|
|
110
|
-
server = https.createServer(options,(request, response)=>
|
|
111
|
-
{
|
|
112
|
-
GLog.info((new Date()) + 'wss Received request for ' + request.url)
|
|
113
|
-
response.writeHead(404)
|
|
114
|
-
response.end()
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
else
|
|
118
|
-
{
|
|
119
|
-
server = http.createServer((request, response)=>
|
|
120
|
-
{
|
|
121
|
-
GLog.info((new Date()) + 'ws Received request for ' + request.url)
|
|
122
|
-
response.writeHead(404)
|
|
123
|
-
response.end()
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
server.listen(this._cfg.port, this.onListenning.bind(this))
|
|
128
|
-
|
|
129
|
-
this._listening_websocket = new ws.server({
|
|
130
|
-
httpServer: server,
|
|
131
|
-
// You should not use autoAcceptConnections for production
|
|
132
|
-
// applications, as it defeats all standard cross-origin protection
|
|
133
|
-
// facilities built into the protocol and the browser. You should
|
|
134
|
-
// *always* verify the connection's origin and decide whether or not
|
|
135
|
-
// to accept it.
|
|
136
|
-
autoAcceptConnections: false
|
|
137
|
-
})
|
|
138
|
-
this._listening_websocket.on('request', this.onRequest.bind(this))
|
|
139
|
-
this._listening_websocket.on('close', this.onClose.bind(this))
|
|
140
|
-
}
|
|
141
|
-
onClose(connection: ws.connection, reason: number, desc: string)
|
|
142
|
-
{
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
onListenning()
|
|
146
|
-
{
|
|
147
|
-
GEventTool.emit("socket_server_init_done")
|
|
148
|
-
let info = (new Date()) + " Server "+ this.name +" is listening on port "+this._cfg.port
|
|
149
|
-
GLog.info(info)
|
|
150
|
-
console.log(info)
|
|
151
|
-
}
|
|
152
|
-
onRequest(req:ws.request)
|
|
153
|
-
{
|
|
154
|
-
if(this._is_closed)
|
|
155
|
-
{
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
let protocol = null
|
|
159
|
-
if(req.requestedProtocols.length>0)
|
|
160
|
-
{
|
|
161
|
-
protocol = req.requestedProtocols[0]
|
|
162
|
-
}
|
|
163
|
-
let allowed = this.isOriginAllowed(req.origin)
|
|
164
|
-
if (!allowed)
|
|
165
|
-
{
|
|
166
|
-
req.reject()
|
|
167
|
-
GLog.info(' Connection from origin ' + req.origin + ' rejected.')
|
|
168
|
-
return
|
|
169
|
-
}
|
|
170
|
-
try
|
|
171
|
-
{
|
|
172
|
-
let conn = req.accept(this._accepted_protocol, req.origin)
|
|
173
|
-
if(!conn)
|
|
174
|
-
{
|
|
175
|
-
GLog.info(' protocol reject')
|
|
176
|
-
return
|
|
177
|
-
}
|
|
178
|
-
GLog.info((new Date()) + ' Connection accepted.')
|
|
179
|
-
let server_name = this._getServerNameByCookies(req.cookies)
|
|
180
|
-
this.createWebSocketObjectByProtocol(server_name,conn)
|
|
181
|
-
}
|
|
182
|
-
catch(e)
|
|
183
|
-
{
|
|
184
|
-
GLog.info(' protocol reject')
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
createWebSocketObjectByProtocol(server_name:string,_ws:ws.connection):IClientWebSocket
|
|
188
|
-
{
|
|
189
|
-
server_name=server_name||"default"
|
|
190
|
-
let cls = this._name_vs_class[server_name]
|
|
191
|
-
if(!cls)
|
|
192
|
-
{
|
|
193
|
-
GLog.error("(createWebSocketObjectByProtocol in server("+this.name+"))no this websocket handle class="+server_name)
|
|
194
|
-
return null
|
|
195
|
-
}
|
|
196
|
-
let ws_server = <IClientWebSocket>(new cls(this))
|
|
197
|
-
this.addClient(ws_server)
|
|
198
|
-
ws_server.onConnect(_ws)
|
|
199
|
-
return ws_server
|
|
200
|
-
}
|
|
201
|
-
protected _getServerNameByCookies(cookies)
|
|
202
|
-
{
|
|
203
|
-
let server_name = ""
|
|
204
|
-
if(!cookies)
|
|
205
|
-
{
|
|
206
|
-
return server_name
|
|
207
|
-
}
|
|
208
|
-
for(let index in cookies)
|
|
209
|
-
{
|
|
210
|
-
let cookie = cookies[index]
|
|
211
|
-
if(cookie.name=="server")
|
|
212
|
-
{
|
|
213
|
-
server_name = cookie.value
|
|
214
|
-
break
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return server_name
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* 广播消息
|
|
221
|
-
* @param msg
|
|
222
|
-
*/
|
|
223
|
-
broadCast(msg:BaseMsg)
|
|
224
|
-
{
|
|
225
|
-
for(var key in this._ws_clients)
|
|
226
|
-
{
|
|
227
|
-
let ws = this._ws_clients[key] as IClientWebSocket
|
|
228
|
-
ws.send(msg)
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* 获取任意客户端连接
|
|
233
|
-
* @returns
|
|
234
|
-
*/
|
|
235
|
-
getAnyWebSocket()
|
|
236
|
-
{
|
|
237
|
-
for(var key in this._ws_clients)
|
|
238
|
-
{
|
|
239
|
-
return this._ws_clients[key] as IClientWebSocket
|
|
240
|
-
}
|
|
241
|
-
return null
|
|
242
|
-
}
|
|
243
|
-
}
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import { GLog } from '../Logic/Log';
|
|
2
|
-
import { GProtoFactory } from './ProtoFilter/ProtoFactory';
|
|
3
|
-
import { IProtoFilter,EProtoType } from "./ProtoFilter/IProtoFilter";
|
|
4
|
-
import * as ws from 'websocket';
|
|
5
|
-
import { core } from '../Core/Core';
|
|
6
|
-
import * as _ from "underscore";
|
|
7
|
-
import { GServerCfg } from '../Config/IServerConfig';
|
|
8
|
-
import { GSyncQueueTool } from '../Logic/SyncQueueTool';
|
|
9
|
-
|
|
10
|
-
export class BaseMsg
|
|
11
|
-
{
|
|
12
|
-
cmd: string
|
|
13
|
-
errcode?: {id:number,des:string}
|
|
14
|
-
servertime=Date.now()
|
|
15
|
-
constructor(cmd:string,errcode?: {id:number,des:string})
|
|
16
|
-
{
|
|
17
|
-
this.cmd=cmd
|
|
18
|
-
this.errcode=errcode
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export class IWebSocket
|
|
22
|
-
{
|
|
23
|
-
/**
|
|
24
|
-
* 是否同步消息
|
|
25
|
-
* 默认为true
|
|
26
|
-
*/
|
|
27
|
-
protected _is_sync_msg = true
|
|
28
|
-
get isSynMsg()
|
|
29
|
-
{
|
|
30
|
-
return this._is_sync_msg
|
|
31
|
-
}
|
|
32
|
-
protected _debug_msg:boolean=false
|
|
33
|
-
get debug_msg()
|
|
34
|
-
{
|
|
35
|
-
return this._debug_msg
|
|
36
|
-
}
|
|
37
|
-
set debug_msg(value)
|
|
38
|
-
{
|
|
39
|
-
this._debug_msg = value
|
|
40
|
-
}
|
|
41
|
-
protected _socket_id: number=0
|
|
42
|
-
get socketId():number
|
|
43
|
-
{
|
|
44
|
-
return this._socket_id
|
|
45
|
-
}
|
|
46
|
-
protected _tipKey:string=""
|
|
47
|
-
get tipKey()
|
|
48
|
-
{
|
|
49
|
-
return this._tipKey
|
|
50
|
-
}
|
|
51
|
-
protected _ws:ws.connection =null
|
|
52
|
-
protected _protoType:EProtoType=EProtoType.Json
|
|
53
|
-
protected _protoFilter:IProtoFilter=null
|
|
54
|
-
protected _protoPath=""
|
|
55
|
-
|
|
56
|
-
protected _ip:string = null
|
|
57
|
-
get remoteHost()
|
|
58
|
-
{
|
|
59
|
-
if(!this._ip)
|
|
60
|
-
{
|
|
61
|
-
this._ip = this._ws.remoteAddress
|
|
62
|
-
this._ip = this._ip.substring(this._ip.lastIndexOf(":")+1)
|
|
63
|
-
}
|
|
64
|
-
return this._ip
|
|
65
|
-
}
|
|
66
|
-
get connected()
|
|
67
|
-
{
|
|
68
|
-
if (this._ws
|
|
69
|
-
&&this._ws.connected==true)
|
|
70
|
-
{
|
|
71
|
-
return true
|
|
72
|
-
}
|
|
73
|
-
return false
|
|
74
|
-
}
|
|
75
|
-
constructor(protoType=EProtoType.Json,protoPath="")
|
|
76
|
-
{
|
|
77
|
-
this._debug_msg = GServerCfg.debug_msg
|
|
78
|
-
this._socket_id = parseInt(_.uniqueId())
|
|
79
|
-
this._protoType=protoType
|
|
80
|
-
this._protoPath=protoPath
|
|
81
|
-
}
|
|
82
|
-
getNewMsg(cmd:string, errcode?:{id:number,des:string}):BaseMsg|any
|
|
83
|
-
{
|
|
84
|
-
let msg = new BaseMsg(cmd,errcode)
|
|
85
|
-
return msg
|
|
86
|
-
}
|
|
87
|
-
receive_heartbeat(jsonData)
|
|
88
|
-
{
|
|
89
|
-
this.send_heartbeat()
|
|
90
|
-
}
|
|
91
|
-
send_heartbeat()
|
|
92
|
-
{
|
|
93
|
-
let msg = this.getNewMsg("heartbeat")
|
|
94
|
-
this.send(msg)
|
|
95
|
-
}
|
|
96
|
-
onConnect(_ws:ws.connection)
|
|
97
|
-
{
|
|
98
|
-
this._ws = _ws
|
|
99
|
-
if(!this._protoFilter)
|
|
100
|
-
{
|
|
101
|
-
this._protoFilter = GProtoFactory.createFilter(this._protoType)
|
|
102
|
-
this._protoFilter.init(this._protoPath)
|
|
103
|
-
}
|
|
104
|
-
this._ws.on("message",this.onMessage.bind(this))
|
|
105
|
-
this._ws.on("error",this.onError.bind(this))
|
|
106
|
-
this._ws.on("close",this.onClose.bind(this))
|
|
107
|
-
this.onOpen()
|
|
108
|
-
}
|
|
109
|
-
onMessage(message:ws.Message)
|
|
110
|
-
{
|
|
111
|
-
try
|
|
112
|
-
{
|
|
113
|
-
let msg = this._onDecode(message)
|
|
114
|
-
if(this._is_sync_msg)
|
|
115
|
-
{
|
|
116
|
-
GSyncQueueTool.add(this._socket_id+"",this._onMessage,this,msg)
|
|
117
|
-
}
|
|
118
|
-
else
|
|
119
|
-
{
|
|
120
|
-
this._onMessage(msg)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
catch (e)
|
|
124
|
-
{
|
|
125
|
-
GLog.error(this.tipKey+' Received Message Handle Error: ' + e)
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
protected _onDecode(message:ws.Message,...params)
|
|
129
|
-
{
|
|
130
|
-
let msg=null
|
|
131
|
-
if (message.type === 'utf8')
|
|
132
|
-
{
|
|
133
|
-
msg=this._protoFilter.decode(message.utf8Data,...params)
|
|
134
|
-
}
|
|
135
|
-
else if (message.type === 'binary')
|
|
136
|
-
{
|
|
137
|
-
msg=this._protoFilter.decode(message.binaryData,...params)
|
|
138
|
-
}
|
|
139
|
-
return msg
|
|
140
|
-
}
|
|
141
|
-
protected _onEncode(data,...params)
|
|
142
|
-
{
|
|
143
|
-
let msg = this._protoFilter.encode(data,...params)
|
|
144
|
-
return msg
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* 过滤消息,每个消息处理之前调用
|
|
148
|
-
* @param msg
|
|
149
|
-
* @returns
|
|
150
|
-
*/
|
|
151
|
-
filterMsg(msg:BaseMsg)
|
|
152
|
-
{
|
|
153
|
-
if(!msg)
|
|
154
|
-
{
|
|
155
|
-
GLog.error({tipKey:this.tipKey,action:"receive",error:"no cmd",msg})
|
|
156
|
-
return false
|
|
157
|
-
}
|
|
158
|
-
if(this._debug_msg && msg.cmd!="heartbeat")
|
|
159
|
-
{
|
|
160
|
-
GLog.info({tipKey:this.tipKey,action:"receive",msg})
|
|
161
|
-
}
|
|
162
|
-
if (!msg.cmd)
|
|
163
|
-
{
|
|
164
|
-
GLog.error({tipKey:this.tipKey,action:"receive",error:"no cmd",msg})
|
|
165
|
-
return false
|
|
166
|
-
}
|
|
167
|
-
return true
|
|
168
|
-
}
|
|
169
|
-
protected async _onMessage(data)
|
|
170
|
-
{
|
|
171
|
-
let jsonData = data
|
|
172
|
-
let func:Function = this["receive_"+jsonData.cmd]
|
|
173
|
-
let ret = this.filterMsg(jsonData)
|
|
174
|
-
if(!ret)
|
|
175
|
-
{
|
|
176
|
-
return
|
|
177
|
-
}
|
|
178
|
-
else if (!func)
|
|
179
|
-
{
|
|
180
|
-
let otherfunc:Function=this["receive_other_all"]
|
|
181
|
-
if(otherfunc)
|
|
182
|
-
{
|
|
183
|
-
await core.safeCall(otherfunc,this,jsonData)
|
|
184
|
-
}
|
|
185
|
-
else
|
|
186
|
-
{
|
|
187
|
-
GLog.error(this.tipKey+' Received Message warning: no cmd handle,cmd=' + jsonData.cmd)
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
else
|
|
191
|
-
{
|
|
192
|
-
await core.safeCall(func,this,jsonData)
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
onOpen(e?)
|
|
196
|
-
{
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
onError(e:Error)
|
|
200
|
-
{
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
onClose(reasonCode:number, description:string)
|
|
204
|
-
{
|
|
205
|
-
GLog.info(this.tipKey+" onClose resonCode="+reasonCode+" des="+description)
|
|
206
|
-
}
|
|
207
|
-
send(msg:BaseMsg)
|
|
208
|
-
{
|
|
209
|
-
if (!this.connected)
|
|
210
|
-
{
|
|
211
|
-
return
|
|
212
|
-
}
|
|
213
|
-
if (!msg)
|
|
214
|
-
{
|
|
215
|
-
GLog.error(this.tipKey+" Send Message warning:null data!")
|
|
216
|
-
return
|
|
217
|
-
}
|
|
218
|
-
if(this._debug_msg
|
|
219
|
-
&&msg.cmd!="heartbeat")
|
|
220
|
-
{
|
|
221
|
-
GLog.info({tipKey:this.tipKey,action:"send",msg})
|
|
222
|
-
}
|
|
223
|
-
let data = this._onEncode(msg)
|
|
224
|
-
this._ws.send(data)
|
|
225
|
-
}
|
|
226
|
-
close()
|
|
227
|
-
{
|
|
228
|
-
this._ws.close()
|
|
229
|
-
}
|
|
230
|
-
getServerNameFromCmd(cmd)
|
|
231
|
-
{
|
|
232
|
-
if(!cmd||!core.isString(cmd))
|
|
233
|
-
{
|
|
234
|
-
return null
|
|
235
|
-
}
|
|
236
|
-
let index = cmd.indexOf("_")
|
|
237
|
-
if(index<=0)
|
|
238
|
-
{
|
|
239
|
-
return null
|
|
240
|
-
}
|
|
241
|
-
return cmd.substring(0,index)
|
|
242
|
-
}
|
|
243
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { IProtoFilter } from './IProtoFilter';
|
|
2
|
-
import { core } from '../../Core/Core';
|
|
3
|
-
import { GLog } from '../../Logic/Log';
|
|
4
|
-
import * as protobufjs from 'protobufjs';
|
|
5
|
-
|
|
6
|
-
export class GoogleProtoFilter implements IProtoFilter
|
|
7
|
-
{
|
|
8
|
-
protected _root:protobufjs.Root=new protobufjs.Root()
|
|
9
|
-
protected _inited=false
|
|
10
|
-
init(path?:string):boolean
|
|
11
|
-
{
|
|
12
|
-
if(this._inited)
|
|
13
|
-
{
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
this._inited=true
|
|
17
|
-
try
|
|
18
|
-
{
|
|
19
|
-
this._root.loadSync(path,{keepCase:true})
|
|
20
|
-
}
|
|
21
|
-
catch(e)
|
|
22
|
-
{
|
|
23
|
-
GLog.error(e)
|
|
24
|
-
return false
|
|
25
|
-
}
|
|
26
|
-
return true
|
|
27
|
-
}
|
|
28
|
-
encode(data,root:string)
|
|
29
|
-
{
|
|
30
|
-
let msg={cmd:data.cmd}
|
|
31
|
-
msg[msg.cmd]=data
|
|
32
|
-
msg[msg.cmd].cmd=undefined
|
|
33
|
-
|
|
34
|
-
msg["errcode"]=data.errcode
|
|
35
|
-
msg["tip"]=data.tip
|
|
36
|
-
data.errcode=undefined
|
|
37
|
-
|
|
38
|
-
delete data.errcode
|
|
39
|
-
delete msg[msg.cmd].cmd
|
|
40
|
-
|
|
41
|
-
let body = this._root.lookupType(root)
|
|
42
|
-
var errMsg = body.verify(msg)
|
|
43
|
-
if (errMsg)
|
|
44
|
-
throw Error(errMsg)
|
|
45
|
-
var msgBody = body.create(msg);
|
|
46
|
-
var bufferBody = body.encode(msgBody).finish();
|
|
47
|
-
return bufferBody
|
|
48
|
-
}
|
|
49
|
-
decode(data,root:string)
|
|
50
|
-
{
|
|
51
|
-
let body = this._root.lookupType(root)
|
|
52
|
-
if(!body)
|
|
53
|
-
{
|
|
54
|
-
GLog.info("proto body not in proto(!"+root+")")
|
|
55
|
-
return null
|
|
56
|
-
}
|
|
57
|
-
let msgBody = body.decode(data)
|
|
58
|
-
if(!msgBody)
|
|
59
|
-
{
|
|
60
|
-
GLog.info("proto body decode wrong!")
|
|
61
|
-
return null
|
|
62
|
-
}
|
|
63
|
-
let objBody = body.toObject(msgBody)
|
|
64
|
-
let obj = objBody[objBody.cmd]
|
|
65
|
-
obj.cmd=objBody.cmd
|
|
66
|
-
return obj
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { IProtoFilter } from './IProtoFilter';
|
|
2
|
-
import { core } from '../../Core/Core';
|
|
3
|
-
import { GLog } from '../../Logic/Log';
|
|
4
|
-
export class JsonProtoFilter implements IProtoFilter
|
|
5
|
-
{
|
|
6
|
-
init(path?:string)
|
|
7
|
-
{
|
|
8
|
-
return true
|
|
9
|
-
}
|
|
10
|
-
encode(data)
|
|
11
|
-
{
|
|
12
|
-
if(!core.isString(data))
|
|
13
|
-
{
|
|
14
|
-
data = JSON.stringify(data)
|
|
15
|
-
}
|
|
16
|
-
return data
|
|
17
|
-
}
|
|
18
|
-
decode(data)
|
|
19
|
-
{
|
|
20
|
-
try
|
|
21
|
-
{
|
|
22
|
-
if(core.isString(data))
|
|
23
|
-
{
|
|
24
|
-
data = JSON.parse(data)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
catch(e)
|
|
28
|
-
{
|
|
29
|
-
GLog.error("decode json data Failed-----data="+data)
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
return data
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { GoogleProtoFilter } from './GoogleProtoFilter';
|
|
2
|
-
import { JsonProtoFilter } from './JsonProtoFilter';
|
|
3
|
-
import { IProtoFilter } from './IProtoFilter';
|
|
4
|
-
import { EProtoType } from "./IProtoFilter";
|
|
5
|
-
|
|
6
|
-
export let GProtoFactory:ProtoFactory=null
|
|
7
|
-
class ProtoFactory
|
|
8
|
-
{
|
|
9
|
-
protected _filters=new Map<EProtoType,IProtoFilter>()
|
|
10
|
-
createFilter(type:EProtoType):IProtoFilter
|
|
11
|
-
{
|
|
12
|
-
let filter = this._filters.get(type)
|
|
13
|
-
if(filter)
|
|
14
|
-
{
|
|
15
|
-
return filter
|
|
16
|
-
}
|
|
17
|
-
switch(type)
|
|
18
|
-
{
|
|
19
|
-
case EProtoType.GoogleProtoBuffer:
|
|
20
|
-
{
|
|
21
|
-
filter = new GoogleProtoFilter()
|
|
22
|
-
break
|
|
23
|
-
}
|
|
24
|
-
default:
|
|
25
|
-
{
|
|
26
|
-
filter = new JsonProtoFilter()
|
|
27
|
-
break
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
this._filters.set(type,filter)
|
|
31
|
-
return filter
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
GProtoFactory=new ProtoFactory()
|