From f7025ed27c891c26c03e7ada9a337105c03167c7 Mon Sep 17 00:00:00 2001 From: Mili Date: Sat, 11 Mar 2023 21:07:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0RoomList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunGame.Server/Main.cs | 1 + FunGame.Server/Model/ServerModel.cs | 12 ++++++++---- FunGame.Server/Others/Config.cs | 2 ++ FunGame.Server/Utility/Utility.cs | 4 +--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/FunGame.Server/Main.cs b/FunGame.Server/Main.cs index 5879a4c..1e5f230 100644 --- a/FunGame.Server/Main.cs +++ b/FunGame.Server/Main.cs @@ -84,6 +84,7 @@ void StartServer() ListeningSocket = ServerSocket.StartListening(); // 开始监听连接 + Config.RoomList = new(ListeningSocket); ServerHelper.WriteLine("Listen -> " + Config.ServerPort); ServerHelper.WriteLine("服务器启动成功,开始监听 . . ."); diff --git a/FunGame.Server/Model/ServerModel.cs b/FunGame.Server/Model/ServerModel.cs index 8a3365c..deffa2c 100644 --- a/FunGame.Server/Model/ServerModel.cs +++ b/FunGame.Server/Model/ServerModel.cs @@ -32,13 +32,13 @@ namespace Milimoe.FunGame.Server.Model private Task? _Task = null; private string _ClientName = ""; - private Guid Token = Guid.Empty; private Guid CheckLoginKey = Guid.Empty; private string RegVerify = ""; private int FailedTimes = 0; // 超过一定次数断开连接 private string UserName = ""; private string Password = ""; private string RoomID = ""; + private readonly Guid Token; private readonly ServerSocket Server; private readonly MySQLHelper SQLHelper; private readonly MailSender? MailSender; @@ -298,7 +298,12 @@ namespace Milimoe.FunGame.Server.Model return Send(socket, type, false, msg); case SocketMessageType.UpdateRoom: - break; + List list = new(); + if (Config.RoomList != null) + { + list = Config.RoomList.GetList(); + } + return Send(socket, type, list); case SocketMessageType.CreateRoom: break; @@ -409,8 +414,7 @@ namespace Milimoe.FunGame.Server.Model private void GetUsersCount() { - ServerHelper.WriteLine($"目前在线客户端数量: {Config.OnlinePlayersCount}"); - ServerHelper.WriteLine($"目前在线玩家数量: {Server.UsersCount}"); + ServerHelper.WriteLine($"目前在线客户端数量: {Config.OnlinePlayersCount}(已登录的玩家数量:{Server.UsersCount})"); } private void CreateStreamReader() diff --git a/FunGame.Server/Others/Config.cs b/FunGame.Server/Others/Config.cs index 8d62781..aa916d9 100644 --- a/FunGame.Server/Others/Config.cs +++ b/FunGame.Server/Others/Config.cs @@ -1,6 +1,7 @@ using System.Text; using System.Collections; using Milimoe.FunGame.Core.Library.Constant; +using Milimoe.FunGame.Core.Library.Server; namespace Milimoe.FunGame.Server.Others { @@ -21,6 +22,7 @@ namespace Milimoe.FunGame.Server.Others 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; } } public static class OfficialEmail diff --git a/FunGame.Server/Utility/Utility.cs b/FunGame.Server/Utility/Utility.cs index 22874fc..c237612 100644 --- a/FunGame.Server/Utility/Utility.cs +++ b/FunGame.Server/Utility/Utility.cs @@ -1,10 +1,8 @@ using System.Collections; -using MySql.Data.MySqlClient; using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Server.Others; using Milimoe.FunGame.Core.Api.Transmittal; -using System.Xml.Linq; namespace Milimoe.FunGame.Server.Utility { @@ -12,7 +10,7 @@ namespace Milimoe.FunGame.Server.Utility { public static string GetPrefix() { - DateTime now = System.DateTime.Now; + DateTime now = DateTime.Now; return now.AddMilliseconds(-now.Millisecond).ToString() + " " + Config.ServerName + ":"; }