forked from SoDOff-Project/sodoff-mmo
support for server configuration
This commit is contained in:
parent
31420034ff
commit
7c504bb80a
@ -7,6 +7,25 @@ namespace sodoffmmo.CommandHandlers;
|
|||||||
[ExtensionCommandHandler("SCM")]
|
[ExtensionCommandHandler("SCM")]
|
||||||
class ChatMessageHandler : ICommandHandler {
|
class ChatMessageHandler : ICommandHandler {
|
||||||
public void Handle(Client client, NetworkObject receivedObject) {
|
public void Handle(Client client, NetworkObject receivedObject) {
|
||||||
|
if (!Configuration.ServerConfiguration.EnableChat) {
|
||||||
|
ChatDisabled(client, receivedObject);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Chat(client, receivedObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChatDisabled(Client client, NetworkObject receivedObject) {
|
||||||
|
NetworkObject cmd = new();
|
||||||
|
NetworkObject data = new();
|
||||||
|
data.Add("arr", new string[] { "CMR", "-1", "-1", "1", "Unfortunately, chat has been disabled by server administrators", "", "1", "Server" });
|
||||||
|
cmd.Add("c", "CMR");
|
||||||
|
cmd.Add("p", data);
|
||||||
|
|
||||||
|
NetworkPacket packet = NetworkObject.WrapObject(1, 13, cmd).Serialize();
|
||||||
|
client.Send(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Chat(Client client, NetworkObject receivedObject) {
|
||||||
string message = receivedObject.Get<NetworkObject>("p").Get<string>("chm");
|
string message = receivedObject.Get<NetworkObject>("p").Get<string>("chm");
|
||||||
|
|
||||||
NetworkObject cmd = new();
|
NetworkObject cmd = new();
|
||||||
|
31
src/Core/Configuration.cs
Normal file
31
src/Core/Configuration.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace sodoffmmo.Core;
|
||||||
|
internal static class Configuration {
|
||||||
|
|
||||||
|
public static ServerConfiguration ServerConfiguration { get; private set; } = new ServerConfiguration();
|
||||||
|
|
||||||
|
public static void Initialize() {
|
||||||
|
IConfigurationRoot config = new ConfigurationBuilder()
|
||||||
|
.AddJsonFile("appsettings.json", true)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
ServerConfiguration? serverConfiguration = config.GetSection("ServerConfiguration").Get<ServerConfiguration>();
|
||||||
|
if (serverConfiguration is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ServerConfiguration = serverConfiguration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class ServerConfiguration {
|
||||||
|
public bool EnableChat { get; set; } = true;
|
||||||
|
public int Port { get; set; } = 9933;
|
||||||
|
public int EventTimer { get; set; } = 30;
|
||||||
|
|
||||||
|
}
|
@ -195,7 +195,7 @@ class WorldEvent {
|
|||||||
|
|
||||||
// schedule next event, set timer to call PreInit() and send new WEN_ info
|
// schedule next event, set timer to call PreInit() and send new WEN_ info
|
||||||
private void PostEndEvent2(Object source, ElapsedEventArgs e) {
|
private void PostEndEvent2(Object source, ElapsedEventArgs e) {
|
||||||
ScheduleEvent(30); // WE_ != WEN_
|
ScheduleEvent(Configuration.ServerConfiguration.EventTimer); // WE_ != WEN_
|
||||||
AnnounceEvent(false, true); // send only WEN_ (WE_ should stay unchanged ... as WE_..._End)
|
AnnounceEvent(false, true); // send only WEN_ (WE_ should stay unchanged ... as WE_..._End)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
using sodoffmmo;
|
using sodoffmmo;
|
||||||
|
using sodoffmmo.Core;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
Server server = new(IPAddress.Any, 9933);
|
Configuration.Initialize();
|
||||||
|
Server server = new(IPAddress.Any, Configuration.ServerConfiguration.Port);
|
||||||
await server.Run();
|
await server.Run();
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ComponentAce.Compression.Libs.zlib" Version="1.0.4" />
|
<PackageReference Include="ComponentAce.Compression.Libs.zlib" Version="1.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user