Skip to content

Commit

Permalink
add support for multiple cedmod instances
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexInABox committed Nov 28, 2024
1 parent fbc09ea commit f7cff9f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ SERVER_CLIENT_ID="dj28041orSomethingLikeThat"
SCP_SERVER_TIMEOUT=300000

CEDMOD_INSTANCE_ID="1234"
CEDMOD_WHICH_SERVER="1"

SCPLISTKR_INSTANCE_ID="12345; scplist.kr instance id";

Expand Down
8 changes: 4 additions & 4 deletions lib/CedMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function writeServerStats() {



async function refreshPlayerList(instanceId) {
async function refreshPlayerList(instanceId, whichServer) {
const options = {
'method': 'GET',
'url': `https://queryws.cedmod.nl/Api/Realtime/QueryServers/GetPopulation?instanceId=${instanceId}`,
Expand All @@ -39,15 +39,15 @@ async function refreshPlayerList(instanceId) {
} catch (e) {
throw new Error("Failed to parse response from CedMod!");
}
if (!response || !response[0] || response[0].playerCount === undefined || response[0].userIds === undefined)
if (!response || !response[whichServer] || response[whichServer].playerCount === undefined || response[whichServer].userIds === undefined)
throw new Error("Invalid response from CedMod!");


await readServerStats();

serverStats.state = "";
serverStats.playerCount = response[0].playerCount || 0;
serverStats.playerList = response[0].userIds || [];
serverStats.playerCount = response[whichServer].playerCount || 0;
serverStats.playerList = response[whichServer].userIds || [];
serverStats.provider = "CedMod";
serverStats.timestamp = Date.now();

Expand Down
3 changes: 2 additions & 1 deletion lib/ServerStatsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async function readServerStats() {

const timeoutThreshold = Number.parseInt(process.env.SCP_SERVER_TIMEOUT) | 30000;
const instanceId = process.env.CEDMOD_INSTANCE_ID;
const whichCedmodServer = process.env.CEDMOD_WHICH_SERVER - 1;
const serverId = process.env.SCPLISTKR_SERVER_ID;


Expand All @@ -32,7 +33,7 @@ async function mainloop() {
console.log("DataTransmitServer hasn't sent any data in the last 30 seconds. Trying to get player list from alternative sources...");

try{
await CedMod.refreshPlayerList(instanceId);
await CedMod.refreshPlayerList(instanceId, whichCedmodServer);
}catch(e){
console.error("Failed to get player list from CedMod. Trying SCPListKr...");
console.error(e);
Expand Down

0 comments on commit f7cff9f

Please sign in to comment.