cgserver 6.6.7 → 6.7.445
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/dist/lib/Logic/AsyncQueueTool.js +2 -2
- package/dist/lib/Logic/SyncQueueTool.js +43 -0
- package/dist/lib/SocketServer/IWebSocket.js +42 -77
- package/dist/lib/index.js +3 -3
- package/dist/types/Logic/AsyncQueueTool.d.ts +1 -1
- package/dist/types/Logic/SyncQueueTool.d.ts +21 -0
- package/dist/types/SocketServer/IWebSocket.d.ts +25 -9
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GSyncQueueTool = void 0;
|
|
4
4
|
const Core_1 = require("../Core/Core");
|
|
5
5
|
class AsyncQueueItem {
|
|
6
6
|
key = "";
|
|
@@ -40,4 +40,4 @@ class AsyncQueueTool {
|
|
|
40
40
|
return error;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
exports.
|
|
43
|
+
exports.GSyncQueueTool = new AsyncQueueTool();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GSyncQueueTool = void 0;
|
|
4
|
+
const Core_1 = require("../Core/Core");
|
|
5
|
+
class SyncQueueItem {
|
|
6
|
+
key = "";
|
|
7
|
+
running = false;
|
|
8
|
+
funcs = [];
|
|
9
|
+
constructor(key) {
|
|
10
|
+
this.key = key;
|
|
11
|
+
}
|
|
12
|
+
async add(func, thisArg = null, ...params) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
this.funcs.push({ func: func, thisArg: thisArg, params: params, resolve: resolve });
|
|
15
|
+
this._run();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async _run() {
|
|
19
|
+
if (this.running) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
this.running = true;
|
|
23
|
+
while (this.funcs.length > 0) {
|
|
24
|
+
let funcitem = this.funcs.shift();
|
|
25
|
+
if (!funcitem.func) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
let rs = await Core_1.core.safeCall(funcitem.func, funcitem.thisArg, ...funcitem.params);
|
|
29
|
+
await Core_1.core.safeCall(funcitem.resolve, null, rs);
|
|
30
|
+
}
|
|
31
|
+
this.running = false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class SyncQueueTool {
|
|
35
|
+
//队列数据,一个key队列必须有先后
|
|
36
|
+
_queues = {};
|
|
37
|
+
async add(key, func, thisArg = null, ...params) {
|
|
38
|
+
this._queues[key] = this._queues[key] || new SyncQueueItem(key);
|
|
39
|
+
let error = await this._queues[key].add(func, thisArg, ...params);
|
|
40
|
+
return error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.GSyncQueueTool = new SyncQueueTool();
|
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IWebSocket = void 0;
|
|
3
|
+
exports.IWebSocket = exports.BaseMsg = void 0;
|
|
4
4
|
const Log_1 = require("../Logic/Log");
|
|
5
5
|
const ProtoFactory_1 = require("./ProtoFilter/ProtoFactory");
|
|
6
6
|
const IProtoFilter_1 = require("./ProtoFilter/IProtoFilter");
|
|
7
7
|
const Core_1 = require("../Core/Core");
|
|
8
8
|
const _ = require("underscore");
|
|
9
9
|
const ServerConfig_1 = require("../Config/ServerConfig");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const SyncQueueTool_1 = require("../Logic/SyncQueueTool");
|
|
11
|
+
class BaseMsg {
|
|
12
|
+
cmd;
|
|
13
|
+
errcode;
|
|
14
|
+
servertime = Date.now();
|
|
15
|
+
constructor(cmd, errcode) {
|
|
16
|
+
this.cmd = cmd;
|
|
17
|
+
this.errcode = errcode;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.BaseMsg = BaseMsg;
|
|
16
21
|
class IWebSocket {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
/**
|
|
23
|
+
* 是否同步消息
|
|
24
|
+
* 默认为true
|
|
25
|
+
*/
|
|
26
|
+
_is_sync_msg = true;
|
|
27
|
+
get isSynMsg() {
|
|
28
|
+
return this._is_sync_msg;
|
|
20
29
|
}
|
|
21
30
|
_debug_msg = false;
|
|
22
31
|
get debug_msg() {
|
|
@@ -54,16 +63,12 @@ class IWebSocket {
|
|
|
54
63
|
}
|
|
55
64
|
constructor(protoType = IProtoFilter_1.EProtoType.Json, protoPath = "") {
|
|
56
65
|
this._debug_msg = ServerConfig_1.GServerCfg.debug_msg;
|
|
57
|
-
this._socket_id =
|
|
66
|
+
this._socket_id = parseInt(_.uniqueId());
|
|
58
67
|
this._protoType = protoType;
|
|
59
68
|
this._protoPath = protoPath;
|
|
60
69
|
}
|
|
61
70
|
getNewMsg(cmd, errcode) {
|
|
62
|
-
let msg =
|
|
63
|
-
cmd: cmd,
|
|
64
|
-
errcode: errcode,
|
|
65
|
-
servertime: new Date().getTime()
|
|
66
|
-
};
|
|
71
|
+
let msg = new BaseMsg(cmd, errcode);
|
|
67
72
|
return msg;
|
|
68
73
|
}
|
|
69
74
|
receive_heartbeat(jsonData) {
|
|
@@ -84,15 +89,11 @@ class IWebSocket {
|
|
|
84
89
|
this._ws.on("close", this.onClose.bind(this));
|
|
85
90
|
this.onOpen();
|
|
86
91
|
}
|
|
87
|
-
_msgs = [];
|
|
88
92
|
onMessage(message) {
|
|
89
93
|
try {
|
|
90
94
|
let msg = this._onDecode(message);
|
|
91
|
-
if (this.
|
|
92
|
-
this.
|
|
93
|
-
if (!this._run_await) {
|
|
94
|
-
this._awaitMessages();
|
|
95
|
-
}
|
|
95
|
+
if (this._is_sync_msg) {
|
|
96
|
+
SyncQueueTool_1.GSyncQueueTool.add(this._socket_id + "", this._onMessage, this, msg);
|
|
96
97
|
}
|
|
97
98
|
else {
|
|
98
99
|
this._onMessage(msg);
|
|
@@ -116,30 +117,21 @@ class IWebSocket {
|
|
|
116
117
|
let msg = this._protoFilter.encode(data, ...params);
|
|
117
118
|
return msg;
|
|
118
119
|
}
|
|
119
|
-
_run_await = false;
|
|
120
|
-
async _awaitMessages() {
|
|
121
|
-
this._run_await = true;
|
|
122
|
-
while (this._msgs.length > 0) {
|
|
123
|
-
let msg = this._msgs.shift();
|
|
124
|
-
await this._onMessage(msg);
|
|
125
|
-
}
|
|
126
|
-
this._run_await = false;
|
|
127
|
-
}
|
|
128
120
|
/**
|
|
129
121
|
* 过滤消息,每个消息处理之前调用
|
|
130
|
-
* @param
|
|
122
|
+
* @param msg
|
|
131
123
|
* @returns
|
|
132
124
|
*/
|
|
133
|
-
filterMsg(
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
Log_1.GLog.error({ tipKey: this.tipKey,
|
|
125
|
+
filterMsg(msg) {
|
|
126
|
+
if (!msg) {
|
|
127
|
+
Log_1.GLog.error({ tipKey: this.tipKey, action: "receive", error: "no cmd", msg });
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (this._debug_msg && msg.cmd != "heartbeat") {
|
|
131
|
+
Log_1.GLog.info({ tipKey: this.tipKey, action: "receive", msg });
|
|
132
|
+
}
|
|
133
|
+
if (!msg.cmd) {
|
|
134
|
+
Log_1.GLog.error({ tipKey: this.tipKey, action: "receive", error: "no cmd", msg });
|
|
143
135
|
return false;
|
|
144
136
|
}
|
|
145
137
|
return true;
|
|
@@ -154,40 +146,14 @@ class IWebSocket {
|
|
|
154
146
|
else if (!func) {
|
|
155
147
|
let otherfunc = this["receive_other_all"];
|
|
156
148
|
if (otherfunc) {
|
|
157
|
-
|
|
158
|
-
if (Core_1.core.isAsyncFunc(otherfunc)) {
|
|
159
|
-
//默认支持其他所有处理消息
|
|
160
|
-
await otherfunc.call(this, jsonData).catch((reason) => {
|
|
161
|
-
Log_1.GLog.error(reason);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
otherfunc.call(this, jsonData);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
catch (e) {
|
|
169
|
-
Log_1.GLog.error(this.tipKey + e.stack);
|
|
170
|
-
}
|
|
149
|
+
await Core_1.core.safeCall(otherfunc, this, jsonData);
|
|
171
150
|
}
|
|
172
151
|
else {
|
|
173
152
|
Log_1.GLog.error(this.tipKey + ' Received Message warning: no cmd handle,cmd=' + jsonData.cmd);
|
|
174
153
|
}
|
|
175
154
|
}
|
|
176
155
|
else {
|
|
177
|
-
|
|
178
|
-
if (Core_1.core.isAsyncFunc(func)) {
|
|
179
|
-
//默认支持其他所有处理消息
|
|
180
|
-
await func.call(this, jsonData).catch((reason) => {
|
|
181
|
-
Log_1.GLog.error(reason);
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
func.call(this, jsonData);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch (e) {
|
|
189
|
-
Log_1.GLog.error(this.tipKey + " error msg:data=" + JSON.stringify(jsonData) + "\n" + e.stack);
|
|
190
|
-
}
|
|
156
|
+
await Core_1.core.safeCall(func, this, jsonData);
|
|
191
157
|
}
|
|
192
158
|
}
|
|
193
159
|
onOpen(e) {
|
|
@@ -197,21 +163,20 @@ class IWebSocket {
|
|
|
197
163
|
onClose(reasonCode, description) {
|
|
198
164
|
Log_1.GLog.info(this.tipKey + " onClose resonCode=" + reasonCode + " des=" + description);
|
|
199
165
|
}
|
|
200
|
-
send(
|
|
166
|
+
send(msg) {
|
|
201
167
|
if (!this.connected) {
|
|
202
168
|
return;
|
|
203
169
|
}
|
|
204
|
-
if (!
|
|
170
|
+
if (!msg) {
|
|
205
171
|
Log_1.GLog.error(this.tipKey + " Send Message warning:null data!");
|
|
206
172
|
return;
|
|
207
173
|
}
|
|
208
174
|
if (this._debug_msg
|
|
209
|
-
&&
|
|
210
|
-
Log_1.GLog.info(this.tipKey
|
|
211
|
-
Log_1.GLog.info({ tipKey: this.tipKey, data });
|
|
175
|
+
&& msg.cmd != "heartbeat") {
|
|
176
|
+
Log_1.GLog.info({ tipKey: this.tipKey, action: "send", msg });
|
|
212
177
|
}
|
|
213
|
-
let
|
|
214
|
-
this._ws.send(
|
|
178
|
+
let data = this._onEncode(msg);
|
|
179
|
+
this._ws.send(data);
|
|
215
180
|
}
|
|
216
181
|
close() {
|
|
217
182
|
this._ws.close();
|
package/dist/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GoogleProtoFilter = exports.MongoCacheModel = exports.GMongoCacheSer = exports.MongoUserModel = exports.MysqlUserModel = exports.MongoUserService = exports.MysqlUserService = exports.GMongoAccountSer = exports.MongoAccountService = exports.GMysqlAccountSer = exports.MysqlAccountService = exports.EAccountFrom = exports.EUserState = exports.ERoleGroup = exports.GLog = exports.GHttpTool = exports.GCacheTool = exports.RedisManager = exports.GRedisMgr = exports.GMysqlMgr = exports.MysqlBaseService = exports.GMSSqlMgr = exports.GMongoMgr = exports.MongoBaseModel = exports.MysqlBaseModel = exports.MongoBaseService = exports.EPropertyType = exports.Type = exports.Table = exports.Property = exports.PrimaryKey = exports.NotNull = exports.AutoIncrement = exports.Timer = exports.core = exports.GServerCfg = exports.ServerConfig = exports.FrameworkConfig = exports.Config = exports.FrameworkErrorCode = exports.GTriggerMgr = exports.Trigger = exports.Point = exports.Entity = exports.BehaviorAI = exports.AStar = exports.AiObject = exports.GDBCache = exports.GProtoFactory = exports.GCgServer = void 0;
|
|
4
|
-
exports.EAccountState = exports.GEventTool = exports.
|
|
4
|
+
exports.EAccountState = exports.GEventTool = exports.GSyncQueueTool = exports.WebServerConfig = exports.Response = exports.Request = exports.RazorJs = exports.Engine = exports.GCtrMgr = exports.JsonCreatorValidate = exports.JsonAuthorityValidate = exports.JsonAdminValidate = exports.CreatorValidate = exports.AuthorityValidate = exports.AdminValidate = exports.MongoAccountModel = exports.MysqlAccountModel = exports.MongoBaseUserController = exports.BaseUserController = exports.BaseController = exports.IWebServer = exports.GWechatTool = exports.GWechatOATool = exports.GQQTool = exports.GQiniuTool = exports.GOpenSocial = exports.GEmailTool = exports.GAppleTool = exports.GSmsTool = exports.GAlipayTool = exports.IWebSocket = exports.ISocketServer = exports.IServerWebSocket = exports.IClientWebSocket = exports.JsonProtoFilter = void 0;
|
|
5
5
|
var cgserver_1 = require("./cgserver");
|
|
6
6
|
Object.defineProperty(exports, "GCgServer", { enumerable: true, get: function () { return cgserver_1.GCgServer; } });
|
|
7
7
|
var ProtoFactory_1 = require("./SocketServer/ProtoFilter/ProtoFactory");
|
|
@@ -158,8 +158,8 @@ var Response_1 = require("./WebServer/Engine/Response");
|
|
|
158
158
|
Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return Response_1.Response; } });
|
|
159
159
|
var FrameworkConfig_2 = require("./Config/FrameworkConfig");
|
|
160
160
|
Object.defineProperty(exports, "WebServerConfig", { enumerable: true, get: function () { return FrameworkConfig_2.WebServerConfig; } });
|
|
161
|
-
var
|
|
162
|
-
Object.defineProperty(exports, "
|
|
161
|
+
var SyncQueueTool_1 = require("./Logic/SyncQueueTool");
|
|
162
|
+
Object.defineProperty(exports, "GSyncQueueTool", { enumerable: true, get: function () { return SyncQueueTool_1.GSyncQueueTool; } });
|
|
163
163
|
var EventTool_1 = require("./Logic/EventTool");
|
|
164
164
|
Object.defineProperty(exports, "GEventTool", { enumerable: true, get: function () { return EventTool_1.GEventTool; } });
|
|
165
165
|
var ini_2 = require("./Service/ini");
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare class SyncQueueItem {
|
|
2
|
+
key: string;
|
|
3
|
+
running: boolean;
|
|
4
|
+
funcs: {
|
|
5
|
+
func: Function;
|
|
6
|
+
thisArg: any;
|
|
7
|
+
params: any[];
|
|
8
|
+
resolve?: Function;
|
|
9
|
+
}[];
|
|
10
|
+
constructor(key: string);
|
|
11
|
+
add(func: Function, thisArg?: any, ...params: any[]): Promise<unknown>;
|
|
12
|
+
protected _run(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
declare class SyncQueueTool {
|
|
15
|
+
protected _queues: {
|
|
16
|
+
[key: string]: SyncQueueItem;
|
|
17
|
+
};
|
|
18
|
+
add(key: string, func: Function, thisArg?: any, ...params: any[]): Promise<unknown>;
|
|
19
|
+
}
|
|
20
|
+
export declare let GSyncQueueTool: SyncQueueTool;
|
|
21
|
+
export {};
|
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import { IProtoFilter, EProtoType } from "./ProtoFilter/IProtoFilter";
|
|
2
2
|
import * as ws from 'websocket';
|
|
3
|
+
export declare class BaseMsg {
|
|
4
|
+
cmd: string;
|
|
5
|
+
errcode?: {
|
|
6
|
+
id: number;
|
|
7
|
+
des: string;
|
|
8
|
+
};
|
|
9
|
+
servertime: number;
|
|
10
|
+
constructor(cmd: string, errcode?: {
|
|
11
|
+
id: number;
|
|
12
|
+
des: string;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
3
15
|
export declare class IWebSocket {
|
|
4
|
-
|
|
5
|
-
|
|
16
|
+
/**
|
|
17
|
+
* 是否同步消息
|
|
18
|
+
* 默认为true
|
|
19
|
+
*/
|
|
20
|
+
protected _is_sync_msg: boolean;
|
|
21
|
+
get isSynMsg(): boolean;
|
|
6
22
|
protected _debug_msg: boolean;
|
|
7
23
|
get debug_msg(): boolean;
|
|
8
24
|
set debug_msg(value: boolean);
|
|
@@ -18,27 +34,27 @@ export declare class IWebSocket {
|
|
|
18
34
|
get remoteHost(): string;
|
|
19
35
|
get connected(): boolean;
|
|
20
36
|
constructor(protoType?: EProtoType, protoPath?: string);
|
|
21
|
-
getNewMsg(cmd:
|
|
37
|
+
getNewMsg(cmd: string, errcode?: {
|
|
38
|
+
id: number;
|
|
39
|
+
des: string;
|
|
40
|
+
}): BaseMsg;
|
|
22
41
|
receive_heartbeat(jsonData: any): void;
|
|
23
42
|
send_heartbeat(): void;
|
|
24
43
|
onConnect(_ws: ws.connection): void;
|
|
25
|
-
protected _msgs: Array<any>;
|
|
26
44
|
onMessage(message: ws.Message): void;
|
|
27
45
|
protected _onDecode(message: ws.Message, ...params: any[]): any;
|
|
28
46
|
protected _onEncode(data: any, ...params: any[]): any;
|
|
29
|
-
protected _run_await: boolean;
|
|
30
|
-
protected _awaitMessages(): Promise<void>;
|
|
31
47
|
/**
|
|
32
48
|
* 过滤消息,每个消息处理之前调用
|
|
33
|
-
* @param
|
|
49
|
+
* @param msg
|
|
34
50
|
* @returns
|
|
35
51
|
*/
|
|
36
|
-
filterMsg(
|
|
52
|
+
filterMsg(msg: BaseMsg): boolean;
|
|
37
53
|
protected _onMessage(data: any): Promise<void>;
|
|
38
54
|
onOpen(e?: any): void;
|
|
39
55
|
onError(e: Error): void;
|
|
40
56
|
onClose(reasonCode: number, description: string): void;
|
|
41
|
-
send(
|
|
57
|
+
send(msg: BaseMsg): void;
|
|
42
58
|
close(): void;
|
|
43
59
|
getServerNameFromCmd(cmd: any): any;
|
|
44
60
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -73,6 +73,6 @@ export { RazorJs } from './WebServer/Engine/RazorJs';
|
|
|
73
73
|
export { Request } from './WebServer/Engine/Request';
|
|
74
74
|
export { Response } from './WebServer/Engine/Response';
|
|
75
75
|
export { WebServerConfig } from './Config/FrameworkConfig';
|
|
76
|
-
export {
|
|
76
|
+
export { GSyncQueueTool } from './Logic/SyncQueueTool';
|
|
77
77
|
export { GEventTool } from './Logic/EventTool';
|
|
78
78
|
export { EAccountState } from './Service/ini';
|