feat(config): 公测渠道game-server和批量脚本

This commit is contained in:
liangtongchuan
2023-04-27 12:44:05 +08:00
parent c958a2efc3
commit 97263f7812
3 changed files with 1261 additions and 11 deletions

View File

@@ -0,0 +1,153 @@
// 根据配置生成 servers 文件
import * as fs from 'fs';
import * as path from 'path';
// 各种 server 的起始端口
const CONNECTOR_CLIENT_START_PORT = 3051;
const CONNECTOR_START_PORT = 4051;
const GM_CONNECTOR_CLIENT_PORT = 3099;
const GM_CONNECTOR_PORT = 4099;
const CHAT_START_PORT = 6011;
const ROLE_START_PORT = 6021;
const BATTLE_START_PORT = 6031;
const GUILD_START_PORT = 6041;
const ACTIVITY_START_PORT = 6051;
const ORDER_START_PORT = 6061;
const GM_START_PORT = 6071;
const SYSTIMER_START_PORT = 6081;
interface ServerConfig { name: string, host: string, clientHost: string, connectorCnt: number, chatCnt: number, roleCnt: number, battleCnt: number, guildCnt: number, activityCnt: number, orderCnt: number, gmCnt: number, systimerCnt: number, gmConnectorCnt: number };
let [totalConnector, totalChat, totalRole, totalBattle, totalGuild, totalActivity, totalOrder, totalGm, totalSystimer, totalGmConnector] = Array(10).fill(0);
// 服务器配置:公测渠道
const CH_SERVERS_FILE = 'yjz_ch.ts';
const ch1ServerConfig: ServerConfig[] = [
{ name: 'ch1', host: '172.16.4.144', clientHost: 'yjz-ch-game1.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 6, battleCnt: 2, guildCnt: 6, activityCnt: 2, orderCnt: 2, gmCnt: 1, systimerCnt: 1, gmConnectorCnt: 0 },
{ name: 'ch2', host: '172.16.4.139', clientHost: 'yjz-ch-game2.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 6, battleCnt: 4, guildCnt: 6, activityCnt: 3, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
{ name: 'ch3', host: '172.16.4.143', clientHost: 'yjz-ch-game3.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 6, battleCnt: 2, guildCnt: 6, activityCnt: 2, orderCnt: 2, gmCnt: 2, systimerCnt: 0, gmConnectorCnt: 1 },
{ name: 'ch4', host: '172.16.4.175', clientHost: 'yjz-ch-game4.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 6, battleCnt: 4, guildCnt: 6, activityCnt: 4, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
{ name: 'ch5', host: '172.16.4.172', clientHost: 'yjz-ch-game5.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 6, battleCnt: 4, guildCnt: 6, activityCnt: 4, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
{ name: 'ch6', host: '172.16.4.170', clientHost: 'yjz-ch-game6.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 6, battleCnt: 4, guildCnt: 6, activityCnt: 4, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
];
function genServer(config: ServerConfig) {
const servers = {};
const { host, clientHost, connectorCnt, chatCnt, roleCnt, battleCnt, guildCnt, activityCnt, orderCnt, gmCnt, systimerCnt, gmConnectorCnt } = config;
const connectorServers = [];
for (let i = 0; i < connectorCnt; i++) {
connectorServers.push({ 'id': `connector-server-${totalConnector + 1}`, 'host': host, 'port': CONNECTOR_START_PORT + i, 'clientHost': clientHost, 'clientPort': CONNECTOR_CLIENT_START_PORT + i, 'frontend': true });
totalConnector++;
}
for (let i = 0; i < gmConnectorCnt; i++) {
connectorServers.push({ 'id': `connector-server-gm`, 'host': host, 'port': GM_CONNECTOR_PORT, 'clientHost': clientHost, 'clientPort': GM_CONNECTOR_CLIENT_PORT, 'frontend': true, 'isGm': true });
totalGmConnector++;
}
servers['connector'] = connectorServers;
const chatServers = [];
for (let i = 0; i < chatCnt; i++) {
chatServers.push({ 'id': `chat-server-${totalChat + 1}`, 'host': host, 'port': CHAT_START_PORT + i });
totalChat++;
}
servers['chat'] = chatServers;
const roleServers = [];
for (let i = 0; i < roleCnt; i++) {
roleServers.push({ 'id': `role-server-${totalRole + 1}`, 'host': host, 'port': ROLE_START_PORT + i });
totalRole++;
}
servers['role'] = roleServers;
const battleServers = [];
for (let i = 0; i < battleCnt; i++) {
battleServers.push({ 'id': `battle-server-${totalBattle + 1}`, 'host': host, 'port': BATTLE_START_PORT + i });
totalBattle++;
}
servers['battle'] = battleServers;
const guildServers = [];
for (let i = 0; i < guildCnt; i++) {
guildServers.push({ 'id': `guild-server-${totalGuild + 1}`, 'host': host, 'port': GUILD_START_PORT + i });
totalGuild++;
}
servers['guild'] = guildServers;
const activityServers = [];
for (let i = 0; i < activityCnt; i++) {
activityServers.push({ 'id': `activity-server-${totalActivity + 1}`, 'host': host, 'port': ACTIVITY_START_PORT + i });
totalActivity++;
}
servers['activity'] = activityServers;
const orderServers = [];
for (let i = 0; i < orderCnt; i++) {
orderServers.push({ 'id': `order-server-${totalOrder + 1}`, 'host': host, 'port': ORDER_START_PORT + i });
totalOrder++;
}
servers['order'] = orderServers;
const gmServers = [];
for (let i = 0; i < gmCnt; i++) {
gmServers.push({ 'id': `gm-server-${totalGm + 1}`, 'host': host, 'port': GM_START_PORT + i });
totalGm++;
}
servers['gm'] = gmServers;
const systimerServers = [];
for (let i = 0; i < systimerCnt; i++) {
systimerServers.push({ 'id': `systimer-server-${totalSystimer + 1}`, 'host': host, 'port': SYSTIMER_START_PORT + i });
totalSystimer++;
}
servers['systimer'] = systimerServers;
return servers;
}
function writeServersFile(serverName: string, serverConfig: any, fileName: string) {
const serverPath = path.join(__dirname, `../config/${fileName}`);
// 追加写入到文件
fs.appendFileSync(serverPath, `\nexport const ${serverName} = ${JSON.stringify(serverConfig, null, 4)};`);
}
function printTotal() {
// 打印各 server 数量
console.log(`totalConnector: ${totalConnector}`);
console.log(`totalGmConnector: ${totalGmConnector}`);
console.log(`totalChat: ${totalChat}`);
console.log(`totalRole: ${totalRole}`);
console.log(`totalBattle: ${totalBattle}`);
console.log(`totalGuild: ${totalGuild}`);
console.log(`totalActivity: ${totalActivity}`);
console.log(`totalOrder: ${totalOrder}`);
console.log(`totalGm: ${totalGm}`);
console.log(`totalSystimer: ${totalSystimer}`);
}
function genServers(fileName: string, serverConfig: ServerConfig[]) {
// 清空文件
const serverPath = path.join(__dirname, `../config/${fileName}`);
fs.writeFileSync(serverPath, '');
for (let i = 0; i < serverConfig.length; i++) {
const config = serverConfig[i];
const servers = genServer(config);
writeServersFile(config.name, servers, fileName);
}
if (totalSystimer !== 1) {
throw new Error(`totalSystimer !== 1`);
}
// 检测是否有 server 数量为 0 的
if (totalConnector === 0 || totalChat === 0 || totalRole === 0 || totalBattle === 0 || totalGuild === 0 || totalActivity === 0 || totalOrder === 0 || totalGm === 0) {
throw new Error(`有 server 数量为 0totalConnector: ${totalConnector}, totalChat: ${totalChat}, totalRole: ${totalRole}, totalBattle: ${totalBattle}, totalGuild: ${totalGuild}, totalActivity: ${totalActivity}, totalOrder: ${totalOrder}, totalGm: ${totalGm}`);
}
printTotal();
}
// 将 serverConfig 转换成 servers然后写入到文件
genServers(CH_SERVERS_FILE, ch1ServerConfig);

View File

@@ -1,4 +1,5 @@
const { zy1, zy2, zy3, zy4, zy5, zy6, zy7, zy8, zy9, zy10, yjzios } = require("./yjz_zy");
const { ch1, ch2, ch3, ch4, ch5, ch6 } = require("./yjz_ch");
module.exports = {
'development': {
@@ -627,15 +628,7 @@ module.exports = {
'activity': [],
'order': [],
},
'zy1': zy1,
'zy2': zy2,
'zy3': zy3,
'zy4': zy4,
'zy5': zy5,
'zy6': zy6,
'zy7': zy7,
'zy8': zy8,
'zy9': zy9,
'zy10': zy10,
'yjzios': yjzios,
'zy1': zy1, 'zy2': zy2, 'zy3': zy3, 'zy4': zy4, 'zy5': zy5, 'zy6': zy6, 'zy7': zy7, 'zy8': zy8, 'zy9': zy9, 'zy10': zy10, // 公测自营服务器
'yjzios': yjzios, // 公测 ios 审核服
'ch1': ch1, 'ch2': ch2, 'ch3': ch3, 'ch4': ch4, 'ch5': ch5, 'ch6': ch6, // 公测渠道服
};

1104
game-server/config/yjz_ch.ts Normal file

File diff suppressed because it is too large Load Diff