Skip to content

Commit

Permalink
Merge pull request #243 from lythx/dev
Browse files Browse the repository at this point in the history
changes for 1.4.3
  • Loading branch information
wsrvn authored Jan 21, 2024
2 parents fc8d4b0 + 6a30a77 commit f88c21f
Show file tree
Hide file tree
Showing 40 changed files with 376 additions and 245 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ WEBSERVICES_PASSWORD=
LOG_LEVEL=3

# Discord logging
DISCORD_LOG_ENABLED=YES
DISCORD_LOG_ENABLED=NO
DISCORD_LOG_LEVEL=2
DISCORD_WEBHOOK_URL=
DISCORD_EMBED_IMAGES=
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: Docker

on:
schedule:
- cron: '19 22 * * *'
- cron: '19 22 1 * *'
push:
branches: [ "main" ]
# Publish semver tags as releases.
Expand Down
27 changes: 14 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
# Creates a runnable environment with a dedicated server and trakman
FROM node:lts-alpine
# setup directory
RUN mkdir -p /app/server
# create directory, install xml editing tool and setup non-root user
RUN adduser -h /app/server -s /bin/sh -D -u 1001 server && \
apk add xmlstarlet su-exec
USER server
WORKDIR /app/server
# copy useful trakman files and entrypoint command
COPY ./config ./trakmanbk/config
COPY ./plugins ./trakmanbk/plugins
COPY ./src ./trakmanbk/src
COPY ./Plugins.ts ./package.json ./tsconfig.json ./CHANGELOG.md ./trakmanbk/
COPY --chmod=0755 ./docker_run.sh ./docker_run.sh
COPY --chown=1001:1001 ./config ./trakmanbk/config
COPY --chown=1001:1001 ./plugins ./trakmanbk/plugins
COPY --chown=1001:1001 ./src ./trakmanbk/src
COPY --chown=1001:1001 ./Plugins.ts ./package.json ./tsconfig.json ./CHANGELOG.md ./trakmanbk/
COPY --chown=1001:1001 --chmod=0755 ./docker_run.sh ./docker_run.sh
# download dedicated server and remove unnecessary files
RUN wget -O serv.zip http://files2.trackmaniaforever.com/TrackmaniaServer_2011-02-21.zip && \
unzip serv.zip && \
rm -r serv.zip CommandLine.html ListCallbacks.html ListMethods.html \
Readme_Dedicated.html RemoteControlExamples TrackmaniaServer.exe manialink_dedicatedserver.txt
# get trakman dependencies and build
WORKDIR /app/server/trakmanbk
RUN npm i typescript@latest && \
RUN npm i && \
npm run build
WORKDIR /app/server
# backup important files to prevent them being deleted by mounting the volume
# and install xml editing tool for server config
RUN mv GameData/Config/dedicated_cfg.txt dedicated_cfg.txt.bk && \
mkdir -p Tracksbk/MatchSettings && \
mkdir -p Tracksbk/Campaigns/Nations && \
mv GameData/Tracks/MatchSettings/Nations/NationsBlue.txt Tracksbk/MatchSettings/MatchSettings.txt && \
mv GameData/Tracks/Campaigns/Nations/Blue Tracksbk/Campaigns/Nations/ && \
apk add xmlstarlet
mv GameData/Tracks/Campaigns/Nations/Blue Tracksbk/Campaigns/Nations/
# expose volumes
VOLUME /app/server/GameData/Config
VOLUME /app/server/GameData/Tracks
VOLUME /app/server/trakman
VOLUME /root/.pm2/logs

