From fa8709333cde078ca30b493728c26612e5475878 Mon Sep 17 00:00:00 2001 From: zhl Date: Mon, 14 Dec 2020 19:33:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=80=E4=B8=AA=E6=9C=BA?= =?UTF-8?q?=E5=99=A8=E4=BA=BA=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecosystem.config.js | 28 ++++++++++++ package-lock.json | 94 +++++++++++++++++++++++++++++++++++++++- package.json | 1 + src/robot/RobotClient.ts | 1 + 4 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 ecosystem.config.js diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..881342b --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,28 @@ +const os = require('os'); +module.exports = { + apps: [ + // { + // port : 80, + // name : "card-proxy", + // script : "./node_modules/@colyseus/proxy/bin/proxy", + // instances : 1, // scale this up if the proxy becomes the bottleneck + // exec_mode : 'cluster', + // env: { + // PORT: 80, + // REDIS_URL: "redis://127.0.0.1:6379/0" + // } + // }, + { + port : 8080, + name : "card_svr", + script : "lib/index.js", // your entrypoint file + watch : true, // optional + instances : 2, + exec_mode : 'fork', // IMPORTANT: do not use cluster mode. + env: { + DEBUG: "colyseus:errors", + NODE_ENV: "production", + } + } + ] +} diff --git a/package-lock.json b/package-lock.json index 81c7d77..0fe2b9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -90,6 +90,15 @@ "node-os-utils": "^1.2.0" } }, + "@colyseus/proxy": { + "version": "0.12.2", + "resolved": "https://registry.npmjs.org/@colyseus/proxy/-/proxy-0.12.2.tgz", + "integrity": "sha512-4j+p7TwQBzpZWEAF5c9GJGf+VixUUDyHcaKARDrt1eQYtK++JCB3tYHY0TCWBGYVr0c9tuWsX/s7VBQIIeZqnw==", + "requires": { + "http-proxy": "^1.18.0", + "ioredis": "^4.9.0" + } + }, "@colyseus/schema": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@colyseus/schema/-/schema-1.0.3.tgz", @@ -584,6 +593,11 @@ "readdirp": "~3.5.0" } }, + "cluster-key-slot": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.0.tgz", + "integrity": "sha512-2Nii8p3RwAPiFwsnZvukotvow2rIHM+yQ6ZcBXGHdniadkYGZYiGmkHJIbZPIV9nfv7m/U1IPMVVcAhoWFeklw==" + }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -856,6 +870,11 @@ "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" }, + "eventemitter3": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", + "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==" + }, "execa": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", @@ -1011,6 +1030,11 @@ "pinkie-promise": "^2.0.0" } }, + "follow-redirects": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz", + "integrity": "sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg==" + }, "forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -1159,6 +1183,16 @@ "toidentifier": "1.0.0" } }, + "http-proxy": { + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz", + "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==", + "requires": { + "eventemitter3": "^4.0.0", + "follow-redirects": "^1.0.0", + "requires-port": "^1.0.0" + } + }, "http-signature": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", @@ -1246,6 +1280,33 @@ "ipaddr.js": "^1.9.0" } }, + "ioredis": { + "version": "4.19.4", + "resolved": "https://registry.npmjs.org/ioredis/-/ioredis-4.19.4.tgz", + "integrity": "sha512-3haQWw9dpEjcfVcRktXlayVNrrqvvc2io7Q/uiV2UsYw8/HC2YwwJr78Wql7zu5bzwci0x9bZYA69U7KkevAvw==", + "requires": { + "cluster-key-slot": "^1.1.0", + "debug": "^4.1.1", + "denque": "^1.1.0", + "lodash.defaults": "^4.2.0", + "lodash.flatten": "^4.4.0", + "p-map": "^2.1.0", + "redis-commands": "1.6.0", + "redis-errors": "^1.2.0", + "redis-parser": "^3.0.0", + "standard-as-callback": "^2.0.1" + }, + "dependencies": { + "redis-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz", + "integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=", + "requires": { + "redis-errors": "^1.0.0" + } + } + } + }, "ip-regex": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz", @@ -1442,6 +1503,16 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" }, + "lodash.defaults": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", + "integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=" + }, + "lodash.flatten": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz", + "integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=" + }, "lodash.includes": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", @@ -1814,6 +1885,11 @@ "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=" }, + "p-map": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-2.1.0.tgz", + "integrity": "sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw==" + }, "parse-json": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", @@ -2023,8 +2099,12 @@ "redis-commands": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.6.0.tgz", - "integrity": "sha512-2jnZ0IkjZxvguITjFTrGiLyzQZcTvaw8DAaCXxZq/dsHXz7KfMQ3OUJy7Tz9vnRtZRVz6VRCPDvruvU8Ts44wQ==", - "optional": true + "integrity": "sha512-2jnZ0IkjZxvguITjFTrGiLyzQZcTvaw8DAaCXxZq/dsHXz7KfMQ3OUJy7Tz9vnRtZRVz6VRCPDvruvU8Ts44wQ==" + }, + "redis-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz", + "integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60=" }, "redis-parser": { "version": "2.6.0", @@ -2089,6 +2169,11 @@ "semver": "^5.1.0" } }, + "requires-port": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=" + }, "resolve": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz", @@ -2295,6 +2380,11 @@ "tweetnacl": "~0.14.0" } }, + "standard-as-callback": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/standard-as-callback/-/standard-as-callback-2.0.1.tgz", + "integrity": "sha512-NQOxSeB8gOI5WjSaxjBgog2QFw55FV8TkS6Y07BiB3VJ8xNTvUYm0wl0s8ObgQ5NhdpnNfigMIKjgPESzgr4tg==" + }, "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", diff --git a/package.json b/package.json index 9124825..732708d 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "dependencies": { "@colyseus/command": "^0.1.6", "@colyseus/monitor": "^0.12.2", + "@colyseus/proxy": "^0.12.2", "@colyseus/social": "^0.10.9", "colyseus": "^0.14.0", "cors": "^2.8.5", diff --git a/src/robot/RobotClient.ts b/src/robot/RobotClient.ts index 310a3a9..c20f5cf 100644 --- a/src/robot/RobotClient.ts +++ b/src/robot/RobotClient.ts @@ -80,6 +80,7 @@ export class RobotClient implements Client { self.selectHero(); break; case GameStateConst.STATE_CHANGE_CARD: + self.cards = self.svrstate.players.get(self.sessionId).cards; self.changeCard(); break; case GameStateConst.STATE_BEGIN_EAT: