cgserver 7.10.2113 → 7.11.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 +1 -1
- 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,168 +0,0 @@
|
|
|
1
|
-
import * as _ from "underscore";
|
|
2
|
-
import { MysqlBaseService, BaseModel } from "../Database/MysqlBaseService";
|
|
3
|
-
import { PrimaryKey } from "../Database/Decorator/PrimaryKey";
|
|
4
|
-
import { NotNull } from "../Database/Decorator/NotNull";
|
|
5
|
-
import { EPropertyType } from "../Database/Decorator/Property";
|
|
6
|
-
import { Type } from "../Database/Decorator/Type";
|
|
7
|
-
import { ERoleGroup, EUserState } from "./ini";
|
|
8
|
-
|
|
9
|
-
export class UserModel extends BaseModel
|
|
10
|
-
{
|
|
11
|
-
@Type(EPropertyType.Int)
|
|
12
|
-
@NotNull
|
|
13
|
-
@PrimaryKey
|
|
14
|
-
id:number=-1
|
|
15
|
-
|
|
16
|
-
@NotNull
|
|
17
|
-
@Type(EPropertyType.Int,-1)
|
|
18
|
-
account_id:number=-1
|
|
19
|
-
|
|
20
|
-
@NotNull
|
|
21
|
-
@Type(EPropertyType.Varchar,"noname",32)
|
|
22
|
-
nickname:string=""
|
|
23
|
-
|
|
24
|
-
@NotNull
|
|
25
|
-
@Type(EPropertyType.SmallInt,0)
|
|
26
|
-
sex:number=-1
|
|
27
|
-
|
|
28
|
-
@NotNull
|
|
29
|
-
@Type(EPropertyType.Varchar,"",255)
|
|
30
|
-
logo:string=""
|
|
31
|
-
|
|
32
|
-
@NotNull
|
|
33
|
-
@Type(EPropertyType.Int,0)
|
|
34
|
-
state:number=EUserState.Waitting
|
|
35
|
-
|
|
36
|
-
@NotNull
|
|
37
|
-
@Type(EPropertyType.Int,4)
|
|
38
|
-
role_group:number=4
|
|
39
|
-
|
|
40
|
-
@NotNull
|
|
41
|
-
@Type(EPropertyType.Int,0)
|
|
42
|
-
role:number=0
|
|
43
|
-
|
|
44
|
-
@NotNull
|
|
45
|
-
@Type(EPropertyType.Varchar,"")
|
|
46
|
-
phone:string=""
|
|
47
|
-
|
|
48
|
-
@NotNull
|
|
49
|
-
@Type(EPropertyType.Varchar,"")
|
|
50
|
-
wechat:string=""
|
|
51
|
-
|
|
52
|
-
@NotNull
|
|
53
|
-
@Type(EPropertyType.Varchar,"")
|
|
54
|
-
qq:string=""
|
|
55
|
-
|
|
56
|
-
@NotNull
|
|
57
|
-
@Type(EPropertyType.Varchar,"")
|
|
58
|
-
email:string=""
|
|
59
|
-
|
|
60
|
-
@NotNull
|
|
61
|
-
@Type(EPropertyType.Varchar,"",512)
|
|
62
|
-
about:string=""
|
|
63
|
-
|
|
64
|
-
@NotNull
|
|
65
|
-
@Type(EPropertyType.Int,-1)
|
|
66
|
-
pre_user_id:number=-1
|
|
67
|
-
|
|
68
|
-
@NotNull
|
|
69
|
-
@Type(EPropertyType.Int,0)
|
|
70
|
-
exp:number = 0
|
|
71
|
-
|
|
72
|
-
@NotNull
|
|
73
|
-
@Type(EPropertyType.Int,1)
|
|
74
|
-
level:number = 1//等级
|
|
75
|
-
|
|
76
|
-
@NotNull
|
|
77
|
-
@Type(EPropertyType.Int,0)
|
|
78
|
-
vip_exp:number = 0
|
|
79
|
-
|
|
80
|
-
@NotNull
|
|
81
|
-
@Type(EPropertyType.Int,0)
|
|
82
|
-
vip_level:number = 0//等级
|
|
83
|
-
|
|
84
|
-
@NotNull
|
|
85
|
-
@Type(EPropertyType.TinyInt,0)
|
|
86
|
-
is_robot:number = 0
|
|
87
|
-
|
|
88
|
-
@NotNull
|
|
89
|
-
@Type(EPropertyType.BigInt,0)
|
|
90
|
-
create_time:number = 0
|
|
91
|
-
}
|
|
92
|
-
//暂时不实例化,方便重写
|
|
93
|
-
export let GUserSer:UserService<UserModel>=null
|
|
94
|
-
export class UserService<T extends UserModel> extends MysqlBaseService<T>
|
|
95
|
-
{
|
|
96
|
-
constructor(type: { new(): T})
|
|
97
|
-
{
|
|
98
|
-
super(type)
|
|
99
|
-
GUserSer = this
|
|
100
|
-
}
|
|
101
|
-
protected _newUserModel():T
|
|
102
|
-
{
|
|
103
|
-
return <T>(new UserModel())
|
|
104
|
-
}
|
|
105
|
-
protected async _createNewUser(account_id:number,nickname:string,sex:number,logo:string,group?:ERoleGroup)
|
|
106
|
-
{
|
|
107
|
-
group = group || ERoleGroup.Common
|
|
108
|
-
let um = this._newUserModel()
|
|
109
|
-
um.account_id = account_id
|
|
110
|
-
um.nickname = nickname
|
|
111
|
-
if(!um.nickname||um.nickname.length==0)
|
|
112
|
-
{
|
|
113
|
-
um.nickname = "noname"
|
|
114
|
-
}
|
|
115
|
-
um.sex = sex||0
|
|
116
|
-
um.logo = logo||""
|
|
117
|
-
um.account_id = account_id
|
|
118
|
-
um.state = EUserState.Waitting
|
|
119
|
-
um.role_group = group
|
|
120
|
-
um.role = 0
|
|
121
|
-
//随机userid
|
|
122
|
-
let id = 0
|
|
123
|
-
do
|
|
124
|
-
{
|
|
125
|
-
id=_.random(1000000,9999999)
|
|
126
|
-
let p = await this.get("id","id=?",[id])
|
|
127
|
-
if(!p)
|
|
128
|
-
{
|
|
129
|
-
break
|
|
130
|
-
}
|
|
131
|
-
}while(true)
|
|
132
|
-
um.id = id
|
|
133
|
-
return um
|
|
134
|
-
}
|
|
135
|
-
async updateBaseInfoByAccount(account_id:number,nickname:string,sex:number,logo:string)
|
|
136
|
-
{
|
|
137
|
-
let sr = await this.updateProperty("nickname=?,sex=?,logo=?","account_id=?",[nickname,sex,logo,account_id])
|
|
138
|
-
if(sr.error&&sr.results.affectedRows<=0)
|
|
139
|
-
{
|
|
140
|
-
return "更新失败"
|
|
141
|
-
}
|
|
142
|
-
return
|
|
143
|
-
}
|
|
144
|
-
async add(account_id:number,nickname:string,sex:number,logo:string,group?:ERoleGroup)
|
|
145
|
-
{
|
|
146
|
-
let um:any = await this._createNewUser(account_id,nickname,sex,logo,group)
|
|
147
|
-
let sr = await this.insert(um)
|
|
148
|
-
if(sr.error||sr.results.length<=0)
|
|
149
|
-
{
|
|
150
|
-
return null
|
|
151
|
-
}
|
|
152
|
-
return um
|
|
153
|
-
}
|
|
154
|
-
async updateRoleGroup(user_id:number,role_group:ERoleGroup)
|
|
155
|
-
{
|
|
156
|
-
let sr = await this.updateProperty("role_group=?","id=?",[role_group,user_id])
|
|
157
|
-
if(sr.error&&sr.results.affectedRows<=0)
|
|
158
|
-
{
|
|
159
|
-
return "更新失败"
|
|
160
|
-
}
|
|
161
|
-
return
|
|
162
|
-
}
|
|
163
|
-
async getByAccountId(account_id:number)
|
|
164
|
-
{
|
|
165
|
-
let pm:T = await this.get(null,"account_id=?",[account_id])
|
|
166
|
-
return pm
|
|
167
|
-
}
|
|
168
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export enum ERoleGroup
|
|
2
|
-
{
|
|
3
|
-
Creator=1,//创始人
|
|
4
|
-
Admin,//管理员
|
|
5
|
-
Proxy,//代理
|
|
6
|
-
Common//普通成员
|
|
7
|
-
}
|
|
8
|
-
export enum EUserState
|
|
9
|
-
{
|
|
10
|
-
Ban=-1,
|
|
11
|
-
Waitting=0,
|
|
12
|
-
Normarl=1
|
|
13
|
-
}
|
|
14
|
-
export enum EAccountState
|
|
15
|
-
{
|
|
16
|
-
Delete=-2,
|
|
17
|
-
Ban=-1,
|
|
18
|
-
Waitting=0,
|
|
19
|
-
Normarl=1
|
|
20
|
-
}
|
|
21
|
-
export enum EAccountFrom
|
|
22
|
-
{
|
|
23
|
-
Guest=0,
|
|
24
|
-
OpenSocial,
|
|
25
|
-
WeChat,
|
|
26
|
-
QQ,
|
|
27
|
-
Phone,
|
|
28
|
-
Email,
|
|
29
|
-
Name,
|
|
30
|
-
QuickPhone,
|
|
31
|
-
Apple,
|
|
32
|
-
Google
|
|
33
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { ISocketServer } from './ISocketServer';
|
|
2
|
-
import { IWebSocket } from './IWebSocket';
|
|
3
|
-
import { GLog } from '../Logic/Log';
|
|
4
|
-
import { EProtoType } from './ProtoFilter/IProtoFilter';
|
|
5
|
-
import * as ws from 'websocket';
|
|
6
|
-
/**
|
|
7
|
-
* 服务器接收到的客户端的连接
|
|
8
|
-
* 客户端的session对象
|
|
9
|
-
*/
|
|
10
|
-
export class IClientWebSocket extends IWebSocket
|
|
11
|
-
{
|
|
12
|
-
protected _server:ISocketServer=null
|
|
13
|
-
get server()
|
|
14
|
-
{
|
|
15
|
-
return this._server
|
|
16
|
-
}
|
|
17
|
-
constructor(server:ISocketServer,protoType=EProtoType.Json,protoPath="")
|
|
18
|
-
{
|
|
19
|
-
super(protoType,protoPath)
|
|
20
|
-
this._server = server
|
|
21
|
-
this._tipKey=this._server.name
|
|
22
|
-
}
|
|
23
|
-
onClose (reasonCode:number, description:string)
|
|
24
|
-
{
|
|
25
|
-
super.onClose(reasonCode, description)
|
|
26
|
-
this._server.removeServerWebSocketBySocketId(this._socket_id)
|
|
27
|
-
}
|
|
28
|
-
broadCast(data)
|
|
29
|
-
{
|
|
30
|
-
if (!data)
|
|
31
|
-
{
|
|
32
|
-
GLog.info("Send Message warning:null data!")
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
GLog.info("broadCast:----------------------------------")
|
|
36
|
-
GLog.info(data)
|
|
37
|
-
let msg = this._protoFilter.encode(data)
|
|
38
|
-
this._server.broadCast(msg)
|
|
39
|
-
}
|
|
40
|
-
protected _onDecode(message:ws.Message,...params)
|
|
41
|
-
{
|
|
42
|
-
let msg = super._onDecode(message,"msgReq")
|
|
43
|
-
return msg
|
|
44
|
-
}
|
|
45
|
-
protected _onEncode(data,...params)
|
|
46
|
-
{
|
|
47
|
-
let msg = super._onEncode(data,"msgRes")
|
|
48
|
-
return msg
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import _ = require("underscore");
|
|
2
|
-
import { GEventTool } from "../Logic/EventTool";
|
|
3
|
-
import { GLog } from "../Logic/Log";
|
|
4
|
-
import { IRpc, RpcBaseMsg } from "./IRpc";
|
|
5
|
-
import { IClientWebSocket } from "./IClientWebSocket";
|
|
6
|
-
|
|
7
|
-
export class IRpcClientWebSocket extends IClientWebSocket implements IRpc
|
|
8
|
-
{
|
|
9
|
-
protected _genId(pre="")
|
|
10
|
-
{
|
|
11
|
-
return pre+"_"+Date.now()%10000000000+"_"+_.uniqueId()+_.random(9999999)
|
|
12
|
-
}
|
|
13
|
-
getNewMsg(cmd: string, errcode?: { id: number; des: string; }) {
|
|
14
|
-
let msg = super.getNewMsg(cmd,errcode) as RpcBaseMsg|any
|
|
15
|
-
msg.__rpcid=this._genId(cmd)
|
|
16
|
-
return msg
|
|
17
|
-
}
|
|
18
|
-
extendRetMsg(msg:RpcBaseMsg,errcode?: { id: number; des: string; })
|
|
19
|
-
{
|
|
20
|
-
let basemsg = super.getNewMsg(msg.cmd,errcode)
|
|
21
|
-
basemsg.__rpcid=msg.__rpcid
|
|
22
|
-
_.extend(msg,basemsg)
|
|
23
|
-
return msg
|
|
24
|
-
}
|
|
25
|
-
async callRemote(msg: RpcBaseMsg)
|
|
26
|
-
{
|
|
27
|
-
if(!msg)
|
|
28
|
-
{
|
|
29
|
-
GLog.error("send null msg!")
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
if(!msg.__rpcid)
|
|
33
|
-
{
|
|
34
|
-
msg.__rpcid=this._genId(msg.cmd)
|
|
35
|
-
}
|
|
36
|
-
return new Promise((resolve,reject)=>
|
|
37
|
-
{
|
|
38
|
-
let handler = null
|
|
39
|
-
let func=(jsonData)=>
|
|
40
|
-
{
|
|
41
|
-
if(handler)
|
|
42
|
-
{
|
|
43
|
-
clearTimeout(handler)
|
|
44
|
-
handler=null
|
|
45
|
-
}
|
|
46
|
-
resolve(jsonData)
|
|
47
|
-
}
|
|
48
|
-
handler = setTimeout(()=>
|
|
49
|
-
{
|
|
50
|
-
GEventTool.off(msg.__rpcid,func)
|
|
51
|
-
resolve({errcode:{id:10086,des:"timeout"}})
|
|
52
|
-
},3000)
|
|
53
|
-
GEventTool.once(msg.__rpcid,func)
|
|
54
|
-
super.send(msg)
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
receive_other_all(msg:RpcBaseMsg)
|
|
58
|
-
{
|
|
59
|
-
if(msg.__return)
|
|
60
|
-
{
|
|
61
|
-
GEventTool.emit(msg.__rpcid,msg)
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
GLog.error({des:"no handle",msg})
|
|
65
|
-
}
|
|
66
|
-
protected async _onMessage(msg:RpcBaseMsg)
|
|
67
|
-
{
|
|
68
|
-
if(msg.__return)
|
|
69
|
-
{
|
|
70
|
-
GEventTool.emit(msg.__rpcid,msg)
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
super._onMessage(msg)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import _ = require("underscore");
|
|
2
|
-
import { GEventTool } from "../Logic/EventTool";
|
|
3
|
-
import { GLog } from "../Logic/Log";
|
|
4
|
-
import { IServerWebSocket } from "./IServerWebSocket";
|
|
5
|
-
import { IRpc, RpcBaseMsg } from "./IRpc";
|
|
6
|
-
import { BaseMsg } from "./IWebSocket";
|
|
7
|
-
|
|
8
|
-
export class IRpcServerWebSocket extends IServerWebSocket implements IRpc
|
|
9
|
-
{
|
|
10
|
-
protected _genId(pre="")
|
|
11
|
-
{
|
|
12
|
-
return pre+"_"+Date.now()%10000000000+"_"+_.uniqueId()+_.random(9999999)
|
|
13
|
-
}
|
|
14
|
-
getNewMsg(cmd: string, errcode?: { id: number; des: string; }) {
|
|
15
|
-
let msg = super.getNewMsg(cmd,errcode) as RpcBaseMsg|any
|
|
16
|
-
msg.__rpcid=this._genId(cmd)
|
|
17
|
-
return msg
|
|
18
|
-
}
|
|
19
|
-
extendRetMsg(msg:RpcBaseMsg,errcode?: { id: number; des: string; })
|
|
20
|
-
{
|
|
21
|
-
let basemsg = super.getNewMsg(msg.cmd,errcode)
|
|
22
|
-
basemsg.__rpcid=msg.__rpcid
|
|
23
|
-
_.extend(msg,basemsg)
|
|
24
|
-
return msg
|
|
25
|
-
}
|
|
26
|
-
async callRemote(msg: RpcBaseMsg)
|
|
27
|
-
{
|
|
28
|
-
if(!msg)
|
|
29
|
-
{
|
|
30
|
-
GLog.error("send null msg!")
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
if(!msg.__rpcid)
|
|
34
|
-
{
|
|
35
|
-
msg.__rpcid=this._genId(msg.cmd)
|
|
36
|
-
}
|
|
37
|
-
return new Promise((resolve,reject)=>
|
|
38
|
-
{
|
|
39
|
-
let handler = null
|
|
40
|
-
let func=(jsonData)=>
|
|
41
|
-
{
|
|
42
|
-
if(handler)
|
|
43
|
-
{
|
|
44
|
-
clearTimeout(handler)
|
|
45
|
-
handler=null
|
|
46
|
-
}
|
|
47
|
-
resolve(jsonData)
|
|
48
|
-
}
|
|
49
|
-
handler = setTimeout(()=>
|
|
50
|
-
{
|
|
51
|
-
GEventTool.off(msg.__rpcid,func)
|
|
52
|
-
resolve({errcode:{id:10086,des:"timeout"}})
|
|
53
|
-
},3000)
|
|
54
|
-
GEventTool.once(msg.__rpcid,func)
|
|
55
|
-
super.send(msg)
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
receive_other_all(msg:RpcBaseMsg)
|
|
59
|
-
{
|
|
60
|
-
if(msg.__rpcid)
|
|
61
|
-
{
|
|
62
|
-
GEventTool.emit(msg.__rpcid,msg)
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
GLog.error({des:"no handle",msg})
|
|
66
|
-
}
|
|
67
|
-
protected async _onMessage(msg:RpcBaseMsg)
|
|
68
|
-
{
|
|
69
|
-
if(msg.__return)
|
|
70
|
-
{
|
|
71
|
-
GEventTool.emit(msg.__rpcid,msg)
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
super._onMessage(msg)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { IWebSocket } from './IWebSocket';
|
|
2
|
-
import * as ws from 'websocket';
|
|
3
|
-
import { GLog } from '../Logic/Log';
|
|
4
|
-
import { EProtoType } from './ProtoFilter/IProtoFilter';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 连接到服务器的websocket
|
|
8
|
-
* 默认自动重连
|
|
9
|
-
*/
|
|
10
|
-
export class IServerWebSocket extends IWebSocket
|
|
11
|
-
{
|
|
12
|
-
protected _host:string = ""
|
|
13
|
-
/**
|
|
14
|
-
* 连接的服务器地址
|
|
15
|
-
*/
|
|
16
|
-
get host()
|
|
17
|
-
{
|
|
18
|
-
return this._host
|
|
19
|
-
}
|
|
20
|
-
protected _port:number = -1
|
|
21
|
-
/**
|
|
22
|
-
* 连接的服务器端口
|
|
23
|
-
*/
|
|
24
|
-
get port()
|
|
25
|
-
{
|
|
26
|
-
return this._port
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
protected _need_close:boolean=false
|
|
30
|
-
constructor(protoType=EProtoType.Json,protoPath="")
|
|
31
|
-
{
|
|
32
|
-
super(protoType,protoPath)
|
|
33
|
-
}
|
|
34
|
-
connect(domain:string,port:number)
|
|
35
|
-
{
|
|
36
|
-
this._host = domain || this._host
|
|
37
|
-
this._port = port || this._port
|
|
38
|
-
this._connect()
|
|
39
|
-
}
|
|
40
|
-
protected _connect()
|
|
41
|
-
{
|
|
42
|
-
let url = "ws://" + this._host + ":" + this._port + "/"
|
|
43
|
-
GLog.info("Trying to connect to server : " + url)
|
|
44
|
-
let _ws = new ws.client()
|
|
45
|
-
_ws.on("connect",super.onConnect.bind(this))
|
|
46
|
-
_ws.on("connectFailed",this.onClose.bind(this))
|
|
47
|
-
_ws.connect(url,null,null,{cookie:"client="+this._tipKey})
|
|
48
|
-
}
|
|
49
|
-
onOpen(e?)
|
|
50
|
-
{
|
|
51
|
-
super.onOpen(e)
|
|
52
|
-
GLog.info("success to connect to " + this._host + ":" + this._port)
|
|
53
|
-
}
|
|
54
|
-
onClose(reasonCode:number, description:string)
|
|
55
|
-
{
|
|
56
|
-
super.onClose(reasonCode, description)
|
|
57
|
-
if(!this._need_close)
|
|
58
|
-
{
|
|
59
|
-
setTimeout(()=>
|
|
60
|
-
{
|
|
61
|
-
if(!this._need_close)
|
|
62
|
-
{
|
|
63
|
-
this.connect(this._host,this._port)
|
|
64
|
-
}
|
|
65
|
-
},1000)
|
|
66
|
-
return true
|
|
67
|
-
}
|
|
68
|
-
else
|
|
69
|
-
{
|
|
70
|
-
return false
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
close()
|
|
74
|
-
{
|
|
75
|
-
this._need_close = true
|
|
76
|
-
super.close()
|
|
77
|
-
}
|
|
78
|
-
protected _onDecode(message:ws.Message,...params)
|
|
79
|
-
{
|
|
80
|
-
let msg = super._onDecode(message,"msgRes")
|
|
81
|
-
return msg
|
|
82
|
-
}
|
|
83
|
-
protected _onEncode(data,...params)
|
|
84
|
-
{
|
|
85
|
-
let msg = super._onEncode(data,"msgReq")
|
|
86
|
-
return msg
|
|
87
|
-
}
|
|
88
|
-
}
|