@ohd-tools/utils
Version:
Utilities for OHD-RCON
136 lines (135 loc) • 6.08 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GameINI = void 0;
const ini_1 = require("ini");
const gameIniDefault = {
RCON_Enabled: false,
RCON_ListenAddress: '',
RCON_ListenPort: 7779,
RCON_Password: '',
RCON_MaxActiveConnections: 5,
RCON_MaxAuthAttempts: 3,
GameSession_MaxPlayers: 16,
GameSession_MinPlayers: 1,
GameSession_ServerName: '',
GameSession_Password: '',
GameSession_SupportersOnlyWhitelist: false,
Gamemode_BotAutofill: false,
Gamemode_WarmupTime: 0,
Gamemode_RoundTimeLimit: 0,
Gamemode_RoundScoreLimit: 0,
Gamemode_TimeBetweenMatches: 10,
Gamemode_BalanceTeams: true,
Gamemode_BalanceTimerInterval: 60.0,
Gamemode_AutoAssignHumanTeam: 255,
Gamemode_AllowVoting: false,
Gamemode_AllowedVoteIssues: '/Script/DonkehFramework.DFVoteIssuePlayerKick',
Gamemode_RandomPlayerTeamBalance: false,
Voting_BanDuration: 300.0,
Voting_PassRatio: 0.51,
Voting_Duration: 0,
Voting_PassedVoteCooldown: 0,
Voting_FailedVoteCooldown: 0,
Voting_DenyVACBannedUsersFromVoting: false,
Voting_DisableVACBanCheckWhileAdminIsOnline: false,
Voting_OnlyAdminsCanInitiateVote: false,
Access_DenyVACBannedUsers: false,
Access_DenyGameBannedUsers: false,
Access_DenyCommunityBannedUsers: false,
Access_DenyUsersWithPrivateProfiles: false,
Access_NumVACBansAllowed: 0,
Access_NumGameBansAllowed: 0,
Access_NumBanAgeDaysAllowed: 30,
Access_MinRequiredAccountAgeDays: 7,
Access_MinRequiredAccountPlaytimeHours: 0,
Access_MaxLoginQueryCacheAgeMinutes: 60.0,
};
const toBoolean = (b) => (b ? 'True' : 'False');
const toNumber = (n) => `${n}`;
const toString = (s) => s;
class GameINI {
Settings;
constructor(settings = {}) {
if (typeof settings == 'string') {
const ini = GameINI.parse(settings);
this.Settings = ini.Settings;
return;
}
this.Settings = { ...gameIniDefault, ...settings };
}
static parse(fileContent) {
const raw = (0, ini_1.parse)(fileContent);
return new GameINI(raw);
}
toString() {
const s = this.Settings;
const fileRaw = {
'/Script/RCON': {
RCONServerSystem: {
bEnabled: toBoolean(s.RCON_Enabled),
ListenAddress: toString(s.RCON_ListenAddress),
ListenPort: toNumber(s.RCON_ListenPort),
Password: toString(s.RCON_Password),
MaxActiveConnections: toNumber(s.RCON_MaxActiveConnections),
MaxAuthAttempts: toNumber(s.RCON_MaxAuthAttempts),
},
},
'/Script/Engine': {
GameSession: {
MaxPlayers: toNumber(s.GameSession_MaxPlayers),
},
},
'/Script/DonkehFramework': {
DFGameSession: {
MinPlayers: toNumber(s.GameSession_MinPlayers),
ServerName: toString(s.GameSession_ServerName),
Password: toString(s.GameSession_Password),
},
DFBaseGameMode: {
bBotAutofill: toBoolean(s.Gamemode_BotAutofill),
WarmupTime: toNumber(s.Gamemode_WarmupTime),
RoundTimeLimit: toNumber(s.Gamemode_RoundTimeLimit),
RoundScoreLimit: toNumber(s.Gamemode_RoundScoreLimit),
TimeBetweenMatches: toNumber(s.Gamemode_TimeBetweenMatches),
bBalanceTeams: toBoolean(s.Gamemode_BalanceTeams),
BalanceTimerInterval: toNumber(s.Gamemode_BalanceTimerInterval),
AutoAssignHumanTeam: toNumber(s.Gamemode_AutoAssignHumanTeam),
bAllowVoting: toBoolean(s.Gamemode_AllowVoting),
AllowedVoteIssues: toString(s.Gamemode_AllowedVoteIssues),
},
DFVoteIssuePlayerKick: {
BanDuration: toNumber(s.Voting_BanDuration),
PassRatio: toNumber(s.Voting_PassRatio),
Duration: toNumber(s.Voting_Duration),
PassedVoteCooldown: toNumber(s.Voting_PassedVoteCooldown),
FailedVoteCooldown: toNumber(s.Voting_FailedVoteCooldown),
bDenyVACBannedUsersFromVoting: toBoolean(s.Voting_DenyVACBannedUsersFromVoting),
bDisableVACBanCheckWhileAdminIsOnline: toBoolean(s.Voting_DisableVACBanCheckWhileAdminIsOnline),
bOnlyAdminsCanInitiateVote: toBoolean(s.Voting_OnlyAdminsCanInitiateVote),
},
},
'/Script/HDMain': {
HDGameSession: {
bSupportersOnlyWhitelist: toBoolean(s.GameSession_SupportersOnlyWhitelist),
},
HDBaseGameMode: {
bRandomPlayerTeamBalance: toBoolean(s.Gamemode_RandomPlayerTeamBalance),
},
},
AccessControlSteam: {
bDenyVACBannedUsers: toBoolean(s.Access_DenyVACBannedUsers),
bDenyGameBannedUsers: toBoolean(s.Access_DenyGameBannedUsers),
bDenyCommunityBannedUsers: toBoolean(s.Access_DenyCommunityBannedUsers),
bDenyUsersWithPrivateProfiles: toBoolean(s.Access_DenyUsersWithPrivateProfiles),
NumVACBansAllowed: toNumber(s.Access_NumVACBansAllowed),
NumGameBansAllowed: toNumber(s.Access_NumGameBansAllowed),
NumBanAgeDaysAllowed: toNumber(s.Access_NumBanAgeDaysAllowed),
MinRequiredAccountAgeDays: toNumber(s.Access_MinRequiredAccountAgeDays),
MinRequiredAccountPlaytimeHours: toNumber(s.Access_MinRequiredAccountPlaytimeHours),
MaxLoginQueryCacheAgeMinutes: toNumber(s.Access_MaxLoginQueryCacheAgeMinutes),
},
};
return (0, ini_1.stringify)(fileRaw, { sort: true });
}
}
exports.GameINI = GameINI;