cgserver 6.5.0 → 6.5.3

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
@@ -0,0 +1,4 @@
1
+ 6.5.3
2
+ 1、事件分发器GEventTool添加emit
3
+ 6.5.2
4
+ 1、添加事件分发器GEventTool
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GEventTool = void 0;
4
+ const EventEmitter = require("events");
5
+ class EventTool {
6
+ _event_emitter = new EventEmitter();
7
+ constructor() {
8
+ this._event_emitter.setMaxListeners(0);
9
+ }
10
+ on(event, func) {
11
+ this._event_emitter.on(event, func);
12
+ }
13
+ off(event, func) {
14
+ this._event_emitter.off(event, func);
15
+ }
16
+ once(event, func) {
17
+ this._event_emitter.once(event, func);
18
+ }
19
+ emit(event, ...args) {
20
+ this._event_emitter.emit(event, ...args);
21
+ }
22
+ }
23
+ exports.GEventTool = new EventTool();
@@ -84,6 +84,9 @@ class BaseUserController extends BaseController_1.BaseController {
84
84
  user = (await UserService_1.GUserSer.getById(user_id));
85
85
  }
86
86
  }
87
+ if (user) {
88
+ this._login(user);
89
+ }
87
90
  return user;
88
91
  }
89
92
  _logout() {
@@ -6,8 +6,8 @@ const CacheTool_1 = require("../../Logic/CacheTool");
6
6
  const FrameworkConfig_1 = require("../../Config/FrameworkConfig");
7
7
  const RedisManager_1 = require("../../Database/RedisManager");
8
8
  const MongoCacheService_1 = require("../../Service/MongoCacheService");
9
- const MongoUserService_1 = require("../../Service/MongoUserService");
10
9
  const ini_1 = require("../../Service/ini");
10
+ const MongoUserService_1 = require("../../Service/MongoUserService");
11
11
  class MongoBaseUserController extends BaseController_1.BaseController {
12
12
  _user_session_id = "user_session_id";
13
13
  _self_user = null;
@@ -39,29 +39,14 @@ class MongoBaseUserController extends BaseController_1.BaseController {
39
39
  this._session_id = this._request.getCookie(this._user_session_id) || this._request.params.session_id || this._request.postData.session_id;
40
40
  let userId = -1;
41
41
  if (this._session_id) {
42
- let user = null;
43
- if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Cache) {
44
- user = CacheTool_1.GCacheTool.get(this._session_id);
45
- }
46
- else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
47
- let user_id = parseInt((await RedisManager_1.GRedisMgr.get(this._session_id)) || "-1");
48
- if (user_id > 0) {
49
- user = (await MongoUserService_1.GUserSer.getById(user_id));
50
- }
51
- }
52
- else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
53
- let user_id = (await MongoCacheService_1.GMongoCacheSer.getData(this._session_id)) || -1;
54
- if (user_id > 0) {
55
- user = (await MongoUserService_1.GUserSer.getById(user_id));
56
- }
57
- }
42
+ let user = await this._getUserBySession(this._session_id);
58
43
  if (!user) {
59
44
  this._update_session();
60
45
  //Session不存在清除客户端cookie
61
46
  this._response.clearCookie(this._user_session_id);
62
47
  }
63
48
  else {
64
- await this._login(user);
49
+ this._login(user);
65
50
  userId = user.id;
66
51
  }
67
52
  }
@@ -74,6 +59,36 @@ class MongoBaseUserController extends BaseController_1.BaseController {
74
59
  this._user = this._self_user;
75
60
  }
76
61
  }
