增加项目配置项
This commit is contained in:
parent
a10b071c69
commit
9557e4e521
@ -1 +1,117 @@
|
|||||||
[{"id":99001,"type_id":1,"value":6},{"id":99002,"type_id":1,"value":2},{"id":99003,"type_id":2,"value":20},{"id":99004,"type_id":1,"value":2},{"id":99005,"type_id":1,"value":3},{"id":99006,"type_id":1,"value":4},{"id":99007,"type_id":1,"value":12},{"id":99008,"type_id":2,"value":12},{"id":99009,"type_id":2,"value":15},{"id":99010,"type_id":2,"value":18},{"id":99011,"type_id":2,"value":20},{"id":99012,"type_id":2,"value":5},{"id":99013,"type_id":1,"value":5},{"id":99014,"type_id":2,"value":5},{"id":99015,"type_id":1,"value":10},{"id":99016,"type_id":1,"value":10},{"id":99017,"type_id":2,"value":12},{"id":99018,"type_id":2,"value":12},{"id":99019,"type_id":2,"value":3},{"id":99020,"type_id":2,"value":20},{"id":99021,"type_id":3,"value":30},{"id":99022,"type_id":3,"value":70}]
|
[
|
||||||
|
{
|
||||||
|
"id": 99001,
|
||||||
|
"type_id": 1,
|
||||||
|
"value": 6
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99002,
|
||||||
|
"type_id": 1,
|
||||||
|
"value": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99003,
|
||||||
|
"type_id": 2,
|
||||||
|
"value": 20
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99004,
|
||||||
|
"type_id": 1,
|
||||||
|
"value": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99005,
|
||||||
|
"type_id": 1,
|
||||||
|
"value": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99006,
|
||||||
|
"type_id": 1,
|
||||||
|
"value": 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99007,
|
||||||
|
"type_id": 1,
|
||||||
|
"value": 12
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99008,
|
||||||
|
"type_id": 2,
|
||||||
|
"value": 12
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99009,
|
||||||
|
"type_id": 2,
|
||||||
|
"value": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99010,
|
||||||
|
"type_id": 2,
|
||||||
|
"value": 18
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99011,
|
||||||
|
"type_id": 2,
|
||||||
|
"value": 20
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99012,
|
||||||
|
"type_id": 2,
|
||||||
|
"value": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99013,
|
||||||
|
"type_id": 1,
|
||||||
|
"value": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99014,
|
||||||
|
"type_id": 2,
|
||||||
|
"value": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99015,
|
||||||
|
"type_id": 1,
|
||||||
|
"value": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99016,
|
||||||
|
"type_id": 1,
|
||||||
|
"value": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99017,
|
||||||
|
"type_id": 2,
|
||||||
|
"value": 12
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99018,
|
||||||
|
"type_id": 2,
|
||||||
|
"value": 12
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99019,
|
||||||
|
"type_id": 2,
|
||||||
|
"value": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99020,
|
||||||
|
"type_id": 2,
|
||||||
|
"value": 20
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99021,
|
||||||
|
"type_id": 3,
|
||||||
|
"value": 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99022,
|
||||||
|
"type_id": 3,
|
||||||
|
"value": 70
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 99023,
|
||||||
|
"type_id": 1,
|
||||||
|
"value": 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
4
config/config.json
Normal file
4
config/config.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"redis": "redis://127.0.0.1:6379/15",
|
||||||
|
"mongodb": "mongodb://127.0.0.1/card-development"
|
||||||
|
}
|
@ -1,26 +1,37 @@
|
|||||||
const os = require('os');
|
const os = require('os');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
apps: [
|
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,
|
port : 2567,
|
||||||
|
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: {
|
||||||
|
REDIS_URL: "redis://127.0.0.1:6379/15"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
port : 4000,
|
||||||
name : "card_svr",
|
name : "card_svr",
|
||||||
script : "lib/index.js", // your entrypoint file
|
script : "lib/index.js", // your entrypoint file
|
||||||
watch : true, // optional
|
watch : true, // optional
|
||||||
instances : 2,
|
instances : 2,
|
||||||
exec_mode : 'fork', // IMPORTANT: do not use cluster mode.
|
exec_mode : 'fork', // IMPORTANT: do not use cluster mode.
|
||||||
env: {
|
env: {
|
||||||
DEBUG: "colyseus:errors",
|
DEBUG: "colyseus:errors,colyseus:matchmaking,jc:*",
|
||||||
|
NODE_ENV: "production",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
port : 2500,
|
||||||
|
name : "card_bot",
|
||||||
|
script : "lib/robot.js", // your entrypoint file
|
||||||
|
watch : true, // optional
|
||||||
|
instances : 1,
|
||||||
|
exec_mode : 'fork', // IMPORTANT: do not use cluster mode.
|
||||||
|
env: {
|
||||||
|
DEBUG: "colyseus:errors,jc:*",
|
||||||
NODE_ENV: "production",
|
NODE_ENV: "production",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
src/cfg/Config.ts
Normal file
4
src/cfg/Config.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface Config {
|
||||||
|
redis: string;
|
||||||
|
mongodb: string;
|
||||||
|
}
|
@ -4,7 +4,6 @@ import {GameEnv} from "../cfg/GameEnv";
|
|||||||
let delayRun = function (max: number, min?: number) {
|
let delayRun = function (max: number, min?: number) {
|
||||||
min = min || 0;
|
min = min || 0;
|
||||||
let milliseconds = (Math.random() * (max - min) + min) * 1000 | 0;
|
let milliseconds = (Math.random() * (max - min) + min) * 1000 | 0;
|
||||||
console.log(`delay time: ${milliseconds}`)
|
|
||||||
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
||||||
}
|
}
|
||||||
const baseCfg = singleton(GameEnv);
|
const baseCfg = singleton(GameEnv);
|
||||||
|
14
src/index.ts
14
src/index.ts
@ -1,18 +1,22 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import { Server } from "colyseus";
|
import {RedisPresence, Server} from "colyseus";
|
||||||
import { monitor } from "@colyseus/monitor";
|
import { monitor } from "@colyseus/monitor";
|
||||||
// import socialRoutes from "@colyseus/social/express"
|
// import socialRoutes from "@colyseus/social/express"
|
||||||
|
|
||||||
import { GeneralRoom } from "./rooms/GeneralRoom";
|
import { GeneralRoom } from "./rooms/GeneralRoom";
|
||||||
import {MongooseDriver} from "colyseus/lib/matchmaker/drivers/MongooseDriver";
|
import {MongooseDriver} from "colyseus/lib/matchmaker/drivers/MongooseDriver";
|
||||||
import {initData} from "./common/GConfig";
|
import {initData} from "./common/GConfig";
|
||||||
|
import {Config} from "./cfg/Config";
|
||||||
|
|
||||||
require('./rooms/MSender');
|
require('./rooms/MSender');
|
||||||
require('./rooms/RoomExtMethod');
|
require('./rooms/RoomExtMethod');
|
||||||
|
|
||||||
|
let config: Config = require('../config/config.json');
|
||||||
|
|
||||||
const port = Number(process.env.PORT || 2567);
|
const port = Number(process.env.PORT || 2567);
|
||||||
|
// const port = Number(process.env.PORT) + Number(process.env.NODE_APP_INSTANCE);
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
|
|
||||||
@ -23,7 +27,8 @@ const server = http.createServer(app);
|
|||||||
const gameServer = new Server({
|
const gameServer = new Server({
|
||||||
server,
|
server,
|
||||||
// driver: new MongooseDriver('mongodb://127.0.0.1/card-development'),
|
// driver: new MongooseDriver('mongodb://127.0.0.1/card-development'),
|
||||||
// driver: new MongooseDriver('mongodb://192.168.100.24/card-development2'),
|
// driver: new MongooseDriver(config.mongodb),
|
||||||
|
// presence: new RedisPresence({url: config.redis}),
|
||||||
});
|
});
|
||||||
|
|
||||||
// register your room handlers
|
// register your room handlers
|
||||||
@ -39,6 +44,9 @@ gameServer.define('general_room', GeneralRoom);
|
|||||||
|
|
||||||
// register colyseus monitor AFTER registering your room handlers
|
// register colyseus monitor AFTER registering your room handlers
|
||||||
app.use("/colyseus", monitor());
|
app.use("/colyseus", monitor());
|
||||||
|
gameServer.onShutdown(function () {
|
||||||
|
console.log("master process is being shut down!");
|
||||||
|
//TODO:: 保存所有数据至db, 重启时恢复
|
||||||
|
});
|
||||||
gameServer.listen(port).then(()=>{});
|
gameServer.listen(port).then(()=>{});
|
||||||
console.log(`Listening on ws://localhost:${ port }`)
|
console.log(`Listening on ws://localhost:${ port }`)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user