mirror of
https://github.com/SoDOff-Project/sodoff-mmo.git
synced 2025-10-11 00:08:50 -07:00
room alerts configuration via appsettings.json
thanks to HaiFire for alert config for SS
This commit is contained in:
parent
883214cb57
commit
7321b95821
@ -32,6 +32,7 @@ internal sealed class ServerConfiguration {
|
||||
public string EventName { get; set; } = "ScoutAttack";
|
||||
public int EventTimer { get; set; } = 30;
|
||||
public int FirstEventTimer { get; set; } = 10;
|
||||
public Dictionary<string, string[][]> RoomAlerts { get; set; } = new();
|
||||
public int RacingMaxPlayers { get; set; } = 6;
|
||||
public int RacingMinPlayers { get; set; } = 2;
|
||||
public int RacingMainLobbyTimer { get; set; } = 15;
|
||||
|
@ -174,14 +174,18 @@ public class Room {
|
||||
|
||||
private void StartAlert(AlertInfo alert, Client? specificClient = null) {
|
||||
if (specificClient != null) return; // Disables joining ongoing alerts.
|
||||
alert.songId = random.Next(0, alert.songs);
|
||||
|
||||
NetworkArray NewRoomVariables = new();
|
||||
NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_START, alertId++, isPersistent: true));
|
||||
NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_TYPE, alert.type, isPersistent: true));
|
||||
double duration = (alert.endTime - DateTime.Now).TotalSeconds;
|
||||
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 == "3") NewRoomVariables.Add(NetworkArray.VlElement(REDALERT_SONG, (double)alert.songId, isPersistent: true));
|
||||
if (alert.type == "1") {
|
||||
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);
|
||||
if (specificClient is null) {
|
||||
RoomVariables = NewRoomVariables;
|
||||
|
@ -28,10 +28,19 @@ public class Server {
|
||||
if (IPv6AndIPv4)
|
||||
listener.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, 0);
|
||||
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));
|
||||
Room.GetOrAdd("Spaceport").AddAlert(new Room.AlertInfo("2", 120.0, 1800, 3600));
|
||||
Room.GetOrAdd("Academy").AddAlert(new Room.AlertInfo("1", 20.0, 300, 300));
|
||||
|
||||
foreach (var room in Configuration.ServerConfiguration.RoomAlerts) {
|
||||
foreach (var alert in room.Value) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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": 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": 6,
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user