add support for dance alert

This commit is contained in:
Robert Paciorek 2024-04-06 11:49:17 +00:00
parent 0f161d899c
commit 518c01c43f
2 changed files with 49 additions and 0 deletions

48
src/Core/RoomWithAlert.cs Normal file
View File

@ -0,0 +1,48 @@
using sodoffmmo.Data;
using System.Timers;
namespace sodoffmmo.Core;
class RoomWithAlert : Room {
private int alertId;
private System.Timers.Timer? timer = null;
private Random random = new Random();
private int minTime;
private int maxTime;
private int songs;
public RoomWithAlert(string name, int minTime = 30, int maxTime = 240, int songs = 16) : base (name) {
alertId = -1;
this.minTime = minTime;
this.maxTime = maxTime;
this.songs = songs;
SetTimer();
}
private void StartAlert(Object? source, ElapsedEventArgs e) {
int songId = random.Next(0, songs);
RoomVariables = new();
RoomVariables.Add(NetworkArray.VlElement("RA_S", ++alertId, isPersistent: true));
RoomVariables.Add(NetworkArray.VlElement("RA_A", "3", isPersistent: true));
RoomVariables.Add(NetworkArray.VlElement("RA_L", 20.0, isPersistent: true));
RoomVariables.Add(NetworkArray.VlElement("RA_SO", (double)songId, isPersistent: true));
NetworkPacket packet = Utils.VlNetworkPacket(RoomVariables, Id);
Send(packet);
SetTimer();
}
private void SetTimer() {
if (timer != null) {
timer.Stop();
timer.Close();
}
timer = new System.Timers.Timer(
random.Next(minTime * 1000, maxTime * 1000)
);
timer.AutoReset = false;
timer.Enabled = true;
timer.Elapsed += StartAlert;
}
}

View File

@ -28,6 +28,7 @@ public class Server {
if (IPv6AndIPv4)
listener.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, 0);
listener.Bind(new IPEndPoint(ipAddress, port));
new RoomWithAlert("LoungeInt"); // FIXME use config for this
await Listen(listener);
}