62
+ async _getUserBySession(session) {
63
+ let user = null;
64
+ if (!session) {
65
+ return user;
66
+ }
67
+ //每次强制从cache中先找,提高效率
68
+ //if(this._engine.cfg.session_type==ESessionType.Cache)
69
+ {
70
+ user = CacheTool_1.GCacheTool.get(this._session_id);
71
+ }
72
+ if (user) {
73
+ return user;
74
+ }
75
+ if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
76
+ let user_id = parseInt((await RedisManager_1.GRedisMgr.get(this._session_id)) || "-1");
77
+ if (user_id > 0) {
78
+ user = (await MongoUserService_1.GUserSer.getById(user_id));
79
+ }
80
+ }
81
+ else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
82
+ let user_id = (await MongoCacheService_1.GMongoCacheSer.getData(this._session_id)) || -1;
83
+ if (user_id > 0) {
84
+ user = (await MongoUserService_1.GUserSer.getById(user_id));
85
+ }
86
+ }
87
+ if (user) {
88
+ this._login(user);
89
+ }
90
+ return user;
91
+ }
77
92
  _logout() {
78
93
  if (this._session_id) {
79
94
  if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Cache) {
@@ -94,7 +109,7 @@ class MongoBaseUserController extends BaseController_1.BaseController {
94
109
  return;
95
110
  }
96
111
  if (!this._session_id) {
97
- this._session_id = Math.random().toString(36).substr(2) + user.id;
112
+ this._session_id = Math.random().toString(36).substring(2) + user.id;
98
113
  }
99
114
  let time = 0;
100
115
  if (this._request.postData.remember == "on") {
@@ -104,10 +119,16 @@ class MongoBaseUserController extends BaseController_1.BaseController {
104
119
  time = this._engine.cfg.cookie.expires.account;
105
120
  }
106
121
  this._response.setCookie(this._user_session_id, this._session_id, time);
107
- if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Cache) {
108
- CacheTool_1.GCacheTool.add(this._session_id, user, time * 1000);
122
+ //if(this._engine.cfg.session_type==ESessionType.Cache)
123
+ {
124
+ if (time > 24 * 60 * 60) {
125
+ CacheTool_1.GCacheTool.add(this._session_id, user, 24 * 60 * 60 * 1000);
126
+ }
127
+ else {
128
+ CacheTool_1.GCacheTool.add(this._session_id, user, time * 1000);
129
+ }
109
130
  }
110
- else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
131
+ if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
111
132
  RedisManager_1.GRedisMgr.set(this._session_id, user.id).then(() => {
112
133
  RedisManager_1.GRedisMgr.expire(this._session_id, time);
113
134
  });
@@ -122,29 +143,9 @@ class MongoBaseUserController extends BaseController_1.BaseController {
122
143
  this._self_user = user;
123
144
  }
124
145
  /**
125
- * 用户信息发生更改,同步更新session里面的用户信息
146
+ * 已经被启用
126
147
  */
127
148
  async _update_session() {
128
- if (!this._session_id) {
129
- return;
130
- }
131
- let user_id = -1;
132
- let um = null;
133
- if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Cache) {
134
- um = CacheTool_1.GCacheTool.get(this._session_id);
135
- if (um) {
136
- user_id = um.id;
137
- }
138
- }
139
- else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
140
- user_id = parseInt((await RedisManager_1.GRedisMgr.get(this._session_id)) || "-1");
141
- }
142
- if (user_id < 0) {
143
- this._session_id = null;
144
- return;
145
- }
146
- um = (await MongoUserService_1.GUserSer.getById(user_id));
147
- this._login(um);
148
149
  }
149
150
  async update_user(user_id) {
150
151
  let user = (await MongoUserService_1.GUserSer.getById(user_id));
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonProtoFilter = 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.ServerConfig = exports.GFCfg = exports.FrameworkConfig = exports.Config = exports.FrameworkErrorCode = exports.GTriggerMgr = exports.Trigger = exports.Point = exports.Entity = exports.BehaviorAI = exports.AStar = exports.AiObject = exports.GDBCache = exports.GProtoFactory = void 0;
4
- exports.GCgServer = exports.GAsyncQueueTool = 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 = void 0;
4
+ exports.GCgServer = exports.GEventTool = exports.GAsyncQueueTool = 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 = void 0;
5
5
  var ProtoFactory_1 = require("./SocketServer/ProtoFilter/ProtoFactory");
6
6
  Object.defineProperty(exports, "GProtoFactory", { enumerable: true, get: function () { return ProtoFactory_1.GProtoFactory; } });
7
7
  var DBCache_1 = require("./Database/Decorator/DBCache");
@@ -159,6 +159,8 @@ var FrameworkConfig_2 = require("./Config/FrameworkConfig");
159
159
  Object.defineProperty(exports, "WebServerConfig", { enumerable: true, get: function () { return FrameworkConfig_2.WebServerConfig; } });
160
160
  var AsyncQueueTool_1 = require("./Logic/AsyncQueueTool");
161
161
  Object.defineProperty(exports, "GAsyncQueueTool", { enumerable: true, get: function () { return AsyncQueueTool_1.GAsyncQueueTool; } });
162
+ var EventTool_1 = require("./Logic/EventTool");
163
+ Object.defineProperty(exports, "GEventTool", { enumerable: true, get: function () { return EventTool_1.GEventTool; } });
162
164
  const Log_2 = require("./Logic/Log");
163
165
  class CgServer {
164
166
  constructor() {
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ import * as EventEmitter from "events";
3
+ declare class EventTool {
4
+ protected _event_emitter: EventEmitter;
5
+ constructor();
6
+ on(event: string, func: (...args: any[]) => void): void;
7
+ off(event: string, func: (...args: any[]) => void): void;
8
+ once(event: string, func: (...args: any[]) => void): void;
9
+ emit(event: string, ...args: any[]): void;
10
+ }
11
+ export declare let GEventTool: EventTool;
12
+ export {};
@@ -13,10 +13,11 @@ export declare class MongoBaseUserController<T extends UserModel> extends BaseCo
13
13
  get isProxy(): boolean;
14
14
  get isCommon(): boolean;
15
15
  init(): Promise<void>;
16
+ protected _getUserBySession(session: string): Promise<T>;
16
17
  protected _logout(): void;
17
18
  protected _login(user: T): void;
18
19
  /**
19
- * 用户信息发生更改,同步更新session里面的用户信息
20
+ * 已经被启用
20
21
  */
21
22
  protected _update_session(): Promise<void>;
22
23
  update_user(user_id: number): Promise<void>;
@@ -73,6 +73,7 @@ export { Request } from './WebServer/Engine/Request';
73
73
  export { Response } from './WebServer/Engine/Response';
74
74
  export { WebServerConfig } from './Config/FrameworkConfig';
75
75
  export { GAsyncQueueTool } from './Logic/AsyncQueueTool';
76
+ export { GEventTool } from './Logic/EventTool';
76
77
  declare class CgServer {
77
78
  constructor();
78
79
  init(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "6.5.0",
3
+ "version": "6.5.3",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",