mirror of
https://github.com/SoDOff-Project/sodoff-mmo.git
synced 2025-10-11 08:18:49 -07:00
add Optional Authentication mode
this allow run managment command (after authentication) on open mmo servers (with player from external api servers)
This commit is contained in:
parent
87a199fc19
commit
dcb0644af4
@ -32,8 +32,10 @@ class ChatMessageHandler : CommandHandler {
|
||||
}
|
||||
|
||||
public void Chat(Client client, string message) {
|
||||
if (Configuration.ServerConfiguration.Authentication && client.PlayerData.DiplayName == "placeholder")
|
||||
if (Configuration.ServerConfiguration.Authentication >= AuthenticationMode.RequiredForChat && client.PlayerData.DiplayName == "placeholder") {
|
||||
client.Send(Utils.BuildServerSideMessage("You must be authenticated to use the chat", "Server"));
|
||||
return;
|
||||
}
|
||||
|
||||
client.Room.Send(Utils.BuildChatMessage(client.PlayerData.Uid, message, client.PlayerData.DiplayName), client);
|
||||
|
||||
|
@ -72,9 +72,10 @@ class LoginHandler : CommandHandler
|
||||
}
|
||||
|
||||
private bool ValidToken(Client client) {
|
||||
if (!Configuration.ServerConfiguration.Authentication ||
|
||||
if (Configuration.ServerConfiguration.Authentication == AuthenticationMode.Disabled ||
|
||||
(client.PlayerData.UNToken == Configuration.ServerConfiguration.BypassToken && !string.IsNullOrEmpty(Configuration.ServerConfiguration.BypassToken)))
|
||||
return true;
|
||||
|
||||
try {
|
||||
HttpClient httpClient = new();
|
||||
var content = new FormUrlEncodedContent(
|
||||
@ -87,7 +88,7 @@ class LoginHandler : CommandHandler
|
||||
string? responseString = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
return false;
|
||||
throw new Exception($"Response status code {response.StatusCode}");
|
||||
if (responseString == null)
|
||||
throw new Exception("Response string null");
|
||||
|
||||
@ -100,6 +101,6 @@ class LoginHandler : CommandHandler
|
||||
} catch (Exception ex) {
|
||||
Console.WriteLine($"Authentication exception IID: {client.ClientID} - {ex}");
|
||||
}
|
||||
return false;
|
||||
return Configuration.ServerConfiguration.Authentication != AuthenticationMode.Required; // return true on auth err if not Required mode
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ internal static class Configuration {
|
||||
|
||||
ServerConfiguration = serverConfiguration;
|
||||
if (string.IsNullOrEmpty(ServerConfiguration.ApiUrl)) {
|
||||
ServerConfiguration.Authentication = false;
|
||||
ServerConfiguration.Authentication = AuthenticationMode.Disabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -37,7 +37,11 @@ internal sealed class ServerConfiguration {
|
||||
public int PingDelay { get; set; } = 17;
|
||||
public bool EnableChat { get; set; } = true;
|
||||
public bool AllowChaos { get; set; } = false;
|
||||
public bool Authentication { get; set; } = false;
|
||||
public AuthenticationMode Authentication { get; set; } = AuthenticationMode.Disabled;
|
||||
public string ApiUrl { get; set; } = "";
|
||||
public string BypassToken { get; set; } = "";
|
||||
}
|
||||
|
||||
public enum AuthenticationMode {
|
||||
Disabled, Optional, RequiredForChat, Required
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class ManagementCommandProcessor {
|
||||
static bool initialized = false;
|
||||
|
||||
public static void Initialize() {
|
||||
if (!Configuration.ServerConfiguration.Authentication)
|
||||
if (Configuration.ServerConfiguration.Authentication == AuthenticationMode.Disabled)
|
||||
return;
|
||||
commands.Clear();
|
||||
var handlerTypes = Assembly.GetExecutingAssembly().GetTypes()
|
||||
@ -28,7 +28,7 @@ public class ManagementCommandProcessor {
|
||||
}
|
||||
|
||||
public static bool ProcessCommand(string message, Client client) {
|
||||
if (!Configuration.ServerConfiguration.Authentication || !initialized)
|
||||
if (!initialized)
|
||||
return false;
|
||||
if (!message.StartsWith("::") || message.Length < 3)
|
||||
return false;
|
||||
|
@ -25,6 +25,19 @@
|
||||
"RacingMinPlayers": 2,
|
||||
|
||||
"// AllowChaos": "disable server side exploit protection",
|
||||
"AllowChaos": false
|
||||
"AllowChaos": false,
|
||||
|
||||
"// Authentication": "Player authentication mode: Disabled, Optional, RequiredForChat, Required",
|
||||
"// Authentication Disabled": "authentication is disabled, anyone can connect to mmo",
|
||||
"// 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": "Disabled",
|
||||
|
||||
"// ApiUrl": "SoDOff API server URL for authentication calls",
|
||||
"ApiUrl": "http://localhost:5000",
|
||||
|
||||
"// BypassToken": "Token allowed to connect without authentication",
|
||||
"BypassToken": ""
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user