From 35a060f69370b94d886bf3383dd08e0767d9ce04 Mon Sep 17 00:00:00 2001 From: Mili Date: Wed, 7 Sep 2022 00:23:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BB=93=E6=9E=84=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0Socket=E5=92=8C=E5=8F=8D=E5=B0=84=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunGame.Core.Api/Model/Enum/CommonEnums.cs | 71 ++++++++++++++- FunGame.Core.Api/Model/Enum/FunGameEnums.cs | 50 ++++++++++ FunGame.Core.Api/Model/Enum/SocketEnums.cs | 27 ------ FunGame.Core.Api/Util/AssemblyHelper.cs | 54 +---------- FunGame.Desktop/Images/green.png | Bin 1708 -> 1821 bytes FunGame.Desktop/Images/red.png | Bin 1708 -> 1814 bytes FunGame.Desktop/Images/yellow.png | Bin 0 -> 1814 bytes FunGame.Desktop/Models/Config/Config.cs | 1 + .../Properties/Resources.Designer.cs | 10 ++ FunGame.Desktop/Properties/Resources.resx | 9 +- FunGame.Desktop/UI/Main/Main.Designer.cs | 6 +- FunGame.Desktop/UI/Main/Main.cs | 76 +++++++++++----- FunGame.Desktop/Utils/WebHelper.cs | 86 ++++++++---------- 13 files changed, 235 insertions(+), 155 deletions(-) create mode 100644 FunGame.Core.Api/Model/Enum/FunGameEnums.cs delete mode 100644 FunGame.Core.Api/Model/Enum/SocketEnums.cs create mode 100644 FunGame.Desktop/Images/yellow.png diff --git a/FunGame.Core.Api/Model/Enum/CommonEnums.cs b/FunGame.Core.Api/Model/Enum/CommonEnums.cs index e85c056..ccc2701 100644 --- a/FunGame.Core.Api/Model/Enum/CommonEnums.cs +++ b/FunGame.Core.Api/Model/Enum/CommonEnums.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; @@ -8,7 +9,7 @@ namespace FunGame.Core.Api.Model.Enum { /// /// 这里存放框架实现相关的State Type Result Method - /// 添加FunGame.Core.Api接口和实现时,需要在这里同步添加:InterfaceType和InterfaceMethod + /// 添加FunGame.Core.Api接口和实现时,需要在这里同步添加:InterfaceType、InterfaceMethod /// public static class CommonEnums { @@ -63,6 +64,23 @@ namespace FunGame.Core.Api.Model.Enum ServerInterface = 2 } + public enum LightType + { + Green = 1, + Yellow = 2, + Red = 3 + } + + public enum SocketType + { + Unknown = 0, + GetNotice = 1, + Login = 2, + CheckLogin = 3, + Logout = 4, + HeartBeat = 5 + } + #endregion #region Result @@ -96,5 +114,56 @@ namespace FunGame.Core.Api.Model.Enum #endregion + #region 工具方法 + + /// + /// 获取实现类类名 + /// + /// 接口代号 + /// + public static string GetImplementClassName(int Interface) + { + foreach (string str in System.Enum.GetNames(typeof(InterfaceType))) + { + InterfaceType temp = (InterfaceType)System.Enum.Parse(typeof(InterfaceType), Interface.ToString(), true); + if (temp.ToString() == str) + return temp + "Impl"; + } + return ""; + } + + /// + /// 获取实现类的方法名 + /// + /// 方法代号 + /// + public static string GetImplementMethodName(int Method) + { + foreach (string str in System.Enum.GetNames(typeof(InterfaceMethod))) + { + InterfaceMethod temp = (InterfaceMethod)System.Enum.Parse(typeof(InterfaceMethod), Method.ToString(), true); + if (temp.ToString() == str) + return temp.ToString(); + } + return ""; + } + + /// + /// 获取Socket枚举名 + /// + /// Socket枚举 + /// + public static string GetSocketTypeName(int SocketType) + { + foreach (string str in System.Enum.GetNames(typeof(SocketType))) + { + SocketType temp = (SocketType)System.Enum.Parse(typeof(SocketType), SocketType.ToString(), true); + if (temp.ToString() == str) + return temp.ToString(); + } + return ""; + } + + #endregion } } diff --git a/FunGame.Core.Api/Model/Enum/FunGameEnums.cs b/FunGame.Core.Api/Model/Enum/FunGameEnums.cs new file mode 100644 index 0000000..53d3901 --- /dev/null +++ b/FunGame.Core.Api/Model/Enum/FunGameEnums.cs @@ -0,0 +1,50 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FunGame.Core.Api.Model.Enum +{ + /// + /// 鐢ㄤ簬璁板綍鐗堟湰鍙峰拰鏇存柊鏃ュ織 + /// + public static class FunGameEnums + { + public const string FunGame_Core = "FunGame Core"; + public const string FunGame_Core_Api = "FunGame Core Api"; + public const string FunGame_Console = "FunGame Console"; + public const string FunGame_Desktop = "FunGame Desktop"; + public const string FunGame_Server = "FunGame Server"; + + public const int FirstVersion = 1; + public const int SecondVersion = 0; + public const int ThirdVersion = 0; + + public enum Patch + { + Latest = 20221001, + Patch20220906 = 20220906 + } + + public enum History + { + Latest = 20221001, + R20220906 = 20220906 + } + + public static string GetVersion() + { + return "=/=\\=/=\\=/=\\=/= > FunGame鐗堟湰淇℃伅 < =\\=/=\\=/=\\=/=\\=" + "\n" + + FunGame_Core + " -> v" + FirstVersion + "." + SecondVersion + ((int)Patch.Latest == (int)History.Latest ? " Patch" + (int)Patch.Latest : "") + "\n" + + FunGame_Core_Api + " -> v" + FirstVersion + "." + SecondVersion + ((int)Patch.Latest == (int)History.Latest ? " Patch" + (int)Patch.Latest : "") + "\n" + + FunGame_Desktop + " -> v" + FirstVersion + "." + SecondVersion + ((int)Patch.Latest == (int)History.Latest ? " Patch" + (int)Patch.Latest : ""); + } + + /** + * 鏇存柊鏃ュ織 + * + * + */ + } +} diff --git a/FunGame.Core.Api/Model/Enum/SocketEnums.cs b/FunGame.Core.Api/Model/Enum/SocketEnums.cs deleted file mode 100644 index f737320..0000000 --- a/FunGame.Core.Api/Model/Enum/SocketEnums.cs +++ /dev/null @@ -1,27 +0,0 @@ -锘縰sing System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace FunGame.Core.Api.Model.Enum -{ - public static class SocketEnums - { - public enum Type - { - GetNotice = 1, - Login = 2, - CheckLogin = 3, - Logout = 4, - HeartBeat = 5 - } - - public const string TYPE_UNKNOWN = "Unknown Type"; - public const string TYPE_GetNotice = "GetNotice"; - public const string TYPE_Login = "Login"; - public const string TYPE_CheckLogin = "CheckLogin"; - public const string TYPE_Logout = "Logout"; - public const string TYPE_HeartBeat = "HeartBeat"; - } -} diff --git a/FunGame.Core.Api/Util/AssemblyHelper.cs b/FunGame.Core.Api/Util/AssemblyHelper.cs index ff6bcd2..f989ad1 100644 --- a/FunGame.Core.Api/Util/AssemblyHelper.cs +++ b/FunGame.Core.Api/Util/AssemblyHelper.cs @@ -12,57 +12,10 @@ namespace FunGame.Core.Api.Util { /// /// 鍦‵unGame.Core.Api涓坊鍔犳柊鎺ュ彛鍜屾柊瀹炵幇鏃讹紝闇瑕侊細 - /// 1銆佸湪杩欓噷瀹氫箟绫诲悕鍜屾柟娉曞悕 - /// 2銆佸湪FunGame.Core.Api.Model.Enum.CommonEnums閲屽悓姝ユ坊鍔營nterfaceType鍜孖nterfaceMethod - /// 3銆佸湪GetClassName(int)銆丟etMethodName(int)涓坊鍔爏witch鍒嗘敮 + /// 鍦‵unGame.Core.Api.Model.Enum.CommonEnums閲屽悓姝ユ坊鍔營nterfaceType銆両nterfaceMethod /// public class AssemblyHelper { - /** - * 瀹氫箟绫诲悕 - */ - public const string ClientConnectInterface = "ClientConnectInterface"; - public const string ServerInterface = "ServerInterface"; - - /** - * 瀹氫箟鏂规硶鍚 - */ - public const string RemoteServerIP = "RemoteServerIP"; - public const string DBConnection = "DBConnection"; - public const string GetServerSettings = "GetServerSettings"; - - /// - /// 鑾峰彇瀹炵幇绫荤被鍚嶏紙xxInterfaceImpl锛 - /// - /// 鎺ュ彛浠e彿 - /// - private string GetClassName(int Interface) - { - return Interface switch - { - (int)CommonEnums.InterfaceType.ClientConnectInterface => ClientConnectInterface + Implement, - (int)CommonEnums.InterfaceType.ServerInterface => ServerInterface + Implement, - _ => "", - }; - } - - /// - /// 鑾峰彇鏂规硶鍚 - /// - /// 鏂规硶浠e彿 - /// - private string GetMethodName(int Method) - { - // 閫氳繃AssemblyHelperType鏉ヨ幏鍙栨柟娉曞悕 - return Method switch - { - (int)CommonEnums.InterfaceMethod.RemoteServerIP => RemoteServerIP, - (int)CommonEnums.InterfaceMethod.DBConnection => DBConnection, - (int)CommonEnums.InterfaceMethod.GetServerSettings => GetServerSettings, - _ => "", - }; - } - /** * 瀹氫箟闇瑕佸弽灏勭殑DLL */ @@ -71,7 +24,6 @@ namespace FunGame.Core.Api.Util /** * 鏃犻渶浜屾淇敼鐨 */ - public const string Implement = "Impl"; // 瀹炵幇绫荤殑鍚庣紑 public static string EXEDocPath = System.Environment.CurrentDirectory.ToString() + "\\"; // 绋嬪簭鐩綍 public static string PluginDocPath = System.Environment.CurrentDirectory.ToString() + "\\plugins\\"; // 鎻掍欢鐩綍 @@ -95,7 +47,7 @@ namespace FunGame.Core.Api.Util private Type? GetFunGameCoreImplement(int Interface) { // 閫氳繃绫诲悕鑾峰彇鑾峰彇鍛藉悕绌洪棿+绫诲悕绉 - string ClassName = GetClassName(Interface); + string ClassName = CommonEnums.GetImplementClassName(Interface); List? Classes = null; if (Assembly != null) { @@ -120,7 +72,7 @@ namespace FunGame.Core.Api.Util { Assembly = Assembly.LoadFile(EXEDocPath + @FUNGAME_CORE + ".dll"); Type = GetFunGameCoreImplement(Interface); // 閫氳繃绫诲悕鑾峰彇鑾峰彇鍛藉悕绌洪棿+绫诲悕绉 - string MethodName = GetMethodName(Method); // 鑾峰彇鏂规硶鍚 + string MethodName = CommonEnums.GetImplementMethodName(Method); // 鑾峰彇鏂规硶鍚 if (Assembly != null && Type != null) this.Method = Type.GetMethod(MethodName); // 浠嶵ype涓煡鎵炬柟娉曞悕 else return null; Instance = Assembly.CreateInstance(Type.Namespace + "." + Type.Name); diff --git a/FunGame.Desktop/Images/green.png b/FunGame.Desktop/Images/green.png index 4f3b032db5d8a6a78af55a607c540606b8a83df0..e88681deb47e9ed8772db97aa55256d08d41588b 100644 GIT binary patch delta 709 zcmZ3(JD1O@Gr-TCmrII^fq{Y7)59eQNDF~52OE$KJJ%Nuq&N#aB8wRq_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19871355998175127d56bd5008..1414926c753d5c3fc487ae260f9dc2146f219cee 100644 GIT binary patch delta 702 zcmZ3(JB`n(Gr-TCmrII^fq{Y7)59eQNDF~52OE$KJJ%Nuq&N#aB8wRq_>O=u<5X=v zX$A(?6C15!n5-;y4a`D}46O_etqd%+4J@n-43rcqato|{Q%e$45=#duB*%*?@|#IX#l$q(AkEk^RX5SV+)&rTz{El~$uK2V*TB@sAUQQP&BP+b zVzMK%mWrXFNs3X5fuSzY8lW)-CMLR;$)=XNspf`hrUq$728KzAllz%fRLoM+ERBqe zQ*@1!jm&i|%}kPX6D`e>bdA%DO^pnbjf_%KOebGw)}O4;66#8fVkL#*64$a4tMZK0 zJnUXO$x`M@j7Nwu$!78a*8KYL-XG4unE2x9;uvDlyY}*4FJ?!PwukBLwx0MoYR>-7d6K@>~B)J$bU+GotOE7(B>7QAA*}b4wUoGJHOyh zL}(@Nj+KrjvL71uG^rd{Na!-|F`v*=*q1qLE0g<-HHtHjoRR)~+5X77t9>(%-%HfW x(KQjdaahrBO7V?D`gR|hta+w{e>yM!PFqM%#N*HW$G{L^@O1TaS?83{1OSTm>7f7s delta 594 zcmbQnw}#iMGr-TCmrII^fq{Y7)59eQNQ;0l2OE&=?UdyOQk(@Ik;M!QddeWoSh3W; zjDdmm<3_6(CMyeFL*o!511lp7D-#QC0}Cqy10{uu+yX1#)RM%M#F9jp#FA87B_jhP zBV7X&#gi{E$?>9!{AN;8F)}t!GcZj{(={+pNz_d?HZj(4R{Ik}%%MJ37D(#*ub z&{!8JYN(rL2~?ProMxnJVrZ0y^dl)QWDRU*p$HbUq zGkH2|e(kelfhb^Ha;3A%|=zzhRtjH549J3ep@bKJ- z^$={3^jPy72%lWAJqKb6Mw<&;$Tp-lus0 diff --git a/FunGame.Desktop/Images/yellow.png b/FunGame.Desktop/Images/yellow.png new file mode 100644 index 0000000000000000000000000000000000000000..cab8859ac55082b73c836ccf3da8dfa635f48f16 GIT binary patch literal 1814 zcmcIlTWs4@7|s}MW1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im*dl;pjlY6EHj_x>l>fBpxg8Odk zh40~k*N-<`nrQ$0T=v1Go6TRdjc~_(txpPH!vp8rT2GI3p3t|A?N5-u?*Tda)06T2 zEw|0?UG^T|`C-eK_oteEe(IxZHhocAY57sPi8;}kzTuJYW-oqn;|~$yr)wXI5lzha z`@gj{Z+|iL@`hN$p@ogxm=`*q9&3JOvF*ZN^UD)Q&@*q|vXs?3_bo1WTs+%*>i7do z&n|v5amVTt?au1TmfPpV)o(X%FMV+9z+CW;mDcVaI@A4UOZnH8?jKAp+% + /// 鏌ユ壘 System.Drawing.Bitmap 绫诲瀷鐨勬湰鍦板寲璧勬簮銆 + /// + internal static System.Drawing.Bitmap yellow { + get { + object obj = ResourceManager.GetObject("yellow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/FunGame.Desktop/Properties/Resources.resx b/FunGame.Desktop/Properties/Resources.resx index 54e14d9..6000db2 100644 --- a/FunGame.Desktop/Properties/Resources.resx +++ b/FunGame.Desktop/Properties/Resources.resx @@ -133,13 +133,16 @@ ..\images\back.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\images\min.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Images\favicon.ico;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\images\min.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Images\logo.ico;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Images\yellow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/FunGame.Desktop/UI/Main/Main.Designer.cs b/FunGame.Desktop/UI/Main/Main.Designer.cs index cde0a3b..60f9ca8 100644 --- a/FunGame.Desktop/UI/Main/Main.Designer.cs +++ b/FunGame.Desktop/UI/Main/Main.Designer.cs @@ -145,7 +145,7 @@ namespace FunGame.Desktop.UI this.Light.Image = global::FunGame.Desktop.Properties.Resources.red; this.Light.Location = new System.Drawing.Point(777, 426); this.Light.Name = "Light"; - this.Light.Size = new System.Drawing.Size(20, 20); + this.Light.Size = new System.Drawing.Size(18, 18); this.Light.TabIndex = 93; // // SendTalkText @@ -407,7 +407,7 @@ namespace FunGame.Desktop.UI this.NoticeText.ReadOnly = true; this.NoticeText.Size = new System.Drawing.Size(174, 86); this.NoticeText.TabIndex = 0; - this.NoticeText.Text = "杩欓噷灞曠ず鍏憡"; + this.NoticeText.Text = ""; // // InfoBox // @@ -452,7 +452,7 @@ namespace FunGame.Desktop.UI this.GameInfo.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical; this.GameInfo.Size = new System.Drawing.Size(452, 331); this.GameInfo.TabIndex = 1; - this.GameInfo.Text = "杩欓噷灞曠ず娓告垙淇℃伅锛屽寘鎷郴缁熼氱煡鍜屾父鎴忓弽棣"; + this.GameInfo.Text = ""; // // QuitRoom // diff --git a/FunGame.Desktop/UI/Main/Main.cs b/FunGame.Desktop/UI/Main/Main.cs index 4d7e371..7b6a3e2 100644 --- a/FunGame.Desktop/UI/Main/Main.cs +++ b/FunGame.Desktop/UI/Main/Main.cs @@ -8,6 +8,7 @@ using System.Text; using FunGame.Core.Api.Model.Entity; using FunGame.Desktop.Models.Config; using FunGame.Desktop.Utils; +using FunGame.Core.Api.Model.Enum; using static FunGame.Core.Api.Model.Enum.CommonEnums; namespace FunGame.Desktop.UI @@ -53,8 +54,7 @@ namespace FunGame.Desktop.UI { this.PresetText.SelectedIndex = 0; // 蹇嵎娑堟伅鍒濆閫夋嫨 SetRoomid("-1"); // 鎴块棿鍙峰垵濮嬪寲 - WritelnGameInfo(); // 鍒濆鍖栨秷鎭槦鍒 - SetLoginUser(new object[] { new User("Mili") }); // Debug锛屽垵濮嬪寲鐜╁鍚嶅瓧 + ShowFunGameInfo(); // 鏄剧ずFunGame淇℃伅 GetServerConnection(); // 寮濮嬭繛鎺ユ湇鍔″櫒 } @@ -81,7 +81,7 @@ namespace FunGame.Desktop.UI Usercfg.FunGame_isRetrying = false; WebHelper_Action = (main) => { - SetServerStatusLight(true); + SetServerStatusLight((int)CommonEnums.LightType.Green); }; if (InvokeRequired) BeginInvoke(WebHelper_Action, this); @@ -94,7 +94,20 @@ namespace FunGame.Desktop.UI Usercfg.FunGame_isRetrying = false; WebHelper_Action = (main) => { - SetServerStatusLight(true, GetServerPing(Config.SERVER_IPADRESS)); + SetServerStatusLight((int)CommonEnums.LightType.Green, GetServerPing(Config.SERVER_IPADRESS)); + }; + if (InvokeRequired) + BeginInvoke(WebHelper_Action, this); + else + WebHelper_Action(this); + Usercfg.FunGame_isConnected = true; + NOW_CONNECTEDRETRY = 0; + break; + case Config.WebHelper_SetYellow: + Usercfg.FunGame_isRetrying = false; + WebHelper_Action = (main) => + { + SetServerStatusLight((int)CommonEnums.LightType.Yellow); }; if (InvokeRequired) BeginInvoke(WebHelper_Action, this); @@ -106,7 +119,7 @@ namespace FunGame.Desktop.UI case Config.WebHelper_SetRed: WebHelper_Action = (main) => { - SetServerStatusLight(false); + SetServerStatusLight((int)CommonEnums.LightType.Red); }; if (InvokeRequired) BeginInvoke(WebHelper_Action, this); @@ -118,7 +131,7 @@ namespace FunGame.Desktop.UI Usercfg.FunGame_isRetrying = false; WebHelper_Action = (main) => { - SetServerStatusLight(false); + SetServerStatusLight((int)CommonEnums.LightType.Red); }; if (InvokeRequired) BeginInvoke(WebHelper_Action, this); @@ -147,7 +160,10 @@ namespace FunGame.Desktop.UI return LoginUser; return null; default: - WritelnGameInfo(webHelper, msg); + if (needTime) + WritelnGameInfo(webHelper, GetNowShortTime() + msg); + else + WritelnGameInfo(webHelper, msg); return null; } } @@ -188,7 +204,7 @@ namespace FunGame.Desktop.UI } catch (Exception e) { - WritelnGameInfo(">> 鏌ユ壘鍙敤鐨勬湇鍔″櫒澶辫触锛岃閲嶅惎FunGame锛乗n" + e.StackTrace); + WritelnGameInfo(">> 鏌ユ壘鍙敤鐨勬湇鍔″櫒澶辫触锛岃閲嶅惎FunGame銆俓n" + e.StackTrace); ShowMessage.ErrorMessage("鏌ユ壘鍙敤鐨勬湇鍔″櫒澶辫触锛"); } } @@ -683,30 +699,46 @@ namespace FunGame.Desktop.UI /// /// 璁剧疆鏈嶅姟鍣ㄨ繛鎺ョ姸鎬佹寚绀虹伅 /// - /// + /// /// - private void SetServerStatusLight(bool green, int ping = 0) + private void SetServerStatusLight(int light, int ping = 0) { - if (green) + switch(light) { - if (ping > 0) - { - Connection.Text = "蹇冭烦寤惰繜 " + ping + "ms"; - this.Light.Image = Properties.Resources.green; - } - else - { + case (int)CommonEnums.LightType.Green: Connection.Text = "鏈嶅姟鍣ㄨ繛鎺ユ垚鍔"; this.Light.Image = Properties.Resources.green; - } + break; + case (int)CommonEnums.LightType.Yellow: + Connection.Text = "绛夊緟鐧诲綍璐﹀彿"; + this.Light.Image = Properties.Resources.yellow; + break; + case (int)CommonEnums.LightType.Red: + default: + Connection.Text = "鏈嶅姟鍣ㄨ繛鎺ュけ璐"; + this.Light.Image = Properties.Resources.red; + break; } - else + if (ping > 0) { - Connection.Text = "鏈嶅姟鍣ㄨ繛鎺ュけ璐"; - this.Light.Image = Properties.Resources.red; + Connection.Text = "蹇冭烦寤惰繜 " + ping + "ms"; + if (ping < 100) + this.Light.Image = Properties.Resources.green; + else if (ping >= 100 && ping < 200) + this.Light.Image = Properties.Resources.yellow; + else if (ping >= 200) + this.Light.Image = Properties.Resources.red; } } + /// + /// 鏄剧ずFunGame淇℃伅 + /// + private void ShowFunGameInfo() + { + WritelnGameInfo(FunGameEnums.GetVersion()); + } + #endregion #region 浜嬩欢 diff --git a/FunGame.Desktop/Utils/WebHelper.cs b/FunGame.Desktop/Utils/WebHelper.cs index bce8813..ed03872 100644 --- a/FunGame.Desktop/Utils/WebHelper.cs +++ b/FunGame.Desktop/Utils/WebHelper.cs @@ -66,7 +66,7 @@ namespace FunGame.Desktop.Utils client.Connect(server); if (IsConnected()) { - Main.GetMessage(this, Config.WebHelper_SetGreen); + Main.GetMessage(this, Config.WebHelper_SetYellow); break; } } @@ -79,12 +79,8 @@ namespace FunGame.Desktop.Utils objs = new object[] { main, socket, obj }; else objs = new object[] { main, socket }; - Task.Factory.StartNew(() => - { - - }); - if (Send((int)SocketEnums.Type.CheckLogin, objs)) // 纭杩炴帴鐨勭帺瀹 - StartWebHelper(); // 寮濮嬪垱寤篢CP娴 + if (Send((int)CommonEnums.SocketType.GetNotice, objs)) // 鎺ヨЕ鏈嶅姟鍣ㄥ苟鑾峰彇鍏憡 + main.GetMessage(this, " >> 杩炴帴鏈嶅姟鍣ㄦ垚鍔燂紝璇风櫥褰曡处鍙蜂互浣撻獙FunGame銆", true); }; Task t = Task.Factory.StartNew(() => { @@ -142,25 +138,28 @@ namespace FunGame.Desktop.Utils { string msg = Config.DEFAULT_ENCODING.GetString(buffer, 0, length); int type = GetType(msg); - string typestring = GetTypeString(type); + string typestring = CommonEnums.GetSocketTypeName(type); string read = GetMessage(msg); - main.GetMessage(this, read); switch (type) { - case (int)SocketEnums.Type.GetNotice: - break; - case (int)SocketEnums.Type.Login: - break; - case (int)SocketEnums.Type.CheckLogin: + case (int)CommonEnums.SocketType.GetNotice: + main.GetMessage(this, read, true); return true; - case (int)SocketEnums.Type.Logout: + case (int)CommonEnums.SocketType.Login: break; - case (int)SocketEnums.Type.HeartBeat: + case (int)CommonEnums.SocketType.CheckLogin: + StartWebHelper(); // 寮濮嬪垱寤篢CP娴 + return true; + case (int)CommonEnums.SocketType.Logout: + break; + case (int)CommonEnums.SocketType.HeartBeat: if (WaitHeartBeat != null && !WaitHeartBeat.IsCompleted) WaitHeartBeat.Wait(1); Config.WebHelper_HeartBeatFaileds = 0; main.GetMessage(this, Config.WebHelper_SetGreenAndPing); return true; } + main.GetMessage(this, read); + return true; } else throw new Exception("ERROR锛氭湭鏀跺埌浠讳綍鏉ヨ嚜鏈嶅姟鍣ㄧ殑淇℃伅锛屼笌鏈嶅姟鍣ㄨ繛鎺ュ彲鑳戒涪澶便"); @@ -198,16 +197,26 @@ namespace FunGame.Desktop.Utils } if (socket != null) { + string msg = ""; + byte[] buffer; + int length; // 鍙戦佹秷鎭粰鏈嶅姟鍣ㄧ switch (i) { - case (int)SocketEnums.Type.GetNotice: + case (int)CommonEnums.SocketType.GetNotice: + msg = "鑾峰彇鍏憡"; + buffer = new byte[2048]; + buffer = Config.DEFAULT_ENCODING.GetBytes(MakeMessage((int)CommonEnums.SocketType.GetNotice, msg)); + length = socket.Send(buffer); + if (length > 0) + { + return Read(objs); + } break; - case (int)SocketEnums.Type.Login: + case (int)CommonEnums.SocketType.Login: break; - case (int)SocketEnums.Type.CheckLogin: + case (int)CommonEnums.SocketType.CheckLogin: User user; - string msg; if (objs != null && objs.Length > 2) { user = (User)objs[2]; @@ -216,22 +225,22 @@ namespace FunGame.Desktop.Utils else { Usercfg.FunGame_isAutoRetry = false; - throw new Exception("SUCCESS锛氭湇鍔″櫒杩炴帴鎴愬姛锛屾娴嬪埌鏈櫥褰曡处鍙峰凡鑷姩鏂紑锛岃鐧诲綍鍚庢墜鍔ㄥ彂璧锋湇鍔″櫒杩炴帴銆"); + throw new Exception("ERROR: 璇风櫥褰曡处鍙枫"); } - byte[] buffer = new byte[2048]; - buffer = Config.DEFAULT_ENCODING.GetBytes(MakeMessage((int)SocketEnums.Type.CheckLogin, msg)); - int l = socket.Send(buffer); - if (l > 0) + buffer = new byte[2048]; + buffer = Config.DEFAULT_ENCODING.GetBytes(MakeMessage((int)CommonEnums.SocketType.CheckLogin, msg)); + length = socket.Send(buffer); + if (length > 0) { return Read(objs); } else throw new Exception("ERROR锛氭秷鎭湭閫佽揪鏈嶅姟鍣紝涓庢湇鍔″櫒杩炴帴鍙兘涓㈠け銆"); - case (int)SocketEnums.Type.Logout: + case (int)CommonEnums.SocketType.Logout: break; - case (int)SocketEnums.Type.HeartBeat: + case (int)CommonEnums.SocketType.HeartBeat: buffer = new byte[2048]; - buffer = Config.DEFAULT_ENCODING.GetBytes(Convert.ToString(MakeMessage((int)SocketEnums.Type.HeartBeat, "蹇冭烦妫娴"))); + buffer = Config.DEFAULT_ENCODING.GetBytes(Convert.ToString(MakeMessage((int)CommonEnums.SocketType.HeartBeat, "蹇冭烦妫娴"))); if (socket.Send(buffer) > 0) { WaitHeartBeat = Task.Run(() => @@ -292,25 +301,6 @@ namespace FunGame.Desktop.Utils return Convert.ToInt32(msg[..1]); } - private string GetTypeString(int type) - { - switch (type) - { - case (int)SocketEnums.Type.GetNotice: - return SocketEnums.TYPE_GetNotice; - case (int)SocketEnums.Type.Login: - return SocketEnums.TYPE_Login; - case (int)SocketEnums.Type.CheckLogin: - return SocketEnums.TYPE_CheckLogin; - case (int)SocketEnums.Type.Logout: - return SocketEnums.TYPE_Logout; - case (int)SocketEnums.Type.HeartBeat: - return SocketEnums.TYPE_HeartBeat; - default: - return SocketEnums.TYPE_UNKNOWN; - } - } - private string GetMessage(string msg) { int index = msg.IndexOf(';') + 1; @@ -353,7 +343,7 @@ namespace FunGame.Desktop.Utils Main.GetMessage(this, "Creating: SendHeartBeatStream...OK"); while (IsConnected()) { - Send((int)SocketEnums.Type.HeartBeat); // 鍙戦佸績璺冲寘 + Send((int)CommonEnums.SocketType.HeartBeat); // 鍙戦佸績璺冲寘 Thread.Sleep(20000); } }