diff --git a/server/Util.ts b/server/Util.ts index 2b73109..7507aab 100644 --- a/server/Util.ts +++ b/server/Util.ts @@ -32,4 +32,8 @@ export function isNullOrEmpty(str:string | undefined | null) { } return false; +} + +export function enumHasFlag(value:number, flag:number) : boolean { + return (value & flag) === flag; } \ No newline at end of file diff --git a/server/enums/Mods.ts b/server/enums/Mods.ts index 4cabd58..eb26974 100644 --- a/server/enums/Mods.ts +++ b/server/enums/Mods.ts @@ -1,4 +1,33 @@ -// TODO: Mods enum +// TODO: Complete mods enum. export enum Mods { - None + None, + NoFail = 1 << 0, + Easy = 1 << 1, + // 2 was used for the "No Video" mod but that's gone now. + Hidden = 1 << 3, + HardRock = 1 << 4, + SuddenDeath = 1 << 5, + DoubleTime = 1 << 6, + Relax = 1 << 7, + HalfTime = 1 << 8, + Nightcore = 1 << 9, + Flashlight = 1 << 10, + Autoplay = 1 << 11, + SpunOut = 1 << 12, + Autopilot = 1 << 13, // I think this is autopilot??? + Perfect = 1 << 14, + Mania4K = 1 << 15, + Mania5K = 1 << 16, + Mania6K = 1 << 17, + Mania7K = 1 << 18, + Mania8K = 1 << 19, + FadeIn = 1 << 20, + Random = 1 << 21, + Cinema = 1 << 22, + Target = 1 << 23, + Mania9K = 1 << 24, + ManiaCoop = 1 << 25, + Mania1K = 1 << 26, + Mania3K = 1 << 27, + Mania2K = 1 << 28 } \ No newline at end of file diff --git a/server/objects/Match.ts b/server/objects/Match.ts index 8a97108..bf29664 100644 --- a/server/objects/Match.ts +++ b/server/objects/Match.ts @@ -11,8 +11,14 @@ import MatchStartSkipData from "../interfaces/MatchStartSkipData"; import { Mods } from "../enums/Mods"; import PlayerScore from "../interfaces/PlayerScore"; import MatchScoreData from "../interfaces/MatchScoreData"; +import { enumHasFlag } from "../Util"; import osu from "../../osuTyping"; +// Mods which need to be applied to the match during freemod. +const matchFreemodGlobalMods:Array = [ + Mods.DoubleTime, Mods.Nightcore, Mods.HalfTime +] + export default class Match { // osu! Data public matchId:number = -1; @@ -431,6 +437,19 @@ export default class Match { if (this.specialModes === 1) { slot.mods = mods; + // Extra check for host during freemod + if (User.Equals(this.host, user)) { + let generatedMatchModList = 0; + for (const mod of matchFreemodGlobalMods) { + if (enumHasFlag(slot.mods, mod)) { + slot.mods -= mod; + generatedMatchModList += mod; + } + } + + this.activeMods = generatedMatchModList; + } + this.sendMatchUpdate(); } else { if (!User.Equals(this.host, user)) { @@ -632,7 +651,7 @@ export default class Match { return; } - matchScoreData.id = user.id; + matchScoreData.id = user.matchSlot.slotId; // Update playerScores for (const playerScore of this.playerScores) {