From c3d1909bc64c8d5202b037a3a102b4bdfbc68a97 Mon Sep 17 00:00:00 2001 From: Mili Date: Mon, 21 Nov 2022 23:53:09 +0800 Subject: [PATCH] update with core --- FunGame.Implement/FunGame.Implement.csproj | 1 + FunGame.Server/Controller/ServerController.cs | 12 +++++ FunGame.Server/FunGame.Server.csproj | 5 +- FunGame.Server/Main.cs | 10 ++-- .../Model/{ClientSocket.cs => ServerModel.cs} | 8 ++-- FunGame.Server/Others/Config.cs | 48 +++++++++++++++++++ FunGame.Server/Others/Config/Config.cs | 48 ------------------- .../Others/{Config => }/OrderDictionary.cs | 0 FunGame.Server/Utility/Utility.cs | 2 +- 9 files changed, 72 insertions(+), 62 deletions(-) create mode 100644 FunGame.Server/Controller/ServerController.cs rename FunGame.Server/Model/{ClientSocket.cs => ServerModel.cs} (98%) create mode 100644 FunGame.Server/Others/Config.cs delete mode 100644 FunGame.Server/Others/Config/Config.cs rename FunGame.Server/Others/{Config => }/OrderDictionary.cs (100%) diff --git a/FunGame.Implement/FunGame.Implement.csproj b/FunGame.Implement/FunGame.Implement.csproj index 8979406..7093e97 100644 --- a/FunGame.Implement/FunGame.Implement.csproj +++ b/FunGame.Implement/FunGame.Implement.csproj @@ -12,6 +12,7 @@ C:\milimoe\FunGame\bin 1.0 1.0 + Milimoe.$(MSBuildProjectName.Replace(" ", "_")) diff --git a/FunGame.Server/Controller/ServerController.cs b/FunGame.Server/Controller/ServerController.cs new file mode 100644 index 0000000..6d814aa --- /dev/null +++ b/FunGame.Server/Controller/ServerController.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FunGame.Server.Controller +{ + internal class ServerController + { + } +} diff --git a/FunGame.Server/FunGame.Server.csproj b/FunGame.Server/FunGame.Server.csproj index c8ed7c9..c6c8fe7 100644 --- a/FunGame.Server/FunGame.Server.csproj +++ b/FunGame.Server/FunGame.Server.csproj @@ -15,6 +15,7 @@ 1.0 1.0 FunGameServer + Milimoe.$(MSBuildProjectName.Replace(" ", "_")) @@ -51,8 +52,4 @@ - - - - diff --git a/FunGame.Server/Main.cs b/FunGame.Server/Main.cs index 325e6b7..5824e9d 100644 --- a/FunGame.Server/Main.cs +++ b/FunGame.Server/Main.cs @@ -4,14 +4,14 @@ using System.Text; using System.Text.RegularExpressions; using System; using System.Net.WebSockets; -using Milimoe.FunGame.Server.Others; using Milimoe.FunGame.Server.Utility; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Api.Utility; -using FunGame.Server.Model; +using Milimoe.FunGame.Server.Model; +using Milimoe.FunGame.Server.Others; Console.Title = Config.SERVER_NAME; -Console.WriteLine(FunGameEnum.GetInfo(Config.FunGameType)); +Console.WriteLine(FunGameEnum.GetInfo((FunGameEnum.FunGame)Config.FunGameType)); bool Running = true; Socket? ServerSocket = null; @@ -65,7 +65,7 @@ void StartServer() if (!INIHelper.ExistINIFile()) { ServerHelper.WriteLine("未检测到配置文件,将自动创建配置文件 . . ."); - INIHelper.Init(Config.FunGameType); + INIHelper.Init((FunGameEnum.FunGame)Config.FunGameType); ServerHelper.WriteLine("配置文件FunGame.ini创建成功,请修改该配置文件,然后重启服务器。"); ServerHelper.WriteLine("请输入 help 来获取帮助,输入 quit 关闭服务器。"); return; @@ -114,7 +114,7 @@ void StartServer() ServerHelper.WriteLine("客户端" + clientIPaddress + "连接 . . ."); if (Read(socket, clientIPaddress) && Send(socket, clientIPaddress)) { - ClientSocket cs = new(socket, Running); + ServerModel cs = new(socket, Running); Task t = Task.Factory.StartNew(() => { cs.Start(); diff --git a/FunGame.Server/Model/ClientSocket.cs b/FunGame.Server/Model/ServerModel.cs similarity index 98% rename from FunGame.Server/Model/ClientSocket.cs rename to FunGame.Server/Model/ServerModel.cs index 5ca90f9..c7896c8 100644 --- a/FunGame.Server/Model/ClientSocket.cs +++ b/FunGame.Server/Model/ServerModel.cs @@ -12,12 +12,12 @@ using MySqlX.XDevAPI.Common; using Milimoe.FunGame.Server.Utility; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Api.Utility; -using Milimoe.FunGame.Server.Others; using Milimoe.FunGame.Core.Entity; +using Milimoe.FunGame.Server.Others; -namespace FunGame.Server.Model +namespace Milimoe.FunGame.Server.Model { - public class ClientSocket + public class ServerModel { /** * Public @@ -32,7 +32,7 @@ namespace FunGame.Server.Model */ private User? User = null; - public ClientSocket(Socket socket, bool running) + public ServerModel(Socket socket, bool running) { Socket = socket; Running = running; diff --git a/FunGame.Server/Others/Config.cs b/FunGame.Server/Others/Config.cs new file mode 100644 index 0000000..11715bc --- /dev/null +++ b/FunGame.Server/Others/Config.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Net.Sockets; +using System.Reflection.Metadata; +using System.Text; +using System.Threading.Tasks; +using Milimoe.FunGame.Core.Library.Constant; +using Milimoe.FunGame.Core.Api.Utility; + +namespace Milimoe.FunGame.Server.Others +{ + public static class Config + { + public static string SERVER_NAME { get; set; } = "FunGame Server"; // 服务器名称 + public static int SERVER_PORT { get; set; } = 22222; // 默认端口 + public static int SERVER_STATUS { get; set; } = 1; // 默认状态:1可连接 0不可连接 -1不可用 + public static string SERVER_NOTICE { get; set; } = ""; // 服务器的公告 + public static string SERVER_PASSWORD { get; set; } = ""; // 服务器的密码 + public static string SERVER_DESCRIBE { get; set; } = ""; // 服务器的描述 + public static string SERVER_KEY { get; set; } = ""; // 注册社区服务器的Key + public static int MAX_PLAYERS { get; set; } = 20; // 最多接受连接的玩家数量 + public static int MAX_CONNECTFAILED { get; set; } = 5; // 最大连接失败次数 + public static int ONLINE_PLAYERS { get; set; } = 0; // 已连接的玩家数量 + public static int CONNECTING_PLAYERS { get; set; } = 0; // 正在连接的玩家数量 + public static Encoding DEFAULT_ENCODING { get; } = General.DEFAULT_ENCODING; // 默认传输字符集 + public static int FunGameType { get; } = (int)FunGameEnum.FunGame.FunGame_Server; + + public static Hashtable OrderList { get; } = new(); + + public static Hashtable OnlineClients { get; } = new Hashtable(); + + /// + /// string: 玩家标识ID + /// Task:玩家线程 + /// + public static ConcurrentDictionary OnlinePlayers { get; } = new ConcurrentDictionary(); + + /** + * string:房间号 + * Task:玩家线程 + */ + public static ConcurrentDictionary PlayingPlayers { get; } = new ConcurrentDictionary(); + + } +} diff --git a/FunGame.Server/Others/Config/Config.cs b/FunGame.Server/Others/Config/Config.cs deleted file mode 100644 index 9ada4e6..0000000 --- a/FunGame.Server/Others/Config/Config.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Net.Sockets; -using System.Reflection.Metadata; -using System.Text; -using System.Threading.Tasks; -using Milimoe.FunGame.Core.Library.Constant; -using Milimoe.FunGame.Core.Api.Utility; - -namespace Milimoe.FunGame.Server.Others -{ - public static class Config - { - public static string SERVER_NAME = "FunGame Server"; // 服务器名称 - public static int SERVER_PORT = 22222; // 默认端口 - public static int SERVER_STATUS = 1; // 默认状态:1可连接 0不可连接 -1不可用 - public static string SERVER_NOTICE = ""; // 服务器的公告 - public static string SERVER_PASSWORD = ""; // 服务器的密码 - public static string SERVER_DESCRIBE = ""; // 服务器的描述 - public static string SERVER_KEY = ""; // 注册社区服务器的Key - public static int MAX_PLAYERS = 20; // 最多接受连接的玩家数量 - public static int MAX_CONNECTFAILED = 5; // 最大连接失败次数 - public static int ONLINE_PLAYERS = 0; // 已连接的玩家数量 - public static int CONNECTING_PLAYERS = 0; // 正在连接的玩家数量 - public static Encoding DEFAULT_ENCODING = Encoding.UTF8; // 默认传输字符集 - public static FunGameEnum.FunGame FunGameType = FunGameEnum.FunGame.FunGame_Server; - - public static Hashtable OrderList = new(); - - public static Hashtable OnlineClients = new Hashtable(); - - /// - /// string: 玩家标识ID - /// Task:玩家线程 - /// - public static ConcurrentDictionary OnlinePlayers = new ConcurrentDictionary(); - - /** - * string:房间号 - * Task:玩家线程 - */ - public static ConcurrentDictionary PlayingPlayers= new ConcurrentDictionary(); - - } -} diff --git a/FunGame.Server/Others/Config/OrderDictionary.cs b/FunGame.Server/Others/OrderDictionary.cs similarity index 100% rename from FunGame.Server/Others/Config/OrderDictionary.cs rename to FunGame.Server/Others/OrderDictionary.cs diff --git a/FunGame.Server/Utility/Utility.cs b/FunGame.Server/Utility/Utility.cs index 9c90bbb..cff974f 100644 --- a/FunGame.Server/Utility/Utility.cs +++ b/FunGame.Server/Utility/Utility.cs @@ -7,8 +7,8 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using Milimoe.FunGame.Core.Api.Utility; -using Milimoe.FunGame.Server.Others; using Milimoe.FunGame.Core.Entity; +using Milimoe.FunGame.Server.Others; namespace Milimoe.FunGame.Server.Utility {