@xmobitea/gn-server 2.6.8 → 2.6.9

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.
@@ -9,6 +9,7 @@ declare abstract class BuilderBase {
9
9
  protected enableSendAndReceiveDebug: boolean;
10
10
  protected enablePostViaMsgPack: boolean;
11
11
  protected enablePostViaJson: boolean;
12
+ protected trustProxy: boolean;
12
13
  getEnable(): boolean;
13
14
  getOrigin(): string;
14
15
  getMethods(): MethodType[];
@@ -17,6 +18,7 @@ declare abstract class BuilderBase {
17
18
  getEnableSendAndReceiveDebug(): boolean;
18
19
  getEnablePostViaMsgPack(): boolean;
19
20
  getEnablePostViaJson(): boolean;
21
+ getTrustProxy(): boolean;
20
22
  constructor();
21
23
  }
22
24
  declare class Builder extends BuilderBase implements IBuilder<HttpAppSettings> {
@@ -31,6 +33,7 @@ declare class Builder extends BuilderBase implements IBuilder<HttpAppSettings> {
31
33
  setEnableSendAndReceiveDebug(enableSendAndReceiveDebug: boolean): Builder;
32
34
  setEnablePostViaMsgPack(enablePostViaMsgPack: boolean): Builder;
33
35
  setEnablePostViaJson(enablePostViaJson: boolean): Builder;
36
+ setTrustProxy(trustProxy: boolean): Builder;
34
37
  build(): HttpAppSettings;
35
38
  constructor();
36
39
  }
package/dist/index.js CHANGED
@@ -15100,6 +15100,9 @@ class ApiMiddleware {
15100
15100
  if (this.headerIP != null) {
15101
15101
  ip = req.header(this.headerIP);
15102
15102
  }
15103
+ if (ip == null) {
15104
+ ip = req.ip;
15105
+ }
15103
15106
  if (ip == null) {
15104
15107
  ip = req.socket.remoteAddress;
15105
15108
  }
@@ -16694,6 +16697,7 @@ class HttpAppSettings_BuilderBase {
16694
16697
  enableSendAndReceiveDebug;
16695
16698
  enablePostViaMsgPack;
16696
16699
  enablePostViaJson;
16700
+ trustProxy;
16697
16701
  getEnable() {
16698
16702
  return this.enable;
16699
16703
  }
@@ -16718,6 +16722,9 @@ class HttpAppSettings_BuilderBase {
16718
16722
  getEnablePostViaJson() {
16719
16723
  return this.enablePostViaJson;
16720
16724
  }
16725
+ getTrustProxy() {
16726
+ return this.trustProxy;
16727
+ }
16721
16728
  constructor() { }
16722
16729
  }
16723
16730
  class HttpAppSettings_Builder extends HttpAppSettings_BuilderBase {
@@ -16770,6 +16777,10 @@ class HttpAppSettings_Builder extends HttpAppSettings_BuilderBase {
16770
16777
  this.enablePostViaJson = enablePostViaJson;
16771
16778
  return this;
16772
16779
  }
16780
+ setTrustProxy(trustProxy) {
16781
+ this.trustProxy = trustProxy;
16782
+ return this;
16783
+ }
16773
16784
  build() {
16774
16785
  return new HttpAppSettings(this);
16775
16786
  }
@@ -16783,6 +16794,7 @@ class HttpAppSettings_Builder extends HttpAppSettings_BuilderBase {
16783
16794
  this.enableSendAndReceiveDebug = false;
16784
16795
  this.enablePostViaMsgPack = false;
16785
16796
  this.enablePostViaJson = false;
16797
+ this.trustProxy = false;
16786
16798
  }
16787
16799
  }
16788
16800
  class HttpAppSettings extends HttpAppSettings_BuilderBase {
@@ -16796,6 +16808,7 @@ class HttpAppSettings extends HttpAppSettings_BuilderBase {
16796
16808
  this.enableSendAndReceiveDebug = builder.getEnableSendAndReceiveDebug();
16797
16809
  this.enablePostViaMsgPack = builder.getEnablePostViaMsgPack();
16798
16810
  this.enablePostViaJson = builder.getEnablePostViaJson();
16811
+ this.trustProxy = builder.getTrustProxy();
16799
16812
  }
16800
16813
  static Builder() {
16801
16814
  return new HttpAppSettings_Builder();
@@ -17170,8 +17183,8 @@ class ClusterHandler {
17170
17183
  init() {
17171
17184
  this.clusterRouter = external_express_default().Router();
17172
17185
  this.router.use("/cluster", wrap((req, res, next) => {
17173
- let pkt = req.header("privateKeyToken");
17174
- if (!pkt || pkt != this.privateKeyToken) {
17186
+ let privateKeyToken = req.header("pkt");
17187
+ if (!privateKeyToken || privateKeyToken != this.privateKeyToken) {
17175
17188
  return res.sendStatus(401);
17176
17189
  }
17177
17190
  return next();
@@ -17287,12 +17300,13 @@ class ClusterHandler {
17287
17300
  let okPrimaryInstanceInfos = [];
17288
17301
  for (let i = 0; i < currentPrimaryInstanceInfos.length; i++) {
17289
17302
  let currentPrimaryInstanceInfo = currentPrimaryInstanceInfos[i];
17290
- if (currentPrimaryInstanceInfo.lostPing > 1) {
17303
+ if (currentPrimaryInstanceInfo.lostPing < 1) {
17291
17304
  okPrimaryInstanceInfos.push(currentPrimaryInstanceInfo);
17292
17305
  }
17293
17306
  }
17294
17307
  if (okPrimaryInstanceInfos.length == 0) {
17295
17308
  if (!this.instanceInfoStatus.isPrimary) {
17309
+ this.isPrimary = true;
17296
17310
  this.instanceInfoStatus.isPrimary = true;
17297
17311
  this.instanceInfoStatus.tsPrimary = xDatetime.getCurrentMilliseconds();
17298
17312
  this.instanceInfoStatus.currentInstanceIdPrimary = this.instanceId;
@@ -17307,7 +17321,7 @@ class ClusterHandler {
17307
17321
  }
17308
17322
  }
17309
17323
  else {
17310
- okPrimaryInstanceInfos.sort((a, b) => a.tsPrimary - b.tsPrimary);
17324
+ okPrimaryInstanceInfos.sort((a, b) => a.tsPrimary < b.tsPrimary ? -1 : 1);
17311
17325
  let primaryInstanceInfo = okPrimaryInstanceInfos[0];
17312
17326
  // neu khong phai la primary thi cap nhat thong tin primary hien tai
17313
17327
  if (!this.instanceInfoStatus.isPrimary) {
@@ -17326,6 +17340,7 @@ class ClusterHandler {
17326
17340
  // neu dang la primary thi conflict va can phai thong nhat xem ai la primary
17327
17341
  else {
17328
17342
  if (this.instanceInfoStatus.tsPrimary > primaryInstanceInfo.tsPrimary) {
17343
+ this.isPrimary = false;
17329
17344
  this.instanceInfoStatus.isPrimary = false;
17330
17345
  this.instanceInfoStatus.tsPrimary = 0;
17331
17346
  this.instanceInfoStatus.currentInstanceIdPrimary = primaryInstanceInfo.instanceId;
@@ -17442,6 +17457,8 @@ class HttpApp {
17442
17457
  this.logSettings = logSettings;
17443
17458
  }
17444
17459
  run() {
17460
+ if (this.appSettings.getTrustProxy())
17461
+ this.app.enable("trust proxy");
17445
17462
  this.app.use(external_express_default().urlencoded({ extended: false }));
17446
17463
  this.app.get("/", (req, res) => {
17447
17464
  return res.sendStatus(403);
@@ -87354,6 +87371,7 @@ class DefaultApplicationStartup {
87354
87371
  .setEnableSendAndReceiveDebug(true)
87355
87372
  .setEnablePostViaJson(true)
87356
87373
  .setEnablePostViaMsgPack(true)
87374
+ .setTrustProxy(true)
87357
87375
  .build();
87358
87376
  let socketAppSettings = SocketAppSettings.Builder()
87359
87377
  .setEnable(true)
@@ -87493,6 +87511,7 @@ class ServerApplicationStartup extends DefaultApplicationStartup {
87493
87511
  "enableSendAndReceiveDebug": true,
87494
87512
  "enablePostViaMsgPack": true,
87495
87513
  "enablePostViaJson": true,
87514
+ "trustProxy": true,
87496
87515
  };
87497
87516
  let httpAppSettings = HttpAppSettings.Builder()
87498
87517
  .setEnable(gnHttpAppSettings["enable"] ?? true)
@@ -87503,6 +87522,7 @@ class ServerApplicationStartup extends DefaultApplicationStartup {
87503
87522
  .setEnableSendAndReceiveDebug(gnHttpAppSettings["enableSendAndReceiveDebug"] ?? true)
87504
87523
  .setEnablePostViaMsgPack(gnHttpAppSettings["enablePostViaMsgPack"] ?? true)
87505
87524
  .setEnablePostViaJson(gnHttpAppSettings["enablePostViaJson"] ?? true)
87525
+ .setTrustProxy(gnHttpAppSettings["trustProxy"] ?? true)
87506
87526
  .build();
87507
87527
  let gnSocketAppSettings = this.gnConfig["socketAppSettings"];
87508
87528
  if (gnSocketAppSettings == null)
package/gn.sh CHANGED
@@ -110,7 +110,8 @@ init_create_GNConfigDebugJson() {
110
110
  "allowHeaders": ["Auth-Token", "Content-Type", "Secret-Key", "Game-Id", "Content-Length", "User-Agent", "X-Real-IP"],
111
111
  "enableSendAndReceiveDebug": true,
112
112
  "enablePostViaMsgPack": true,
113
- "enablePostViaJson": true
113
+ "enablePostViaJson": true,
114
+ "trustProxy": true
114
115
  },
115
116
 
116
117
  "socketAppSettings": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmobitea/gn-server",
3
- "version": "2.6.8",
3
+ "version": "2.6.9",
4
4
  "description": "GearN Server by XmobiTea (Pro)",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
@@ -32,7 +32,7 @@
32
32
  "@msgpack/msgpack": "^2.8.0",
33
33
  "@socket.io/mongo-adapter": "^0.3.2",
34
34
  "@socket.io/mongo-emitter": "^0.2.0",
35
- "@xmobitea/gn-typescript-client": "^2.6.9",
35
+ "@xmobitea/gn-typescript-client": "^2.6.10",
36
36
  "axios": "^1.10.0",
37
37
  "bcrypt": "^5.1.1",
38
38
  "cors": "^2.8.5",