diff --git a/FunGame.Core/Api/Data/SQLHelper.cs b/FunGame.Core/Api/Data/SQLHelper.cs index f76dfaf..b09707d 100644 --- a/FunGame.Core/Api/Data/SQLHelper.cs +++ b/FunGame.Core/Api/Data/SQLHelper.cs @@ -7,10 +7,13 @@ using System.Threading.Tasks; using Milimoe.FunGame.Core.Interface.Base; using Milimoe.FunGame.Core.Library.Common.Network; using Milimoe.FunGame.Core.Library.Constant; -using Milimoe.FunGame.Core.Service; namespace Milimoe.FunGame.Core.Api.Data { + /// + /// 需要在Server中继承此类实现。 + /// Milimoe.FunGame.Core.Service.SQLManager也是 + /// public class SQLHelper : ISQLHelper { public string Script { get; set; } = ""; @@ -39,17 +42,9 @@ namespace Milimoe.FunGame.Core.Api.Data this.UpdateRows = rows; } - public SQLResult Execute() + public virtual SQLResult Execute() { - switch (EntityType) - { - case EntityType.NotEntity: - SQLManager SQLManager = new(this); - return SQLManager.Execute(Script); - default: - break; - } - return Result; + return SQLResult.NotFound; } } } diff --git a/FunGame.Core/Api/Utility/Singleton.cs b/FunGame.Core/Api/Utility/Singleton.cs index 104affe..8a2e908 100644 --- a/FunGame.Core/Api/Utility/Singleton.cs +++ b/FunGame.Core/Api/Utility/Singleton.cs @@ -15,11 +15,22 @@ namespace Milimoe.FunGame.Core.Api.Utility { private static readonly Hashtable SingletonTable = new(); - public static bool IsExist(string key) + /// + /// 查询目标的类是否已经有实例 + /// + /// 单例对象 + /// + public static bool IsExist(object single) { - return SingletonTable.ContainsKey(key); + return SingletonTable.ContainsKey(single.GetType().ToString()); } + /// + /// 将目标和目标的类添加至单例表 + /// + /// 单例对象 + /// + /// 添加单例到单例表时遇到错误 public static bool Add(object single) { string type = single.GetType().ToString(); @@ -38,6 +49,11 @@ namespace Milimoe.FunGame.Core.Api.Utility return false; } + /// + /// 将目标和目标的类从单例表中移除 + /// + /// 单例对象 + /// public static bool Remove(object single) { string type = single.GetType().ToString(); @@ -52,6 +68,12 @@ namespace Milimoe.FunGame.Core.Api.Utility } } + /// + /// 获取单例对象 + /// + /// 目标类 + /// + /// 不能从单例表中获取到指定的单例 public static T? Get() { T? single = default; @@ -70,15 +92,21 @@ namespace Milimoe.FunGame.Core.Api.Utility } return single; } - - public static object? Get(string key) + + /// + /// 获取单例对象 + /// + /// 目标类 + /// + /// 不能从单例表中获取到指定的单例 + public static object? Get(Type type) { object? single = default; - if (SingletonTable.ContainsKey(key)) + if (SingletonTable.ContainsKey(type)) { try { - single = SingletonTable[key]; + single = SingletonTable[type]; } catch { diff --git a/FunGame.Core/Interface/Base/BaseSQLService.cs b/FunGame.Core/Interface/Base/BaseSQLService.cs deleted file mode 100644 index 3fde255..0000000 --- a/FunGame.Core/Interface/Base/BaseSQLService.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Milimoe.FunGame.Core.Library.Constant; - -namespace Milimoe.FunGame.Core.Interface.Base -{ - internal abstract class BaseSQLService - { - internal abstract SQLResult Execute(); - internal abstract SQLResult Execute(StringBuilder sql); - internal abstract SQLResult Execute(string sql); - internal abstract int Update(StringBuilder sql, ref SQLResult result); - internal abstract int Remove(StringBuilder sql, ref SQLResult result); - internal abstract int Add(StringBuilder sql, ref SQLResult result); - internal abstract int Update(string sql, ref SQLResult result); - internal abstract int Remove(string sql, ref SQLResult result); - internal abstract int Add(string sql, ref SQLResult result); - internal abstract object Query(EntityType type, StringBuilder sql); - internal abstract T Query(StringBuilder sql); - internal abstract object Query(EntityType type, string sql); - internal abstract T Query(string sql); - } -} diff --git a/FunGame.Core/Interface/General/IClient.cs b/FunGame.Core/Interface/General/IClient.cs index b8c1008..4ad5b76 100644 --- a/FunGame.Core/Interface/General/IClient.cs +++ b/FunGame.Core/Interface/General/IClient.cs @@ -1,14 +1,14 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Milimoe.FunGame.Core.Interface +namespace Milimoe.FunGame.Core.Interface { public interface IClient { + public string FunGameIcon { get; } + public string FunGameBackGround { get; } + public string FunGameMainMusic { get; } + public string FunGameMusic1 { get; } + public string FunGameMusic2 { get; } + public string FunGameMusic3 { get; } + public string RemoteServerIP(); } } diff --git a/FunGame.Core/Library/Constant/ConstantSet.cs b/FunGame.Core/Library/Constant/ConstantSet.cs index 1f1eaac..02d9e6d 100644 --- a/FunGame.Core/Library/Constant/ConstantSet.cs +++ b/FunGame.Core/Library/Constant/ConstantSet.cs @@ -29,6 +29,7 @@ namespace Milimoe.FunGame.Core.Library.Constant public const int MaxConnection_General = 20; public const int MaxConnection_4C4G = 40; + public const string Socket = "Socket"; public const string Unknown = "Unknown"; public const string Connect = "Connect"; public const string GetNotice = "GetNotice"; diff --git a/FunGame.Core/Library/Constant/General.cs b/FunGame.Core/Library/Constant/General.cs index e1c5df6..4eb3e31 100644 --- a/FunGame.Core/Library/Constant/General.cs +++ b/FunGame.Core/Library/Constant/General.cs @@ -11,7 +11,7 @@ namespace Milimoe.FunGame.Core.Library.Constant { // Static Variable public static Empty EntityInstance { get; } = new(); - public static Encoding DEFAULT_ENCODING { get; } = Encoding.UTF8; + public static Encoding DefaultEncoding { get; } = Encoding.UTF8; // Const public const int MaxRetryTimes = 20; diff --git a/FunGame.Core/Library/Constant/TypeEnum.cs b/FunGame.Core/Library/Constant/TypeEnum.cs index 72d6b03..d1912e0 100644 --- a/FunGame.Core/Library/Constant/TypeEnum.cs +++ b/FunGame.Core/Library/Constant/TypeEnum.cs @@ -131,8 +131,7 @@ namespace Milimoe.FunGame.Core.Library.Constant PassiveSkill, GameStatistics, Character, - CharacterStatistics, - NotEntity + CharacterStatistics } public enum TimeType diff --git a/FunGame.Core/Service/SQLManager.cs b/FunGame.Core/Service/SQLManager.cs index 59c9f14..c7999f6 100644 --- a/FunGame.Core/Service/SQLManager.cs +++ b/FunGame.Core/Service/SQLManager.cs @@ -5,12 +5,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Milimoe.FunGame.Core.Api.Data; -using Milimoe.FunGame.Core.Interface.Base; using Milimoe.FunGame.Core.Library.Constant; namespace Milimoe.FunGame.Core.Service { - internal class SQLManager : BaseSQLService + /// + /// 需要在Server中继承此类实现 + /// + public class SQLManager { internal SQLHelper SQLHelper { get; } @@ -19,69 +21,69 @@ namespace Milimoe.FunGame.Core.Service this.SQLHelper = SQLHelper; } - internal override int Add(StringBuilder sql, ref SQLResult result) + protected virtual int Add(StringBuilder sql, ref SQLResult result) { - throw new NotImplementedException(); + return 0; } - internal override int Add(string sql, ref SQLResult result) + protected virtual int Add(string sql, ref SQLResult result) { - throw new NotImplementedException(); + return 0; } - internal override SQLResult Execute() + protected virtual SQLResult Execute() { - throw new NotImplementedException(); + return SQLResult.NotFound; } - internal override SQLResult Execute(StringBuilder sql) + protected virtual SQLResult Execute(StringBuilder sql) { - throw new NotImplementedException(); + return SQLResult.NotFound; } - internal override SQLResult Execute(string sql) + protected virtual SQLResult Execute(string sql) { - throw new NotImplementedException(); + return SQLResult.NotFound; } - internal override object Query(EntityType type, StringBuilder sql) + protected virtual object Query(EntityType type, StringBuilder sql) { - throw new NotImplementedException(); + return General.EntityInstance; } - internal override T Query(StringBuilder sql) + protected virtual T? Query(StringBuilder sql) { - throw new NotImplementedException(); + return default; } - internal override object Query(EntityType type, string sql) + protected virtual object Query(EntityType type, string sql) { - throw new NotImplementedException(); + return General.EntityInstance; } - internal override T Query(string sql) + protected virtual T? Query(string sql) { - throw new NotImplementedException(); + return default; } - internal override int Remove(StringBuilder sql, ref SQLResult result) + protected virtual int Remove(StringBuilder sql, ref SQLResult result) { - throw new NotImplementedException(); + return 0; } - internal override int Remove(string sql, ref SQLResult result) + protected virtual int Remove(string sql, ref SQLResult result) { - throw new NotImplementedException(); + return 0; } - internal override int Update(StringBuilder sql, ref SQLResult result) + protected virtual int Update(StringBuilder sql, ref SQLResult result) { - throw new NotImplementedException(); + return 0; } - internal override int Update(string sql, ref SQLResult result) + protected virtual int Update(string sql, ref SQLResult result) { - throw new NotImplementedException(); + return 0; } } } diff --git a/FunGame.Core/Service/SocketManager.cs b/FunGame.Core/Service/SocketManager.cs index 8c90e1b..ce45e66 100644 --- a/FunGame.Core/Service/SocketManager.cs +++ b/FunGame.Core/Service/SocketManager.cs @@ -134,7 +134,7 @@ namespace Milimoe.FunGame.Core.Service { if (ClientSocket != null && objs != null && objs.Length > 0) { - if (ClientSocket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0) + if (ClientSocket.Send(General.DefaultEncoding.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0) { return SocketResult.Success; } @@ -157,7 +157,7 @@ namespace Milimoe.FunGame.Core.Service } if (Socket != null) { - if (Socket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0) + if (Socket.Send(General.DefaultEncoding.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0) { return SocketResult.Success; } @@ -180,7 +180,7 @@ namespace Milimoe.FunGame.Core.Service int length = Socket.Receive(buffer); if (length > 0) { - string msg = General.DEFAULT_ENCODING.GetString(buffer, 0, length); + string msg = General.DefaultEncoding.GetString(buffer, 0, length); Library.Common.Network.JsonObject? json = Library.Common.Network.JsonObject.GetObject(msg); if (json != null) { @@ -207,7 +207,7 @@ namespace Milimoe.FunGame.Core.Service int length = ClientSocket.Receive(buffer); if (length > 0) { - string msg = General.DEFAULT_ENCODING.GetString(buffer, 0, length); + string msg = General.DefaultEncoding.GetString(buffer, 0, length); Library.Common.Network.JsonObject? json = Library.Common.Network.JsonObject.GetObject(msg); if (json != null) { diff --git a/FunGame.Desktop/Controller/LoginController.cs b/FunGame.Desktop/Controller/LoginController.cs index 4e8138c..b16462a 100644 --- a/FunGame.Desktop/Controller/LoginController.cs +++ b/FunGame.Desktop/Controller/LoginController.cs @@ -3,10 +3,24 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Milimoe.FunGame.Desktop.Library.Interface; +using Milimoe.FunGame.Desktop.Model; +using Milimoe.FunGame.Desktop.UI; namespace Milimoe.FunGame.Desktop.Controller { - public class LoginController + public class LoginController : ILogin { + LoginModel LoginModel { get; } + + public LoginController(Login Login) + { + LoginModel = new LoginModel(Login); + } + + public bool LoginAccount() + { + return LoginModel.LoginAccount(); + } } } diff --git a/FunGame.Desktop/Controller/MainController.cs b/FunGame.Desktop/Controller/MainController.cs index 001aa8e..10c9a15 100644 --- a/FunGame.Desktop/Controller/MainController.cs +++ b/FunGame.Desktop/Controller/MainController.cs @@ -7,23 +7,29 @@ using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Library.Common.Event; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Exception; +using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library.Component; +using Milimoe.FunGame.Desktop.Library.Interface; using Milimoe.FunGame.Desktop.Model; -using Milimoe.FunGame.Desktop.Others; using Milimoe.FunGame.Desktop.UI; namespace Milimoe.FunGame.Desktop.Controller { - public class MainController + public class MainController : IMain { private MainModel MainModel { get; } + public bool Connected => Do(MainControllerSet.Connected); + public MainController(Main Main) { MainModel = new MainModel(Main); } - public T Do(string DoType) + /** + * 从内部去调用Model的方法,并记录日志。 + */ + private T Do(string DoType) { object result = new(); switch(DoType) @@ -35,8 +41,7 @@ namespace Milimoe.FunGame.Desktop.Controller result = MainModel.Connect(); break; case MainControllerSet.Connected: - if (MainModel.Socket is null) result = false; - else result = MainModel.Socket.Connected; + result = MainModel.Connected; break; case MainControllerSet.Disconnect: MainModel.Disconnect(); @@ -61,9 +66,6 @@ namespace Milimoe.FunGame.Desktop.Controller case MainControllerSet.LogOut: result = MainModel.Logout(); break; - case MainControllerSet.LogIn: - result = MainModel.Login(); - break; case MainControllerSet.Close: result = MainModel.Close(); break; @@ -72,5 +74,70 @@ namespace Milimoe.FunGame.Desktop.Controller } return (T)result; } + + public bool GetServerConnection() + { + return Do(MainControllerSet.GetServerConnection); + } + + public ConnectResult Connect() + { + return Do(MainControllerSet.Connect); + } + + public void Disconnect() + { + Do(MainControllerSet.Disconnect); + } + + public void Disconnected() + { + Do(MainControllerSet.Disconnected); + } + + public void SetWaitConnectAndSetYellow() + { + throw new NotImplementedException(); + } + + public void SetWaitLoginAndSetYellow() + { + throw new NotImplementedException(); + } + + public void SetGreenAndPing() + { + throw new NotImplementedException(); + } + + public void SetGreen() + { + throw new NotImplementedException(); + } + + public void SetYellow() + { + throw new NotImplementedException(); + } + + public void SetRed() + { + throw new NotImplementedException(); + } + + public void SetUser() + { + throw new NotImplementedException(); + } + + public bool LogOut() + { + return Do(MainControllerSet.LogOut); + } + + public bool Close() + { + return Do(MainControllerSet.Close); + } } } diff --git a/FunGame.Desktop/Controller/RegisterController.cs b/FunGame.Desktop/Controller/RegisterController.cs index 03e4c5d..ae7fb2f 100644 --- a/FunGame.Desktop/Controller/RegisterController.cs +++ b/FunGame.Desktop/Controller/RegisterController.cs @@ -3,10 +3,24 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Milimoe.FunGame.Desktop.Library.Interface; +using Milimoe.FunGame.Desktop.Model; +using Milimoe.FunGame.Desktop.UI; namespace Milimoe.FunGame.Desktop.Controller { - public class RegisterController + public class RegisterController : IReg { + RegisterModel RegisterModel { get; } + + public RegisterController(Register Register) + { + RegisterModel = new RegisterModel(Register); + } + + public bool Reg() + { + return RegisterModel.Reg(); + } } } diff --git a/FunGame.Desktop/Others/Config.cs b/FunGame.Desktop/Library/Config/Config.cs similarity index 89% rename from FunGame.Desktop/Others/Config.cs rename to FunGame.Desktop/Library/Config/Config.cs index 44dfbf2..5e4e688 100644 --- a/FunGame.Desktop/Others/Config.cs +++ b/FunGame.Desktop/Library/Config/Config.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Milimoe.FunGame.Desktop.Others +namespace Milimoe.FunGame.Desktop.Library { public class Config { @@ -23,5 +23,8 @@ namespace Milimoe.FunGame.Desktop.Others public static string FunGame_Roomid { get; set; } = "-1"; // 房间号 public static string FunGame_ServerName { get; set; } = ""; // 服务器名称 public static string FunGame_Notice { get; set; } = ""; // 公告 + + /*** GUID For Socket ***/ + public static Guid Guid_Socket { get; set; } = Guid.Empty; } } diff --git a/FunGame.Desktop/Others/Constant.cs b/FunGame.Desktop/Library/Config/Constant.cs similarity index 90% rename from FunGame.Desktop/Others/Constant.cs rename to FunGame.Desktop/Library/Config/Constant.cs index d3ffbae..fbf81f3 100644 --- a/FunGame.Desktop/Others/Constant.cs +++ b/FunGame.Desktop/Library/Config/Constant.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Library.Constant; -namespace Milimoe.FunGame.Desktop.Others +namespace Milimoe.FunGame.Desktop.Library { public class MainControllerSet { @@ -28,6 +28,11 @@ namespace Milimoe.FunGame.Desktop.Others public const string Close = ".close"; } + public class RunTime + { + public static Core.Library.Common.Network.Socket? Socket { get; set; } = null; + } + public class Constant { /** @@ -38,9 +43,9 @@ namespace Milimoe.FunGame.Desktop.Others /** * Socket Configs */ - public static string SERVER_IPADRESS { get; set; } = ""; // 服务器IP地址 - public static int SERVER_PORT { get; set; } = 0; // 服务器端口号 - public static Encoding DEFAULT_ENCODING { get; } = Core.Library.Constant.General.DEFAULT_ENCODING; + public static string Server_Address { get; set; } = ""; // 服务器IP地址 + public static int Server_Port { get; set; } = 0; // 服务器端口号 + public static Encoding Default_Encoding { get; } = General.DefaultEncoding; /** * FunGame Configs diff --git a/FunGame.Desktop/Others/Usercfg.cs b/FunGame.Desktop/Library/Config/Usercfg.cs similarity index 90% rename from FunGame.Desktop/Others/Usercfg.cs rename to FunGame.Desktop/Library/Config/Usercfg.cs index d679971..693d819 100644 --- a/FunGame.Desktop/Others/Usercfg.cs +++ b/FunGame.Desktop/Library/Config/Usercfg.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using Milimoe.FunGame.Core.Entity; -namespace Milimoe.FunGame.Desktop.Others +namespace Milimoe.FunGame.Desktop.Library { public class Usercfg { diff --git a/FunGame.Desktop/Library/Interface/ILogin.cs b/FunGame.Desktop/Library/Interface/ILogin.cs new file mode 100644 index 0000000..6f478eb --- /dev/null +++ b/FunGame.Desktop/Library/Interface/ILogin.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Milimoe.FunGame.Desktop.Library.Interface +{ + public interface ILogin + { + public bool LoginAccount(); + } +} diff --git a/FunGame.Desktop/Library/Interface/IMain.cs b/FunGame.Desktop/Library/Interface/IMain.cs new file mode 100644 index 0000000..0b9bb67 --- /dev/null +++ b/FunGame.Desktop/Library/Interface/IMain.cs @@ -0,0 +1,23 @@ +using Milimoe.FunGame.Core.Library.Constant; + +namespace Milimoe.FunGame.Desktop.Library.Interface +{ + public interface IMain + { + public bool Connected { get; } + + public bool GetServerConnection(); + public ConnectResult Connect(); + public void Disconnect(); + public void Disconnected(); + public void SetWaitConnectAndSetYellow(); + public void SetWaitLoginAndSetYellow(); + public void SetGreenAndPing(); + public void SetGreen(); + public void SetYellow(); + public void SetRed(); + public void SetUser(); + public bool LogOut(); + public bool Close(); + } +} diff --git a/FunGame.Desktop/Library/Interface/IReg.cs b/FunGame.Desktop/Library/Interface/IReg.cs new file mode 100644 index 0000000..8c20ff8 --- /dev/null +++ b/FunGame.Desktop/Library/Interface/IReg.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Milimoe.FunGame.Desktop.Library.Interface +{ + public interface IReg + { + public bool Reg(); + } +} diff --git a/FunGame.Desktop/Model/LoginModel.cs b/FunGame.Desktop/Model/LoginModel.cs index 8c99e9f..2ea81fb 100644 --- a/FunGame.Desktop/Model/LoginModel.cs +++ b/FunGame.Desktop/Model/LoginModel.cs @@ -3,10 +3,38 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Milimoe.FunGame.Core.Api.Utility; +using Milimoe.FunGame.Core.Library.Constant; +using Milimoe.FunGame.Core.Library.Exception; +using Milimoe.FunGame.Desktop.Library; +using Milimoe.FunGame.Desktop.Library.Interface; +using Milimoe.FunGame.Desktop.UI; namespace Milimoe.FunGame.Desktop.Model { - public class LoginModel + public class LoginModel : ILogin { + private readonly Login Login; + private Core.Library.Common.Network.Socket? Socket; + + public LoginModel(Login login) + { + Login = login; + Socket = RunTime.Socket; + } + + public bool LoginAccount() + { + try + { + if (Socket != null && Socket.Send(SocketMessageType.Login, "Mili", "OK") == SocketResult.Success) + return true; + } + catch (Exception e) + { + e.GetErrorInfo(); + } + return false; + } } } diff --git a/FunGame.Desktop/Model/MainModel.cs b/FunGame.Desktop/Model/MainModel.cs index 4a0c935..5d2e007 100644 --- a/FunGame.Desktop/Model/MainModel.cs +++ b/FunGame.Desktop/Model/MainModel.cs @@ -8,46 +8,26 @@ using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Library.Common.Event; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Exception; -using Milimoe.FunGame.Desktop.Controller; +using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library.Component; -using Milimoe.FunGame.Desktop.Others; +using Milimoe.FunGame.Desktop.Library.Interface; using Milimoe.FunGame.Desktop.UI; namespace Milimoe.FunGame.Desktop.Model { - public class MainModel + public class MainModel : IMain { - public Core.Library.Common.Network.Socket? Socket - { - get - { - return _Socket; - } - } - public Main Main { get; } + public bool Connected => Socket != null && Socket.Connected; + private readonly Main Main; private Task? ReceivingTask; - private Core.Library.Common.Network.Socket? _Socket; + private Core.Library.Common.Network.Socket? Socket; public MainModel(Main main) { Main = main; } - public bool Login() - { - try - { - if (Socket != null && Socket.Send(SocketMessageType.Login, "Mili", "OK") == SocketResult.Success) - return true; - } - catch (Exception e) - { - Main?.GetMessage(e.GetErrorInfo()); - } - return false; - } - public bool Logout() { try @@ -73,6 +53,11 @@ namespace Milimoe.FunGame.Desktop.Model } } + public void Disconnected() + { + Disconnect(); + } + public bool GetServerConnection() { try @@ -84,8 +69,8 @@ namespace Milimoe.FunGame.Desktop.Model string[] s = ipaddress.Split(':'); if (s != null && s.Length > 1) { - Others.Constant.SERVER_IPADRESS = s[0]; - Others.Constant.SERVER_PORT = Convert.ToInt32(s[1]); + Constant.Server_Address = s[0]; + Constant.Server_Port = Convert.ToInt32(s[1]); if (Connect() == ConnectResult.Success) return true; // 连接服务器 } } @@ -106,20 +91,20 @@ namespace Milimoe.FunGame.Desktop.Model public ConnectResult Connect() { - if (Others.Constant.SERVER_IPADRESS == "" || Others.Constant.SERVER_PORT <= 0) + if (Constant.Server_Address == "" || Constant.Server_Port <= 0) { ShowMessage.ErrorMessage("查找可用的服务器失败!"); return ConnectResult.FindServerFailed; } try { - if (Others.Config.FunGame_isRetrying) + if (Config.FunGame_isRetrying) { Main?.GetMessage("正在连接服务器,请耐心等待。"); Config.FunGame_isRetrying = false; return ConnectResult.CanNotConnect; } - if (!Others.Config.FunGame_isConnected) + if (!Config.FunGame_isConnected) { Main!.CurrentRetryTimes++; if (Main!.CurrentRetryTimes == 0) Main!.GetMessage("开始连接服务器...", true, TimeType.General); @@ -131,10 +116,12 @@ namespace Milimoe.FunGame.Desktop.Model } // 与服务器建立连接 Socket?.Close(); - Others.Config.FunGame_isRetrying = true; - _Socket = Core.Library.Common.Network.Socket.Connect(Others.Constant.SERVER_IPADRESS, Others.Constant.SERVER_PORT); + Config.FunGame_isRetrying = true; + Socket = Core.Library.Common.Network.Socket.Connect(Constant.Server_Address, Constant.Server_Port); if (Socket != null && Socket.Connected) { + // 设置可复用Socket + RunTime.Socket = Socket; // 发送连接请求 if (Socket.Send(SocketMessageType.Connect) == SocketResult.Success) { @@ -169,7 +156,7 @@ namespace Milimoe.FunGame.Desktop.Model Task.Run(() => { Thread.Sleep(5000); - if (Others.Config.FunGame_isAutoRetry) Connect(); // 再次判断是否开启自动重连 + if (Config.FunGame_isAutoRetry) Connect(); // 再次判断是否开启自动重连 }); Main?.GetMessage("连接服务器失败,5秒后自动尝试重连。"); } @@ -185,7 +172,7 @@ namespace Milimoe.FunGame.Desktop.Model if (Socket != null) { Socket.Close(); - _Socket = null; + Socket = null; } if (ReceivingTask != null && !ReceivingTask.IsCompleted) { @@ -201,6 +188,46 @@ namespace Milimoe.FunGame.Desktop.Model return true; } + public void SetWaitConnectAndSetYellow() + { + throw new NotImplementedException(); + } + + public void SetWaitLoginAndSetYellow() + { + throw new NotImplementedException(); + } + + public void SetGreenAndPing() + { + throw new NotImplementedException(); + } + + public void SetGreen() + { + throw new NotImplementedException(); + } + + public void SetYellow() + { + throw new NotImplementedException(); + } + + public void SetRed() + { + throw new NotImplementedException(); + } + + public void SetUser() + { + throw new NotImplementedException(); + } + + public bool LogOut() + { + throw new NotImplementedException(); + } + private void StartReceiving() { ReceivingTask = Task.Factory.StartNew(() => @@ -317,6 +344,5 @@ namespace Milimoe.FunGame.Desktop.Model Main?.UpdateUI(MainControllerSet.Disconnect); Close(); } - } } diff --git a/FunGame.Desktop/Model/RegisterModel.cs b/FunGame.Desktop/Model/RegisterModel.cs index 49137a3..fc46040 100644 --- a/FunGame.Desktop/Model/RegisterModel.cs +++ b/FunGame.Desktop/Model/RegisterModel.cs @@ -3,10 +3,27 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Milimoe.FunGame.Core.Api.Utility; +using Milimoe.FunGame.Desktop.Library; +using Milimoe.FunGame.Desktop.Library.Interface; +using Milimoe.FunGame.Desktop.UI; namespace Milimoe.FunGame.Desktop.Model { - public class RegisterModel + public class RegisterModel : IReg { + private readonly Register Register; + private Core.Library.Common.Network.Socket? Socket; + + public RegisterModel(Register register) + { + Register = register; + Socket = RunTime.Socket; + } + + public bool Reg() + { + return true; + } } } diff --git a/FunGame.Desktop/UI/Main/Main.Designer.cs b/FunGame.Desktop/UI/Main/Main.Designer.cs index 97cf0e4..4eed058 100644 --- a/FunGame.Desktop/UI/Main/Main.Designer.cs +++ b/FunGame.Desktop/UI/Main/Main.Designer.cs @@ -1,5 +1,5 @@ +using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library.Component; -using Milimoe.FunGame.Desktop.Others; namespace Milimoe.FunGame.Desktop.UI { diff --git a/FunGame.Desktop/UI/Main/Main.cs b/FunGame.Desktop/UI/Main/Main.cs index 86824ea..27f7f43 100644 --- a/FunGame.Desktop/UI/Main/Main.cs +++ b/FunGame.Desktop/UI/Main/Main.cs @@ -6,8 +6,8 @@ using System.Windows.Forms; using System.Net.NetworkInformation; using System.Text; using Milimoe.FunGame.Core.Api.Utility; +using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library.Component; -using Milimoe.FunGame.Desktop.Others; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Desktop.Controller; using Milimoe.FunGame.Core.Library.Exception; @@ -32,7 +32,6 @@ namespace Milimoe.FunGame.Desktop.UI * 定义全局对象 */ private Task? MatchFunGame = null; // 匹配线程 - //private MainModel? MainModel = null; private MainController? MainController = null; /** @@ -72,7 +71,7 @@ namespace Milimoe.FunGame.Desktop.UI void action() { if (Config.FunGame_isAutoConnect) - MainController.Do(MainControllerSet.GetServerConnection); + MainController.GetServerConnection(); } InvokeUpdateUI(action); }); @@ -99,69 +98,69 @@ namespace Milimoe.FunGame.Desktop.UI { switch (updatetype) { - case Others.MainControllerSet.SetGreen: - Others.Config.FunGame_isRetrying = false; + case MainControllerSet.SetGreen: + Config.FunGame_isRetrying = false; SetServerStatusLight((int)LightType.Green); SetButtonEnableIfLogon(true, ClientState.Online); - Others.Config.FunGame_isConnected = true; + Config.FunGame_isConnected = true; CurrentRetryTimes = 0; break; - case Others.MainControllerSet.SetGreenAndPing: - Others.Config.FunGame_isRetrying = false; - SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(Others.Constant.SERVER_IPADRESS)); + case MainControllerSet.SetGreenAndPing: + Config.FunGame_isRetrying = false; + SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(Constant.Server_Address)); SetButtonEnableIfLogon(true, ClientState.Online); - Others.Config.FunGame_isConnected = true; + Config.FunGame_isConnected = true; CurrentRetryTimes = 0; break; - case Others.MainControllerSet.SetYellow: - Others.Config.FunGame_isRetrying = false; + case MainControllerSet.SetYellow: + Config.FunGame_isRetrying = false; SetServerStatusLight((int)LightType.Yellow); SetButtonEnableIfLogon(false, ClientState.WaitConnect); - Others.Config.FunGame_isConnected = true; + Config.FunGame_isConnected = true; CurrentRetryTimes = 0; break; - case Others.MainControllerSet.WaitConnectAndSetYellow: - Others.Config.FunGame_isRetrying = false; + case MainControllerSet.WaitConnectAndSetYellow: + Config.FunGame_isRetrying = false; SetServerStatusLight((int)LightType.Yellow); SetButtonEnableIfLogon(false, ClientState.WaitConnect); - Others.Config.FunGame_isConnected = true; + Config.FunGame_isConnected = true; CurrentRetryTimes = 0; - if (MainController != null && Others.Config.FunGame_isAutoConnect) + if (MainController != null && Config.FunGame_isAutoConnect) { // 自动连接服务器 - MainController.Do(MainControllerSet.Connected); + MainController.Connect(); } break; - case Others.MainControllerSet.WaitLoginAndSetYellow: - Others.Config.FunGame_isRetrying = false; + case MainControllerSet.WaitLoginAndSetYellow: + Config.FunGame_isRetrying = false; SetServerStatusLight((int)LightType.Yellow, true); SetButtonEnableIfLogon(false, ClientState.WaitLogin); - Others.Config.FunGame_isConnected = true; + Config.FunGame_isConnected = true; CurrentRetryTimes = 0; break; - case Others.MainControllerSet.SetRed: + case MainControllerSet.SetRed: SetServerStatusLight((int)LightType.Red); SetButtonEnableIfLogon(false, ClientState.WaitConnect); - Others.Config.FunGame_isConnected = false; + Config.FunGame_isConnected = false; break; - case Others.MainControllerSet.Disconnected: - Others.Config.FunGame_isRetrying = false; - Others.Config.FunGame_isConnected = false; + case MainControllerSet.Disconnected: + Config.FunGame_isRetrying = false; + Config.FunGame_isConnected = false; SetServerStatusLight((int)LightType.Red); SetButtonEnableIfLogon(false, ClientState.WaitConnect); LogoutAccount(); - if (Others.Config.FunGame_isAutoRetry && CurrentRetryTimes <= MaxRetryTimes) + if (Config.FunGame_isAutoRetry && CurrentRetryTimes <= MaxRetryTimes) { Task.Run(() => { Thread.Sleep(5000); - if (Others.Config.FunGame_isAutoRetry) MainController?.Do(MainControllerSet.Connect); // 再次判断是否开启自动重连 + if (Config.FunGame_isAutoRetry) MainController?.Connect(); // 再次判断是否开启自动重连 }); WritelnSystemInfo("连接服务器失败,5秒后自动尝试重连。"); } @@ -169,50 +168,50 @@ namespace Milimoe.FunGame.Desktop.UI WritelnSystemInfo("无法连接至服务器,请检查你的网络连接。"); break; - case Others.MainControllerSet.Disconnect: - Others.Config.FunGame_isAutoRetry = false; - Others.Config.FunGame_isRetrying = false; - Others.Config.FunGame_isAutoConnect = false; - Others.Config.FunGame_isAutoLogin = false; - Others.Config.FunGame_isConnected = false; + case MainControllerSet.Disconnect: + Config.FunGame_isAutoRetry = false; + Config.FunGame_isRetrying = false; + Config.FunGame_isAutoConnect = false; + Config.FunGame_isAutoLogin = false; + Config.FunGame_isConnected = false; SetServerStatusLight((int)LightType.Yellow); SetButtonEnableIfLogon(false, ClientState.WaitConnect); LogoutAccount(); break; - case Others.MainControllerSet.LogOut: - Others.Config.FunGame_isRetrying = false; - Others.Config.FunGame_isConnected = false; - Others.Config.FunGame_isAutoLogin = false; + case MainControllerSet.LogOut: + Config.FunGame_isRetrying = false; + Config.FunGame_isConnected = false; + Config.FunGame_isAutoLogin = false; SetServerStatusLight((int)LightType.Yellow); SetButtonEnableIfLogon(false, ClientState.WaitConnect); LogoutAccount(); - if (Others.Config.FunGame_isAutoConnect) + if (Config.FunGame_isAutoConnect) { CurrentRetryTimes = -1; Task.Run(() => { Thread.Sleep(1000); - MainController?.Do(MainControllerSet.Connect); + MainController?.Connect(); }); } break; - case Others.MainControllerSet.SetUser: + case MainControllerSet.SetUser: if (objs != null && objs.Length > 1) { SetLoginUser(objs); } break; - case Others.MainControllerSet.Connected: + case MainControllerSet.Connected: Action action = () => { - NoticeText.Text = Others.Config.FunGame_Notice; - if (MainController != null && Others.Config.FunGame_isAutoLogin) + NoticeText.Text = Config.FunGame_Notice; + if (MainController != null && Config.FunGame_isAutoLogin) { - // 自动登录 - MainController.Do(MainControllerSet.LogIn); + // 自动登录 [TODO] + } }; if (InvokeRequired) @@ -229,7 +228,7 @@ namespace Milimoe.FunGame.Desktop.UI catch (Exception e) { WritelnGameInfo(e.GetErrorInfo()); - UpdateUI(Others.MainControllerSet.SetRed); + UpdateUI(MainControllerSet.SetRed); } } InvokeUpdateUI(action); @@ -285,15 +284,15 @@ namespace Milimoe.FunGame.Desktop.UI string isAutoConncet = INIHelper.ReadINI("Config", "AutoConnect"); string isAutoLogin = INIHelper.ReadINI("Config", "AutoLogin"); if (isAutoConncet != null && !isAutoConncet.Equals("") && (isAutoConncet.Equals("false") || isAutoConncet.Equals("true"))) - Others.Config.FunGame_isAutoConnect = Convert.ToBoolean(isAutoConncet); + Config.FunGame_isAutoConnect = Convert.ToBoolean(isAutoConncet); else throw new Exception("读取配置文件出错,参数格式不正确"); if (isAutoLogin != null && !isAutoLogin.Equals("") && (isAutoLogin.Equals("false") || isAutoLogin.Equals("true"))) - Others.Config.FunGame_isAutoLogin = Convert.ToBoolean(isAutoLogin); + Config.FunGame_isAutoLogin = Convert.ToBoolean(isAutoLogin); else throw new Exception("读取配置文件出错,参数格式不正确"); } else { - INIHelper.Init((FunGameInfo.FunGame)Others.Constant.FunGameType); + INIHelper.Init((FunGameInfo.FunGame)Constant.FunGameType); WritelnGameInfo(">> 首次启动,已自动为你创建配置文件。"); GetFunGameConfig(); } @@ -310,12 +309,12 @@ namespace Milimoe.FunGame.Desktop.UI /// private void SetRoomid(string roomid) { - Others.Config.FunGame_Roomid = roomid; + Config.FunGame_Roomid = roomid; if (!roomid.Equals("-1")) { WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 加入房间"); - WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已加入房间 -> [ " + Others.Config.FunGame_Roomid + " ]"); - Room.Text = "[ 当前房间 ]\n" + Convert.ToString(Others.Config.FunGame_Roomid); + WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已加入房间 -> [ " + Config.FunGame_Roomid + " ]"); + Room.Text = "[ 当前房间 ]\n" + Convert.ToString(Config.FunGame_Roomid); } else Room.Text = "暂未进入房间"; @@ -389,7 +388,7 @@ namespace Milimoe.FunGame.Desktop.UI // 显示:匹配、创建房间 // 隐藏:退出房间、房间设定 WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 离开房间"); - WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已离开房间 -> [ " + Others.Config.FunGame_Roomid + " ]"); + WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已离开房间 -> [ " + Config.FunGame_Roomid + " ]"); SetRoomid("-1"); QuitRoom.Visible = false; StartMatch.Visible = true; @@ -419,15 +418,15 @@ namespace Milimoe.FunGame.Desktop.UI { case ClientState.Online: PresetText.Items.Clear(); - PresetText.Items.AddRange(Others.Constant.PresetOnineItems); + PresetText.Items.AddRange(Constant.PresetOnineItems); break; case ClientState.WaitConnect: PresetText.Items.Clear(); - PresetText.Items.AddRange(Others.Constant.PresetNoConnectItems); + PresetText.Items.AddRange(Constant.PresetNoConnectItems); break; case ClientState.WaitLogin: PresetText.Items.Clear(); - PresetText.Items.AddRange(Others.Constant.PresetNoLoginItems); + PresetText.Items.AddRange(Constant.PresetNoLoginItems); break; } this.PresetText.SelectedIndex = 0; @@ -454,7 +453,7 @@ namespace Milimoe.FunGame.Desktop.UI { if (CheckRoomIDExist(roomid)) { - if (Others.Config.FunGame_Roomid.Equals("-1")) + if (Config.FunGame_Roomid.Equals("-1")) { if (ShowMessage.YesNoMessage("已找到房间 -> [ " + roomid + " ]\n是否加入?", "已找到房间") == MessageResult.Yes) { @@ -482,7 +481,7 @@ namespace Milimoe.FunGame.Desktop.UI { if (CheckRoomIDExist(roomid)) { - if (Others.Config.FunGame_Roomid.Equals("-1")) + if (Config.FunGame_Roomid.Equals("-1")) { if (ShowMessage.YesNoMessage("已找到房间 -> [ " + roomid + " ]\n是否加入?", "已找到房间") == MessageResult.Yes) { @@ -513,7 +512,7 @@ namespace Milimoe.FunGame.Desktop.UI { case (int)StartMatchState.Matching: // 开始匹配 - Others.Config.FunGame_isMatching = true; + Config.FunGame_isMatching = true; int loop = 0; string roomid = Convert.ToString(new Random().Next(1, 10000)); // 匹配中 匹配成功返回房间号 @@ -521,7 +520,7 @@ namespace Milimoe.FunGame.Desktop.UI { // 创建新线程,防止主界面阻塞 Thread.Sleep(3000); - while (loop < 10000 && Others.Config.FunGame_isMatching) + while (loop < 10000 && Config.FunGame_isMatching) { loop++; if (loop == Convert.ToInt32(roomid)) @@ -545,7 +544,7 @@ namespace Milimoe.FunGame.Desktop.UI }); break; case (int)StartMatchState.Success: - Others.Config.FunGame_isMatching = false; + Config.FunGame_isMatching = false; // 匹配成功返回房间号 roomid = "-1"; if (objs != null) roomid = (string)objs[0]; @@ -591,7 +590,7 @@ namespace Milimoe.FunGame.Desktop.UI case (int)StartMatchState.Cancel: WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 终止匹配"); WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已终止匹配。"); - Others.Config.FunGame_isMatching = false; + Config.FunGame_isMatching = false; StartMatch_Action = (i, objs) => { StartMatch_Method(i, objs); @@ -709,7 +708,7 @@ namespace Milimoe.FunGame.Desktop.UI /// 可传多个参数 private void CreateRoom_Method(int i, object[]? objs = null) { - if (!Others.Config.FunGame_Roomid.Equals("-1")) + if (!Config.FunGame_Roomid.Equals("-1")) { ShowMessage.WarningMessage("已在房间中,无法创建房间。"); return; @@ -787,7 +786,7 @@ namespace Milimoe.FunGame.Desktop.UI /// private void ShowFunGameInfo() { - WritelnGameInfo(FunGameInfo.GetInfo((FunGameInfo.FunGame)Others.Constant.FunGameType)); + WritelnGameInfo(FunGameInfo.GetInfo((FunGameInfo.FunGame)Constant.FunGameType)); } #endregion @@ -805,7 +804,7 @@ namespace Milimoe.FunGame.Desktop.UI { if (MainController != null) { - MainController.Do(MainControllerSet.Close); + MainController.Close(); MainController = null; } Environment.Exit(0); @@ -854,11 +853,11 @@ namespace Milimoe.FunGame.Desktop.UI WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 开始匹配"); WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 开始匹配"); WriteGameInfo(">> 匹配参数:"); - if (!Others.Config.Match_Mix && !Others.Config.Match_Team && !Others.Config.Match_HasPass) + if (!Config.Match_Mix && !Config.Match_Team && !Config.Match_HasPass) WritelnGameInfo("无"); else { - WriteGameInfo((Others.Config.Match_Mix ? " 混战房间 " : "") + (Others.Config.Match_Team ? " 团队房间 " : "") + (Others.Config.Match_HasPass ? " 密码房间 " : "")); + WriteGameInfo((Config.Match_Mix ? " 混战房间 " : "") + (Config.Match_Team ? " 团队房间 " : "") + (Config.Match_HasPass ? " 密码房间 " : "")); WritelnGameInfo(); } // 显示停止匹配按钮 @@ -894,26 +893,26 @@ namespace Milimoe.FunGame.Desktop.UI private void CreateRoom_Click(object sender, EventArgs e) { string roomtype = ""; - if (Others.Config.Match_Mix && Others.Config.Match_Team) + if (Config.Match_Mix && Config.Match_Team) { ShowMessage.WarningMessage("创建房间不允许同时勾选混战和团队!"); return; } - else if (Others.Config.Match_Mix && !Others.Config.Match_Team && !Others.Config.Match_HasPass) + else if (Config.Match_Mix && !Config.Match_Team && !Config.Match_HasPass) { - roomtype = Others.Constant.GameMode_Mix; + roomtype = Constant.GameMode_Mix; } - else if (!Others.Config.Match_Mix && Others.Config.Match_Team && !Others.Config.Match_HasPass) + else if (!Config.Match_Mix && Config.Match_Team && !Config.Match_HasPass) { - roomtype = Others.Constant.GameMode_Team; + roomtype = Constant.GameMode_Team; } - else if (Others.Config.Match_Mix && !Others.Config.Match_Team && Others.Config.Match_HasPass) + else if (Config.Match_Mix && !Config.Match_Team && Config.Match_HasPass) { - roomtype = Others.Constant.GameMode_MixHasPass; + roomtype = Constant.GameMode_MixHasPass; } - else if (!Others.Config.Match_Mix && Others.Config.Match_Team && Others.Config.Match_HasPass) + else if (!Config.Match_Mix && Config.Match_Team && Config.Match_HasPass) { - roomtype = Others.Constant.GameMode_TeamHasPass; + roomtype = Constant.GameMode_TeamHasPass; } if (roomtype.Equals("")) { @@ -973,7 +972,7 @@ namespace Milimoe.FunGame.Desktop.UI { if (ShowMessage.OKCancelMessage("你确定要退出登录吗?", "退出登录") == MessageResult.OK) { - if (MainController == null || !MainController.Do(MainControllerSet.LogOut)) + if (MainController == null || !MainController.LogOut()) ShowMessage.WarningMessage("请求无效:退出登录失败!"); } } @@ -985,7 +984,7 @@ namespace Milimoe.FunGame.Desktop.UI /// private void Login_Click(object sender, EventArgs e) { - if (MainController != null && Others.Config.FunGame_isConnected) + if (MainController != null && Config.FunGame_isConnected) new Login().ShowDialog(); else ShowMessage.WarningMessage("请先连接服务器!"); @@ -1030,8 +1029,8 @@ namespace Milimoe.FunGame.Desktop.UI /// private void CheckMix_CheckedChanged(object sender, EventArgs e) { - if (CheckMix.Checked) Others.Config.Match_Mix = true; - else Others.Config.Match_Mix = false; + if (CheckMix.Checked) Config.Match_Mix = true; + else Config.Match_Mix = false; } /// @@ -1041,8 +1040,8 @@ namespace Milimoe.FunGame.Desktop.UI /// private void CheckTeam_CheckedChanged(object sender, EventArgs e) { - if (CheckTeam.Checked) Others.Config.Match_Team = true; - else Others.Config.Match_Team = false; + if (CheckTeam.Checked) Config.Match_Team = true; + else Config.Match_Team = false; } /// @@ -1052,8 +1051,8 @@ namespace Milimoe.FunGame.Desktop.UI /// private void CheckHasPass_CheckedChanged(object sender, EventArgs e) { - if (CheckHasPass.Checked) Others.Config.Match_HasPass = true; - else Others.Config.Match_HasPass = false; + if (CheckHasPass.Checked) Config.Match_HasPass = true; + else Config.Match_HasPass = false; } /// @@ -1205,81 +1204,81 @@ namespace Milimoe.FunGame.Desktop.UI { switch (s) { - case Others.Constant.FunGame_SignIn: + case Constant.FunGame_SignIn: break; - case Others.Constant.FunGame_ShowCredits: + case Constant.FunGame_ShowCredits: break; - case Others.Constant.FunGame_ShowStock: + case Constant.FunGame_ShowStock: break; - case Others.Constant.FunGame_ShowStore: + case Constant.FunGame_ShowStore: break; - case Others.Constant.FunGame_CreateMix: + case Constant.FunGame_CreateMix: CreateRoom_Action = (i, objs) => { CreateRoom_Method(i, objs); }; if (InvokeRequired) { - Invoke(CreateRoom_Action, (int)CreateRoomState.Creating, new object[] { Others.Constant.GameMode_Mix }); + Invoke(CreateRoom_Action, (int)CreateRoomState.Creating, new object[] { Constant.GameMode_Mix }); } else { - CreateRoom_Action((int)CreateRoomState.Creating, new object[] { Others.Constant.GameMode_Mix }); + CreateRoom_Action((int)CreateRoomState.Creating, new object[] { Constant.GameMode_Mix }); } break; - case Others.Constant.FunGame_CreateTeam: + case Constant.FunGame_CreateTeam: CreateRoom_Action = (i, objs) => { CreateRoom_Method(i, objs); }; if (InvokeRequired) { - Invoke(CreateRoom_Action, (int)CreateRoomState.Creating, new object[] { Others.Constant.GameMode_Team }); + Invoke(CreateRoom_Action, (int)CreateRoomState.Creating, new object[] { Constant.GameMode_Team }); } else { - CreateRoom_Action((int)CreateRoomState.Creating, new object[] { Others.Constant.GameMode_Team }); + CreateRoom_Action((int)CreateRoomState.Creating, new object[] { Constant.GameMode_Team }); } break; - case Others.Constant.FunGame_StartGame: + case Constant.FunGame_StartGame: break; - case Others.Constant.FunGame_AutoRetryOn: + case Constant.FunGame_AutoRetryOn: WritelnGameInfo(">> 自动重连开启"); - Others.Config.FunGame_isAutoRetry = true; + Config.FunGame_isAutoRetry = true; break; - case Others.Constant.FunGame_AutoRetryOff: + case Constant.FunGame_AutoRetryOff: WritelnGameInfo(">> 自动重连关闭"); - Others.Config.FunGame_isAutoRetry = false; + Config.FunGame_isAutoRetry = false; break; - case Others.Constant.FunGame_Retry: - if (!Others.Config.FunGame_isRetrying) + case Constant.FunGame_Retry: + if (!Config.FunGame_isRetrying) { CurrentRetryTimes = -1; - MainController?.Do(MainControllerSet.Connect); + MainController?.Connect(); } else WritelnGameInfo(">> 你不能在连接服务器的同时重试连接!"); break; - case Others.Constant.FunGame_Connect: - if (!Others.Config.FunGame_isConnected) + case Constant.FunGame_Connect: + if (!Config.FunGame_isConnected) { CurrentRetryTimes = -1; - MainController?.Do(MainControllerSet.GetServerConnection); + MainController?.GetServerConnection(); } break; - case Others.Constant.FunGame_Disconnect: - if (Others.Config.FunGame_isConnected && MainController != null) + case Constant.FunGame_Disconnect: + if (Config.FunGame_isConnected && MainController != null) { - MainController?.Do(MainControllerSet.Disconnect); + MainController?.Disconnect(); } break; - case Others.Constant.FunGame_DisconnectWhenNotLogin: - if (Others.Config.FunGame_isConnected && MainController != null) + case Constant.FunGame_DisconnectWhenNotLogin: + if (Config.FunGame_isConnected && MainController != null) { - MainController?.Do(MainControllerSet.Disconnect); + MainController?.Disconnect(); } break; - case Others.Constant.FunGame_ConnectTo: + case Constant.FunGame_ConnectTo: string msg = ShowMessage.InputMessage("请输入服务器IP地址和端口号,如: 127.0.0.1:22222。", "连接指定服务器"); if (msg.Equals("")) return; string[] addr = msg.Split(':'); @@ -1303,10 +1302,10 @@ namespace Milimoe.FunGame.Desktop.UI ErrorType ErrorType = NetworkUtility.IsServerAddress(ip, port); if (ErrorType == Core.Library.Constant.ErrorType.None) { - Others.Constant.SERVER_IPADRESS = ip; - Others.Constant.SERVER_PORT = port; + Constant.Server_Address = ip; + Constant.Server_Port = port; CurrentRetryTimes = -1; - MainController?.Do(MainControllerSet.Connect); + MainController?.Connect(); } else if (ErrorType == Core.Library.Constant.ErrorType.IsNotIP) ShowMessage.ErrorMessage("这不是一个IP地址!"); else if (ErrorType == Core.Library.Constant.ErrorType.IsNotPort) ShowMessage.ErrorMessage("这不是一个端口号!\n正确范围:1~65535"); diff --git a/FunGame.Desktop/Utility/OpenForm.cs b/FunGame.Desktop/Utility/OpenForm.cs index a3b62ae..8516fb6 100644 --- a/FunGame.Desktop/Utility/OpenForm.cs +++ b/FunGame.Desktop/Utility/OpenForm.cs @@ -1,21 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Sockets; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using System.ComponentModel.DataAnnotations; -using System.Net.NetworkInformation; -using Milimoe.FunGame.Core.Entity; -using Milimoe.FunGame.Desktop.Others; -using Milimoe.FunGame.Desktop.UI; -using Milimoe.FunGame.Core.Api.Utility; -using Milimoe.FunGame.Core.Api.Factory; +using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Library.Constant; -using Milimoe.FunGame.Desktop.Library.Component; -using System.Drawing.Drawing2D; -using System.Windows.Forms; +using Milimoe.FunGame.Desktop.UI; namespace Milimoe.FunGame.Desktop.Utility { @@ -23,50 +8,11 @@ namespace Milimoe.FunGame.Desktop.Utility { public static void SingleForm(FormType type, OpenFormType opentype = OpenFormType.General) { - string formtype = ""; - switch(type) - { - case FormType.Register: - formtype = FormSet.Register; - break; - case FormType.Login: - formtype = FormSet.Login; - break; - case FormType.Inventory: - formtype = FormSet.Inventory; - break; - case FormType.RoomSetting: - formtype = FormSet.RoomSetting; - break; - case FormType.Store: - formtype = FormSet.Store; - break; - case FormType.UserCenter: - formtype = FormSet.UserCenter; - break; - case FormType.Main: - formtype = FormSet.Main; - break; - default: - break; - } - if (!Singleton.IsExist(formtype)) - { - NewSingleForm(type, opentype); - } - else - { - OpenSingleForm(formtype, opentype); - } - } - - private static void NewSingleForm(FormType type, OpenFormType opentype) - { - System.Windows.Forms.Form form = new(); + Form form = new(); switch (type) { case FormType.Register: - form = new Register(); + form = new Register(); break; case FormType.Login: form = new Login(); @@ -85,6 +31,18 @@ namespace Milimoe.FunGame.Desktop.Utility default: break; } + if (!Singleton.IsExist(form)) + { + NewSingleForm(form, opentype); + } + else + { + throw new Exception("目标窗口可能已处于打开状态。"); + } + } + + private static void NewSingleForm(Form form, OpenFormType opentype) + { if (Singleton.Add(form)) { if (opentype == OpenFormType.Dialog) form.ShowDialog(); @@ -92,39 +50,5 @@ namespace Milimoe.FunGame.Desktop.Utility } else throw new Exception("无法打开指定窗口。"); } - - private static void OpenSingleForm(string key, OpenFormType opentype) - { - System.Windows.Forms.Form form = new(); - object? obj = Singleton.Get(key); - if (obj != null) - { - switch (key) - { - case FormSet.Register: - form = (Register)obj; - break; - case FormSet.Login: - form = (Login)obj; - break; - case FormSet.Inventory: - break; - case FormSet.RoomSetting: - break; - case FormSet.Store: - break; - case FormSet.UserCenter: - break; - case FormSet.Main: - form = (Main)obj; - break; - default: - break; - } - if (opentype == OpenFormType.Dialog) form.ShowDialog(); - else form.Show(); - } - else throw new Exception("无法打开指定窗口。"); - } } }