~furry/mamoru-server

4daa88e7a11ccefed94a02c50defb81c4313825c — nora a month ago 8c9819c
replace websocketsharp with watsonwebsocket
4 files changed, 28 insertions(+), 18 deletions(-)

D Connections/ServerLogConnection.cs
M Mamoru.cs
M Mamoru.csproj
A Managers/ConnectionsManager.cs
D Connections/ServerLogConnection.cs => Connections/ServerLogConnection.cs +0 -18
@@ 1,18 0,0 @@
// using WebSocketSharp;
// using WebSocketSharp.Server;
//
// namespace Mamoru.Connections;
//
// public class ServerLogConnection : WebSocketBehavior {
//   public static string Path = "/serverlog";
//
//   protected override void OnMessage(MessageEventArgs e) {
//     Send(e.Data);
//     Log.Info(e.Data);
//   }
//
//   protected override void OnOpen() {
//     Log.Info("New client connected.");
//     base.OnOpen();
//   }
// }
\ No newline at end of file

M Mamoru.cs => Mamoru.cs +4 -0
@@ 6,6 6,8 @@ namespace Mamoru;
public class Mamoru : Plugin<Config> {
  public ConfigManager ConfigManager = null!;
  public RoutesManager RoutesManager = null!;
  public ConnectionsManager ConnectionsManager = null!;
  
  public static Mamoru Instance { get; } = new();

  public override string Name => "Mamoru";


@@ 14,6 16,7 @@ public class Mamoru : Plugin<Config> {
  public override void OnEnabled() {
    ConfigManager = new ConfigManager();
    RoutesManager = new RoutesManager();
    ConnectionsManager = new ConnectionsManager();

    Log.Info("Mamoru was enabled.");
    base.OnEnabled();


@@ 21,6 24,7 @@ public class Mamoru : Plugin<Config> {

  public override void OnDisabled() {
    RoutesManager.StopHttpServer();
    ConnectionsManager.StopWebsocketServer();

    Log.Info("Mamoru was disabled.");
    base.OnDisabled();

M Mamoru.csproj => Mamoru.csproj +2 -0
@@ 11,9 11,11 @@
    <ItemGroup>
        <PackageReference Include="EXILED" Version="9.0.0-beta.5" />
        <PackageReference Include="Watson" Version="6.2.2" />
        <PackageReference Include="WatsonWebsocket" Version="4.1.2" />
    </ItemGroup>

    <ItemGroup>
        <Folder Include="Connections\" />
        <Folder Include="Models.EXILED\"/>
    </ItemGroup>
</Project>

A Managers/ConnectionsManager.cs => Managers/ConnectionsManager.cs +22 -0
@@ 0,0 1,22 @@
using System.Net;
using PluginAPI.Core;
using WatsonWebsocket;

namespace Mamoru.Managers;

public class ConnectionsManager {
  private readonly WatsonWsServer _wsServer = new(IPAddress.Loopback.ToString(), 4650);
  
  public ConnectionsManager() {
    _wsServer.ClientConnected += (sender, args) => {
      Log.Info(args.HttpRequest.Headers.ToString());
    };
    
    Log.Info("Starting websocket server...");
    _wsServer.Start();
  }
  
  public void StopWebsocketServer() {
    _wsServer.Stop();
  }
}
\ No newline at end of file