Files
ZYZ/game-server/config/genServers.ts
2023-09-13 17:15:37 +08:00

196 lines
14 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 根据配置生成 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;
const COM_BATTLE_START_PORT = 6091;
interface ServerConfig { name: string, host: string, clientHost: string, connectorCnt: number, chatCnt: number, roleCnt: number, battleCnt: number, comBattleCnt: number, guildCnt: number, activityCnt: number, orderCnt: number, gmCnt: number, systimerCnt: number, gmConnectorCnt: number };
let [totalConnector, totalChat, totalRole, totalBattle, totalComBattle, totalGuild, totalActivity, totalOrder, totalGm, totalSystimer, totalGmConnector] = Array(11).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, comBattleCnt: 1, 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, comBattleCnt: 1, 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: 4, comBattleCnt: 1, 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, comBattleCnt: 1, 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, comBattleCnt: 1, 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, comBattleCnt: 1, guildCnt: 6, activityCnt: 4, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// // { name: 'ch7', host: '172.16.4.199', clientHost: 'yjz-bk-game10.fdd73.com', connectorCnt: 6, chatCnt: 0, roleCnt: 20, battleCnt: 0, comBattleCnt: 0, guildCnt: 0, activityCnt: 2, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// // { name: 'ch8', host: '172.16.4.200', clientHost: 'yjz-bk-game11.fdd73.com', connectorCnt: 6, chatCnt: 0, roleCnt: 10, battleCnt: 5, comBattleCnt: 2, guildCnt: 0, activityCnt: 5, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// // { name: 'ch9', host: '172.16.4.201', clientHost: 'yjz-bk-game12.fdd73.com', connectorCnt: 6, chatCnt: 0, roleCnt: 10, battleCnt: 5, comBattleCnt: 2, guildCnt: 0, activityCnt: 5, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// // { name: 'ch10', host: '172.16.4.203', clientHost: 'yjz-bk-game13.fdd73.com', connectorCnt: 0, chatCnt: 0, roleCnt: 0, battleCnt: 0, comBattleCnt: 0, guildCnt: 0, activityCnt: 0, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// // { name: 'ch11', host: '172.16.4.198', clientHost: 'yjz-bk-game14.fdd73.com', connectorCnt: 0, chatCnt: 0, roleCnt: 0, battleCnt: 0, comBattleCnt: 0, guildCnt: 0, activityCnt: 0, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// // { name: 'ch12', host: '172.16.4.204', clientHost: 'yjz-bk-game15.fdd73.com', connectorCnt: 0, chatCnt: 0, roleCnt: 0, battleCnt: 0, comBattleCnt: 0, guildCnt: 0, activityCnt: 0, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// ];
// 服务器配置:自营
const ZY_SERVERS_FILE = 'yjz_zy.ts';
// 公测配置2023-05-07
const zy1ServerConfig: ServerConfig[] = [
{ name: 'zy1', host: '172.16.4.140', clientHost: 'yjz-zy-game1.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 9, battleCnt: 2, comBattleCnt: 1, guildCnt: 3, activityCnt: 2, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
{ name: 'zy2', host: '172.16.4.146', clientHost: 'yjz-zy-game2.fdd73.com', connectorCnt: 4, chatCnt: 2, roleCnt: 9, battleCnt: 4, comBattleCnt: 1, guildCnt: 0, activityCnt: 3, orderCnt: 2, gmCnt: 1, systimerCnt: 1, gmConnectorCnt: 0 },
{ name: 'zy3', host: '172.16.4.142', clientHost: 'yjz-zy-game3.fdd73.com', connectorCnt: 2, chatCnt: 2, roleCnt: 9, battleCnt: 4, comBattleCnt: 1, guildCnt: 5, activityCnt: 1, orderCnt: 2, gmCnt: 2, systimerCnt: 0, gmConnectorCnt: 1 },
{ name: 'zy4', host: '172.16.4.145', clientHost: 'yjz-zy-game4.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 9, battleCnt: 3, comBattleCnt: 1, guildCnt: 5, activityCnt: 3, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
{ name: 'zy5', host: '172.16.4.141', clientHost: 'yjz-zy-game5.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 9, battleCnt: 3, comBattleCnt: 1, guildCnt: 5, activityCnt: 3, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
{ name: 'zy6', host: '172.16.4.174', clientHost: 'yjz-zy-game6.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 9, battleCnt: 3, comBattleCnt: 1, guildCnt: 5, activityCnt: 3, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
{ name: 'zy7', host: '172.16.4.173', clientHost: 'yjz-zy-game7.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 9, battleCnt: 3, comBattleCnt: 1, guildCnt: 5, activityCnt: 3, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
{ name: 'zy8', host: '172.16.4.169', clientHost: 'yjz-zy-game8.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 9, battleCnt: 2, comBattleCnt: 2, guildCnt: 5, activityCnt: 3, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// { name: 'zy9', host: '172.16.4.176', clientHost: 'yjz-zy-game9.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 9, battleCnt: 2, comBattleCnt: 1, guildCnt: 5, activityCnt: 3, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// { name: 'zy10', host: '172.16.4.171', clientHost: 'yjz-zy-game10.fdd73.com', connectorCnt: 6, chatCnt: 2, roleCnt: 9, battleCnt: 2, comBattleCnt: 1, guildCnt: 5, activityCnt: 3, orderCnt: 2, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// { name: 'zy11', host: '172.16.4.195', clientHost: 'yjz-bk-game1.fdd73.com', connectorCnt: 6, chatCnt: 0, roleCnt: 20, battleCnt: 0, comBattleCnt: 0, guildCnt: 2, activityCnt: 0, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// { name: 'zy12', host: '172.16.4.196', clientHost: 'yjz-bk-game2.fdd73.com', connectorCnt: 6, chatCnt: 0, roleCnt: 20, battleCnt: 0, comBattleCnt: 0, guildCnt: 2, activityCnt: 0, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// { name: 'zy13', host: '172.16.4.193', clientHost: 'yjz-bk-game3.fdd73.com', connectorCnt: 6, chatCnt: 0, roleCnt: 20, battleCnt: 0, comBattleCnt: 0, guildCnt: 2, activityCnt: 0, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// { name: 'zy14', host: '172.16.4.194', clientHost: 'yjz-bk-game4.fdd73.com', connectorCnt: 6, chatCnt: 0, roleCnt: 0, battleCnt: 10, comBattleCnt: 0, guildCnt: 2, activityCnt: 10, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// { name: 'zy15', host: '172.16.4.197', clientHost: 'yjz-bk-game5.fdd73.com', connectorCnt: 6, chatCnt: 0, roleCnt: 0, battleCnt: 10, comBattleCnt: 0, guildCnt: 2, activityCnt: 10, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// { name: 'zy16', host: '172.16.4.205', clientHost: 'yjz-bk-game6.fdd73.com', connectorCnt: 6, chatCnt: 0, roleCnt: 0, battleCnt: 10, comBattleCnt: 5, guildCnt: 5, activityCnt: 0, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// { name: 'zy17', host: '172.16.4.202', clientHost: 'yjz-bk-game7.fdd73.com', connectorCnt: 0, chatCnt: 0, roleCnt: 0, battleCnt: 0, comBattleCnt: 0, guildCnt: 0, activityCnt: 0, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// { name: 'zy18', host: '172.16.4.207', clientHost: 'yjz-bk-game8.fdd73.com', connectorCnt: 0, chatCnt: 0, roleCnt: 0, battleCnt: 0, comBattleCnt: 0, guildCnt: 0, activityCnt: 0, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
// { name: 'zy19', host: '172.16.4.206', clientHost: 'yjz-bk-game9.fdd73.com', connectorCnt: 0, chatCnt: 0, roleCnt: 0, battleCnt: 0, comBattleCnt: 0, guildCnt: 0, activityCnt: 0, orderCnt: 0, gmCnt: 0, systimerCnt: 0, gmConnectorCnt: 0 },
];
function genServer(config: ServerConfig) {
const servers = {};
const { host, clientHost, connectorCnt, chatCnt, roleCnt, battleCnt, comBattleCnt, 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 comBattleServers = [];
for (let i = 0; i < comBattleCnt; i++) {
comBattleServers.push({ 'id': `comBattle-server-${totalComBattle + 1}`, 'host': host, 'port': COM_BATTLE_START_PORT + i });
totalComBattle++;
}
servers['comBattle'] = comBattleServers;
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}`);
console.log(`totalComBattle: ${totalComBattle}`);
console.log(`total: ${totalConnector + totalGmConnector + totalChat + totalRole + totalBattle + totalGuild + totalActivity + totalOrder + totalGm + totalSystimer + totalComBattle}`);
}
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);
genServers(ZY_SERVERS_FILE, zy1ServerConfig);