forked from SoDOff-Project/sodoff-mmo
implement custom `SUE
` command for handling api
This commit is contained in:
parent
b378ff2689
commit
13e9723626
@ -90,6 +90,7 @@ class LoginHandler : CommandHandler
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Console.WriteLine($"Authentication exception IID: {client.ClientID} - {ex}");
|
||||
Console.WriteLine("This Can Be Ignored If API Is The One Logging In.");
|
||||
}
|
||||
return Configuration.ServerConfiguration.Authentication != AuthenticationMode.Required; // return true on auth err if not Required mode
|
||||
}
|
||||
|
32
src/CommandHandlers/SendUserEventHandler.cs
Normal file
32
src/CommandHandlers/SendUserEventHandler.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using sodoffmmo.Attributes;
|
||||
using sodoffmmo.Core;
|
||||
using sodoffmmo.Data;
|
||||
|
||||
namespace sodoffmmo.CommandHandlers
|
||||
{
|
||||
[ExtensionCommandHandler("SUE")]
|
||||
public class SendUserEventHandler : CommandHandler
|
||||
{
|
||||
public override Task Handle(Client client, NetworkObject receivedObject)
|
||||
{
|
||||
NetworkObject p = receivedObject.Get<NetworkObject>("p");
|
||||
|
||||
string userId = p.Get<string>("UID");
|
||||
string cmd = p.Get<string>("CMD");
|
||||
string[] arr = p.Get<string[]>("ARR");
|
||||
|
||||
// find client in all clients list
|
||||
Client? client1 = Server.AllClients.FirstOrDefault(e => e.PlayerData.Uid == userId);
|
||||
|
||||
// send command
|
||||
if (client1 != null) client1.Send(Utils.ArrNetworkPacket(arr, cmd));
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,11 +12,14 @@ public class Server {
|
||||
readonly IPAddress ipAddress;
|
||||
readonly bool IPv6AndIPv4;
|
||||
ModuleManager moduleManager = new();
|
||||
public static List<Client> AllClients { get; private set; }
|
||||
|
||||
public Server(IPAddress ipAdress, int port, bool IPv6AndIPv4) {
|
||||
this.ipAddress = ipAdress;
|
||||
this.port = port;
|
||||
this.IPv6AndIPv4 = IPv6AndIPv4;
|
||||
|
||||
AllClients = new List<Client>();
|
||||
}
|
||||
|
||||
public async Task Run() {
|
||||
@ -47,6 +50,7 @@ public class Server {
|
||||
|
||||
private async Task HandleClient(Socket handler) {
|
||||
Client client = new(handler);
|
||||
AllClients.Add(client);
|
||||
try {
|
||||
while (client.Connected) {
|
||||
await client.Receive();
|
||||
@ -59,6 +63,7 @@ public class Server {
|
||||
} finally {
|
||||
try {
|
||||
client.SetRoom(null);
|
||||
AllClients.Remove(client);
|
||||
} catch (Exception) { }
|
||||
client.Disconnect();
|
||||
Console.WriteLine("Socket disconnected IID: " + client.ClientID);
|
||||
|
@ -25,15 +25,18 @@
|
||||
"// 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')",
|
||||
"// alert types": "1 - Red Alert, 2 - Disco Alert, 3 - Dance Off",
|
||||
"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] ],
|
||||
"JunkYardEMD": [ ["1", 20.0, 240, 300, 60, 0] ],
|
||||
"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 ] ],
|
||||
"JunkYardEMD": [ [ "1", 20.0, 240, 300, 60, 0 ] ]
|
||||
},
|
||||
|
||||
"// AmbassadorRooms": "Rooms with ambassadors (MB funzones).",
|
||||
"AmbassadorRooms": ["Spaceport"],
|
||||
"AmbassadorRooms": [ "Spaceport" ],
|
||||
|
||||
"// AmbassadorGaugeStart": "The starting value for all ambassador gauges (MB funzones).",
|
||||
"AmbassadorGaugeStart": 75,
|
||||
@ -61,7 +64,7 @@
|
||||
"// Authentication Optional": "authentication is required only for moderation activities",
|
||||
"// Authentication RequiredForChat": "authentication is required only for moderation activities and using chat (if chat is enabled)",
|
||||
"// Authentication Required": "authentication is required to connect to mmo",
|
||||
"Authentication": "Required",
|
||||
"Authentication": "RequiredForChat",
|
||||
|
||||
"// ApiUrl": "SoDOff API server URL for authentication calls and other calls",
|
||||
"ApiUrl": "http://localhost:5000",
|
||||
|
Loading…
x
Reference in New Issue
Block a user