建立登录框架

This commit is contained in:
Mili 2023-02-22 23:43:09 +08:00
parent 6d4eb9cacf
commit e4e471e3f1
17 changed files with 687 additions and 169 deletions

View File

@ -1,8 +1,9 @@
using Milimoe.FunGame.Core.Library.Constant; using System.Net.NetworkInformation;
using System.Net.NetworkInformation; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Milimoe.FunGame.Core.Library.Constant;
// 通用工具类,客户端和服务器端都可以直接调用的工具方法都可以写在这里 // 通用工具类,客户端和服务器端都可以直接调用的工具方法都可以写在这里
namespace Milimoe.FunGame.Core.Api.Utility namespace Milimoe.FunGame.Core.Api.Utility
@ -215,4 +216,31 @@ namespace Milimoe.FunGame.Core.Api.Utility
} }
#endregion #endregion
#region
/// <summary>
/// 使用HMACSHA512算法加密
/// </summary>
public class Encryption
{
/// <summary>
/// 使用HMACSHA512算法加密
/// </summary>
/// <param name="Message">需要加密的值</param>
/// <param name="Key">秘钥</param>
/// <returns></returns>
public static string HmacSha512(string Message, string Key)
{
byte[] MessageBytes = General.DefaultEncoding.GetBytes(Message);
Key = Convert.ToBase64String(General.DefaultEncoding.GetBytes(Key));
byte[] KeyBytes = General.DefaultEncoding.GetBytes(Key);
HMACSHA512 Hmacsha512 = new(KeyBytes);
byte[] Hash = Hmacsha512.ComputeHash(MessageBytes);
string Hamc = BitConverter.ToString(Hash).Replace("-", "");
return Hamc.ToLower();
}
}
#endregion
} }

View File

@ -3,7 +3,7 @@ namespace Milimoe.FunGame.Core.Entity
public class User public class User
{ {
public int Id { get; set; } public int Id { get; set; }
public string Userame { get; set; } = ""; public string Username { get; set; } = "";
public string Password { get; set; } = ""; public string Password { get; set; } = "";
public DateTime RegTime { get; set; } public DateTime RegTime { get; set; }
public DateTime LastTime { get; set; } public DateTime LastTime { get; set; }
@ -27,12 +27,12 @@ namespace Milimoe.FunGame.Core.Entity
internal User(string username) internal User(string username)
{ {
Userame = username; Username = username;
} }
internal User(string username, string password) internal User(string username, string password)
{ {
Userame = username; Username = username;
Password = password; Password = password;
} }
} }

View File

