建立登录框架

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.Json;
using System.Text.RegularExpressions;
using Milimoe.FunGame.Core.Library.Constant;
// 通用工具类,客户端和服务器端都可以直接调用的工具方法都可以写在这里
namespace Milimoe.FunGame.Core.Api.Utility
@ -215,4 +216,31 @@ namespace Milimoe.FunGame.Core.Api.Utility
}
#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 int Id { get; set; }
public string Userame { get; set; } = "";
public string Username { get; set; } = "";
public string Password { get; set; } = "";
public DateTime RegTime { get; set; }
public DateTime LastTime { get; set; }
@ -27,12 +27,12 @@ namespace Milimoe.FunGame.Core.Entity
internal User(string username)
{
Userame = username;
Username = username;
}
internal User(string username, string password)
{
Userame = username;
Username = username;
Password = password;
}
}

View File

@ -130,6 +130,7 @@
public enum TimeType
{
None,
General,
DateOnly,
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.UI;
@ -6,16 +7,34 @@ namespace Milimoe.FunGame.Desktop.Controller
{
public class LoginController : ILogin
{
LoginModel LoginModel { get; }
private LoginModel LoginModel { get; }
private Login Login { get; }
public LoginController(Login Login)
{
this.Login = 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.Interface;
using Milimoe.FunGame.Desktop.Model;
@ -8,12 +9,14 @@ namespace Milimoe.FunGame.Desktop.Controller
{
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)
{
this.Main = Main;
MainModel = new MainModel(Main);
}
@ -25,41 +28,67 @@ namespace Milimoe.FunGame.Desktop.Controller
object result = new();
switch(DoType)
{
case MainControllerSet.GetServerConnection:
case MainSet.GetServerConnection:
result = MainModel.GetServerConnection();
break;
case MainControllerSet.Connect:
case MainSet.Connect:
Main.OnBeforeConnectEvent(new GeneralEventArgs());
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;
case MainControllerSet.Connected:
case MainSet.Connected:
result = MainModel.Connected;
break;
case MainControllerSet.Disconnect:
case MainSet.Disconnect:
Main.OnBeforeDisconnectEvent(new GeneralEventArgs());
MainModel.Disconnect();
Main.OnAfterDisconnectEvent(new GeneralEventArgs());
break;
case MainSet.Disconnected:
MainModel.Disconnect();
break;
case MainControllerSet.Disconnected:
MainModel.Disconnect();
case MainSet.WaitConnectAndSetYellow:
break;
case MainControllerSet.WaitConnectAndSetYellow:
case MainSet.WaitLoginAndSetYellow:
break;
case MainControllerSet.WaitLoginAndSetYellow:
case MainSet.SetGreenAndPing:
break;
case MainControllerSet.SetGreenAndPing:
case MainSet.SetGreen:
break;
case MainControllerSet.SetGreen:
case MainSet.SetYellow:
break;
case MainControllerSet.SetYellow:
case MainSet.SetRed:
break;
case MainControllerSet.SetRed:
case MainSet.SetUser:
break;
case MainControllerSet.SetUser:
break;
case MainControllerSet.LogOut:
case MainSet.LogOut:
result = MainModel.Logout();
break;
case MainControllerSet.Close:
case MainSet.Close:
result = MainModel.Close();
break;
default:
break;
}
@ -68,22 +97,22 @@ namespace Milimoe.FunGame.Desktop.Controller
public bool GetServerConnection()
{
return Do<bool>(MainControllerSet.GetServerConnection);
return Do<bool>(MainSet.GetServerConnection);
}
public ConnectResult Connect()
{
return Do<ConnectResult>(MainControllerSet.Connect);
return Do<ConnectResult>(MainSet.Connect);
}
public void Disconnect()
{
Do<object>(MainControllerSet.Disconnect);
Do<object>(MainSet.Disconnect);
}
public void Disconnected()
{
Do<object>(MainControllerSet.Disconnected);
Do<object>(MainSet.Disconnected);
}
public void SetWaitConnectAndSetYellow()
@ -123,12 +152,12 @@ namespace Milimoe.FunGame.Desktop.Controller
public bool LogOut()
{
return Do<bool>(MainControllerSet.LogOut);
return Do<bool>(MainSet.LogOut);
}
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
{
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.AfterEventHandler? AfterConnect;
@ -129,5 +130,333 @@ namespace Milimoe.FunGame.Desktop.Library.Base
}
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
{
public class MainControllerSet
public class MainSet
{
public const string SetGreen = ".set green";
public const string SetGreenAndPing = ".set greenandping";

View File

@ -2,6 +2,6 @@
{
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.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Interface;
@ -17,13 +18,39 @@ namespace Milimoe.FunGame.Desktop.Model
Socket = RunTime.Socket;
}
public bool LoginAccount()
public static bool LoginAccount(params object[]? objs)
{
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;
}
}
catch (Exception e)
{
e.GetErrorInfo();

View File

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

View File

@ -44,6 +44,15 @@
this.TransparentRect.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
//
this.ExitButton.Anchor = System.Windows.Forms.AnchorStyles.None;
@ -58,11 +67,11 @@
this.ExitButton.ForeColor = System.Drawing.Color.Red;
this.ExitButton.Location = new System.Drawing.Point(451, 4);
this.ExitButton.Name = "ExitButton";
this.ExitButton.RelativeForm = this;
this.ExitButton.Size = new System.Drawing.Size(47, 47);
this.ExitButton.TabIndex = 7;
this.ExitButton.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.ExitButton.UseVisualStyleBackColor = false;
this.ExitButton.RelativeForm = this;
//
// MinButton
//
@ -78,21 +87,11 @@
this.MinButton.ForeColor = System.Drawing.Color.Black;
this.MinButton.Location = new System.Drawing.Point(398, 4);
this.MinButton.Name = "MinButton";
this.MinButton.RelativeForm = this;
this.MinButton.Size = new System.Drawing.Size(47, 47);
this.MinButton.TabIndex = 6;
this.MinButton.TextAlign = System.Drawing.ContentAlignment.TopLeft;
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
//
@ -151,6 +150,7 @@
this.GoToLogin.TabIndex = 2;
this.GoToLogin.Text = "账号登录";
this.GoToLogin.UseVisualStyleBackColor = true;
this.GoToLogin.Click += new System.EventHandler(this.GoToLogin_Click);
//
// ForgetPassword
//
@ -161,6 +161,7 @@
this.ForgetPassword.TabIndex = 5;
this.ForgetPassword.Text = "找回密码";
this.ForgetPassword.UseVisualStyleBackColor = true;
this.ForgetPassword.Click += new System.EventHandler(this.ForgetPassword_Click);
//
// FastLogin
//
@ -171,6 +172,7 @@
this.FastLogin.TabIndex = 3;
this.FastLogin.Text = "快捷登录";
this.FastLogin.UseVisualStyleBackColor = true;
this.FastLogin.Click += new System.EventHandler(this.FastLogin_Click);
//
// TransparentRect
//
@ -195,6 +197,17 @@
this.TransparentRect.Size = new System.Drawing.Size(503, 289);
this.TransparentRect.TabIndex = 11;
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
//
@ -203,7 +216,6 @@
this.BackColor = System.Drawing.Color.WhiteSmoke;
this.ClientSize = new System.Drawing.Size(503, 289);
this.Controls.Add(this.TransparentRect);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Login";
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;
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();
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>
@ -19,5 +54,20 @@ namespace Milimoe.FunGame.Desktop.UI
{
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=
</value>
</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">
<value>True</value>
</metadata>
@ -82,37 +88,28 @@
xlOMpxhPMZ5iPMV4ivGUU3xC//iESizRsfmRb9P6wwAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="Title.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">
<metadata name="FastLogin.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="UsernameText.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</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>
</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>
</metadata>
<metadata name="GoToLogin.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</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>
</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>
</metadata>
<metadata name="TransparentRect.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">
<metadata name="PasswordText.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<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.Text = "向消息队列发送消息...";
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.Leave += new System.EventHandler(this.TalkText_Leave);
//
@ -292,7 +293,8 @@ namespace Milimoe.FunGame.Desktop.UI
this.RoomText.TabIndex = 1;
this.RoomText.Text = "键入房间代号...";
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.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.Utility;
using System.Diagnostics;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace Milimoe.FunGame.Desktop.UI
{
public partial class Main : BaseMain, IConnectEvent
public partial class Main : BaseMain
{
#region
@ -78,8 +79,6 @@ namespace Milimoe.FunGame.Desktop.UI
protected override void BindEvent()
{
base.BindEvent();
AfterConnect += AfterConnectEvent;
BeforeConnect += BeforeConnectEvent;
FailedConnect += FailedConnectEvent;
SucceedConnect += SucceedConnectEvent;
}
@ -103,7 +102,7 @@ namespace Milimoe.FunGame.Desktop.UI
{
switch (updatetype)
{
case MainControllerSet.SetGreen:
case MainSet.SetGreen:
Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Green);
SetButtonEnableIfLogon(true, ClientState.Online);
@ -111,7 +110,7 @@ namespace Milimoe.FunGame.Desktop.UI
CurrentRetryTimes = 0;
break;
case MainControllerSet.SetGreenAndPing:
case MainSet.SetGreenAndPing:
Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(Constant.Server_Address));
SetButtonEnableIfLogon(true, ClientState.Online);
@ -119,7 +118,7 @@ namespace Milimoe.FunGame.Desktop.UI
CurrentRetryTimes = 0;
break;
case MainControllerSet.SetYellow:
case MainSet.SetYellow:
Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
@ -127,7 +126,7 @@ namespace Milimoe.FunGame.Desktop.UI
CurrentRetryTimes = 0;
break;
case MainControllerSet.WaitConnectAndSetYellow:
case MainSet.WaitConnectAndSetYellow:
Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
@ -140,7 +139,7 @@ namespace Milimoe.FunGame.Desktop.UI
}
break;
case MainControllerSet.WaitLoginAndSetYellow:
case MainSet.WaitLoginAndSetYellow:
Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow, true);
SetButtonEnableIfLogon(false, ClientState.WaitLogin);
@ -148,32 +147,21 @@ namespace Milimoe.FunGame.Desktop.UI
CurrentRetryTimes = 0;
break;
case MainControllerSet.SetRed:
case MainSet.SetRed:
SetServerStatusLight((int)LightType.Red);
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
Config.FunGame_isConnected = false;
break;
case MainControllerSet.Disconnected:
case MainSet.Disconnected:
Config.FunGame_isRetrying = false;
Config.FunGame_isConnected = false;
SetServerStatusLight((int)LightType.Red);
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
LogoutAccount();
if (Config.FunGame_isAutoRetry && CurrentRetryTimes <= MaxRetryTimes)
{
Task.Run(() =>
{
Thread.Sleep(5000);
if (Config.FunGame_isAutoRetry) MainController?.Connect(); // 再次判断是否开启自动重连
});
WritelnSystemInfo("连接服务器失败5秒后自动尝试重连。");
}
else
WritelnSystemInfo("无法连接至服务器,请检查你的网络连接。");
break;
case MainControllerSet.Disconnect:
case MainSet.Disconnect:
Config.FunGame_isAutoRetry = false;
Config.FunGame_isRetrying = false;
Config.FunGame_isAutoConnect = false;
@ -184,7 +172,11 @@ namespace Milimoe.FunGame.Desktop.UI
LogoutAccount();
break;
case MainControllerSet.LogOut:
case MainSet.LogIn:
LoginAccount(objs);
break;
case MainSet.LogOut:
Config.FunGame_isRetrying = false;
Config.FunGame_isConnected = false;
Config.FunGame_isAutoLogin = false;
@ -202,20 +194,20 @@ namespace Milimoe.FunGame.Desktop.UI
}
break;
case MainControllerSet.SetUser:
case MainSet.SetUser:
if (objs != null && objs.Length > 1)
{
SetLoginUser(objs);
}
break;
case MainControllerSet.Connected:
case MainSet.Connected:
NoticeText.Text = Config.FunGame_Notice;
break;
default:
// 直接调用UpdateUI(string)输出该string到控制台。
// 相当于调用GetMessage(string)
// 直接调用UpdateUI(string)相当于调用GetMessage(string)输出该string到控制台。
// 尽量避免使用除MainControllerSet之外的string调用此方法
WritelnSystemInfo(updatetype);
break;
}
@ -224,20 +216,20 @@ namespace Milimoe.FunGame.Desktop.UI
catch (Exception e)
{
WritelnGameInfo(e.GetErrorInfo());
UpdateUI(MainControllerSet.SetRed);
UpdateUI(MainSet.SetRed);
}
}
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()
{
try
{
if (msg == null || msg == "") return;
if (time)
if (timetype != TimeType.None)
{
WritelnGameInfo(DateTimeUtility.GetDateTimeToString(timetype) + " >> " + msg);
}
@ -472,6 +464,7 @@ namespace Milimoe.FunGame.Desktop.UI
RoomText.Enabled = false;
ShowMessage.TipMessage("请输入房间号。");
RoomText.Enabled = true;
RoomText.Focus();
}
else
{
@ -613,14 +606,14 @@ namespace Milimoe.FunGame.Desktop.UI
{
if (objs != null && objs.Length > 0)
{
Usercfg.LoginUser = (User)objs[2];
Usercfg.LoginUserName = Usercfg.LoginUser.Userame;
Usercfg.LoginUser = (User)objs[0];
Usercfg.LoginUserName = Usercfg.LoginUser.Username;
}
NowAccount.Text = "[ID] " + Usercfg.LoginUserName;
Login.Visible = false;
Logout.Visible = true;
SetServerStatusLight((int)LightType.Green);
ShowMessage.TipMessage("欢迎回来, " + Usercfg.LoginUserName + "", "登录成功", 5);
ShowMessage.Message($"欢迎回来,{Usercfg.LoginUserName}", "登录成功", 5);
}
/// <summary>
@ -673,6 +666,7 @@ namespace Milimoe.FunGame.Desktop.UI
TalkText.Enabled = false;
ShowMessage.TipMessage("消息不能为空,请重新输入。");
TalkText.Enabled = true;
TalkText.Focus();
}
}
@ -950,7 +944,7 @@ namespace Milimoe.FunGame.Desktop.UI
private void Login_Click(object sender, EventArgs e)
{
if (MainController != null && Config.FunGame_isConnected)
OpenForm.SingleForm(FormType.Login, OpenFormType.Dialog);
OpenForm.SingleForm(FormType.Login, OpenFormType.Dialog, this);
else
ShowMessage.WarningMessage("请先连接服务器!");
}
@ -1021,11 +1015,11 @@ namespace Milimoe.FunGame.Desktop.UI
}
/// <summary>
/// 点击房间号输入框事件
/// 房间号输入框点击/焦点事件
/// </summary>
/// <param name="sender"></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("键入房间代号..."))
{
@ -1064,11 +1058,11 @@ namespace Milimoe.FunGame.Desktop.UI
}
/// <summary>
/// 点击聊天框事件
/// 聊天框点击/焦点事件
/// </summary>
/// <param name="sender"></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("向消息队列发送消息..."))
{
@ -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>
@ -1160,6 +1132,16 @@ namespace Milimoe.FunGame.Desktop.UI
/// <returns></returns>
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;
}

View File

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