Skip to content

Commit

Permalink
Fix/migrate to eos (#354)
Browse files Browse the repository at this point in the history
* ID parser implemented.

* Cleanup player join logging.

Since last update all data necessary to identify a player comes in 2 logs
within the same chain, so many previous loggers are deprecated.

`JOIN_SUCCEEDED` is now used as an emit trigger because this is where
we obtain the last piece of data for the log - `playerSuffix`.

* Rework admins features to be able to recieve any ID as an identifier.

As an added side effect, methods like `server.getAdminPermsBySteamID()`
will only return data for admins that are currently in-game (because
to map anyID onto eosID it needs player's data which is not persistent
and is available only when a player is online).

* Migrate core code to eosID and anyID.

* Update plugins to eosID.

Plugins that were not updated:
1. db-log
   SteamID is basically it's backbone. Migrading to EOS would require
   obtaining all steam -> EOS pairs, migrating databasesm etc. Maybe we
   could make a db-logV2 with new data and migration assisting tools so
   that anyone willing to migrate can do it in an assisted mode.
2. awn-api
   Not something that I use or know, left as is.
3. cbl-info
   Again, steamID seems to be it's backbone, I don't want to mess with a
   project that has maintainers that know ins and outs way better than
   me.

Plugins that were partially updated:
1. discord-killfeed
   CBL integration is left untouched, other things are updated.

* Fix attemts to access non-existent oldPlayerInfo.

* Refactor id-parser.

Renamed main function, rewrote ID iterations, fixed a bug in
`anyIDsToPlayers()` (wasn't eliminating duplicats in returned list),
minor comments cleanup.

* refactor: getAdminsWithPermission extended.

1. `getAdminsWithPermission` now supports both legacy and new call
   conventions.
2. any-id.js is also refactored a bit (added `isPlayerID` function).
3. Minor JSDoc fixes.

* Add safeguerds for `INVALID` IDs.

Parsers will skip lines with `INVALID` Online IDs.
  • Loading branch information
Ulibos authored Jul 3, 2024
1 parent 78fed13 commit 078f722
Show file tree
Hide file tree
Showing 37 changed files with 451 additions and 398 deletions.
61 changes: 61 additions & 0 deletions core/id-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const ID_MATCHER = /\s*(?<name>[^\s:]+)\s*:\s*(?<id>[^\s]+)/g;

// COMMON CONSTANTS

/** All possible IDs that a player can have. */
export const playerIdNames = ["steamID", "eosID"];

// PARSING AND ITERATION

/**
* Main function intended for parsing `Online IDs:` body.
* @arg {string} idsStr - String with ids. Extra whitespace is allowed,
* Number of {platform: ID} pairs can be arbitrary. String example:
" platform1:id1 platform2: id2 platform3 : id3 "
Keys and values are not allowed contain colons or whitespace
characters.
* @returns {IdsIterator} An iterator that yields {platform: ID} pairs.
*/
export const iterateIDs = (idsStr) => {
return new IdsIterator(idsStr.matchAll(ID_MATCHER));
};

class IdsIterator {
constructor(matchIterator) {
this.inner = matchIterator;
}

[Symbol.iterator]() {
return this;
}

next() {
const match = this.inner.next();
if (match.done) return { value: undefined, done: true };
return { value: { key: match.value[1], value: match.value[2] }, done: false };
}

forEach(callbackFn) {
for (const { key, value } of this) callbackFn(key, value);
}
}

// FORMATTING

/**
* Generates capitalized ID names. Examples:
* steam -> SteamID
* EOSID -> EOSID
*/
export const capitalID = (str) => {
return str.charAt(0).toUpperCase() + str.slice(1) + 'ID';
};

/**
* Generates lowercase ID names. Examples:
* steam -> steamID
* EOSID -> eosID
*/
export const lowerID = (str) => {
return str.toLowerCase() + 'ID';
};
14 changes: 5 additions & 9 deletions core/log-parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ export default class LogParser extends EventEmitter {

this.eventStore = {
disconnected: {}, // holding area, cleared on map change.
players: [], // persistent data, steamid, controller, suffix.
playersEOS: [], // proxies from EOSID to persistent data, steamid, controller, suffix.
connectionIdToSteamID: new Map(),
players: {}, // persistent data, steamid, controller, suffix.
session: {}, // old eventstore, nonpersistent data
clients: {}, // used in the connection chain before we resolve a player.
lastConnection: {}, // used to store the last client connection data to then associate a steamid
joinRequests: []
};

Expand Down Expand Up @@ -74,10 +70,10 @@ export default class LogParser extends EventEmitter {
clearEventStore() {
Logger.verbose('LogParser', 2, 'Cleaning Eventstore');
for (const player of Object.values(this.eventStore.players)) {
if (this.eventStore.disconnected[player.steamID] === true) {
Logger.verbose('LogParser', 2, `Removing ${player.steamID} from eventStore`);
delete this.eventStore.players[player.steamID];
delete this.eventStore.disconnected[player.steamID];
if (this.eventStore.disconnected[player.eosID] === true) {
Logger.verbose('LogParser', 2, `Removing ${player.eosID} from eventStore`);
delete this.eventStore.players[player.eosID];
delete this.eventStore.disconnected[player.eosID];
}
}
this.eventStore.session = {};
Expand Down
1 change: 1 addition & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"exports": {
"./log-parser": "./log-parser/index.js",
"./constants": "./constants.js",
"./id-parser": "./id-parser.js",
"./logger": "./logger.js",
"./rcon": "./rcon.js"
},
Expand Down
12 changes: 6 additions & 6 deletions core/rcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,15 @@ export default class Rcon extends EventEmitter {
return util.inspect(decodedPacket, { breakLength: Infinity });
}

async warn(steamID, message) {
await this.execute(`AdminWarn "${steamID}" ${message}`);
async warn(anyID, message) {
await this.execute(`AdminWarn "${anyID}" ${message}`);
}

async kick(steamID, reason) {
await this.execute(`AdminKick "${steamID}" ${reason}`);
async kick(anyID, reason) {
await this.execute(`AdminKick "${anyID}" ${reason}`);
}

async forceTeamChange(steamID) {
await this.execute(`AdminForceTeamChange "${steamID}"`);
async forceTeamChange(anyID) {
await this.execute(`AdminForceTeamChange "${anyID}"`);
}
}
Loading

0 comments on commit 078f722

Please sign in to comment.