From 8db0dd9fa1c5af5f9254bc266f0fbb097e38c30a Mon Sep 17 00:00:00 2001 From: Mili Date: Sun, 12 Mar 2023 11:54:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0BannedList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunGame.Server/Main.cs | 12 +++++++++++- FunGame.Server/Others/Config.cs | 2 +- FunGame.Server/Utility/Utility.cs | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/FunGame.Server/Main.cs b/FunGame.Server/Main.cs index 1e5f230..17683d4 100644 --- a/FunGame.Server/Main.cs +++ b/FunGame.Server/Main.cs @@ -84,6 +84,7 @@ void StartServer() ListeningSocket = ServerSocket.StartListening(); // 开始监听连接 + AddBannedList(ListeningSocket); Config.RoomList = new(ListeningSocket); ServerHelper.WriteLine("Listen -> " + Config.ServerPort); ServerHelper.WriteLine("服务器启动成功,开始监听 . . ."); @@ -110,7 +111,7 @@ void StartServer() } Config.ConnectingPlayersCount++; ServerHelper.WriteLine(SocketHelper.MakeClientName(ClientIPAddress) + " 正在连接服务器 . . ."); - if (Config.BannedList.ContainsKey(ClientIPAddress)) + if (ListeningSocket.BannedList.Contains(ClientIPAddress)) { SendRefuseConnect(socket, "服务器已拒绝黑名单用户连接。"); ServerHelper.WriteLine("检测到 " + SocketHelper.MakeClientName(ClientIPAddress) + " 为黑名单用户,已禁止其连接!"); @@ -212,4 +213,13 @@ SQLResult TestSQLConnection() { new MySQLHelper(ServerLoginLogs.Insert_ServerLoginLogs(Config.ServerName, Config.ServerKey)).Execute(out SQLResult TestResult); return TestResult; +} + +void AddBannedList(ServerSocket server) +{ + string[] bans = Config.ServerBannedList.Split(','); + foreach (string banned in bans) + { + server.BannedList.Add(banned); + } } \ No newline at end of file diff --git a/FunGame.Server/Others/Config.cs b/FunGame.Server/Others/Config.cs index aa916d9..088d22f 100644 --- a/FunGame.Server/Others/Config.cs +++ b/FunGame.Server/Others/Config.cs @@ -14,6 +14,7 @@ namespace Milimoe.FunGame.Server.Others public static string ServerPassword { get; set; } = ""; // 服务器的密码 public static string ServerDescription { get; set; } = ""; // 服务器的描述 public static string ServerKey { get; set; } = ""; // 注册社区服务器的Key + public static string ServerBannedList { get; set; } = ""; // 禁止连接的黑名单 public static int MaxPlayers { get; set; } = 20; // 最多接受连接的玩家数量 public static int MaxConnectionFaileds { get; set; } = 5; // 最大连接失败次数 public static int OnlinePlayersCount { get; set; } = 0; // 已连接的玩家数量 @@ -21,7 +22,6 @@ namespace Milimoe.FunGame.Server.Others public static Encoding DefaultEncoding { get; } = General.DefaultEncoding; // 默认传输字符集 public static FunGameInfo.FunGame FunGameType { get; } = FunGameInfo.FunGame.FunGame_Server; public static Hashtable OrderList { get; } = new(); - public static Hashtable BannedList { get; } = new(); public static RoomList? RoomList { get; set; } } diff --git a/FunGame.Server/Utility/Utility.cs b/FunGame.Server/Utility/Utility.cs index c237612..7d6df08 100644 --- a/FunGame.Server/Utility/Utility.cs +++ b/FunGame.Server/Utility/Utility.cs @@ -40,6 +40,7 @@ namespace Milimoe.FunGame.Server.Utility settings.Add("Notice", INIHelper.ReadINI("Server", "Notice")); settings.Add("Key", INIHelper.ReadINI("Server", "Key")); settings.Add("Status", Convert.ToInt32(INIHelper.ReadINI("Server", "Status"))); + settings.Add("BannedList", INIHelper.ReadINI("Server", "BannedList")); settings.Add("OfficialMail", INIHelper.ReadINI("ServerMail", "OfficialMail")); settings.Add("SupportMail", INIHelper.ReadINI("ServerMail", "SupportMail")); settings.Add("Port", Convert.ToInt32(INIHelper.ReadINI("Socket", "Port"))); @@ -61,19 +62,26 @@ namespace Milimoe.FunGame.Server.Utility string? Describe = (string?)settings["Describe"]; string? Notice = (string?)settings["Notice"]; string? Key = (string?)settings["Key"]; + string? BannedList = (string?)settings["BannedList"]; + if (Name != null) Config.ServerName = Name; if (Password != null) Config.ServerPassword = Password; if (Describe != null) Config.ServerDescription = Describe; if (Notice != null) Config.ServerNotice = Notice; if (Key != null) Config.ServerKey = Key; + if (BannedList != null) Config.ServerBannedList = BannedList; + string? OfficialMail = (string?)settings["OfficialMail"]; string? SupportMail = (string?)settings["SupportMail"]; + if (OfficialMail != null) OfficialEmail.Email = OfficialMail; if (SupportMail != null) OfficialEmail.SupportEmail = SupportMail; + int? Status = (int?)settings["Status"]; int? Port = (int?)settings["Port"]; int? MaxPlayer = (int?)settings["MaxPlayer"]; int? MaxConnectFailed = (int?)settings["MaxConnectFailed"]; + if (Status != null) Config.ServerStatus = (int)Status; if (Port != null) Config.ServerPort = (int)Port; if (MaxPlayer != null) Config.MaxPlayers = (int)MaxPlayer;