mirror of
https://github.com/SoDOff-Project/sodoff-mmo.git
synced 2026-01-13 12:51:52 -08:00
Added command handler for room elapsed time.
This commit is contained in:
parent
a94e5f75e0
commit
dcbdc93bbd
20
src/CommandHandlers/ElapsedTimeSyncHandler.cs
Normal file
20
src/CommandHandlers/ElapsedTimeSyncHandler.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using sodoffmmo.Attributes;
|
||||||
|
using sodoffmmo.Core;
|
||||||
|
using sodoffmmo.Data;
|
||||||
|
|
||||||
|
namespace sodoffmmo.CommandHandlers;
|
||||||
|
|
||||||
|
[ExtensionCommandHandler("RTM")]
|
||||||
|
class ElapsedTimeSyncHandler : CommandHandler {
|
||||||
|
public override Task Handle(Client client, NetworkObject receivedObject) {
|
||||||
|
if (client.Room != null) {
|
||||||
|
NetworkObject cmd = new();
|
||||||
|
NetworkObject obj = new();
|
||||||
|
obj.Add("arr", new string[] { "RTM", "-1", client.Room.ElapsedTime.ElapsedMilliseconds.ToString() });
|
||||||
|
cmd.Add("c", "RTM");
|
||||||
|
cmd.Add("p", obj);
|
||||||
|
client.Send(NetworkObject.WrapObject(1, 13, cmd).Serialize());
|
||||||
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using sodoffmmo.Data;
|
using sodoffmmo.Data;
|
||||||
|
|
||||||
namespace sodoffmmo.Core;
|
namespace sodoffmmo.Core;
|
||||||
@ -18,6 +19,7 @@ public class Room {
|
|||||||
|
|
||||||
public bool AllowChatOverride { get; set; } = false;
|
public bool AllowChatOverride { get; set; } = false;
|
||||||
public NetworkArray RoomVariables = new();
|
public NetworkArray RoomVariables = new();
|
||||||
|
public readonly Stopwatch ElapsedTime = new Stopwatch();
|
||||||
|
|
||||||
public Room(string? name, string? group = null, bool autoRemove = false) {
|
public Room(string? name, string? group = null, bool autoRemove = false) {
|
||||||
Id = ++MaxId;
|
Id = ++MaxId;
|
||||||
@ -33,6 +35,7 @@ public class Room {
|
|||||||
}
|
}
|
||||||
AutoRemove = autoRemove;
|
AutoRemove = autoRemove;
|
||||||
rooms.Add(Name, this);
|
rooms.Add(Name, this);
|
||||||
|
ElapsedTime.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ClientsCount => clients.Count;
|
public int ClientsCount => clients.Count;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user