From f8ac401c676510da529fd0d90210816970cfcbb3 Mon Sep 17 00:00:00 2001 From: liangtongchuan Date: Wed, 9 Sep 2020 00:57:26 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E5=88=86=E5=85=AC=E5=85=B1=E4=BB=A3?= =?UTF-8?q?=E7=A0=81db=E5=92=8Cconst=E6=94=BE=E5=88=B0shared=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../servers/connector/handler/entryHandler.ts | 8 +-- .../app/servers/role/handler/roleHandler.ts | 9 +-- game-server/docker-compose.yaml | 1 + game-server/setEnv.sh | 3 + game-server/startGameServer.sh | 2 + game-server/tsconfig.json | 1 + package-lock.json | 69 ++++++++++++++++--- shared/consts/consts.ts | 12 ++++ {game-server/app => shared}/db/BaseModel.ts | 0 {game-server/app => shared}/db/Counter.ts | 0 {game-server/app => shared}/db/Equip.ts | 0 {game-server/app => shared}/db/Game.ts | 2 +- {game-server/app => shared}/db/Hero.ts | 0 {game-server/app => shared}/db/Role.ts | 1 - {game-server/app => shared}/db/Sms.ts | 0 {game-server/app => shared}/db/User.ts | 2 +- web-server/app/consts/consts.ts | 18 ++--- web-server/app/db/Game.ts | 2 +- web-server/app/db/User.ts | 2 +- web-server/app/middleware/parmsDecode.ts | 2 +- web-server/app/service/TurboCore.ts | 2 +- 21 files changed, 99 insertions(+), 37 deletions(-) create mode 100755 game-server/setEnv.sh create mode 100644 shared/consts/consts.ts rename {game-server/app => shared}/db/BaseModel.ts (100%) rename {game-server/app => shared}/db/Counter.ts (100%) rename {game-server/app => shared}/db/Equip.ts (100%) rename {game-server/app => shared}/db/Game.ts (96%) rename {game-server/app => shared}/db/Hero.ts (100%) rename {game-server/app => shared}/db/Role.ts (98%) rename {game-server/app => shared}/db/Sms.ts (100%) rename {game-server/app => shared}/db/User.ts (98%) diff --git a/game-server/app/servers/connector/handler/entryHandler.ts b/game-server/app/servers/connector/handler/entryHandler.ts index 6ed4e3a29..2e3515f2e 100644 --- a/game-server/app/servers/connector/handler/entryHandler.ts +++ b/game-server/app/servers/connector/handler/entryHandler.ts @@ -1,9 +1,9 @@ -import { RoleModel } from './../../../db/Role'; -import { UserModel } from './../../../db/User'; +import { RoleModel } from '../../../../../shared/db/Role'; +import { UserModel } from '../../../../../shared/db/User'; import { Application, Session } from 'pinus'; import {FrontendSession} from 'pinus'; -import Hero from '../../../db/Hero'; -import Equip from '../../../db/Equip'; +import Hero from '../../../../../shared/db/Hero'; +import Equip from '../../../../../shared/db/Equip'; export default function (app: Application) { return new EntryHandler(app); diff --git a/game-server/app/servers/role/handler/roleHandler.ts b/game-server/app/servers/role/handler/roleHandler.ts index 56755a758..3c24211cb 100644 --- a/game-server/app/servers/role/handler/roleHandler.ts +++ b/game-server/app/servers/role/handler/roleHandler.ts @@ -1,10 +1,7 @@ -import { CounterModel } from './../../../db/Counter'; -import { HeroModel } from './../../../db/Hero'; -import { EquipModel } from './../../../db/Equip'; -// import { roleRemote } from '../remote/roleRemote'; +import { CounterModel } from '../../../../../shared/db/Counter'; +import { HeroModel } from '../../../../../shared/db/Hero'; +import { EquipModel } from '../../../../../shared/db/Equip'; import {Application, BackendSession, createTcpMailBox} from 'pinus'; -import { FrontendSession } from 'pinus'; -import Counter from '../../../db/Counter'; export default function(app: Application) { return new RoleHandler(app); diff --git a/game-server/docker-compose.yaml b/game-server/docker-compose.yaml index 0f929e1f7..22aed3ffc 100644 --- a/game-server/docker-compose.yaml +++ b/game-server/docker-compose.yaml @@ -8,6 +8,7 @@ services: # - "redis" volumes: - "$PWD/../game-server:/game-server" + - "$PWD/../shared:/shared" ports: - "3050:3050" - "3051:3051" diff --git a/game-server/setEnv.sh b/game-server/setEnv.sh new file mode 100755 index 000000000..465727065 --- /dev/null +++ b/game-server/setEnv.sh @@ -0,0 +1,3 @@ +npm i -D @types/mongoose +npm i -s @typegoose/typegoose +npm i -s mongoose diff --git a/game-server/startGameServer.sh b/game-server/startGameServer.sh index 2cb552a1b..2ec48f731 100644 --- a/game-server/startGameServer.sh +++ b/game-server/startGameServer.sh @@ -2,4 +2,6 @@ cnpm install -d #安装依赖库 npm run build node generatePm2Config.js #使用pm2来做进程管理,生成进程配置文件 +rm -rf /game-server/shared +cp -r /game-server/dist/shared /game-server pm2-runtime pomeloPm2Start.json #pm2 启动游戏服务器 diff --git a/game-server/tsconfig.json b/game-server/tsconfig.json index b9eac9b6d..c50b0531d 100644 --- a/game-server/tsconfig.json +++ b/game-server/tsconfig.json @@ -24,6 +24,7 @@ "watch":false //在监视模式下运行编译器。会监视输出文件,在它们改变时重新编译。 }, "include":[ + "../shared/**/*.ts", "./app/**/*.ts", "./config/**/*.ts", "./app.ts", diff --git a/package-lock.json b/package-lock.json index f62988770..5e056b8f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3,9 +3,9 @@ "lockfileVersion": 1, "dependencies": { "@typegoose/typegoose": { - "version": "7.3.2", - "resolved": "https://registry.npm.taobao.org/@typegoose/typegoose/download/@typegoose/typegoose-7.3.2.tgz", - "integrity": "sha1-nefcvV1/2cCEPvoEeYQgO5Vgu18=", + "version": "7.3.5", + "resolved": "https://registry.npm.taobao.org/@typegoose/typegoose/download/@typegoose/typegoose-7.3.5.tgz", + "integrity": "sha1-94517zpL5R8DkYh55qjPDR/PecA=", "requires": { "lodash": "^4.17.19", "loglevel": "^1.6.8", @@ -14,6 +14,41 @@ "tslib": "^2.0.0" } }, + "@types/bson": { + "version": "4.0.2", + "resolved": "https://registry.npm.taobao.org/@types/bson/download/@types/bson-4.0.2.tgz", + "integrity": "sha1-esy4WUL8ObvbdRXU3kN8BPaYEV8=", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/mongodb": { + "version": "3.5.27", + "resolved": "https://registry.npm.taobao.org/@types/mongodb/download/@types/mongodb-3.5.27.tgz?cache=0&sync_timestamp=1599138259359&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fmongodb%2Fdownload%2F%40types%2Fmongodb-3.5.27.tgz", + "integrity": "sha1-FYp6Q84l7zWSrIpi5iqzi+v2YfI=", + "dev": true, + "requires": { + "@types/bson": "*", + "@types/node": "*" + } + }, + "@types/mongoose": { + "version": "5.7.36", + "resolved": "https://registry.npm.taobao.org/@types/mongoose/download/@types/mongoose-5.7.36.tgz", + "integrity": "sha1-La4oxjBBxq+6ioPqApafRjs/ECE=", + "dev": true, + "requires": { + "@types/mongodb": "*", + "@types/node": "*" + } + }, + "@types/node": { + "version": "14.6.4", + "resolved": "https://registry.npm.taobao.org/@types/node/download/@types/node-14.6.4.tgz?cache=0&sync_timestamp=1599568905640&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fnode%2Fdownload%2F%40types%2Fnode-14.6.4.tgz", + "integrity": "sha1-oUXMC7FO+cR3c2G3u6+lz446y1o=", + "dev": true + }, "bl": { "version": "2.2.0", "resolved": "https://registry.npm.taobao.org/bl/download/bl-2.2.0.tgz?cache=0&sync_timestamp=1584503263385&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbl%2Fdownload%2Fbl-2.2.0.tgz", @@ -86,8 +121,7 @@ "memory-pager": { "version": "1.5.0", "resolved": "https://registry.npm.taobao.org/memory-pager/download/memory-pager-1.5.0.tgz", - "integrity": "sha1-2HUWVdItOEaCdByXLyw9bfo+ZrU=", - "optional": true + "integrity": "sha1-2HUWVdItOEaCdByXLyw9bfo+ZrU=" }, "mongodb": { "version": "3.6.0", @@ -103,13 +137,13 @@ } }, "mongoose": { - "version": "5.10.0", - "resolved": "https://registry.npm.taobao.org/mongoose/download/mongoose-5.10.0.tgz?cache=0&sync_timestamp=1597421711994&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fmongoose%2Fdownload%2Fmongoose-5.10.0.tgz", - "integrity": "sha1-BaNfWj2EhWE8mYiuuVSChalwg/c=", + "version": "5.10.3", + "resolved": "https://registry.npm.taobao.org/mongoose/download/mongoose-5.10.3.tgz", + "integrity": "sha1-7yjNo/EeW/daMJol6YmfhWpaU3A=", "requires": { "bson": "^1.1.4", "kareem": "2.3.1", - "mongodb": "3.6.0", + "mongodb": "3.6.1", "mongoose-legacy-pluralize": "1.0.2", "mpath": "0.7.0", "mquery": "3.2.2", @@ -118,6 +152,21 @@ "safe-buffer": "5.2.1", "sift": "7.0.1", "sliced": "1.0.1" + }, + "dependencies": { + "mongodb": { + "version": "3.6.1", + "resolved": "https://registry.npm.taobao.org/mongodb/download/mongodb-3.6.1.tgz?cache=0&sync_timestamp=1599050790615&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fmongodb%2Fdownload%2Fmongodb-3.6.1.tgz", + "integrity": "sha1-LFzCqBRWuhg+jEMtgOeHMsxy2r0=", + "requires": { + "bl": "^2.2.0", + "bson": "^1.1.4", + "denque": "^1.4.1", + "require_optional": "^1.0.1", + "safe-buffer": "^5.1.2", + "saslprep": "^1.0.0" + } + } } }, "mongoose-legacy-pluralize": { @@ -220,7 +269,6 @@ "version": "1.0.3", "resolved": "https://registry.npm.taobao.org/saslprep/download/saslprep-1.0.3.tgz", "integrity": "sha1-TAL5RrVs9UKX40e6EJPnrKxM8iY=", - "optional": true, "requires": { "sparse-bitfield": "^3.0.3" } @@ -244,7 +292,6 @@ "version": "3.0.3", "resolved": "https://registry.npm.taobao.org/sparse-bitfield/download/sparse-bitfield-3.0.3.tgz", "integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=", - "optional": true, "requires": { "memory-pager": "^1.0.2" } diff --git a/shared/consts/consts.ts b/shared/consts/consts.ts new file mode 100644 index 000000000..44140a1f9 --- /dev/null +++ b/shared/consts/consts.ts @@ -0,0 +1,12 @@ +export const TURBO_CORE_URL = 'https://coresrv.tgamebox.cn'; +export const APP_ID = 'AXaXmIHPs9eONvzrBesD8aSKQNXYdALF'; +export const TURBO_PARM_SECRET = 'ipqw05du6ob4x130w89t31yrqd6xs005zzltcmg2zpqnvrjp1s'; + +export const ENCRYPT_IV = 'f7182j5f04e377ux'; +export const ENCRYPT_KEY = 'fiqaxijabbantusmprc234fj'; + +export const AUTH_SMS_CNT_PER_DAY = 8; + +export const COUNTER = { + UID: 'uid', +}; diff --git a/game-server/app/db/BaseModel.ts b/shared/db/BaseModel.ts similarity index 100% rename from game-server/app/db/BaseModel.ts rename to shared/db/BaseModel.ts diff --git a/game-server/app/db/Counter.ts b/shared/db/Counter.ts similarity index 100% rename from game-server/app/db/Counter.ts rename to shared/db/Counter.ts diff --git a/game-server/app/db/Equip.ts b/shared/db/Equip.ts similarity index 100% rename from game-server/app/db/Equip.ts rename to shared/db/Equip.ts diff --git a/game-server/app/db/Game.ts b/shared/db/Game.ts similarity index 96% rename from game-server/app/db/Game.ts rename to shared/db/Game.ts index af40b3749..9ed732e7c 100644 --- a/game-server/app/db/Game.ts +++ b/shared/db/Game.ts @@ -1,4 +1,4 @@ -import { APP_ID } from './../consts/consts'; +import { APP_ID } from '../../game-server/app/consts/consts'; import BaseModel from './BaseModel'; import { index, getModelForClass, prop } from '@typegoose/typegoose'; diff --git a/game-server/app/db/Hero.ts b/shared/db/Hero.ts similarity index 100% rename from game-server/app/db/Hero.ts rename to shared/db/Hero.ts diff --git a/game-server/app/db/Role.ts b/shared/db/Role.ts similarity index 98% rename from game-server/app/db/Role.ts rename to shared/db/Role.ts index c8e635654..157b6d2c4 100644 --- a/game-server/app/db/Role.ts +++ b/shared/db/Role.ts @@ -1,4 +1,3 @@ -import { COUNTER } from './../consts/consts'; import { CounterModel } from './Counter'; import BaseModel from './BaseModel'; import { index, getModelForClass, prop } from '@typegoose/typegoose'; diff --git a/game-server/app/db/Sms.ts b/shared/db/Sms.ts similarity index 100% rename from game-server/app/db/Sms.ts rename to shared/db/Sms.ts diff --git a/game-server/app/db/User.ts b/shared/db/User.ts similarity index 98% rename from game-server/app/db/User.ts rename to shared/db/User.ts index ac5dae45f..d5f6b79bb 100644 --- a/game-server/app/db/User.ts +++ b/shared/db/User.ts @@ -26,7 +26,7 @@ export default class User extends BaseModel { telHash: string; @prop({ required: true }) - channelId: string; + channelId: string;COUNTER @prop({ required: true }) guestId: string; diff --git a/web-server/app/consts/consts.ts b/web-server/app/consts/consts.ts index 44140a1f9..d7c281c1a 100644 --- a/web-server/app/consts/consts.ts +++ b/web-server/app/consts/consts.ts @@ -1,12 +1,12 @@ -export const TURBO_CORE_URL = 'https://coresrv.tgamebox.cn'; -export const APP_ID = 'AXaXmIHPs9eONvzrBesD8aSKQNXYdALF'; -export const TURBO_PARM_SECRET = 'ipqw05du6ob4x130w89t31yrqd6xs005zzltcmg2zpqnvrjp1s'; +// export const TURBO_CORE_URL = 'https://coresrv.tgamebox.cn'; +// export const APP_ID = 'AXaXmIHPs9eONvzrBesD8aSKQNXYdALF'; +// export const TURBO_PARM_SECRET = 'ipqw05du6ob4x130w89t31yrqd6xs005zzltcmg2zpqnvrjp1s'; -export const ENCRYPT_IV = 'f7182j5f04e377ux'; -export const ENCRYPT_KEY = 'fiqaxijabbantusmprc234fj'; +// export const ENCRYPT_IV = 'f7182j5f04e377ux'; +// export const ENCRYPT_KEY = 'fiqaxijabbantusmprc234fj'; -export const AUTH_SMS_CNT_PER_DAY = 8; +// export const AUTH_SMS_CNT_PER_DAY = 8; -export const COUNTER = { - UID: 'uid', -}; +// export const COUNTER = { +// UID: 'uid', +// }; diff --git a/web-server/app/db/Game.ts b/web-server/app/db/Game.ts index af40b3749..0a73ed2e0 100644 --- a/web-server/app/db/Game.ts +++ b/web-server/app/db/Game.ts @@ -1,4 +1,4 @@ -import { APP_ID } from './../consts/consts'; +import { APP_ID } from './../../../shared/consts/consts'; import BaseModel from './BaseModel'; import { index, getModelForClass, prop } from '@typegoose/typegoose'; diff --git a/web-server/app/db/User.ts b/web-server/app/db/User.ts index ac5dae45f..cade31cca 100644 --- a/web-server/app/db/User.ts +++ b/web-server/app/db/User.ts @@ -1,4 +1,4 @@ -import { COUNTER } from './../consts/consts'; +import { COUNTER } from './../../../shared/consts/consts'; import { CounterModel } from './Counter'; import BaseModel from './BaseModel'; import { index, getModelForClass, prop } from '@typegoose/typegoose'; diff --git a/web-server/app/middleware/parmsDecode.ts b/web-server/app/middleware/parmsDecode.ts index 4c76b5f97..c91133d04 100644 --- a/web-server/app/middleware/parmsDecode.ts +++ b/web-server/app/middleware/parmsDecode.ts @@ -1,4 +1,4 @@ -import { ENCRYPT_KEY, ENCRYPT_IV } from './../consts/consts'; +import { ENCRYPT_KEY, ENCRYPT_IV } from './../../../shared/consts/consts'; import { Context } from 'egg'; const crypto = require('crypto'); const isJSON = require('koa-is-json'); diff --git a/web-server/app/service/TurboCore.ts b/web-server/app/service/TurboCore.ts index d7e4f886e..ee34349a0 100644 --- a/web-server/app/service/TurboCore.ts +++ b/web-server/app/service/TurboCore.ts @@ -1,4 +1,4 @@ -import { TURBO_CORE_URL, APP_ID, TURBO_PARM_SECRET } from './../consts/consts'; +import { TURBO_CORE_URL, APP_ID, TURBO_PARM_SECRET } from './../../../shared/consts/consts'; import { Service } from 'egg'; const crypto = require('crypto'); /**