diff --git a/FunGame.Core.Api/Model/Enum/CommonEnums.cs b/FunGame.Core.Api/Model/Enum/CommonEnums.cs
index fa15c7e..074da2c 100644
--- a/FunGame.Core.Api/Model/Enum/CommonEnums.cs
+++ b/FunGame.Core.Api/Model/Enum/CommonEnums.cs
@@ -5,124 +5,128 @@ using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
+
namespace FunGame.Core.Api.Model.Enum
{
- ///
- /// 这里存放框架实现相关的State Type Result Method
- /// 添加FunGame.Core.Api接口和实现时,需要在这里同步添加:InterfaceType、InterfaceMethod
- ///
- public static class CommonEnums
+ /**
+ * 这里存放框架实现相关的State Type Result Method
+ * 添加FunGame.Core.Api接口和实现时,需要在这里同步添加:InterfaceType、InterfaceMethod
+ */
+
+ #region State
+
+ public enum StartMatch_State
{
- #region State
+ Matching,
+ Success,
+ Enable,
+ Cancel
+ }
- public enum StartMatch_State
- {
- Matching,
- Success,
- Enable,
- Cancel
- }
+ public enum CreateRoom_State
+ {
+ Creating,
+ Success
+ }
- public enum CreateRoom_State
- {
- Creating,
- Success
- }
+ public enum RoomState
+ {
+ Created,
+ Gaming,
+ Close,
+ Complete
+ }
- public enum RoomState
- {
- Created,
- Gaming,
- Close,
- Complete
- }
+ public enum OnlineState
+ {
+ Offline,
+ Online,
+ Matching,
+ InRoom,
+ Gaming
+ }
- public enum OnlineState
- {
- Offline,
- Online,
- Matching,
- InRoom,
- Gaming
- }
+ #endregion
- #endregion
+ #region Type
- #region Type
+ public enum RoomType
+ {
+ Mix,
+ Team,
+ MixHasPass,
+ TeamHasPass
+ }
- public enum RoomType
- {
- Mix,
- Team,
- MixHasPass,
- TeamHasPass
- }
+ public enum MessageButtonType
+ {
+ OK,
+ OKCancel,
+ YesNo,
+ RetryCancel
+ }
- public enum MessageButtonType
- {
- OK,
- OKCancel,
- YesNo,
- RetryCancel
- }
+ public enum InterfaceType
+ {
+ ClientConnectInterface,
+ ServerInterface
+ }
- public enum InterfaceType
- {
- ClientConnectInterface,
- ServerInterface
- }
+ public enum LightType
+ {
+ Green,
+ Yellow,
+ Red
+ }
- public enum LightType
- {
- Green,
- Yellow,
- Red
- }
+ public enum SocketMessageType
+ {
+ Unknown,
+ GetNotice,
+ Login,
+ CheckLogin,
+ Logout,
+ HeartBeat
+ }
- public enum SocketType
- {
- Unknown,
- GetNotice,
- Login,
- CheckLogin,
- Logout,
- HeartBeat
- }
+ #endregion
- #endregion
+ #region Result
- #region Result
+ public enum MessageResult
+ {
+ OK,
+ Cancel,
+ Yes,
+ No,
+ Retry
+ }
- public enum MessageResult
- {
- OK,
- Cancel,
- Yes,
- No,
- Retry
- }
+ #endregion
- #endregion
+ #region Method
- #region Method
+ public enum WebHelperMethod
+ {
+ CreateSocket,
+ CloseSocket,
+ StartWebHelper,
+ Login,
+ Logout
+ }
- public enum WebHelperMethod
- {
- CreateSocket,
- CloseSocket,
- StartWebHelper,
- Login
- }
+ public enum InterfaceMethod
+ {
+ RemoteServerIP,
+ DBConnection,
+ GetServerSettings
+ }
- public enum InterfaceMethod
- {
- RemoteServerIP,
- DBConnection,
- GetServerSettings
- }
-
- #endregion
+ #endregion
+
+ public class EnumHelper
+ {
#region 工具方法
///
@@ -164,9 +168,9 @@ namespace FunGame.Core.Api.Model.Enum
///
public static string GetSocketTypeName(int SocketType)
{
- foreach (string str in System.Enum.GetNames(typeof(SocketType)))
+ foreach (string str in System.Enum.GetNames(typeof(SocketMessageType)))
{
- SocketType temp = (SocketType)System.Enum.Parse(typeof(SocketType), SocketType.ToString(), true);
+ SocketMessageType temp = (SocketMessageType)System.Enum.Parse(typeof(SocketMessageType), SocketType.ToString(), true);
if (temp.ToString() == str)
return temp.ToString();
}
diff --git a/FunGame.Core.Api/Model/Enum/FunGameEnums.cs b/FunGame.Core.Api/Model/Enum/FunGameEnums.cs
index 2a61d92..2211c18 100644
--- a/FunGame.Core.Api/Model/Enum/FunGameEnums.cs
+++ b/FunGame.Core.Api/Model/Enum/FunGameEnums.cs
@@ -8,15 +8,6 @@ namespace FunGame.Core.Api.Model.Enum
{
public static class FunGameEnums
{
- private const string FunGame_Core = "FunGame Core";
- private const string FunGame_Core_Api = "FunGame Core Api";
- private const string FunGame_Console = "FunGame Console";
- private const string FunGame_Desktop = "FunGame Desktop";
- private const string FunGame_Server = "FunGame Server Console";
-
- private const string FunGame_Version = "v1.0";
- private const string FunGame_VersionPatch = "";
-
public enum FunGame
{
FunGame_Core,
@@ -26,6 +17,15 @@ namespace FunGame.Core.Api.Model.Enum
FunGame_Server
}
+ private const string FunGame_Core = "FunGame Core";
+ private const string FunGame_Core_Api = "FunGame Core Api";
+ private const string FunGame_Console = "FunGame Console";
+ private const string FunGame_Desktop = "FunGame Desktop";
+ private const string FunGame_Server = "FunGame Server Console";
+
+ private const string FunGame_Version = "v1.0";
+ private const string FunGame_VersionPatch = "";
+
public static string GetInfo(FunGame FunGameType)
{
string type = FunGameType switch
@@ -37,10 +37,7 @@ namespace FunGame.Core.Api.Model.Enum
FunGame.FunGame_Server => FunGame_Server,
_ => ""
};
- if (type.Equals(FunGame_Desktop))
- return type + " [ 鐗堟湰: " + FunGame_Version + FunGame_VersionPatch + " ]\n漏2022 Mili.cyou. 淇濈暀鎵鏈夋潈鍒‐n";
- else
- return type + " [ 鐗堟湰: " + FunGame_Version + FunGame_VersionPatch + " ]\n(C)2022 Mili.cyou. 淇濈暀鎵鏈夋潈鍒‐n";
+ return type + " [ 鐗堟湰: " + FunGame_Version + FunGame_VersionPatch + " ]\n" + (type.Equals(FunGame_Desktop) ? "漏" : "(C)") + "2022 Mili.cyou. 淇濈暀鎵鏈夋潈鍒‐n";
}
/**
diff --git a/FunGame.Core.Api/Util/AssemblyHelper.cs b/FunGame.Core.Api/Util/AssemblyHelper.cs
index f989ad1..efa8b05 100644
--- a/FunGame.Core.Api/Util/AssemblyHelper.cs
+++ b/FunGame.Core.Api/Util/AssemblyHelper.cs
@@ -47,7 +47,7 @@ namespace FunGame.Core.Api.Util
private Type? GetFunGameCoreImplement(int Interface)
{
// 閫氳繃绫诲悕鑾峰彇鑾峰彇鍛藉悕绌洪棿+绫诲悕绉
- string ClassName = CommonEnums.GetImplementClassName(Interface);
+ string ClassName = EnumHelper.GetImplementClassName(Interface);
List? Classes = null;
if (Assembly != null)
{
@@ -72,7 +72,7 @@ namespace FunGame.Core.Api.Util
{
Assembly = Assembly.LoadFile(EXEDocPath + @FUNGAME_CORE + ".dll");
Type = GetFunGameCoreImplement(Interface); // 閫氳繃绫诲悕鑾峰彇鑾峰彇鍛藉悕绌洪棿+绫诲悕绉
- string MethodName = CommonEnums.GetImplementMethodName(Method); // 鑾峰彇鏂规硶鍚
+ string MethodName = EnumHelper.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/Models/Component/ShowMessage.cs b/FunGame.Desktop/Models/Component/ShowMessage.cs
index 237bd17..cbf1ece 100644
--- a/FunGame.Desktop/Models/Component/ShowMessage.cs
+++ b/FunGame.Desktop/Models/Component/ShowMessage.cs
@@ -8,7 +8,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FunGame.Core.Api.Model.Enum;
-using static FunGame.Core.Api.Model.Enum.CommonEnums;
+using static FunGame.Core.Api.Model.Enum.EnumHelper;
namespace FunGame.Desktop.Models.Component
{
diff --git a/FunGame.Desktop/Models/Config/Config.cs b/FunGame.Desktop/Models/Config/Config.cs
index eb0d333..951947a 100644
--- a/FunGame.Desktop/Models/Config/Config.cs
+++ b/FunGame.Desktop/Models/Config/Config.cs
@@ -27,6 +27,7 @@ namespace FunGame.Desktop.Models.Config
public const string WebHelper_SetRed = "-WebHelper .set red";
public const string WebHelper_SetYellow = "-WebHelper .set yellow";
public const string WebHelper_Disconnected = "-WebHelper .disconnected";
+ public const string WebHelper_LogOut = "-WebHelper .logout";
public const string WebHelper_GetUser = "-WebHelper .get user";
public const string WebHelper_SetUser = "-WebHelper .set user";
public static int WebHelper_HeartBeatFaileds = 0;
diff --git a/FunGame.Desktop/UI/Main/Main.cs b/FunGame.Desktop/UI/Main/Main.cs
index 0f2fe9a..8fc6b5f 100644
--- a/FunGame.Desktop/UI/Main/Main.cs
+++ b/FunGame.Desktop/UI/Main/Main.cs
@@ -9,7 +9,6 @@ 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
{
@@ -80,7 +79,7 @@ namespace FunGame.Desktop.UI
Usercfg.FunGame_isRetrying = false;
WebHelper_Action = (main) =>
{
- SetServerStatusLight((int)CommonEnums.LightType.Green);
+ SetServerStatusLight((int)LightType.Green);
SetButtonEnableIfLogon(true);
};
if (InvokeRequired)
@@ -94,7 +93,7 @@ namespace FunGame.Desktop.UI
Usercfg.FunGame_isRetrying = false;
WebHelper_Action = (main) =>
{
- SetServerStatusLight((int)CommonEnums.LightType.Green, GetServerPing(Config.SERVER_IPADRESS));
+ SetServerStatusLight((int)LightType.Green, GetServerPing(Config.SERVER_IPADRESS));
SetButtonEnableIfLogon(true);
};
if (InvokeRequired)
@@ -108,7 +107,7 @@ namespace FunGame.Desktop.UI
Usercfg.FunGame_isRetrying = false;
WebHelper_Action = (main) =>
{
- SetServerStatusLight((int)CommonEnums.LightType.Yellow);
+ SetServerStatusLight((int)LightType.Yellow);
SetButtonEnableIfLogon(false);
};
if (InvokeRequired)
@@ -121,7 +120,7 @@ namespace FunGame.Desktop.UI
case Config.WebHelper_SetRed:
WebHelper_Action = (main) =>
{
- SetServerStatusLight((int)CommonEnums.LightType.Red);
+ SetServerStatusLight((int)LightType.Red);
SetButtonEnableIfLogon(false);
};
if (InvokeRequired)
@@ -132,22 +131,22 @@ namespace FunGame.Desktop.UI
break;
case Config.WebHelper_Disconnected:
Usercfg.FunGame_isRetrying = false;
+ Usercfg.FunGame_isConnected = false;
WebHelper_Action = (main) =>
{
- SetServerStatusLight((int)CommonEnums.LightType.Red);
+ SetServerStatusLight((int)LightType.Red);
SetButtonEnableIfLogon(false);
};
if (InvokeRequired)
BeginInvoke(WebHelper_Action, this);
else
WebHelper_Action(this);
- Usercfg.FunGame_isConnected = false;
if (Usercfg.FunGame_isAutoRetry && NOW_CONNECTEDRETRY <= MAX_CONNECTEDRETRY)
{
Task.Run(() =>
{
Thread.Sleep(5000);
- Connect();
+ if (Usercfg.FunGame_isAutoRetry) Connect(); // 鍐嶆鍒ゆ柇鏄惁寮鍚嚜鍔ㄩ噸杩
});
if (needTime)
throw new Exception(GetNowShortTime() + "\nERROR锛氳繛鎺ユ湇鍔″櫒澶辫触锛5绉掑悗鑷姩灏濊瘯閲嶈繛銆");
@@ -159,6 +158,29 @@ namespace FunGame.Desktop.UI
throw new Exception(GetNowShortTime() + "\nERROR锛氭棤娉曡繛鎺ヨ嚦鏈嶅姟鍣紝璇锋鏌ヤ綘鐨勭綉缁滆繛鎺ャ");
else
throw new Exception("ERROR锛氭棤娉曡繛鎺ヨ嚦鏈嶅姟鍣紝璇锋鏌ヤ綘鐨勭綉缁滆繛鎺ャ");
+ case Config.WebHelper_LogOut:
+ Usercfg.FunGame_isRetrying = false;
+ Usercfg.FunGame_isConnected = false;
+ WebHelper_Action = (main) =>
+ {
+ SetServerStatusLight((int)LightType.Red);
+ SetButtonEnableIfLogon(false);
+ LogoutAccount();
+ };
+ if (InvokeRequired)
+ BeginInvoke(WebHelper_Action, this);
+ else
+ WebHelper_Action(this);
+ if (Usercfg.FunGame_isAutoRetry)
+ {
+ NOW_CONNECTEDRETRY = -1;
+ Task.Run(() =>
+ {
+ Thread.Sleep(1000);
+ Connect();
+ });
+ }
+ break;
case Config.WebHelper_GetUser:
if (Usercfg.LoginUser != null)
return Usercfg.LoginUser;
@@ -636,6 +658,8 @@ namespace FunGame.Desktop.UI
///
private void LogoutAccount()
{
+ Usercfg.LoginUser = null;
+ Usercfg.LoginUserName = "";
NowAccount.Text = "璇风櫥褰曡处鍙";
Logout.Visible = false;
Login.Visible = true;
@@ -757,15 +781,15 @@ namespace FunGame.Desktop.UI
{
switch(light)
{
- case (int)CommonEnums.LightType.Green:
+ case (int)LightType.Green:
Connection.Text = "鏈嶅姟鍣ㄨ繛鎺ユ垚鍔";
this.Light.Image = Properties.Resources.green;
break;
- case (int)CommonEnums.LightType.Yellow:
+ case (int)LightType.Yellow:
Connection.Text = "绛夊緟鐧诲綍璐﹀彿";
this.Light.Image = Properties.Resources.yellow;
break;
- case (int)CommonEnums.LightType.Red:
+ case (int)LightType.Red:
default:
Connection.Text = "鏈嶅姟鍣ㄨ繛鎺ュけ璐";
this.Light.Image = Properties.Resources.red;
@@ -972,7 +996,11 @@ namespace FunGame.Desktop.UI
///
private void Logout_Click(object sender, EventArgs e)
{
- LogoutAccount();
+ if (ShowMessage.OKCancelMessage("浣犵‘瀹氳閫鍑虹櫥褰曞悧锛", "閫鍑虹櫥褰") == MessageResult.OK)
+ {
+ if (WebHelper == null || !WebHelper.WebHelpMethod((int)WebHelperMethod.Logout))
+ ShowMessage.WarningMessage("璇锋眰鏃犳晥锛氶鍑虹櫥褰曞け璐ワ紒");
+ }
}
///
@@ -983,7 +1011,7 @@ namespace FunGame.Desktop.UI
private void Login_Click(object sender, EventArgs e)
{
if (WebHelper != null)
- WebHelper.WebHelpMethod((int)CommonEnums.WebHelperMethod.Login);
+ WebHelper.WebHelpMethod((int)WebHelperMethod.Login);
else
ShowMessage.WarningMessage("璇峰厛杩炴帴鏈嶅姟鍣紒");
}
diff --git a/FunGame.Desktop/Utils/WebHelper.cs b/FunGame.Desktop/Utils/WebHelper.cs
index 1f326fe..4f90264 100644
--- a/FunGame.Desktop/Utils/WebHelper.cs
+++ b/FunGame.Desktop/Utils/WebHelper.cs
@@ -38,23 +38,29 @@ namespace FunGame.Desktop.Utils
{
switch (i)
{
- case (int)CommonEnums.WebHelperMethod.CreateSocket:
+ case (int)WebHelperMethod.CreateSocket:
CreateSocket();
break;
- case (int)CommonEnums.WebHelperMethod.CloseSocket:
+ case (int)WebHelperMethod.CloseSocket:
Close();
break;
- case (int)CommonEnums.WebHelperMethod.StartWebHelper:
+ case (int)WebHelperMethod.StartWebHelper:
StartWebHelper();
break;
- case (int)CommonEnums.WebHelperMethod.Login:
+ case (int)WebHelperMethod.Login:
if (client != null)
{
- Send((int)CommonEnums.SocketType.CheckLogin, new object[] { Main, client, new User("Mili") });
+ Send((int)SocketMessageType.CheckLogin, new object[] { Main, client, new User("Mili") });
return true;
}
- else
- return false;
+ return false;
+ case (int)WebHelperMethod.Logout:
+ if (client != null && Usercfg.LoginUser != null)
+ {
+ Send((int)SocketMessageType.Logout, new object[] { Main, client, Usercfg.LoginUser });
+ return true;
+ }
+ return false;
}
return true;
}
@@ -88,7 +94,7 @@ namespace FunGame.Desktop.Utils
objs = new object[] { main, socket, obj };
else
objs = new object[] { main, socket };
- if (Send((int)CommonEnums.SocketType.GetNotice, objs)) // 鎺ヨЕ鏈嶅姟鍣ㄥ苟鑾峰彇鍏憡
+ if (Send((int)SocketMessageType.GetNotice, objs)) // 鎺ヨЕ鏈嶅姟鍣ㄥ苟鑾峰彇鍏憡
main.GetMessage(this, " >> 杩炴帴鏈嶅姟鍣ㄦ垚鍔燂紝璇风櫥褰曡处鍙蜂互浣撻獙FunGame銆", true);
};
Task t = Task.Factory.StartNew(() =>
@@ -147,23 +153,27 @@ namespace FunGame.Desktop.Utils
{
string msg = Config.DEFAULT_ENCODING.GetString(buffer, 0, length);
int type = GetType(msg);
- string typestring = CommonEnums.GetSocketTypeName(type);
+ string typestring = EnumHelper.GetSocketTypeName(type);
string read = GetMessage(msg);
switch (type)
{
- case (int)CommonEnums.SocketType.GetNotice:
+ case (int)SocketMessageType.GetNotice:
main.GetMessage(this, read, true);
return true;
- case (int)CommonEnums.SocketType.Login:
+ case (int)SocketMessageType.Login:
break;
- case (int)CommonEnums.SocketType.CheckLogin:
+ case (int)SocketMessageType.CheckLogin:
Main.GetMessage(this, Config.WebHelper_SetUser, false, objs);
Main.GetMessage(this, read, true);
StartWebHelper(); // 寮濮嬪垱寤篢CP娴
return true;
- case (int)CommonEnums.SocketType.Logout:
- break;
- case (int)CommonEnums.SocketType.HeartBeat:
+ case (int)SocketMessageType.Logout:
+ Main.GetMessage(this, Config.WebHelper_SetUser, false, objs);
+ Main.GetMessage(this, read, true);
+ Main.GetMessage(this, Config.WebHelper_LogOut);
+ Close();
+ return true;
+ case (int)SocketMessageType.HeartBeat:
if (WaitHeartBeat != null && !WaitHeartBeat.IsCompleted) WaitHeartBeat.Wait(1);
Config.WebHelper_HeartBeatFaileds = 0;
main.GetMessage(this, Config.WebHelper_SetGreenAndPing);
@@ -209,11 +219,11 @@ namespace FunGame.Desktop.Utils
if (socket != null)
{
string msg = "";
- CommonEnums.SocketType type = (CommonEnums.SocketType)i;
+ SocketMessageType type = (SocketMessageType)i;
// 鍙戦佹秷鎭粰鏈嶅姟鍣ㄧ
switch (type)
{
- case CommonEnums.SocketType.GetNotice:
+ case SocketMessageType.GetNotice:
msg = MakeMessage(type, "鑾峰彇鍏憡");
if (Send(msg, socket) > 0)
{
@@ -221,9 +231,9 @@ namespace FunGame.Desktop.Utils
}
else
throw new Exception("ERROR锛氭秷鎭湭閫佽揪鏈嶅姟鍣紝涓庢湇鍔″櫒杩炴帴鍙兘涓㈠け銆");
- case CommonEnums.SocketType.Login:
+ case SocketMessageType.Login:
break;
- case CommonEnums.SocketType.CheckLogin:
+ case SocketMessageType.CheckLogin:
User user;
if (objs != null && objs.Length > 2)
{
@@ -236,9 +246,16 @@ namespace FunGame.Desktop.Utils
throw new Exception("ERROR: 璇风櫥褰曡处鍙枫");
}
break;
- case CommonEnums.SocketType.Logout:
- break;
- case CommonEnums.SocketType.HeartBeat:
+ case SocketMessageType.Logout:
+ if (objs != null && objs.Length > 2)
+ {
+ user = (User)objs[2];
+ msg = MakeMessage(type, user.Userame);
+ if (Send(msg, socket) > 0)
+ return true;
+ }
+ return false;
+ case SocketMessageType.HeartBeat:
msg = MakeMessage(type, "蹇冭烦妫娴");
if (Send(msg, socket) > 0)
{
@@ -321,7 +338,7 @@ namespace FunGame.Desktop.Utils
return msg[index..];
}
- private string MakeMessage(CommonEnums.SocketType type, string msg)
+ private string MakeMessage(SocketMessageType type, string msg)
{
return (int)type + ";" + msg;
}
@@ -357,7 +374,7 @@ namespace FunGame.Desktop.Utils
Main.GetMessage(this, "Creating: SendHeartBeatStream...OK");
while (IsConnected())
{
- Send((int)CommonEnums.SocketType.HeartBeat); // 鍙戦佸績璺冲寘
+ Send((int)SocketMessageType.HeartBeat); // 鍙戦佸績璺冲寘
Thread.Sleep(20000);
}
}