Skip to content

Commit

Permalink
Added map change and srb2 login support
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspalmero committed Dec 8, 2022
1 parent 2905927 commit e5c7d3f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions config.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"port": 5029,
"advertise": false,
"configFile": "~/kartserv.cfg",
"addonsfolder": "~/serveraddons/"
"addonsfolder": "~/serveraddons/",
"srb2mode": false,
"showMapChange": false
},
"discord": {
"token": "app token goes here",
Expand All @@ -19,7 +21,8 @@
"pingEveryone": "If a user attempts to write @everyone from within the game, it will get replaced by this message",
"serverShutdown": "Server shutting down...",
"joinedGame": "$1 has joined the game ($2/15 players)",
"leftGame": "$1 has left the game ($2/15 players)"
"leftGame": "$1 has left the game ($2/15 players)",
"mapChange": "Map is now _$1_"
},
"logLocation": "/tmp/somefolderwherelogswillgoin/"
}
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ tail.on("line", (data) => {
}
}
// a login?
else if (config.srb2.srb2mode && regexes.srb2PlayerLogin) {
changeUserAmount(1);
let name = escapeDiscordMarkup(data.match(regexes.matchNameFromSrb2Login));
sendDiscordMessage(
msgs.joinedGame.replace('$1', name).replace('$2', playerAmount),
config.discord.channelIds
);
}
else if (regexes.playerLogin.test(data)) {
changeUserAmount(1);
}
Expand All @@ -148,6 +156,14 @@ tail.on("line", (data) => {
config.discord.channelIds
);
}
// a map change?
else if (config.srb2.showMapChange && regexes.mapChange.test(data)) {
let name = escapeDiscordMarkup(data.match(regexes.matchMapFromMapChange));
sendDiscordMessage(
msgs.mapChange.replace('$1', name),
config.discord.channelIds
)
}
// player left?
else if (regexes.playerLeft.test(data)) {
changeUserAmount(-1);
Expand Down
4 changes: 4 additions & 0 deletions modules/regexes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
module.exports = {
chatMessage: /^<.{1,21}> .{0,223}/,
playerLogin: /^\*Player [0-9]{1,2} has joined the game \(node [0-9]{1,2}\) \([0-9.:]{9,22}\)$/,
srb2PlayerLogin: / has joined the game \(player [0-9]{1,2}\)$/,
mapChange: /^Map is now.*/,
firstNameChange: /^\*Player [0-9]{1,2} renamed to .{1,22}$/,
nameChange: /^\*.{1,22} renamed to .{1,22}$/,
playerLeft: /^\*.{1,22} left the game.*/,
serverStarted: /^Entering main game loop\.\.\.$/,
serverMessage: /^<~SERVER>.*/,
matchNameFromNameChange: /(?<=Player [0-9]{1,2} renamed to ).{1,22}$/,
matchNameFromSrb2Login: /.*(?= entered the game.)/,
matchMapFromMapChange: /"MAP..: .*"/,
matchNameFromLeft: /^.{1,22}(?= left the game)/
};

0 comments on commit e5c7d3f

Please sign in to comment.