@ -130,6 +130,7 @@
public enum TimeType public enum TimeType
{ {
None,
General, General,
DateOnly, DateOnly,
TimeOnly, TimeOnly,

View File

@ -1,4 +1,5 @@
using Milimoe.FunGame.Desktop.Library.Interface; using Milimoe.FunGame.Core.Library.Common.Event;
using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.Model; using Milimoe.FunGame.Desktop.Model;
using Milimoe.FunGame.Desktop.UI; using Milimoe.FunGame.Desktop.UI;
@ -6,16 +7,34 @@ namespace Milimoe.FunGame.Desktop.Controller
{ {
public class LoginController : ILogin public class LoginController : ILogin
{ {
LoginModel LoginModel { get; } private LoginModel LoginModel { get; }
private Login Login { get; }
public LoginController(Login Login) public LoginController(Login Login)
{ {
this.Login = Login;
LoginModel = new LoginModel(Login); LoginModel = new LoginModel(Login);
} }
public bool LoginAccount() public static bool LoginAccount(params object[]? objs)
{ {
return LoginModel.LoginAccount(); return LoginModel.LoginAccount(objs);
}
public bool LoginAccount(string username, string password)
{
Login.OnBeforeLoginEvent(new GeneralEventArgs());
bool result = LoginModel.LoginAccount(username, password);
if (result)
{
Login.OnSucceedLoginEvent(new GeneralEventArgs());
}
else
{
Login.OnFailedLoginEvent(new GeneralEventArgs());
}
Login.OnAfterLoginEvent(new GeneralEventArgs());
return result;
} }
} }
} }

View File

@ -1,4 +1,5 @@
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Common.Event;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Interface; using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.Model; using Milimoe.FunGame.Desktop.Model;
@ -8,12 +9,14 @@ namespace Milimoe.FunGame.Desktop.Controller
{ {
public class MainController : IMain public class MainController : IMain
{ {
private MainModel MainModel { get; } public bool Connected => Do<bool>(MainSet.Connected);
public bool Connected => Do<bool>(MainControllerSet.Connected); private MainModel MainModel { get; }
private Main Main { get; }
public MainController(Main Main) public MainController(Main Main)
{ {
this.Main = Main;
MainModel = new MainModel(Main); MainModel = new MainModel(Main);
} }
@ -25,41 +28,67 @@ namespace Milimoe.FunGame.Desktop.Controller
object result = new(); object result = new();
switch(DoType) switch(DoType)
{ {
case MainControllerSet.GetServerConnection: case MainSet.GetServerConnection:
result = MainModel.GetServerConnection(); result = MainModel.GetServerConnection();
break; break;
case MainControllerSet.Connect:
case MainSet.Connect:
Main.OnBeforeConnectEvent(new GeneralEventArgs());
result = MainModel.Connect(); result = MainModel.Connect();
if ((ConnectResult)result == ConnectResult.Success)
{
Main.OnSucceedConnectEvent(new GeneralEventArgs());
}
else if ((ConnectResult)result == ConnectResult.ConnectFailed)
{
Main.OnFailedConnectEvent(new GeneralEventArgs());
}
Main.OnAfterConnectEvent(new GeneralEventArgs());
break; break;
case MainControllerSet.Connected:
case MainSet.Connected:
result = MainModel.Connected; result = MainModel.Connected;
break; break;
case MainControllerSet.Disconnect:
case MainSet.Disconnect:
Main.OnBeforeDisconnectEvent(new GeneralEventArgs());
MainModel.Disconnect();
Main.OnAfterDisconnectEvent(new GeneralEventArgs());
break;
case MainSet.Disconnected:
MainModel.Disconnect(); MainModel.Disconnect();
break; break;
case MainControllerSet.Disconnected:
MainModel.Disconnect(); case MainSet.WaitConnectAndSetYellow:
break; break;
case MainControllerSet.WaitConnectAndSetYellow:
case MainSet.WaitLoginAndSetYellow:
break; break;
case MainControllerSet.WaitLoginAndSetYellow:
case MainSet.SetGreenAndPing:
break; break;
case MainControllerSet.SetGreenAndPing:
case MainSet.SetGreen:
break; break;
case MainControllerSet.SetGreen:
case MainSet.SetYellow:
break; break;
case MainControllerSet.SetYellow:
case MainSet.SetRed:
break; break;
case MainControllerSet.SetRed:
case MainSet.SetUser:
break; break;
case MainControllerSet.SetUser:
break; case MainSet.LogOut:
case MainControllerSet.LogOut:
result = MainModel.Logout(); result = MainModel.Logout();
break; break;
case MainControllerSet.Close:
case MainSet.Close:
result = MainModel.Close(); result = MainModel.Close();
break; break;
default: default:
break; break;
} }
@ -68,22 +97,22 @@ namespace Milimoe.FunGame.Desktop.Controller
public bool GetServerConnection() public bool GetServerConnection()
{ {
return Do<bool>(MainControllerSet.GetServerConnection); return Do<bool>(MainSet.GetServerConnection);
} }
public ConnectResult Connect() public ConnectResult Connect()
{ {
return Do<ConnectResult>(MainControllerSet.Connect); return Do<ConnectResult>(MainSet.Connect);
} }
public void Disconnect() public void Disconnect()
{ {
Do<object>(MainControllerSet.Disconnect); Do<object>(MainSet.Disconnect);
} }
public void Disconnected() public void Disconnected()
{ {
Do<object>(MainControllerSet.Disconnected); Do<object>(MainSet.Disconnected);
} }
public void SetWaitConnectAndSetYellow() public void SetWaitConnectAndSetYellow()
@ -123,12 +152,12 @@ namespace Milimoe.FunGame.Desktop.Controller
public bool LogOut() public bool LogOut()
{ {
return Do<bool>(MainControllerSet.LogOut); return Do<bool>(MainSet.LogOut);
} }
public bool Close() public bool Close()
{ {
return Do<bool>(MainControllerSet.Close); return Do<bool>(MainSet.Close);
} }
} }
} }

View File

@ -0,0 +1,51 @@
using Milimoe.FunGame.Core.Interface;
using Milimoe.FunGame.Core.Library.Common.Event;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Desktop.Library.Component;
namespace Milimoe.FunGame.Desktop.Library.Base
{
public class BaseLogin : GeneralForm, ILoginEventHandler
{
public event IEventHandler.BeforeEventHandler? BeforeLogin;
public event IEventHandler.AfterEventHandler? AfterLogin;
public event IEventHandler.SucceedEventHandler? SucceedLogin;
public event IEventHandler.FailedEventHandler? FailedLogin;
public EventResult OnAfterLoginEvent(GeneralEventArgs e)
{
if (AfterLogin != null)
{
return AfterLogin(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnBeforeLoginEvent(GeneralEventArgs e)
{
if (BeforeLogin != null)
{
return BeforeLogin(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnFailedLoginEvent(GeneralEventArgs e)
{
if (FailedLogin != null)
{
return FailedLogin(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnSucceedLoginEvent(GeneralEventArgs e)
{
if (SucceedLogin != null)
{
return SucceedLogin(this, e);
}
else return EventResult.NoEventImplement;
}
}
}

View File

@ -5,7 +5,8 @@ using Milimoe.FunGame.Desktop.Library.Component;
namespace Milimoe.FunGame.Desktop.Library.Base namespace Milimoe.FunGame.Desktop.Library.Base
{ {
public class BaseMain : GeneralForm, IConnectEventHandler, IDisconnectEventHandler, ILogoutEventHandler public class BaseMain : GeneralForm, IConnectEventHandler, IDisconnectEventHandler, ILogoutEventHandler, IIntoRoomEventHandler, ISendTalkEventHandler,
ICreateRoomEventHandler, IQuitRoomEventHandler, IStartMatchEventHandler, IStartGameEventHandler, IOpenInventoryEventHandler, IOpenStoreEventHandler
{ {
public event IEventHandler.BeforeEventHandler? BeforeConnect; public event IEventHandler.BeforeEventHandler? BeforeConnect;
public event IEventHandler.AfterEventHandler? AfterConnect; public event IEventHandler.AfterEventHandler? AfterConnect;
@ -129,5 +130,333 @@ namespace Milimoe.FunGame.Desktop.Library.Base
} }
else return EventResult.NoEventImplement; else return EventResult.NoEventImplement;
} }
public event IEventHandler.BeforeEventHandler? BeforeIntoRoom;
public event IEventHandler.AfterEventHandler? AfterIntoRoom;
public event IEventHandler.SucceedEventHandler? SucceedIntoRoom;
public event IEventHandler.FailedEventHandler? FailedIntoRoom;
public EventResult OnBeforeIntoRoomEvent(GeneralEventArgs e)
{
if (BeforeIntoRoom != null)
{
return BeforeIntoRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnAfterIntoRoomEvent(GeneralEventArgs e)
{
if (AfterIntoRoom != null)
{
return AfterIntoRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnSucceedIntoRoomEvent(GeneralEventArgs e)
{
if (SucceedIntoRoom != null)
{
return SucceedIntoRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnFailedIntoRoomEvent(GeneralEventArgs e)
{
if (FailedIntoRoom != null)
{
return FailedIntoRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public event IEventHandler.BeforeEventHandler? BeforeSendTalk;
public event IEventHandler.AfterEventHandler? AfterSendTalk;
public event IEventHandler.SucceedEventHandler? SucceedSendTalk;
public event IEventHandler.FailedEventHandler? FailedSendTalk;
public EventResult OnBeforeSendTalkEvent(GeneralEventArgs e)
{
if (BeforeSendTalk != null)
{
return BeforeSendTalk(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnAfterSendTalkEvent(GeneralEventArgs e)
{
if (AfterSendTalk != null)
{
return AfterSendTalk(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnSucceedSendTalkEvent(GeneralEventArgs e)
{
if (SucceedSendTalk != null)
{
return SucceedSendTalk(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnFailedSendTalkEvent(GeneralEventArgs e)
{
if (FailedSendTalk != null)
{
return FailedSendTalk(this, e);
}
else return EventResult.NoEventImplement;
}
public event IEventHandler.BeforeEventHandler? BeforeCreateRoom;
public event IEventHandler.AfterEventHandler? AfterCreateRoom;
public event IEventHandler.SucceedEventHandler? SucceedCreateRoom;
public event IEventHandler.FailedEventHandler? FailedCreateRoom;
public EventResult OnBeforeCreateRoomEvent(GeneralEventArgs e)
{
if (BeforeCreateRoom != null)
{
return BeforeCreateRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnAfterCreateRoomEvent(GeneralEventArgs e)
{
if (AfterCreateRoom != null)
{
return AfterCreateRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnSucceedCreateRoomEvent(GeneralEventArgs e)
{
if (SucceedCreateRoom != null)
{
return SucceedCreateRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnFailedCreateRoomEvent(GeneralEventArgs e)
{
if (FailedCreateRoom != null)
{
return FailedCreateRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public event IEventHandler.BeforeEventHandler? BeforeQuitRoom;
public event IEventHandler.AfterEventHandler? AfterQuitRoom;
public event IEventHandler.SucceedEventHandler? SucceedQuitRoom;
public event IEventHandler.FailedEventHandler? FailedQuitRoom;
public EventResult OnBeforeQuitRoomEvent(GeneralEventArgs e)
{
if (BeforeQuitRoom != null)
{
return BeforeQuitRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnAfterQuitRoomEvent(GeneralEventArgs e)
{
if (AfterQuitRoom != null)
{
return AfterQuitRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnSucceedQuitRoomEvent(GeneralEventArgs e)
{
if (SucceedQuitRoom != null)
{
return SucceedQuitRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnFailedQuitRoomEvent(GeneralEventArgs e)
{
if (FailedQuitRoom != null)
{
return FailedQuitRoom(this, e);
}
else return EventResult.NoEventImplement;
}
public event IEventHandler.BeforeEventHandler? BeforeStartMatch;
public event IEventHandler.AfterEventHandler? AfterStartMatch;
public event IEventHandler.SucceedEventHandler? SucceedStartMatch;
public event IEventHandler.FailedEventHandler? FailedStartMatch;
public EventResult OnBeforeStartMatchEvent(GeneralEventArgs e)
{
if (BeforeStartMatch != null)
{
return BeforeStartMatch(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnAfterStartMatchEvent(GeneralEventArgs e)
{
if (AfterStartMatch != null)
{
return AfterStartMatch(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnSucceedStartMatchEvent(GeneralEventArgs e)
{
if (SucceedStartMatch != null)
{
return SucceedStartMatch(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnFailedStartMatchEvent(GeneralEventArgs e)
{
if (FailedStartMatch != null)
{
return FailedStartMatch(this, e);
}
else return EventResult.NoEventImplement;
}
public event IEventHandler.BeforeEventHandler? BeforeStartGame;
public event IEventHandler.AfterEventHandler? AfterStartGame;
public event IEventHandler.SucceedEventHandler? SucceedStartGame;
public event IEventHandler.FailedEventHandler? FailedStartGame;
public EventResult OnBeforeStartGameEvent(GeneralEventArgs e)
{
if (BeforeStartGame != null)
{
return BeforeStartGame(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnAfterStartGameEvent(GeneralEventArgs e)
{
if (AfterStartGame != null)
{
return AfterStartGame(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnSucceedStartGameEvent(GeneralEventArgs e)
{
if (SucceedStartGame != null)
{
return SucceedStartGame(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnFailedStartGameEvent(GeneralEventArgs e)
{
if (FailedStartGame != null)
{
return FailedStartGame(this, e);
}
else return EventResult.NoEventImplement;
}
public event IEventHandler.BeforeEventHandler? BeforeOpenInventory;
public event IEventHandler.AfterEventHandler? AfterOpenInventory;
public event IEventHandler.SucceedEventHandler? SucceedOpenInventory;
public event IEventHandler.FailedEventHandler? FailedOpenInventory;
public EventResult OnBeforeOpenInventoryEvent(GeneralEventArgs e)
{
if (BeforeOpenInventory != null)
{
return BeforeOpenInventory(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnAfterOpenInventoryEvent(GeneralEventArgs e)
{
if (AfterOpenInventory != null)
{
return AfterOpenInventory(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnSucceedOpenInventoryEvent(GeneralEventArgs e)
{
if (SucceedOpenInventory != null)
{
return SucceedOpenInventory(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnFailedOpenInventoryEvent(GeneralEventArgs e)
{
if (FailedOpenInventory != null)
{
return FailedOpenInventory(this, e);
}
else return EventResult.NoEventImplement;
}
public event IEventHandler.BeforeEventHandler? BeforeOpenStore;
public event IEventHandler.AfterEventHandler? AfterOpenStore;
public event IEventHandler.SucceedEventHandler? SucceedOpenStore;
public event IEventHandler.FailedEventHandler? FailedOpenStore;
public EventResult OnBeforeOpenStoreEvent(GeneralEventArgs e)
{
if (BeforeOpenStore != null)
{
return BeforeOpenStore(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnAfterOpenStoreEvent(GeneralEventArgs e)
{
if (AfterOpenStore != null)
{
return AfterOpenStore(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnSucceedOpenStoreEvent(GeneralEventArgs e)
{
if (SucceedOpenStore != null)
{
return SucceedOpenStore(this, e);
}
else return EventResult.NoEventImplement;
}
public EventResult OnFailedOpenStoreEvent(GeneralEventArgs e)
{
if (FailedOpenStore != null)
{
return FailedOpenStore(this, e);
}
else return EventResult.NoEventImplement;
}
} }
} }

View File

@ -3,7 +3,7 @@ using System.Text;
namespace Milimoe.FunGame.Desktop.Library namespace Milimoe.FunGame.Desktop.Library
{ {
public class MainControllerSet public class MainSet
{ {
public const string SetGreen = ".set green"; public const string SetGreen = ".set green";
public const string SetGreenAndPing = ".set greenandping"; public const string SetGreenAndPing = ".set greenandping";

View File

@ -2,6 +2,6 @@
{ {
public interface ILogin public interface ILogin
{ {
public bool LoginAccount(); public bool LoginAccount(string username, string password);
} }
} }

View File

@ -1,4 +1,5 @@
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Common.Event;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Library.Exception; using Milimoe.FunGame.Core.Library.Exception;
using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Interface; using Milimoe.FunGame.Desktop.Library.Interface;
@ -17,12 +18,38 @@ namespace Milimoe.FunGame.Desktop.Model
Socket = RunTime.Socket; Socket = RunTime.Socket;
} }
public bool LoginAccount() public static bool LoginAccount(params object[]? objs)
{ {
try try
{ {
if (Socket != null && Socket.Send(SocketMessageType.Login, "Mili", "OK") == SocketResult.Success) Core.Library.Common.Network.Socket? Socket = RunTime.Socket;
if (Socket != null && objs != null)
{
string username = "";
string password = "";
if (objs.Length > 0) username = (string)objs[0];
if (objs.Length > 1) password = (string)objs[1];
if (Socket.Send(SocketMessageType.Login, username, password) == SocketResult.Success)
{
return true;
}
}
}
catch (Exception e)
{
e.GetErrorInfo();
}
return false;
}
public bool LoginAccount(string username, string password)
{
try
{
if (LoginModel.LoginAccount(username, password))
{
return true; return true;
}
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -40,11 +40,15 @@ namespace Milimoe.FunGame.Desktop.Model
{ {
try try
{ {
Socket?.Send(SocketMessageType.Disconnect, ""); if (Socket?.Send(SocketMessageType.Disconnect, "") == SocketResult.Success)
{
Main.OnSucceedDisconnectEvent(new GeneralEventArgs());
}
} }
catch (Exception e) catch (Exception e)
{ {
Main.GetMessage(e.GetErrorInfo()); Main.GetMessage(e.GetErrorInfo());
Main.OnFailedDisconnectEvent(new GeneralEventArgs());
} }
} }
@ -78,7 +82,7 @@ namespace Milimoe.FunGame.Desktop.Model
} }
catch (Exception e) catch (Exception e)
{ {
Main.GetMessage(e.GetErrorInfo(), false); Main.GetMessage(e.GetErrorInfo(), TimeType.None);
} }
return false; return false;
@ -86,7 +90,6 @@ namespace Milimoe.FunGame.Desktop.Model
public ConnectResult Connect() public ConnectResult Connect()
{ {
Main.OnBeforeConnectEvent(new GeneralEventArgs());
if (Constant.Server_Address == "" || Constant.Server_Port <= 0) if (Constant.Server_Address == "" || Constant.Server_Port <= 0)
{ {
ShowMessage.ErrorMessage("查找可用的服务器失败!"); ShowMessage.ErrorMessage("查找可用的服务器失败!");
@ -103,7 +106,7 @@ namespace Milimoe.FunGame.Desktop.Model
if (!Config.FunGame_isConnected) if (!Config.FunGame_isConnected)
{ {
Main.CurrentRetryTimes++; Main.CurrentRetryTimes++;
if (Main.CurrentRetryTimes == 0) Main.GetMessage("开始连接服务器...", true, TimeType.General); if (Main.CurrentRetryTimes == 0) Main.GetMessage("开始连接服务器...", TimeType.General);
else Main.GetMessage("第" + Main.CurrentRetryTimes + "次重试连接服务器..."); else Main.GetMessage("第" + Main.CurrentRetryTimes + "次重试连接服务器...");
// 超过重连次数上限 // 超过重连次数上限
if (Main.CurrentRetryTimes + 1 > Main.MaxRetryTimes) if (Main.CurrentRetryTimes + 1 > Main.MaxRetryTimes)
@ -126,10 +129,8 @@ namespace Milimoe.FunGame.Desktop.Model
if (Receiving() == SocketMessageType.Connect) if (Receiving() == SocketMessageType.Connect)
{ {
Main.GetMessage("连接服务器成功请登录账号以体验FunGame。"); Main.GetMessage("连接服务器成功请登录账号以体验FunGame。");
Main.UpdateUI(MainControllerSet.Connected); Main.UpdateUI(MainSet.Connected);
StartReceiving(); StartReceiving();
Main.OnSucceedConnectEvent(new GeneralEventArgs());
Main.OnAfterConnectEvent(new GeneralEventArgs());
} }
}); });
return ConnectResult.Success; return ConnectResult.Success;
@ -147,26 +148,10 @@ namespace Milimoe.FunGame.Desktop.Model
} }
catch (Exception e) catch (Exception e)
{ {
Main.GetMessage(e.GetErrorInfo(), false); Main.GetMessage(e.GetErrorInfo(), TimeType.None);
Main.UpdateUI(MainControllerSet.SetRed); Main.UpdateUI(MainSet.SetRed);
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
if (Config.FunGame_isAutoRetry && Main.CurrentRetryTimes <= Main.MaxRetryTimes) return ConnectResult.ConnectFailed;
{
Task.Run(() =>
{
Thread.Sleep(5000);
if (Config.FunGame_isAutoRetry) Connect(); // 再次判断是否开启自动重连
});
Main.GetMessage("连接服务器失败5秒后自动尝试重连。");
Main.OnFailedConnectEvent(new GeneralEventArgs());
Main.OnAfterConnectEvent(new GeneralEventArgs());
}
else
{
Main.OnFailedConnectEvent(new GeneralEventArgs());
Main.OnAfterConnectEvent(new GeneralEventArgs());
return ConnectResult.ConnectFailed;
}
} }
return ConnectResult.CanNotConnect; return ConnectResult.CanNotConnect;
} }
@ -188,7 +173,7 @@ namespace Milimoe.FunGame.Desktop.Model
} }
catch (Exception e) catch (Exception e)
{ {
Main.GetMessage(e.GetErrorInfo(), false); Main.GetMessage(e.GetErrorInfo(), TimeType.None);
return false; return false;
} }
return true; return true;
@ -293,7 +278,7 @@ namespace Milimoe.FunGame.Desktop.Model
case SocketMessageType.HeartBeat: case SocketMessageType.HeartBeat:
if (Socket.Connected && Usercfg.LoginUser != null) if (Socket.Connected && Usercfg.LoginUser != null)
Main.UpdateUI(MainControllerSet.SetGreenAndPing); Main.UpdateUI(MainSet.SetGreenAndPing);
break; break;
case SocketMessageType.Unknown: case SocketMessageType.Unknown:
@ -304,8 +289,9 @@ namespace Milimoe.FunGame.Desktop.Model
catch (Exception e) catch (Exception e)
{ {
// 报错中断服务器连接 // 报错中断服务器连接
Main.GetMessage(e.GetErrorInfo(), false); Main.GetMessage(e.GetErrorInfo(), TimeType.None);
Main.UpdateUI(MainControllerSet.Disconnected); Main.UpdateUI(MainSet.Disconnected);
Main.OnFailedConnectEvent(new GeneralEventArgs());
Close(); Close();
} }
@ -325,7 +311,7 @@ namespace Milimoe.FunGame.Desktop.Model
Socket!.Token = msg; Socket!.Token = msg;
Main.GetMessage($"已连接服务器:{ServerName}。\n\n********** 服务器公告 **********\n\n{ServerNotice}\n\n"); Main.GetMessage($"已连接服务器:{ServerName}。\n\n********** 服务器公告 **********\n\n{ServerNotice}\n\n");
// 设置等待登录的黄灯 // 设置等待登录的黄灯
Main.UpdateUI(MainControllerSet.WaitLoginAndSetYellow); Main.UpdateUI(MainSet.WaitLoginAndSetYellow);
} }
private void SocketHandler_GetNotice(object[] objs) private void SocketHandler_GetNotice(object[] objs)
@ -339,7 +325,7 @@ namespace Milimoe.FunGame.Desktop.Model
// 返回的objs是该Login的User对象的各个属性 // 返回的objs是该Login的User对象的各个属性
if (objs.Length > 0) msg = NetworkUtility.ConvertJsonObject<string>(objs[0])!; if (objs.Length > 0) msg = NetworkUtility.ConvertJsonObject<string>(objs[0])!;
Main.GetMessage(msg); Main.GetMessage(msg);
Main.UpdateUI(MainControllerSet.SetUser, new object[] { Factory.New<User>(msg) }); Main.UpdateUI(MainSet.SetUser, new object[] { Factory.New<User>(msg) });
} }
private void SocketHandler_Disconnect(object[] objs) private void SocketHandler_Disconnect(object[] objs)
@ -347,7 +333,7 @@ namespace Milimoe.FunGame.Desktop.Model
string msg = ""; string msg = "";
if (objs.Length > 0) msg = NetworkUtility.ConvertJsonObject<string>(objs[0])!; if (objs.Length > 0) msg = NetworkUtility.ConvertJsonObject<string>(objs[0])!;
Main.GetMessage(msg); Main.GetMessage(msg);
Main.UpdateUI(MainControllerSet.Disconnect); Main.UpdateUI(MainSet.Disconnect);
Close(); Close();
} }
} }

View File

@ -44,6 +44,15 @@
this.TransparentRect.SuspendLayout(); this.TransparentRect.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// Title
//
this.Title.Font = new System.Drawing.Font("LanaPixel", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
this.Title.Location = new System.Drawing.Point(7, 6);
this.Title.Size = new System.Drawing.Size(387, 47);
this.Title.TabIndex = 8;
this.Title.Text = "Welcome to FunGame!";
this.Title.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// ExitButton // ExitButton
// //
this.ExitButton.Anchor = System.Windows.Forms.AnchorStyles.None; this.ExitButton.Anchor = System.Windows.Forms.AnchorStyles.None;
@ -58,11 +67,11 @@
this.ExitButton.ForeColor = System.Drawing.Color.Red; this.ExitButton.ForeColor = System.Drawing.Color.Red;
this.ExitButton.Location = new System.Drawing.Point(451, 4); this.ExitButton.Location = new System.Drawing.Point(451, 4);
this.ExitButton.Name = "ExitButton"; this.ExitButton.Name = "ExitButton";
this.ExitButton.RelativeForm = this;
this.ExitButton.Size = new System.Drawing.Size(47, 47); this.ExitButton.Size = new System.Drawing.Size(47, 47);
this.ExitButton.TabIndex = 7; this.ExitButton.TabIndex = 7;
this.ExitButton.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.ExitButton.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.ExitButton.UseVisualStyleBackColor = false; this.ExitButton.UseVisualStyleBackColor = false;
this.ExitButton.RelativeForm = this;
// //
// MinButton // MinButton
// //
@ -78,21 +87,11 @@
this.MinButton.ForeColor = System.Drawing.Color.Black; this.MinButton.ForeColor = System.Drawing.Color.Black;
this.MinButton.Location = new System.Drawing.Point(398, 4); this.MinButton.Location = new System.Drawing.Point(398, 4);
this.MinButton.Name = "MinButton"; this.MinButton.Name = "MinButton";
this.MinButton.RelativeForm = this;
this.MinButton.Size = new System.Drawing.Size(47, 47); this.MinButton.Size = new System.Drawing.Size(47, 47);
this.MinButton.TabIndex = 6; this.MinButton.TabIndex = 6;
this.MinButton.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.MinButton.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.MinButton.UseVisualStyleBackColor = false; this.MinButton.UseVisualStyleBackColor = false;
this.MinButton.RelativeForm = this;
//
// Title
//
this.Title.Font = new System.Drawing.Font("LanaPixel", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
this.Title.Location = new System.Drawing.Point(7, 6);
this.Title.Name = "Title";
this.Title.Size = new System.Drawing.Size(387, 47);
this.Title.TabIndex = 8;
this.Title.Text = "Welcome to FunGame!";
this.Title.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
// //
// Username // Username
// //
@ -151,6 +150,7 @@
this.GoToLogin.TabIndex = 2; this.GoToLogin.TabIndex = 2;
this.GoToLogin.Text = "账号登录"; this.GoToLogin.Text = "账号登录";
this.GoToLogin.UseVisualStyleBackColor = true; this.GoToLogin.UseVisualStyleBackColor = true;
this.GoToLogin.Click += new System.EventHandler(this.GoToLogin_Click);
// //
// ForgetPassword // ForgetPassword
// //
@ -161,6 +161,7 @@
this.ForgetPassword.TabIndex = 5; this.ForgetPassword.TabIndex = 5;
this.ForgetPassword.Text = "找回密码"; this.ForgetPassword.Text = "找回密码";
this.ForgetPassword.UseVisualStyleBackColor = true; this.ForgetPassword.UseVisualStyleBackColor = true;
this.ForgetPassword.Click += new System.EventHandler(this.ForgetPassword_Click);
// //
// FastLogin // FastLogin
// //
@ -171,6 +172,7 @@
this.FastLogin.TabIndex = 3; this.FastLogin.TabIndex = 3;
this.FastLogin.Text = "快捷登录"; this.FastLogin.Text = "快捷登录";
this.FastLogin.UseVisualStyleBackColor = true; this.FastLogin.UseVisualStyleBackColor = true;
this.FastLogin.Click += new System.EventHandler(this.FastLogin_Click);
// //
// TransparentRect // TransparentRect
// //
@ -195,6 +197,17 @@
this.TransparentRect.Size = new System.Drawing.Size(503, 289); this.TransparentRect.Size = new System.Drawing.Size(503, 289);
this.TransparentRect.TabIndex = 11; this.TransparentRect.TabIndex = 11;
this.TransparentRect.TabStop = false; this.TransparentRect.TabStop = false;
this.TransparentRect.Controls.SetChildIndex(this.PasswordText, 0);
this.TransparentRect.Controls.SetChildIndex(this.RegButton, 0);
this.TransparentRect.Controls.SetChildIndex(this.Password, 0);
this.TransparentRect.Controls.SetChildIndex(this.GoToLogin, 0);
this.TransparentRect.Controls.SetChildIndex(this.Username, 0);
this.TransparentRect.Controls.SetChildIndex(this.ForgetPassword, 0);
this.TransparentRect.Controls.SetChildIndex(this.UsernameText, 0);
this.TransparentRect.Controls.SetChildIndex(this.FastLogin, 0);
this.TransparentRect.Controls.SetChildIndex(this.ExitButton, 0);
this.TransparentRect.Controls.SetChildIndex(this.MinButton, 0);
this.TransparentRect.Controls.SetChildIndex(this.Title, 0);
// //
// Login // Login
// //
@ -203,7 +216,6 @@
this.BackColor = System.Drawing.Color.WhiteSmoke; this.BackColor = System.Drawing.Color.WhiteSmoke;
this.ClientSize = new System.Drawing.Size(503, 289); this.ClientSize = new System.Drawing.Size(503, 289);
this.Controls.Add(this.TransparentRect); this.Controls.Add(this.TransparentRect);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Login"; this.Name = "Login";
this.Opacity = 0.9D; this.Opacity = 0.9D;

View File

@ -1,13 +1,48 @@
using Milimoe.FunGame.Desktop.Library.Component; using Milimoe.FunGame.Core.Entity;
using Milimoe.FunGame.Core.Library.Exception;
using Milimoe.FunGame.Desktop.Controller;
using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Base;
using Milimoe.FunGame.Desktop.Library.Component;
using Milimoe.FunGame.Desktop.Utility; using Milimoe.FunGame.Desktop.Utility;
namespace Milimoe.FunGame.Desktop.UI namespace Milimoe.FunGame.Desktop.UI
{ {
public partial class Login : GeneralForm public partial class Login : BaseLogin
{ {
public Login() private LoginController LoginController;
private Main Main;
public Login(Main Main)
{ {
InitializeComponent(); InitializeComponent();
this.Main = Main;
LoginController = new LoginController(this);
}
private void Login_Handler()
{
try
{
string username = UsernameText.Text.Trim();
string password = PasswordText.Text.Trim();
if (username == "" || password == "")
{
ShowMessage.ErrorMessage("账号或密码不能为空!");
UsernameText.Focus();
return;
}
password = Core.Api.Utility.Encryption.HmacSha512(password, username);
if (LoginController.LoginAccount(username, password))
{
Main.UpdateUI(MainSet.LogIn, new object[] { Core.Api.Utility.Factory.NewSingle<User>(username, password) });
}
else ShowMessage.Message("登录失败!!", "登录失败");
}
catch (Exception e)
{
RunTime.WritelnSystemInfo(e.GetErrorInfo());
}
} }
/// <summary> /// <summary>
@ -19,5 +54,20 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
OpenForm.SingleForm(Core.Library.Constant.FormType.Register, Core.Library.Constant.OpenFormType.Dialog); OpenForm.SingleForm(Core.Library.Constant.FormType.Register, Core.Library.Constant.OpenFormType.Dialog);
} }
private void FastLogin_Click(object sender, EventArgs e)
{
ShowMessage.TipMessage("与No.16对话即可获得快速登录秘钥,快去试试吧!");
}
private void GoToLogin_Click(object sender, EventArgs e)
{
Login_Handler();
}
private void ForgetPassword_Click(object sender, EventArgs e)
{
ShowMessage.TipMessage("暂不支持找回密码~");
}
} }
} }

View File

@ -71,6 +71,12 @@
eR/MUx+QvEfyPpinPiB5j+R9ME994BT5jv9Q+yX+S74/XvIdkpY7JUbXJnJZ8twAAAAASUVORK5CYII= eR/MUx+QvEfyPpinPiB5j+R9ME994BT5jv9Q+yX+S74/XvIdkpY7JUbXJnJZ8twAAAAASUVORK5CYII=
</value> </value>
</data> </data>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="TransparentRect.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="MinButton.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="MinButton.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
@ -82,37 +88,28 @@
xlOMpxhPMZ5iPMV4ivGUU3xC//iESizRsfmRb9P6wwAAAABJRU5ErkJggg== xlOMpxhPMZ5iPMV4ivGUU3xC//iESizRsfmRb9P6wwAAAABJRU5ErkJggg==
</value> </value>
</data> </data>
<metadata name="Title.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="FastLogin.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Username.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Password.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="UsernameText.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="UsernameText.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="PasswordText.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="ForgetPassword.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="RegButton.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="Username.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="GoToLogin.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="GoToLogin.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="ForgetPassword.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="Password.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="FastLogin.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="RegButton.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="TransparentRect.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="PasswordText.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">

View File

@ -175,7 +175,8 @@ namespace Milimoe.FunGame.Desktop.UI
this.TalkText.TabIndex = 2; this.TalkText.TabIndex = 2;
this.TalkText.Text = "向消息队列发送消息..."; this.TalkText.Text = "向消息队列发送消息...";
this.TalkText.WordWrap = false; this.TalkText.WordWrap = false;
this.TalkText.Click += new System.EventHandler(this.TalkText_Click); this.TalkText.Click += new System.EventHandler(this.TalkText_ClickAndFocused);
this.TalkText.GotFocus += new System.EventHandler(this.TalkText_ClickAndFocused);
this.TalkText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.TalkText_KeyUp); this.TalkText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.TalkText_KeyUp);
this.TalkText.Leave += new System.EventHandler(this.TalkText_Leave); this.TalkText.Leave += new System.EventHandler(this.TalkText_Leave);
// //
@ -292,7 +293,8 @@ namespace Milimoe.FunGame.Desktop.UI
this.RoomText.TabIndex = 1; this.RoomText.TabIndex = 1;
this.RoomText.Text = "键入房间代号..."; this.RoomText.Text = "键入房间代号...";
this.RoomText.WordWrap = false; this.RoomText.WordWrap = false;
this.RoomText.Click += new System.EventHandler(this.RoomText_Click); this.RoomText.Click += new System.EventHandler(this.RoomText_ClickAndFocused);
this.RoomText.GotFocus += new System.EventHandler(this.RoomText_ClickAndFocused);
this.RoomText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.RoomText_KeyUp); this.RoomText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.RoomText_KeyUp);
this.RoomText.Leave += new System.EventHandler(this.RoomText_Leave); this.RoomText.Leave += new System.EventHandler(this.RoomText_Leave);
// //

View File

@ -10,10 +10,11 @@ using Milimoe.FunGame.Desktop.Library.Base;
using Milimoe.FunGame.Desktop.Library.Component; using Milimoe.FunGame.Desktop.Library.Component;
using Milimoe.FunGame.Desktop.Utility; using Milimoe.FunGame.Desktop.Utility;
using System.Diagnostics; using System.Diagnostics;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace Milimoe.FunGame.Desktop.UI namespace Milimoe.FunGame.Desktop.UI
{ {
public partial class Main : BaseMain, IConnectEvent public partial class Main : BaseMain
{ {
#region #region
@ -78,8 +79,6 @@ namespace Milimoe.FunGame.Desktop.UI
protected override void BindEvent() protected override void BindEvent()
{ {
base.BindEvent(); base.BindEvent();
AfterConnect += AfterConnectEvent;
BeforeConnect += BeforeConnectEvent;
FailedConnect += FailedConnectEvent; FailedConnect += FailedConnectEvent;
SucceedConnect += SucceedConnectEvent; SucceedConnect += SucceedConnectEvent;
} }
@ -103,7 +102,7 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
switch (updatetype) switch (updatetype)
{ {
case MainControllerSet.SetGreen: case MainSet.SetGreen:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Green); SetServerStatusLight((int)LightType.Green);
SetButtonEnableIfLogon(true, ClientState.Online); SetButtonEnableIfLogon(true, ClientState.Online);
@ -111,7 +110,7 @@ namespace Milimoe.FunGame.Desktop.UI
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case MainControllerSet.SetGreenAndPing: case MainSet.SetGreenAndPing:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(Constant.Server_Address)); SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(Constant.Server_Address));
SetButtonEnableIfLogon(true, ClientState.Online); SetButtonEnableIfLogon(true, ClientState.Online);
@ -119,7 +118,7 @@ namespace Milimoe.FunGame.Desktop.UI
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case MainControllerSet.SetYellow: case MainSet.SetYellow:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow); SetServerStatusLight((int)LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
@ -127,7 +126,7 @@ namespace Milimoe.FunGame.Desktop.UI
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case MainControllerSet.WaitConnectAndSetYellow: case MainSet.WaitConnectAndSetYellow:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow); SetServerStatusLight((int)LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
@ -140,7 +139,7 @@ namespace Milimoe.FunGame.Desktop.UI
} }
break; break;
case MainControllerSet.WaitLoginAndSetYellow: case MainSet.WaitLoginAndSetYellow:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow, true); SetServerStatusLight((int)LightType.Yellow, true);
SetButtonEnableIfLogon(false, ClientState.WaitLogin); SetButtonEnableIfLogon(false, ClientState.WaitLogin);
@ -148,32 +147,21 @@ namespace Milimoe.FunGame.Desktop.UI
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case MainControllerSet.SetRed: case MainSet.SetRed:
SetServerStatusLight((int)LightType.Red); SetServerStatusLight((int)LightType.Red);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
Config.FunGame_isConnected = false; Config.FunGame_isConnected = false;
break; break;
case MainControllerSet.Disconnected: case MainSet.Disconnected:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
Config.FunGame_isConnected = false; Config.FunGame_isConnected = false;
SetServerStatusLight((int)LightType.Red); SetServerStatusLight((int)LightType.Red);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
LogoutAccount(); LogoutAccount();
if (Config.FunGame_isAutoRetry && CurrentRetryTimes <= MaxRetryTimes)
{
Task.Run(() =>
{
Thread.Sleep(5000);
if (Config.FunGame_isAutoRetry) MainController?.Connect(); // 再次判断是否开启自动重连
});
WritelnSystemInfo("连接服务器失败5秒后自动尝试重连。");
}
else
WritelnSystemInfo("无法连接至服务器,请检查你的网络连接。");
break; break;
case MainControllerSet.Disconnect: case MainSet.Disconnect:
Config.FunGame_isAutoRetry = false; Config.FunGame_isAutoRetry = false;
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
Config.FunGame_isAutoConnect = false; Config.FunGame_isAutoConnect = false;
@ -184,7 +172,11 @@ namespace Milimoe.FunGame.Desktop.UI
LogoutAccount(); LogoutAccount();
break; break;
case MainControllerSet.LogOut: case MainSet.LogIn:
LoginAccount(objs);
break;
case MainSet.LogOut:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
Config.FunGame_isConnected = false; Config.FunGame_isConnected = false;
Config.FunGame_isAutoLogin = false; Config.FunGame_isAutoLogin = false;
@ -202,20 +194,20 @@ namespace Milimoe.FunGame.Desktop.UI
} }
break; break;
case MainControllerSet.SetUser: case MainSet.SetUser:
if (objs != null && objs.Length > 1) if (objs != null && objs.Length > 1)
{ {
SetLoginUser(objs); SetLoginUser(objs);
} }
break; break;
case MainControllerSet.Connected: case MainSet.Connected:
NoticeText.Text = Config.FunGame_Notice; NoticeText.Text = Config.FunGame_Notice;
break; break;
default: default:
// 直接调用UpdateUI(string)输出该string到控制台。 // 直接调用UpdateUI(string)相当于调用GetMessage(string)输出该string到控制台。
// 相当于调用GetMessage(string) // 尽量避免使用除MainControllerSet之外的string调用此方法
WritelnSystemInfo(updatetype); WritelnSystemInfo(updatetype);
break; break;
} }
@ -224,20 +216,20 @@ namespace Milimoe.FunGame.Desktop.UI
catch (Exception e) catch (Exception e)
{ {
WritelnGameInfo(e.GetErrorInfo()); WritelnGameInfo(e.GetErrorInfo());
UpdateUI(MainControllerSet.SetRed); UpdateUI(MainSet.SetRed);
} }
} }
InvokeUpdateUI(action); InvokeUpdateUI(action);
} }
public void GetMessage(string? msg, bool time = true, TimeType timetype = TimeType.TimeOnly) public void GetMessage(string? msg, TimeType timetype = TimeType.TimeOnly)
{ {
void action() void action()
{ {
try try
{ {
if (msg == null || msg == "") return; if (msg == null || msg == "") return;
if (time) if (timetype != TimeType.None)
{ {
WritelnGameInfo(DateTimeUtility.GetDateTimeToString(timetype) + " >> " + msg); WritelnGameInfo(DateTimeUtility.GetDateTimeToString(timetype) + " >> " + msg);
} }
@ -472,6 +464,7 @@ namespace Milimoe.FunGame.Desktop.UI
RoomText.Enabled = false; RoomText.Enabled = false;
ShowMessage.TipMessage("请输入房间号。"); ShowMessage.TipMessage("请输入房间号。");
RoomText.Enabled = true; RoomText.Enabled = true;
RoomText.Focus();
} }
else else
{ {
@ -613,14 +606,14 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
if (objs != null && objs.Length > 0) if (objs != null && objs.Length > 0)
{ {
Usercfg.LoginUser = (User)objs[2]; Usercfg.LoginUser = (User)objs[0];
Usercfg.LoginUserName = Usercfg.LoginUser.Userame; Usercfg.LoginUserName = Usercfg.LoginUser.Username;
} }
NowAccount.Text = "[ID] " + Usercfg.LoginUserName; NowAccount.Text = "[ID] " + Usercfg.LoginUserName;
Login.Visible = false; Login.Visible = false;
Logout.Visible = true; Logout.Visible = true;
SetServerStatusLight((int)LightType.Green); SetServerStatusLight((int)LightType.Green);
ShowMessage.TipMessage("欢迎回来, " + Usercfg.LoginUserName + "", "登录成功", 5); ShowMessage.Message($"欢迎回来,{Usercfg.LoginUserName}", "登录成功", 5);
} }
/// <summary> /// <summary>
@ -673,6 +666,7 @@ namespace Milimoe.FunGame.Desktop.UI
TalkText.Enabled = false; TalkText.Enabled = false;
ShowMessage.TipMessage("消息不能为空,请重新输入。"); ShowMessage.TipMessage("消息不能为空,请重新输入。");
TalkText.Enabled = true; TalkText.Enabled = true;
TalkText.Focus();
} }
} }
@ -950,7 +944,7 @@ namespace Milimoe.FunGame.Desktop.UI
private void Login_Click(object sender, EventArgs e) private void Login_Click(object sender, EventArgs e)
{ {
if (MainController != null && Config.FunGame_isConnected) if (MainController != null && Config.FunGame_isConnected)
OpenForm.SingleForm(FormType.Login, OpenFormType.Dialog); OpenForm.SingleForm(FormType.Login, OpenFormType.Dialog, this);
else else
ShowMessage.WarningMessage("请先连接服务器!"); ShowMessage.WarningMessage("请先连接服务器!");
} }
@ -1021,11 +1015,11 @@ namespace Milimoe.FunGame.Desktop.UI
} }
/// <summary> /// <summary>
/// 点击房间号输入框事件 /// 房间号输入框点击/焦点事件
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void RoomText_Click(object sender, EventArgs e) private void RoomText_ClickAndFocused(object sender, EventArgs e)
{ {
if (RoomText.Text.Equals("键入房间代号...")) if (RoomText.Text.Equals("键入房间代号..."))
{ {
@ -1064,11 +1058,11 @@ namespace Milimoe.FunGame.Desktop.UI
} }
/// <summary> /// <summary>
/// 点击聊天框事件 /// 聊天框点击/焦点事件
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void TalkText_Click(object sender, EventArgs e) private void TalkText_ClickAndFocused(object sender, EventArgs e)
{ {
if (TalkText.Text.Equals("向消息队列发送消息...")) if (TalkText.Text.Equals("向消息队列发送消息..."))
{ {
@ -1130,28 +1124,6 @@ namespace Milimoe.FunGame.Desktop.UI
} }
} }
/// <summary>
/// 连接服务器前触发事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <returns></returns>
public EventResult BeforeConnectEvent(object sender, GeneralEventArgs e)
{
return EventResult.Success;
}
/// <summary>
/// 连接服务器后触发事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <returns></returns>
public EventResult AfterConnectEvent(object sender, GeneralEventArgs e)
{
return EventResult.Success;
}
/// <summary> /// <summary>
/// 连接服务器失败后触发事件 /// 连接服务器失败后触发事件
/// </summary> /// </summary>
@ -1160,6 +1132,16 @@ namespace Milimoe.FunGame.Desktop.UI
/// <returns></returns> /// <returns></returns>
public EventResult FailedConnectEvent(object sender, GeneralEventArgs e) public EventResult FailedConnectEvent(object sender, GeneralEventArgs e)
{ {
if (Config.FunGame_isAutoRetry && CurrentRetryTimes <= MaxRetryTimes)
{
Task.Run(() =>
{
Thread.Sleep(5000);
if (Config.FunGame_isAutoRetry) MainController?.Connect(); // 再次判断是否开启自动重连
});
GetMessage("连接服务器失败5秒后自动尝试重连。");
}
else GetMessage("无法连接至服务器,请检查你的网络连接。");
return EventResult.Success; return EventResult.Success;
} }

View File

@ -29,9 +29,14 @@ namespace Milimoe.FunGame.Desktop.Utility
RunTime.Register = (Register)form; RunTime.Register = (Register)form;
break; break;
case FormType.Login: case FormType.Login:
form = new Login(); Main? main = default;
IsExist = RunTime.Login != null; if (objs != null && objs.Length > 0) main = (Main)objs[0];
RunTime.Login = (Login)form; if (main != null)
{
form = new Login(main);
IsExist = RunTime.Login != null;
RunTime.Login = (Login)form;
}
break; break;
case FormType.Inventory: case FormType.Inventory:
form = new InventoryUI(); form = new InventoryUI();