Files
aaaa/src/server/server.ts
2025-09-11 13:47:30 -04:00

156 lines
6.1 KiB
TypeScript

import { getNetConfig } from "../net.ts";
import { ServerUpdateEvent } from "../serverevents.ts";
import { AvatarContentBase } from "./avatars/base.ts";
import { EventManager } from "./baseevent.ts";
import { CommandsBase } from "./commands/commands.ts";
import { ServerConsumablesBase } from "./consumables/base.ts";
import { ServerContentManager } from "./content/base.ts";
import GameConfigsBase from "./gameconfigs/base.ts";
import { InstanceManager } from "./instances/base.ts";
import { ServerMatchmakingBase } from "./matchmaking/base.ts";
import { Objective, ObjectiveType } from "./objectives/base.ts";
import { PlatformsManager } from "./platforms/base.ts";
import { ServerPresenceBase } from "./presence/base.ts";
import { type PresenceUpdateEvent } from "./presence/events/PresenceUpdateEvent.ts";
import { type ProfileUpdateEvent } from "./profiles/events/ProfileUpdate.ts";
import { ProfileUpdatedSettingEvent } from "./profiles/events/ProfileUpdatedSetting.ts";
import { type RoleUpdateEvent } from "./profiles/events/RoleUpdate.ts";
import ProfileManagerBase from "./profiles/manager.ts";
import { ServerRoomsBase } from "./rooms/base.ts";
import { RoomUpdatedEvent, SubroomUpdatedEvent } from "./rooms/internal/RoomEvents.ts";
import { AnnouncementDTO } from "./types.ts";
interface ServerEvents {
'profile.roleupdate': RoleUpdateEvent,
'profile.update': ProfileUpdateEvent,
'profile.setting.update': ProfileUpdatedSettingEvent,
'presence.update': PresenceUpdateEvent,
'server.start': ServerUpdateEvent,
'server.destroy': ServerUpdateEvent,
'room.updated': RoomUpdatedEvent,
'room.subroom.updated': SubroomUpdatedEvent
}
export interface LevelProgressionItem {
Level: number;
RequiredXp: number;
};
interface AutoMicMutingConfig {
MicSpamVolumeThreshold: number;
MicVolumeSampleInterval: number;
MicVolumeSampleRollingWindowLength: number;
MicSpamSamplePercentageForWarning: number;
MicSpamSamplePercentageForWarningToEnd: number;
MicSpamSamplePercentageForForceMute: number;
MicSpamSamplePercentageForForceMuteToEnd: number;
MicSpamWarningStateVolumeMultiplier: number;
};
export interface PublicConfig {
ShareBaseUrl: string;
ServerMaintenance: {
StartsInMinutes: number;
};
LevelProgressionMaps: LevelProgressionItem[];
DailyObjectives: Objective[][];
AutoMicMutingConfig: AutoMicMutingConfig;
};
class ServerBase extends EventManager<ServerEvents> {
Profiles = new ProfileManagerBase(this, 'profiles', true);
GameConfigs = new GameConfigsBase(this, 'gameconfigs', true);
Commands = new CommandsBase(this, 'commands');
Platforms = new PlatformsManager(this, 'platforms', true);
Avatars = new AvatarContentBase(this, 'avatars');
Instances = new InstanceManager(this, 'instances');
Content = new ServerContentManager(this, "content");
Rooms = new ServerRoomsBase(this, 'rooms', true);
Matchmaking = new ServerMatchmakingBase(this, "match");
Presence = new ServerPresenceBase(this, "pres");
Consumables = new ServerConsumablesBase(this, "consumables");
generateMask(...num: number[]) {
return num.reduce((sum, val) => sum + val, 0);
}
getPublicConfig() {
const netConfig = getNetConfig();
function generateLevelProgressionMap() {
const m: LevelProgressionItem[] = [];
for (let i = 0; i < 31; i++) {
m.push({
Level: i,
RequiredXp: Math.round(i * 1 * 20),
});
}
return m;
}
const conf: PublicConfig = {
ServerMaintenance: {
StartsInMinutes: 0,
},
LevelProgressionMaps: generateLevelProgressionMap(),
DailyObjectives: [
[
{ type: ObjectiveType.Default, score: 0 },
{ type: ObjectiveType.GoToRecCenter, score: 0 },
{ type: ObjectiveType.Default, score: 0 }
],
[
{ type: ObjectiveType.Default, score: 0 },
{ type: ObjectiveType.LevelUp, score: 0 },
{ type: ObjectiveType.Default, score: 0 }
],
[
{ type: ObjectiveType.Default, score: 0 },
{ type: ObjectiveType.SaveOutfitSlot, score: 0 },
{ type: ObjectiveType.Default, score: 0 }
],
[
{ type: ObjectiveType.Default, score: 0 },
{ type: ObjectiveType.ScoreBasketInRecCenter, score: 0 },
{ type: ObjectiveType.Default, score: 0 }
],
[
{ type: ObjectiveType.Default, score: 0 },
{ type: ObjectiveType.VisitACustomRoom, score: 0 },
{ type: ObjectiveType.Default, score: 0 }
],
[
{ type: ObjectiveType.Default, score: 0 },
{ type: ObjectiveType.SubscribeToPlayer, score: 0 },
{ type: ObjectiveType.Default, score: 0 }
],
[
{ type: ObjectiveType.Default, score: 0 },
{ type: ObjectiveType.AddAFriend, score: 0 },
{ type: ObjectiveType.Default, score: 0 }
]
],
AutoMicMutingConfig: {
MicSpamVolumeThreshold: 1.125,
MicVolumeSampleInterval: 0.25,
MicVolumeSampleRollingWindowLength: 7.0,
MicSpamSamplePercentageForWarning: 0.8,
MicSpamSamplePercentageForWarningToEnd: 0.2,
MicSpamSamplePercentageForForceMute: 0.8,
MicSpamSamplePercentageForForceMuteToEnd: 0.2,
MicSpamWarningStateVolumeMultiplier: 0.25
},
ShareBaseUrl: `${netConfig.securePublicHost ? 'https' : 'http'}://${netConfig.publicHost}/{0}` // {0} is replaced by the game
};
return conf;
}
getAnnouncements(): AnnouncementDTO[] {
return [];
}
}
const Server = new ServerBase();
export { ServerBase };
export default Server;