cgserver 9.1.2 → 9.1.4

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/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ 9.1.3
2
+ 1、几乎同意替换成losslessjson
3
+ 2、express使用了raw
1
4
  9.1.2
2
5
  1、losslessjson
3
6
  9.1.1
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GDBCache = exports.VersionModel = void 0;
4
4
  const Log_1 = require("./../../Logic/Log");
5
5
  const fs = require("fs");
6
+ const lossless_json_1 = require("lossless-json");
6
7
  class VersionModel {
7
8
  table = "";
8
9
  version = 0;
@@ -24,7 +25,7 @@ class DBCache {
24
25
  if (fs.existsSync(this._path)) {
25
26
  try {
26
27
  let table = fs.readFileSync(this._path);
27
- this._versions = JSON.parse(table.toString());
28
+ this._versions = (0, lossless_json_1.parse)(table.toString());
28
29
  }
29
30
  catch (e) {
30
31
  Log_1.GLog.info("error:" + this._path);
@@ -18,7 +18,7 @@ class HttpTool {
18
18
  }
19
19
  return new Promise((resolve, reject) => {
20
20
  request.get(options, (error, response, body) => {
21
- let bd = body;
21
+ let originbody = body;
22
22
  if (error) {
23
23
  Log_1.GLog.error("get:" + options.url);
24
24
  Log_1.GLog.error(error);
@@ -33,10 +33,10 @@ class HttpTool {
33
33
  body = qs.parse(body);
34
34
  }
35
35
  catch (e) {
36
- body = bd;
36
+ body = originbody;
37
37
  }
38
38
  }
39
- resolve({ error, response, body });
39
+ resolve({ error, response, body, originbody });
40
40
  });
41
41
  });
42
42
  }
@@ -50,7 +50,7 @@ class HttpTool {
50
50
  }
51
51
  return new Promise((resolve, reject) => {
52
52
  request.post(options, (error, response, body) => {
53
- let bd = body;
53
+ let originbody = body;
54
54
  if (error) {
55
55
  Log_1.GLog.error("post:" + options.url);
56
56
  Log_1.GLog.error(error);
@@ -65,10 +65,10 @@ class HttpTool {
65
65
  body = qs.parse(body);
66
66
  }
67
67
  catch (e) {
68
- body = bd;
68
+ body = originbody;
69
69
  }
70
70
  }
71
- resolve({ error, response, body });
71
+ resolve({ error, response, body, originbody });
72
72
  });
73
73
  });
74
74
  }
@@ -165,18 +165,25 @@ class IWebSocket {
165
165
  onClose(reasonCode, description) {
166
166
  Log_1.GLog.info(this.tipKey + " onClose resonCode=" + reasonCode + " des=" + description);
167
167
  }
168
- send(msg) {
168
+ filterSendMsg(msg) {
169
169
  if (!this.connected) {
170
- return;
170
+ return false;
171
171
  }
172
172
  if (!msg) {
173
173
  Log_1.GLog.error(this.tipKey + " Send Message warning:null data!");
174
- return;
174
+ return false;
175
175
  }
176
176
  if (this._debug_msg
177
177
  && msg.cmd != "heartbeat") {
178
178
  Log_1.GLog.info({ tipKey: this.tipKey, action: "send", msg });
179
179
  }
180
+ return true;
181
+ }
182
+ send(msg) {
183
+ let ret = this.filterSendMsg(msg);
184
+ if (!ret) {
185
+ return;
186
+ }
180
187
  let data = this._onEncode(msg);
181
188
  this._ws.send(data);
182
189
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonProtoFilter = void 0;
4
4
  const Core_1 = require("../../Core/Core");
5
5
  const Log_1 = require("../../Logic/Log");
6
+ const lossless_json_1 = require("lossless-json");
6
7
  class JsonProtoFilter {
7
8
  init(path) {
8
9
  return true;
@@ -16,7 +17,7 @@ class JsonProtoFilter {
16
17
  decode(data) {
17
18
  try {
18
19
  if (Core_1.core.isString(data)) {
19
- data = JSON.parse(data);
20
+ data = (0, lossless_json_1.parse)(data);
20
21
  }
21
22
  }
22
23
  catch (e) {
@@ -6,6 +6,7 @@ const URLEncode = require("urlencode");
6
6
  const IServerConfig_1 = require("../Config/IServerConfig");
7
7
  const HttpTool_1 = require("../Logic/HttpTool");
8
8
  const Log_1 = require("../Logic/Log");
9
+ const lossless_json_1 = require("lossless-json");
9
10
  class QQUserInfo {
10
11
  ret = 0;
11
12
  msg = "";
@@ -92,7 +93,7 @@ class QQTool {
92
93
  body = body.replace("callback( ", "");
93
94
  body = body.replace(" );\n", "");
94
95
  try {
95
- body = JSON.parse(body);
96
+ body = (0, lossless_json_1.parse)(body);
96
97
  }
97
98
  catch (e) { }
98
99
  if (!body.openid) {
@@ -48,6 +48,7 @@ class Engine {
48
48
  Log_1.GLog.info("Server(" + this._cfg.web_name + ") running at https://127.0.0.1:" + (port + 1) + "/");
49
49
  }
50
50
  this._app.use(cookieParser());
51
+ this._app.use(Express.raw());
51
52
  this._app.use(Express.json({ limit: '10mb', verify(req, res, buf, encoding) {
52
53
  req["rawBody"] = buf;
53
54
  }, }));
@@ -4,6 +4,7 @@ exports.Request = void 0;
4
4
  const url_1 = require("url");
5
5
  const Core_1 = require("../../Core/Core");
6
6
  const Log_1 = require("../../Logic/Log");
7
+ const lossless_json_1 = require("lossless-json");
7
8
  class Request {
8
9
  _req = null;
9
10
  get baseReq() {
@@ -70,32 +71,13 @@ class Request {
70
71
  }
71
72
  if (Core_1.core.isString(body)) {
72
73
  try {
73
- body = JSON.parse(body);
74
+ body = (0, lossless_json_1.parse)(body);
74
75
  }
75
76
  catch (e) {
76
77
  Log_1.GLog.error("post data--" + body + "--parse error");
77
78
  body = {};
78
79
  }
79
80
  }
80
- // 暂时去掉强制数值转换
81
- // //服务器会有一层空key的json解析
82
- // for(let k in body)
83
- // {
84
- // var v = body[k]
85
- // if(!core.isString(v))
86
- // {
87
- // continue
88
- // }
89
- // let intv = parseInt(v)
90
- // if(intv==v)
91
- // {
92
- // body[k]=intv
93
- // }
94
- // else if(parseFloat(v)==v)
95
- // {
96
- // body[k]==parseFloat(v)
97
- // }
98
- // }
99
81
  return body;
100
82
  }
101
83
  get url() {
@@ -124,7 +106,6 @@ class Request {
124
106
  ip = ips;
125
107
  }
126
108
  ip = ip ||
127
- this._req.connection.remoteAddress ||
128
109
  this._req.socket.remoteAddress ||
129
110
  this._req.ip || "";
130
111
  ip = ip.replace("::ffff:", "");
@@ -5,11 +5,13 @@ declare class HttpTool {
5
5
  error: any;
6
6
  response: any;
7
7
  body: any;
8
+ originbody: any;
8
9
  }>;
9
10
  post(options_url: request.OptionsWithUrl | string): Promise<{
10
11
  error: any;
11
12
  response: any;
12
13
  body: any;
14
+ originbody: any;
13
15
  }>;
14
16
  }
15
17
  export {};
@@ -55,6 +55,7 @@ export declare class IWebSocket {
55
55
  onOpen(e?: any): void;
56
56
  onError(e: Error): void;
57
57
  onClose(reasonCode: number, description: string): void;
58
+ filterSendMsg(msg: BaseMsg): boolean;
58
59
  send(msg: BaseMsg): void;
59
60
  close(): void;
60
61
  getServerNameFromCmd(cmd: any): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "9.1.2",
3
+ "version": "9.1.4",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",