room alerts configuration via appsettings.json

thanks to HaiFire for alert config for SS
This commit is contained in:
Robert Paciorek 2024-08-12 10:12:42 +00:00
parent 883214cb57
commit 7321b95821
4 changed files with 30 additions and 7 deletions

View File

@ -32,6 +32,7 @@ internal sealed class ServerConfiguration {
public string EventName { get; set; } = "ScoutAttack"; public string EventName { get; set; } = "ScoutAttack";
public int EventTimer { get; set; } = 30; public int EventTimer { get; set; } = 30;
public int FirstEventTimer { get; set; } = 10; public int FirstEventTimer { get; set; } = 10;
public Dictionary<string, string[][]> RoomAlerts { get; set; } = new();
public int RacingMaxPlayers { get; set; } = 6; public int RacingMaxPlayers { get; set; } = 6;
public int RacingMinPlayers { get; set; } = 2; public int RacingMinPlayers { get; set; } = 2;
public int RacingMainLobbyTimer { get; set; } = 15; public int RacingMainLobbyTimer { get; set; } = 15;

View File

@ -174,14 +174,18 @@ public class Room {
private void StartAlert(AlertInfo alert, Client? specificClient = null) { private void StartAlert(AlertInfo alert, Client? specificClient = null) {
if (specificClient != null) return; // Disables joining ongoing alerts. if (specificClient != null) return; // Disables joining ongoing alerts.
alert.songId = random.Next(0, alert.songs);
NetworkArray NewRoomVariables = new(); NetworkArray NewRoomVariables = new();
NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_START, alertId++, isPersistent: true)); NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_START, alertId++, isPersistent: true));
NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_TYPE, alert.type, isPersistent: true)); NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_TYPE, alert.type, isPersistent: true));
double duration = (alert.endTime - DateTime.Now).TotalSeconds; double duration = (alert.endTime - DateTime.Now).TotalSeconds;
NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_LENGTH, alert.type == "1" ? alert.redAlertDuration : duration, isPersistent: true)); NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_LENGTH, alert.type == "1" ? alert.redAlertDuration : duration, isPersistent: true));
if (alert.type == "1") NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_TIMEOUT, duration, isPersistent: true)); if (alert.type == "1") {
if (alert.type == "3") NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_SONG, (double)alert.songId, isPersistent: true)); NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_TIMEOUT, duration, isPersistent: true));
} else if (alert.type == "3") {
alert.songId = random.Next(0, alert.songs);
NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_SONG, (double)alert.songId, isPersistent: true));
}
NetworkPacket packet = Utils.VlNetworkPacket(NewRoomVariables, Id); NetworkPacket packet = Utils.VlNetworkPacket(NewRoomVariables, Id);
if (specificClient is null) { if (specificClient is null) {
RoomVariables = NewRoomVariables; RoomVariables = NewRoomVariables;

View File

@ -28,10 +28,19 @@ public class Server {
if (IPv6AndIPv4) if (IPv6AndIPv4)
listener.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, 0); listener.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, 0);
listener.Bind(new IPEndPoint(ipAddress, port)); listener.Bind(new IPEndPoint(ipAddress, port));
Room.GetOrAdd("LoungeInt").AddAlert(new Room.AlertInfo("3")); // FIXME use config for this
Room.GetOrAdd("Spaceport").AddAlert(new Room.AlertInfo("1", 20.0, 300, 300)); foreach (var room in Configuration.ServerConfiguration.RoomAlerts) {
Room.GetOrAdd("Spaceport").AddAlert(new Room.AlertInfo("2", 120.0, 1800, 3600)); foreach (var alert in room.Value) {
Room.GetOrAdd("Academy").AddAlert(new Room.AlertInfo("1", 20.0, 300, 300)); Console.WriteLine($"Setup alert \"{alert[0]}\" for {room.Key}");
Room.GetOrAdd(room.Key).AddAlert(new Room.AlertInfo(
alert[0], // type
float.Parse(alert[1], System.Globalization.CultureInfo.InvariantCulture.NumberFormat), // duration
Int32.Parse(alert[2]), Int32.Parse(alert[3]), // start min - max for random start time
Int32.Parse(alert[4]), Int32.Parse(alert[5]) // extra parameters for specific alarm types
));
}
}
await Listen(listener); await Listen(listener);
} }

View File

@ -21,6 +21,15 @@
"// EventTimer": "time between start of world events (battle ship events), set both timer values (EventTimer and FirstEventTimer) to 0 to disable events", "// EventTimer": "time between start of world events (battle ship events), set both timer values (EventTimer and FirstEventTimer) to 0 to disable events",
"EventTimer": 30, "EventTimer": 30,
"// RoomAlerts": "List of MMO rooms with alert function. Default empty (not used by SoD), bellow sample config for WoJS, MB and SS.",
"// alert parameters": "alert type, duration [s], minimum time to start [s], maximum time to start [s], redAlertDuration (used for type '1'), number of songs (used for type '3')",
"RoomAlerts": {
"LoungeInt" : [ ["3", 20.0, 30, 240, 0, 16] ],
"Spaceport": [ ["1", 20.0, 300, 300, 60, 0], ["2", 120.0, 1800, 3600, 60, 0] ],
"Academy": [ ["1", 20.0, 300, 300, 60, 0] ],
"ClubSSInt" : [ ["3", 20.0, 30, 240, 0, 16] ],
},
"// RacingMaxPlayers": "maximum players allowed in Thunder Run Racing (no more than 6)", "// RacingMaxPlayers": "maximum players allowed in Thunder Run Racing (no more than 6)",
"RacingMaxPlayers": 6, "RacingMaxPlayers": 6,