VOLUME /app/server/.pm2/logs
# set user back to root to be able to chown volumes in the run script
USER root
CMD /app/server/docker_run.sh
10 changes: 7 additions & 3 deletions config/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ export default {
voteOnPublicAdd: true,
/** Default amount of maps fetched from the TMX search API */
defaultTMXSearchLimit: 50,
/** Whether to reset Cup mode scores after a map is skipped or restarted */
resetCupScoreOnSkipAndRestart: true,
/** Privilege levels for each of the administrative actions */
privileges: {
ban: 2,
blacklist: 2,
mute: 1,
addGuest: 1,
kick: 1,
forceSpectator: 1
forceSpectator: 1,
addMap: 1,
removeMap: 1,
},
/** Whether the maplist gets reloaded on Match Settings updates.
* Enable this if you use external tools to modify the Match Settings */
updateMatchSettingsOnChange: false,
/** Point system for rounds and cup gamemode */
/** Point system for rounds and cup gamemodes */
roundsModePointSystem: [33, 29, 27, 25, 23, 21, 19, 17, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
/** Default time limit in TimeAttack mode (in miliseconds) */
defaultTimeAttackTimeLimit: 300000,
Expand All @@ -59,7 +63,7 @@ export default {
* Used in nickname to login translation in commands. 0.15 is default value */
nicknameToLoginMinimumDifferenceBetweenMatches: 0.15,
/** Current controller version */
version: "1.4.2",
version: "1.4.3",
/** Controller repository link */
repo: "github.com/lythx/trakman",
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
- ./tmf-config:/app/server/GameData/Config
- ./tracks:/app/server/GameData/Tracks
- ./trakman:/app/server/trakman
- ./logs:/root/.pm2/logs
- ./logs:/app/server/.pm2/logs
environment:
# Dedicated server config
SERVER_IP: 127.0.0.1
Expand Down
20 changes: 19 additions & 1 deletion docker_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,25 @@ else
echo 'Setting up trakman...'
mv /app/server/trakmanbk/* /app/server/trakman/
fi
# ugly creating of files to be able to chmod and remove them later
mkdir -p trakman/logs
touch trakman/logs/combined.log
touch trakman/logs/error.log
touch trakman/logs/info.log
mkdir -p .pm2/logs
touch .pm2/logs/Trakman-error.log
touch .pm2/logs/Trakman-out.log
mkdir -p trakman/temp
touch trakman/temp/rank_coherence.txt
mkdir -p trakman/plugins/server_links/temp
touch trakman/plugins/server_links/temp/data.txt
chown -R server:server /app/server
# build and actually run everything
echo "#!/bin/sh
/app/server/TrackmaniaServer /game_settings=MatchSettings/MatchSettings.txt /dedicated_cfg=dedicated_cfg.txt
npm run build --prefix /app/server/trakman
npm run daemon --prefix /app/server/trakman
chmod -R a+w /app/server
npm run daemon --prefix /app/server/trakman" > run.sh
chown server:server run.sh
chmod 766 run.sh
exec su-exec server ./run.sh
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions plugins/actions/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ interface CallerInfo { login: string, nickname: string, title: string, privilege

const sendNoPrivilegeMessage = (info: CallerInfo): void => tm.sendMessage(config.noPermission, info.login)

let eraseObject: { id: string, admin: { login: string, nickname: string } } | undefined
tm.addListener('BeginMap', (info): void => {
if (info.isRestart) { return }
if (eraseObject !== undefined) {
void tm.maps.remove(eraseObject.id, eraseObject.admin)
eraseObject = undefined
}
})

/**
* Provides utilities for various actions.
* @author lythx & wiseraven
Expand Down Expand Up @@ -384,5 +393,70 @@ export const actions = {
}
await tm.admin.setPrivilege(target.login, privilege, caller)
}
},
addMap: async (login: string, nickname: string, title: string, id: number | string, tmxSite?: string, fromUrl: boolean = false) => {
const tmxSites: tm.TMXSite[] = ['TMNF', 'TMN', 'TMO', 'TMS', 'TMU']
const site: tm.TMXSite | undefined = tmxSites.find(a => a === tmxSite?.toUpperCase())
let file: { name: string, content: Buffer } | Error = await tm.tmx.fetchMapFile(id as any, site).catch((err: Error) => err)
if (file instanceof Error) {
const remainingSites: tm.TMXSite[] = tmxSites.filter(a => a !== tmxSite)
for (const e of remainingSites) {
file = await tm.tmx.fetchMapFile(id as any, e).catch((err: Error) => err)
if (!(file instanceof Error)) { break }
}
}
if (file instanceof Error) {
tm.sendMessage(config.addMap.fetchError, login)
return
}
const obj = await tm.maps.writeFileAndAdd(file.name, file.content, { login, nickname })
if (obj instanceof Error) {
tm.log.warn(obj.message)
tm.sendMessage(config.addMap.addError, login)
return
} else if (obj.wasAlreadyAdded) {
tm.sendMessage(tm.utils.strVar(config.addMap.alreadyAdded, {
map: tm.utils.strip(obj.map.name, true),
nickname: tm.utils.strip(nickname, true)
}), config.addMap.public ? undefined : login)
} else {
tm.sendMessage(tm.utils.strVar(config.addMap.added, {
title: title,
map: tm.utils.strip(obj.map.name, true),
nickname: tm.utils.strip(nickname, true)
}), config.addMap.public ? undefined : login)
}
},
removeMap: async (login: string, nickname: string, title: string, id?: string) => {
if (tm.maps.count <= 1) {
tm.sendMessage(config.removeMap.onlyMap, login)
return
}
if (id === undefined) {
if (eraseObject !== undefined) {
tm.sendMessage(config.removeMap.alreadyRemoved, login)
return
}
id = tm.maps.current.id
eraseObject = { id: id, admin: { login, nickname } }
tm.sendMessage(tm.utils.strVar(config.removeMap.removeThis, {
title: title,
nickname: tm.utils.strip(nickname, true),
map: tm.utils.strip(tm.maps.current.name, true)

}), config.removeMap.public ? undefined : login)
return
}
const map = tm.maps.get(id)
if (map === undefined) {
tm.sendMessage(config.removeMap.error, login)
return
}
tm.sendMessage(tm.utils.strVar(config.removeMap.text, {
title: title,
nickname: tm.utils.strip(nickname, true),
map: tm.utils.strip(map.name, true)
}), config.removeMap.public ? undefined : login)
void tm.maps.remove(map.id, { login, nickname })
}
}
16 changes: 16 additions & 0 deletions plugins/actions/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,21 @@ export default {
`${p.highlight}#{nickname}${p.admin} to #{rank}.`,
rightsRemoved: `${p.admin}#{title} ${p.highlight}#{adminNickname}${p.admin} has removed privileges of ${p.highlight}#{nickname}${p.admin}.`,
alreadyIs: `${p.highlight}#{nickname}${p.error} is already #{rank}.`,
},
addMap: {
fetchError: `${p.error}Failed to fetch the map file from TMX.`,
addError: `${p.error}Failed to add the map.`,
alreadyAdded: `${p.admin}Map ${p.highlight}#{map}${p.admin} added by ${p.highlight}#{nickname}${p.admin} is already on the server, ` +
`it will be ${p.highlight}queued ${p.admin}instead.`,
added: `${p.admin}#{title} ${p.highlight}#{nickname}${p.admin} has added and queued ${p.highlight}#{map}${p.admin} from TMX.`,
public: true,
},
removeMap: {
text: `${p.admin}#{title} ${p.highlight}#{nickname}${p.admin} has removed map ${p.highlight}#{map} ${p.admin}from the server.`,
removeThis:`${p.admin}#{title} ${p.highlight}#{nickname}${p .admin} has removed the ongoing map ${p.highlight}#{map} ${p.admin}from the server.`,
alreadyRemoved: `${p.error}This map is already getting removed.`,
error: `${p.error}Error while removing the map.`,
onlyMap: `${p.error}There are no more maps in the server playlist.`,
public: true,
}
}
2 changes: 1 addition & 1 deletion plugins/commands/config/JukeboxCommands.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
public: true,
privilege: 2,
aliases: ['shuf', 'shuffle'],
help: `Shuffle the map queue.`
help: `Shuffle the map list.`
},
clearhistory: {
text: `${p.admin}#{title} ${p.highlight}#{adminName} ${p.admin}has cleared the map history.`,
Expand Down
17 changes: 4 additions & 13 deletions plugins/commands/config/MapCommands.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ const p = tm.utils.palette

export default {
add: {
fetchError: `${p.error}Failed to fetch the map file from TMX.`,
addError: `${p.error}Failed to add the map.`,
alreadyAdded: `${p.admin}Map ${p.highlight}#{map}${p.admin} added by ${p.highlight}#{nickname}${p.admin} is already on the server, ` +
`it will be ${p.highlight}queued ${p.admin}instead.`,
added: `${p.admin}#{title} ${p.highlight}#{nickname}${p.admin} has added and queued ${p.highlight}#{map}${p.admin} from TMX.`,
public: true,
privilege: 1,
privilege: tm.config.controller.privileges.addMap,
aliases: ['add', 'am', 'addmap'],
help: `Add a map from TMX.`
},
Expand All @@ -26,15 +20,12 @@ export default {
added: `${p.admin}#{title} ${p.highlight}#{nickname}${p.admin} has added and queued` +
` ${p.highlight}#{map}${p.admin} from TMX random.`,
public: true,
privilege: 1,
privilege: tm.config.controller.privileges.addMap,
aliases: ['ar', 'addr', 'addrandom'],
help: `Add a random map from TMX.`
},
remove: {
text: `${p.admin}#{title} ${p.highlight}#{nickname}${p.admin} has removed the current map.`,
error: `${p.error}The map is already getting removed.`,
public: true,
privilege: 1,
privilege: tm.config.controller.privileges.removeMap,
aliases: ['et', 'rt', 'erase', 'erasethis'],
help: `Remove a current map from maplist.`
},
Expand All @@ -45,7 +36,7 @@ export default {
`it will be ${p.highlight}queued ${p.admin}instead.`,
added: `${p.admin}#{title} ${p.highlight}#{nickname}${p.admin} has added and queued ${p.highlight}#{map}${p.admin} from url.`,
public: true,
privilege: 1,
privilege: tm.config.controller.privileges.addMap,
aliases: ['afu', 'addfromurl'],
help: `Add a map from url.`
},
Expand Down
Loading

0 comments on commit f88c21f

Please sign in to comment.