更新DesktopModels,单例表和Managers

This commit is contained in:
Mili 2023-02-16 22:39:48 +08:00
parent f0995aa01d
commit 1d4edbff44
24 changed files with 494 additions and 349 deletions

View File

@ -7,10 +7,13 @@ using System.Threading.Tasks;
using Milimoe.FunGame.Core.Interface.Base; using Milimoe.FunGame.Core.Interface.Base;
using Milimoe.FunGame.Core.Library.Common.Network; using Milimoe.FunGame.Core.Library.Common.Network;
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Service;
namespace Milimoe.FunGame.Core.Api.Data namespace Milimoe.FunGame.Core.Api.Data
{ {
/// <summary>
/// 需要在Server中继承此类实现。
/// Milimoe.FunGame.Core.Service.SQLManager也是
/// </summary>
public class SQLHelper : ISQLHelper public class SQLHelper : ISQLHelper
{ {
public string Script { get; set; } = ""; public string Script { get; set; } = "";
@ -39,17 +42,9 @@ namespace Milimoe.FunGame.Core.Api.Data
this.UpdateRows = rows; this.UpdateRows = rows;
} }
public SQLResult Execute() public virtual SQLResult Execute()
{ {
switch (EntityType) return SQLResult.NotFound;
{
case EntityType.NotEntity:
SQLManager SQLManager = new(this);
return SQLManager.Execute(Script);
default:
break;
}
return Result;
} }
} }
} }

View File

@ -15,11 +15,22 @@ namespace Milimoe.FunGame.Core.Api.Utility
{ {
private static readonly Hashtable SingletonTable = new(); private static readonly Hashtable SingletonTable = new();
public static bool IsExist(string key) /// <summary>
/// 查询目标的类是否已经有实例
/// </summary>
/// <param name="single">单例对象</param>
/// <returns></returns>
public static bool IsExist(object single)
{ {
return SingletonTable.ContainsKey(key); return SingletonTable.ContainsKey(single.GetType().ToString());
} }
/// <summary>
/// 将目标和目标的类添加至单例表
/// </summary>
/// <param name="single">单例对象</param>
/// <returns></returns>
/// <exception cref="Exception">添加单例到单例表时遇到错误</exception>
public static bool Add(object single) public static bool Add(object single)
{ {
string type = single.GetType().ToString(); string type = single.GetType().ToString();
@ -38,6 +49,11 @@ namespace Milimoe.FunGame.Core.Api.Utility
return false; return false;
} }
/// <summary>
/// 将目标和目标的类从单例表中移除
/// </summary>
/// <param name="single">单例对象</param>
/// <returns></returns>
public static bool Remove(object single) public static bool Remove(object single)
{ {
string type = single.GetType().ToString(); string type = single.GetType().ToString();
@ -52,6 +68,12 @@ namespace Milimoe.FunGame.Core.Api.Utility
} }
} }
/// <summary>
/// 获取单例对象
/// </summary>
/// <typeparam name="T">目标类</typeparam>
/// <returns></returns>
/// <exception cref="Exception">不能从单例表中获取到指定的单例</exception>
public static T? Get<T>() public static T? Get<T>()
{ {
T? single = default; T? single = default;
@ -70,15 +92,21 @@ namespace Milimoe.FunGame.Core.Api.Utility
} }
return single; return single;
} }
public static object? Get(string key) /// <summary>
/// 获取单例对象
/// </summary>
/// <param name="type">目标类</param>
/// <returns></returns>
/// <exception cref="Exception">不能从单例表中获取到指定的单例</exception>
public static object? Get(Type type)
{ {
object? single = default; object? single = default;
if (SingletonTable.ContainsKey(key)) if (SingletonTable.ContainsKey(type))
{ {
try try
{ {
single = SingletonTable[key]; single = SingletonTable[type];
} }
catch catch
{ {

View File

@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Core.Interface.Base
{
internal abstract class BaseSQLService
{
internal abstract SQLResult Execute();
internal abstract SQLResult Execute(StringBuilder sql);
internal abstract SQLResult Execute(string sql);
internal abstract int Update(StringBuilder sql, ref SQLResult result);
internal abstract int Remove(StringBuilder sql, ref SQLResult result);
internal abstract int Add(StringBuilder sql, ref SQLResult result);
internal abstract int Update(string sql, ref SQLResult result);
internal abstract int Remove(string sql, ref SQLResult result);
internal abstract int Add(string sql, ref SQLResult result);
internal abstract object Query(EntityType type, StringBuilder sql);
internal abstract T Query<T>(StringBuilder sql);
internal abstract object Query(EntityType type, string sql);
internal abstract T Query<T>(string sql);
}
}

View File

@ -1,14 +1,14 @@
using System; namespace Milimoe.FunGame.Core.Interface
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Milimoe.FunGame.Core.Interface
{ {
public interface IClient public interface IClient
{ {
public string FunGameIcon { get; }
public string FunGameBackGround { get; }
public string FunGameMainMusic { get; }
public string FunGameMusic1 { get; }
public string FunGameMusic2 { get; }
public string FunGameMusic3 { get; }
public string RemoteServerIP(); public string RemoteServerIP();
} }
} }

View File

@ -29,6 +29,7 @@ namespace Milimoe.FunGame.Core.Library.Constant
public const int MaxConnection_General = 20; public const int MaxConnection_General = 20;
public const int MaxConnection_4C4G = 40; public const int MaxConnection_4C4G = 40;
public const string Socket = "Socket";
public const string Unknown = "Unknown"; public const string Unknown = "Unknown";
public const string Connect = "Connect"; public const string Connect = "Connect";
public const string GetNotice = "GetNotice"; public const string GetNotice = "GetNotice";

View File

@ -11,7 +11,7 @@ namespace Milimoe.FunGame.Core.Library.Constant
{ {
// Static Variable // Static Variable
public static Empty EntityInstance { get; } = new(); public static Empty EntityInstance { get; } = new();
public static Encoding DEFAULT_ENCODING { get; } = Encoding.UTF8; public static Encoding DefaultEncoding { get; } = Encoding.UTF8;
// Const // Const
public const int MaxRetryTimes = 20; public const int MaxRetryTimes = 20;

View File

@ -131,8 +131,7 @@ namespace Milimoe.FunGame.Core.Library.Constant
PassiveSkill, PassiveSkill,
GameStatistics, GameStatistics,
Character, Character,
CharacterStatistics, CharacterStatistics
NotEntity
} }
public enum TimeType public enum TimeType

View File

@ -5,12 +5,14 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Milimoe.FunGame.Core.Api.Data; using Milimoe.FunGame.Core.Api.Data;
using Milimoe.FunGame.Core.Interface.Base;
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Core.Service namespace Milimoe.FunGame.Core.Service
{ {
internal class SQLManager : BaseSQLService /// <summary>
/// 需要在Server中继承此类实现
/// </summary>
public class SQLManager
{ {
internal SQLHelper SQLHelper { get; } internal SQLHelper SQLHelper { get; }
@ -19,69 +21,69 @@ namespace Milimoe.FunGame.Core.Service
this.SQLHelper = SQLHelper; this.SQLHelper = SQLHelper;
} }
internal override int Add(StringBuilder sql, ref SQLResult result) protected virtual int Add(StringBuilder sql, ref SQLResult result)
{ {
throw new NotImplementedException(); return 0;
} }
internal override int Add(string sql, ref SQLResult result) protected virtual int Add(string sql, ref SQLResult result)
{ {
throw new NotImplementedException(); return 0;
} }
internal override SQLResult Execute() protected virtual SQLResult Execute()
{ {
throw new NotImplementedException(); return SQLResult.NotFound;
} }
internal override SQLResult Execute(StringBuilder sql) protected virtual SQLResult Execute(StringBuilder sql)
{ {
throw new NotImplementedException(); return SQLResult.NotFound;
} }
internal override SQLResult Execute(string sql) protected virtual SQLResult Execute(string sql)
{ {
throw new NotImplementedException(); return SQLResult.NotFound;
} }
internal override object Query(EntityType type, StringBuilder sql) protected virtual object Query(EntityType type, StringBuilder sql)
{ {
throw new NotImplementedException(); return General.EntityInstance;
} }
internal override T Query<T>(StringBuilder sql) protected virtual T? Query<T>(StringBuilder sql)
{ {
throw new NotImplementedException(); return default;
} }
internal override object Query(EntityType type, string sql) protected virtual object Query(EntityType type, string sql)
{ {
throw new NotImplementedException(); return General.EntityInstance;
} }
internal override T Query<T>(string sql) protected virtual T? Query<T>(string sql)
{ {
throw new NotImplementedException(); return default;
} }
internal override int Remove(StringBuilder sql, ref SQLResult result) protected virtual int Remove(StringBuilder sql, ref SQLResult result)
{ {
throw new NotImplementedException(); return 0;
} }
internal override int Remove(string sql, ref SQLResult result) protected virtual int Remove(string sql, ref SQLResult result)
{ {
throw new NotImplementedException(); return 0;
} }
internal override int Update(StringBuilder sql, ref SQLResult result) protected virtual int Update(StringBuilder sql, ref SQLResult result)
{ {
throw new NotImplementedException(); return 0;
} }
internal override int Update(string sql, ref SQLResult result) protected virtual int Update(string sql, ref SQLResult result)
{ {
throw new NotImplementedException(); return 0;
} }
} }
} }

View File

@ -134,7 +134,7 @@ namespace Milimoe.FunGame.Core.Service
{ {
if (ClientSocket != null && objs != null && objs.Length > 0) if (ClientSocket != null && objs != null && objs.Length > 0)
{ {
if (ClientSocket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0) if (ClientSocket.Send(General.DefaultEncoding.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0)
{ {
return SocketResult.Success; return SocketResult.Success;
} }
@ -157,7 +157,7 @@ namespace Milimoe.FunGame.Core.Service
} }
if (Socket != null) if (Socket != null)
{ {
if (Socket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0) if (Socket.Send(General.DefaultEncoding.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0)
{ {
return SocketResult.Success; return SocketResult.Success;
} }
@ -180,7 +180,7 @@ namespace Milimoe.FunGame.Core.Service
int length = Socket.Receive(buffer); int length = Socket.Receive(buffer);
if (length > 0) if (length > 0)
{ {
string msg = General.DEFAULT_ENCODING.GetString(buffer, 0, length); string msg = General.DefaultEncoding.GetString(buffer, 0, length);
Library.Common.Network.JsonObject? json = Library.Common.Network.JsonObject.GetObject(msg); Library.Common.Network.JsonObject? json = Library.Common.Network.JsonObject.GetObject(msg);
if (json != null) if (json != null)
{ {
@ -207,7 +207,7 @@ namespace Milimoe.FunGame.Core.Service
int length = ClientSocket.Receive(buffer); int length = ClientSocket.Receive(buffer);
if (length > 0) if (length > 0)
{ {
string msg = General.DEFAULT_ENCODING.GetString(buffer, 0, length); string msg = General.DefaultEncoding.GetString(buffer, 0, length);
Library.Common.Network.JsonObject? json = Library.Common.Network.JsonObject.GetObject(msg); Library.Common.Network.JsonObject? json = Library.Common.Network.JsonObject.GetObject(msg);
if (json != null) if (json != null)
{ {

View File

@ -3,10 +3,24 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.Model;
using Milimoe.FunGame.Desktop.UI;
namespace Milimoe.FunGame.Desktop.Controller namespace Milimoe.FunGame.Desktop.Controller
{ {
public class LoginController public class LoginController : ILogin
{ {
LoginModel LoginModel { get; }
public LoginController(Login Login)
{
LoginModel = new LoginModel(Login);
}
public bool LoginAccount()
{
return LoginModel.LoginAccount();
}
} }
} }

View File

@ -7,23 +7,29 @@ using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Core.Library.Common.Event; using Milimoe.FunGame.Core.Library.Common.Event;
using Milimoe.FunGame.Core.Library.Constant; 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.Component; using Milimoe.FunGame.Desktop.Library.Component;
using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.Model; using Milimoe.FunGame.Desktop.Model;
using Milimoe.FunGame.Desktop.Others;
using Milimoe.FunGame.Desktop.UI; using Milimoe.FunGame.Desktop.UI;
namespace Milimoe.FunGame.Desktop.Controller namespace Milimoe.FunGame.Desktop.Controller
{ {
public class MainController public class MainController : IMain
{ {
private MainModel MainModel { get; } private MainModel MainModel { get; }
public bool Connected => Do<bool>(MainControllerSet.Connected);
public MainController(Main Main) public MainController(Main Main)
{ {
MainModel = new MainModel(Main); MainModel = new MainModel(Main);
} }
public T Do<T>(string DoType) /**
* Model的方法
*/
private T Do<T>(string DoType)
{ {
object result = new(); object result = new();
switch(DoType) switch(DoType)
@ -35,8 +41,7 @@ namespace Milimoe.FunGame.Desktop.Controller
result = MainModel.Connect(); result = MainModel.Connect();
break; break;
case MainControllerSet.Connected: case MainControllerSet.Connected:
if (MainModel.Socket is null) result = false; result = MainModel.Connected;
else result = MainModel.Socket.Connected;
break; break;
case MainControllerSet.Disconnect: case MainControllerSet.Disconnect:
MainModel.Disconnect(); MainModel.Disconnect();
@ -61,9 +66,6 @@ namespace Milimoe.FunGame.Desktop.Controller
case MainControllerSet.LogOut: case MainControllerSet.LogOut:
result = MainModel.Logout(); result = MainModel.Logout();
break; break;
case MainControllerSet.LogIn:
result = MainModel.Login();
break;
case MainControllerSet.Close: case MainControllerSet.Close:
result = MainModel.Close(); result = MainModel.Close();
break; break;
@ -72,5 +74,70 @@ namespace Milimoe.FunGame.Desktop.Controller
} }
return (T)result; return (T)result;
} }
public bool GetServerConnection()
{
return Do<bool>(MainControllerSet.GetServerConnection);
}
public ConnectResult Connect()
{
return Do<ConnectResult>(MainControllerSet.Connect);
}
public void Disconnect()
{
Do<object>(MainControllerSet.Disconnect);
}
public void Disconnected()
{
Do<object>(MainControllerSet.Disconnected);
}
public void SetWaitConnectAndSetYellow()
{
throw new NotImplementedException();
}
public void SetWaitLoginAndSetYellow()
{
throw new NotImplementedException();
}
public void SetGreenAndPing()
{
throw new NotImplementedException();
}
public void SetGreen()
{
throw new NotImplementedException();
}
public void SetYellow()
{
throw new NotImplementedException();
}
public void SetRed()
{
throw new NotImplementedException();
}
public void SetUser()
{
throw new NotImplementedException();
}
public bool LogOut()
{
return Do<bool>(MainControllerSet.LogOut);
}
public bool Close()
{
return Do<bool>(MainControllerSet.Close);
}
} }
} }

View File

@ -3,10 +3,24 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.Model;
using Milimoe.FunGame.Desktop.UI;
namespace Milimoe.FunGame.Desktop.Controller namespace Milimoe.FunGame.Desktop.Controller
{ {
public class RegisterController public class RegisterController : IReg
{ {
RegisterModel RegisterModel { get; }
public RegisterController(Register Register)
{
RegisterModel = new RegisterModel(Register);
}
public bool Reg()
{
return RegisterModel.Reg();
}
} }
} }

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Milimoe.FunGame.Desktop.Others namespace Milimoe.FunGame.Desktop.Library
{ {
public class Config public class Config
{ {
@ -23,5 +23,8 @@ namespace Milimoe.FunGame.Desktop.Others
public static string FunGame_Roomid { get; set; } = "-1"; // 房间号 public static string FunGame_Roomid { get; set; } = "-1"; // 房间号
public static string FunGame_ServerName { get; set; } = ""; // 服务器名称 public static string FunGame_ServerName { get; set; } = ""; // 服务器名称
public static string FunGame_Notice { get; set; } = ""; // 公告 public static string FunGame_Notice { get; set; } = ""; // 公告
/*** GUID For Socket ***/
public static Guid Guid_Socket { get; set; } = Guid.Empty;
} }
} }

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Desktop.Others namespace Milimoe.FunGame.Desktop.Library
{ {
public class MainControllerSet public class MainControllerSet
{ {
@ -28,6 +28,11 @@ namespace Milimoe.FunGame.Desktop.Others
public const string Close = ".close"; public const string Close = ".close";
} }
public class RunTime
{
public static Core.Library.Common.Network.Socket? Socket { get; set; } = null;
}
public class Constant public class Constant
{ {
/** /**
@ -38,9 +43,9 @@ namespace Milimoe.FunGame.Desktop.Others
/** /**
* Socket Configs * Socket Configs
*/ */
public static string SERVER_IPADRESS { get; set; } = ""; // 服务器IP地址 public static string Server_Address { get; set; } = ""; // 服务器IP地址
public static int SERVER_PORT { get; set; } = 0; // 服务器端口号 public static int Server_Port { get; set; } = 0; // 服务器端口号
public static Encoding DEFAULT_ENCODING { get; } = Core.Library.Constant.General.DEFAULT_ENCODING; public static Encoding Default_Encoding { get; } = General.DefaultEncoding;
/** /**
* FunGame Configs * FunGame Configs

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Entity;
namespace Milimoe.FunGame.Desktop.Others namespace Milimoe.FunGame.Desktop.Library
{ {
public class Usercfg public class Usercfg
{ {

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Milimoe.FunGame.Desktop.Library.Interface
{
public interface ILogin
{
public bool LoginAccount();
}
}

View File

@ -0,0 +1,23 @@
using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Desktop.Library.Interface
{
public interface IMain
{
public bool Connected { get; }
public bool GetServerConnection();
public ConnectResult Connect();
public void Disconnect();
public void Disconnected();
public void SetWaitConnectAndSetYellow();
public void SetWaitLoginAndSetYellow();
public void SetGreenAndPing();
public void SetGreen();
public void SetYellow();
public void SetRed();
public void SetUser();
public bool LogOut();
public bool Close();
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Milimoe.FunGame.Desktop.Library.Interface
{
public interface IReg
{
public bool Reg();
}
}

View File

@ -3,10 +3,38 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Library.Exception;
using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.UI;
namespace Milimoe.FunGame.Desktop.Model namespace Milimoe.FunGame.Desktop.Model
{ {
public class LoginModel public class LoginModel : ILogin
{ {
private readonly Login Login;
private Core.Library.Common.Network.Socket? Socket;
public LoginModel(Login login)
{
Login = login;
Socket = RunTime.Socket;
}
public bool LoginAccount()
{
try
{
if (Socket != null && Socket.Send(SocketMessageType.Login, "Mili", "OK") == SocketResult.Success)
return true;
}
catch (Exception e)
{
e.GetErrorInfo();
}
return false;
}
} }
} }

View File

@ -8,46 +8,26 @@ using Milimoe.FunGame.Core.Entity;
using Milimoe.FunGame.Core.Library.Common.Event; using Milimoe.FunGame.Core.Library.Common.Event;
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Library.Exception; using Milimoe.FunGame.Core.Library.Exception;
using Milimoe.FunGame.Desktop.Controller; using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Component; using Milimoe.FunGame.Desktop.Library.Component;
using Milimoe.FunGame.Desktop.Others; using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.UI; using Milimoe.FunGame.Desktop.UI;
namespace Milimoe.FunGame.Desktop.Model namespace Milimoe.FunGame.Desktop.Model
{ {
public class MainModel public class MainModel : IMain
{ {
public Core.Library.Common.Network.Socket? Socket public bool Connected => Socket != null && Socket.Connected;
{
get
{
return _Socket;
}
}
public Main Main { get; }
private readonly Main Main;
private Task? ReceivingTask; private Task? ReceivingTask;
private Core.Library.Common.Network.Socket? _Socket; private Core.Library.Common.Network.Socket? Socket;
public MainModel(Main main) public MainModel(Main main)
{ {
Main = main; Main = main;
} }
public bool Login()
{
try
{
if (Socket != null && Socket.Send(SocketMessageType.Login, "Mili", "OK") == SocketResult.Success)
return true;
}
catch (Exception e)
{
Main?.GetMessage(e.GetErrorInfo());
}
return false;
}
public bool Logout() public bool Logout()
{ {
try try
@ -73,6 +53,11 @@ namespace Milimoe.FunGame.Desktop.Model
} }
} }
public void Disconnected()
{
Disconnect();
}
public bool GetServerConnection() public bool GetServerConnection()
{ {
try try
@ -84,8 +69,8 @@ namespace Milimoe.FunGame.Desktop.Model
string[] s = ipaddress.Split(':'); string[] s = ipaddress.Split(':');
if (s != null && s.Length > 1) if (s != null && s.Length > 1)
{ {
Others.Constant.SERVER_IPADRESS = s[0]; Constant.Server_Address = s[0];
Others.Constant.SERVER_PORT = Convert.ToInt32(s[1]); Constant.Server_Port = Convert.ToInt32(s[1]);
if (Connect() == ConnectResult.Success) return true; // 连接服务器 if (Connect() == ConnectResult.Success) return true; // 连接服务器
} }
} }
@ -106,20 +91,20 @@ namespace Milimoe.FunGame.Desktop.Model
public ConnectResult Connect() public ConnectResult Connect()
{ {
if (Others.Constant.SERVER_IPADRESS == "" || Others.Constant.SERVER_PORT <= 0) if (Constant.Server_Address == "" || Constant.Server_Port <= 0)
{ {
ShowMessage.ErrorMessage("查找可用的服务器失败!"); ShowMessage.ErrorMessage("查找可用的服务器失败!");
return ConnectResult.FindServerFailed; return ConnectResult.FindServerFailed;
} }
try try
{ {
if (Others.Config.FunGame_isRetrying) if (Config.FunGame_isRetrying)
{ {
Main?.GetMessage("正在连接服务器,请耐心等待。"); Main?.GetMessage("正在连接服务器,请耐心等待。");
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
return ConnectResult.CanNotConnect; return ConnectResult.CanNotConnect;
} }
if (!Others.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("开始连接服务器...", true, TimeType.General);
@ -131,10 +116,12 @@ namespace Milimoe.FunGame.Desktop.Model
} }
// 与服务器建立连接 // 与服务器建立连接
Socket?.Close(); Socket?.Close();
Others.Config.FunGame_isRetrying = true; Config.FunGame_isRetrying = true;
_Socket = Core.Library.Common.Network.Socket.Connect(Others.Constant.SERVER_IPADRESS, Others.Constant.SERVER_PORT); Socket = Core.Library.Common.Network.Socket.Connect(Constant.Server_Address, Constant.Server_Port);
if (Socket != null && Socket.Connected) if (Socket != null && Socket.Connected)
{ {
// 设置可复用Socket
RunTime.Socket = Socket;
// 发送连接请求 // 发送连接请求
if (Socket.Send(SocketMessageType.Connect) == SocketResult.Success) if (Socket.Send(SocketMessageType.Connect) == SocketResult.Success)
{ {
@ -169,7 +156,7 @@ namespace Milimoe.FunGame.Desktop.Model
Task.Run(() => Task.Run(() =>
{ {
Thread.Sleep(5000); Thread.Sleep(5000);
if (Others.Config.FunGame_isAutoRetry) Connect(); // 再次判断是否开启自动重连 if (Config.FunGame_isAutoRetry) Connect(); // 再次判断是否开启自动重连
}); });
Main?.GetMessage("连接服务器失败5秒后自动尝试重连。"); Main?.GetMessage("连接服务器失败5秒后自动尝试重连。");
} }
@ -185,7 +172,7 @@ namespace Milimoe.FunGame.Desktop.Model
if (Socket != null) if (Socket != null)
{ {
Socket.Close(); Socket.Close();
_Socket = null; Socket = null;
} }
if (ReceivingTask != null && !ReceivingTask.IsCompleted) if (ReceivingTask != null && !ReceivingTask.IsCompleted)
{ {
@ -201,6 +188,46 @@ namespace Milimoe.FunGame.Desktop.Model
return true; return true;
} }
public void SetWaitConnectAndSetYellow()
{
throw new NotImplementedException();
}
public void SetWaitLoginAndSetYellow()
{
throw new NotImplementedException();
}
public void SetGreenAndPing()
{
throw new NotImplementedException();
}
public void SetGreen()
{
throw new NotImplementedException();
}
public void SetYellow()
{
throw new NotImplementedException();
}
public void SetRed()
{
throw new NotImplementedException();
}
public void SetUser()
{
throw new NotImplementedException();
}
public bool LogOut()
{
throw new NotImplementedException();
}
private void StartReceiving() private void StartReceiving()
{ {
ReceivingTask = Task.Factory.StartNew(() => ReceivingTask = Task.Factory.StartNew(() =>
@ -317,6 +344,5 @@ namespace Milimoe.FunGame.Desktop.Model
Main?.UpdateUI(MainControllerSet.Disconnect); Main?.UpdateUI(MainControllerSet.Disconnect);
Close(); Close();
} }
} }
} }

View File

@ -3,10 +3,27 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.UI;
namespace Milimoe.FunGame.Desktop.Model namespace Milimoe.FunGame.Desktop.Model
{ {
public class RegisterModel public class RegisterModel : IReg
{ {
private readonly Register Register;
private Core.Library.Common.Network.Socket? Socket;
public RegisterModel(Register register)
{
Register = register;
Socket = RunTime.Socket;
}
public bool Reg()
{
return true;
}
} }
} }

View File

@ -1,5 +1,5 @@
using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Component; using Milimoe.FunGame.Desktop.Library.Component;
using Milimoe.FunGame.Desktop.Others;
namespace Milimoe.FunGame.Desktop.UI namespace Milimoe.FunGame.Desktop.UI
{ {

View File

@ -6,8 +6,8 @@ using System.Windows.Forms;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Text; using System.Text;
using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Component; using Milimoe.FunGame.Desktop.Library.Component;
using Milimoe.FunGame.Desktop.Others;
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Desktop.Controller; using Milimoe.FunGame.Desktop.Controller;
using Milimoe.FunGame.Core.Library.Exception; using Milimoe.FunGame.Core.Library.Exception;
@ -32,7 +32,6 @@ namespace Milimoe.FunGame.Desktop.UI
* *
*/ */
private Task? MatchFunGame = null; // 匹配线程 private Task? MatchFunGame = null; // 匹配线程
//private MainModel? MainModel = null;
private MainController? MainController = null; private MainController? MainController = null;
/** /**
@ -72,7 +71,7 @@ namespace Milimoe.FunGame.Desktop.UI
void action() void action()
{ {
if (Config.FunGame_isAutoConnect) if (Config.FunGame_isAutoConnect)
MainController.Do<object>(MainControllerSet.GetServerConnection); MainController.GetServerConnection();
} }
InvokeUpdateUI(action); InvokeUpdateUI(action);
}); });
@ -99,69 +98,69 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
switch (updatetype) switch (updatetype)
{ {
case Others.MainControllerSet.SetGreen: case MainControllerSet.SetGreen:
Others.Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Green); SetServerStatusLight((int)LightType.Green);
SetButtonEnableIfLogon(true, ClientState.Online); SetButtonEnableIfLogon(true, ClientState.Online);
Others.Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case Others.MainControllerSet.SetGreenAndPing: case MainControllerSet.SetGreenAndPing:
Others.Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(Others.Constant.SERVER_IPADRESS)); SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(Constant.Server_Address));
SetButtonEnableIfLogon(true, ClientState.Online); SetButtonEnableIfLogon(true, ClientState.Online);
Others.Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case Others.MainControllerSet.SetYellow: case MainControllerSet.SetYellow:
Others.Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow); SetServerStatusLight((int)LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
Others.Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case Others.MainControllerSet.WaitConnectAndSetYellow: case MainControllerSet.WaitConnectAndSetYellow:
Others.Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow); SetServerStatusLight((int)LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
Others.Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
if (MainController != null && Others.Config.FunGame_isAutoConnect) if (MainController != null && Config.FunGame_isAutoConnect)
{ {
// 自动连接服务器 // 自动连接服务器
MainController.Do<bool>(MainControllerSet.Connected); MainController.Connect();
} }
break; break;
case Others.MainControllerSet.WaitLoginAndSetYellow: case MainControllerSet.WaitLoginAndSetYellow:
Others.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);
Others.Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case Others.MainControllerSet.SetRed: case MainControllerSet.SetRed:
SetServerStatusLight((int)LightType.Red); SetServerStatusLight((int)LightType.Red);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
Others.Config.FunGame_isConnected = false; Config.FunGame_isConnected = false;
break; break;
case Others.MainControllerSet.Disconnected: case MainControllerSet.Disconnected:
Others.Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
Others.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 (Others.Config.FunGame_isAutoRetry && CurrentRetryTimes <= MaxRetryTimes) if (Config.FunGame_isAutoRetry && CurrentRetryTimes <= MaxRetryTimes)
{ {
Task.Run(() => Task.Run(() =>
{ {
Thread.Sleep(5000); Thread.Sleep(5000);
if (Others.Config.FunGame_isAutoRetry) MainController?.Do<object>(MainControllerSet.Connect); // 再次判断是否开启自动重连 if (Config.FunGame_isAutoRetry) MainController?.Connect(); // 再次判断是否开启自动重连
}); });
WritelnSystemInfo("连接服务器失败5秒后自动尝试重连。"); WritelnSystemInfo("连接服务器失败5秒后自动尝试重连。");
} }
@ -169,50 +168,50 @@ namespace Milimoe.FunGame.Desktop.UI
WritelnSystemInfo("无法连接至服务器,请检查你的网络连接。"); WritelnSystemInfo("无法连接至服务器,请检查你的网络连接。");
break; break;
case Others.MainControllerSet.Disconnect: case MainControllerSet.Disconnect:
Others.Config.FunGame_isAutoRetry = false; Config.FunGame_isAutoRetry = false;
Others.Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
Others.Config.FunGame_isAutoConnect = false; Config.FunGame_isAutoConnect = false;
Others.Config.FunGame_isAutoLogin = false; Config.FunGame_isAutoLogin = false;
Others.Config.FunGame_isConnected = false; Config.FunGame_isConnected = false;
SetServerStatusLight((int)LightType.Yellow); SetServerStatusLight((int)LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
LogoutAccount(); LogoutAccount();
break; break;
case Others.MainControllerSet.LogOut: case MainControllerSet.LogOut:
Others.Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
Others.Config.FunGame_isConnected = false; Config.FunGame_isConnected = false;
Others.Config.FunGame_isAutoLogin = false; Config.FunGame_isAutoLogin = false;
SetServerStatusLight((int)LightType.Yellow); SetServerStatusLight((int)LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
LogoutAccount(); LogoutAccount();
if (Others.Config.FunGame_isAutoConnect) if (Config.FunGame_isAutoConnect)
{ {
CurrentRetryTimes = -1; CurrentRetryTimes = -1;
Task.Run(() => Task.Run(() =>
{ {
Thread.Sleep(1000); Thread.Sleep(1000);
MainController?.Do<object>(MainControllerSet.Connect); MainController?.Connect();
}); });
} }
break; break;
case Others.MainControllerSet.SetUser: case MainControllerSet.SetUser:
if (objs != null && objs.Length > 1) if (objs != null && objs.Length > 1)
{ {
SetLoginUser(objs); SetLoginUser(objs);
} }
break; break;
case Others.MainControllerSet.Connected: case MainControllerSet.Connected:
Action action = () => Action action = () =>
{ {
NoticeText.Text = Others.Config.FunGame_Notice; NoticeText.Text = Config.FunGame_Notice;
if (MainController != null && Others.Config.FunGame_isAutoLogin) if (MainController != null && Config.FunGame_isAutoLogin)
{ {
// 自动登录 // 自动登录 [TODO]
MainController.Do<bool>(MainControllerSet.LogIn);
} }
}; };
if (InvokeRequired) if (InvokeRequired)
@ -229,7 +228,7 @@ namespace Milimoe.FunGame.Desktop.UI
catch (Exception e) catch (Exception e)
{ {
WritelnGameInfo(e.GetErrorInfo()); WritelnGameInfo(e.GetErrorInfo());
UpdateUI(Others.MainControllerSet.SetRed); UpdateUI(MainControllerSet.SetRed);
} }
} }
InvokeUpdateUI(action); InvokeUpdateUI(action);
@ -285,15 +284,15 @@ namespace Milimoe.FunGame.Desktop.UI
string isAutoConncet = INIHelper.ReadINI("Config", "AutoConnect"); string isAutoConncet = INIHelper.ReadINI("Config", "AutoConnect");
string isAutoLogin = INIHelper.ReadINI("Config", "AutoLogin"); string isAutoLogin = INIHelper.ReadINI("Config", "AutoLogin");
if (isAutoConncet != null && !isAutoConncet.Equals("") && (isAutoConncet.Equals("false") || isAutoConncet.Equals("true"))) if (isAutoConncet != null && !isAutoConncet.Equals("") && (isAutoConncet.Equals("false") || isAutoConncet.Equals("true")))
Others.Config.FunGame_isAutoConnect = Convert.ToBoolean(isAutoConncet); Config.FunGame_isAutoConnect = Convert.ToBoolean(isAutoConncet);
else throw new Exception("读取配置文件出错,参数格式不正确"); else throw new Exception("读取配置文件出错,参数格式不正确");
if (isAutoLogin != null && !isAutoLogin.Equals("") && (isAutoLogin.Equals("false") || isAutoLogin.Equals("true"))) if (isAutoLogin != null && !isAutoLogin.Equals("") && (isAutoLogin.Equals("false") || isAutoLogin.Equals("true")))
Others.Config.FunGame_isAutoLogin = Convert.ToBoolean(isAutoLogin); Config.FunGame_isAutoLogin = Convert.ToBoolean(isAutoLogin);
else throw new Exception("读取配置文件出错,参数格式不正确"); else throw new Exception("读取配置文件出错,参数格式不正确");
} }
else else
{ {
INIHelper.Init((FunGameInfo.FunGame)Others.Constant.FunGameType); INIHelper.Init((FunGameInfo.FunGame)Constant.FunGameType);
WritelnGameInfo(">> 首次启动,已自动为你创建配置文件。"); WritelnGameInfo(">> 首次启动,已自动为你创建配置文件。");
GetFunGameConfig(); GetFunGameConfig();
} }
@ -310,12 +309,12 @@ namespace Milimoe.FunGame.Desktop.UI
/// <param name="roomid"></param> /// <param name="roomid"></param>
private void SetRoomid(string roomid) private void SetRoomid(string roomid)
{ {
Others.Config.FunGame_Roomid = roomid; Config.FunGame_Roomid = roomid;
if (!roomid.Equals("-1")) if (!roomid.Equals("-1"))
{ {
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 加入房间"); WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 加入房间");
WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已加入房间 -> [ " + Others.Config.FunGame_Roomid + " ]"); WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已加入房间 -> [ " + Config.FunGame_Roomid + " ]");
Room.Text = "[ 当前房间 ]\n" + Convert.ToString(Others.Config.FunGame_Roomid); Room.Text = "[ 当前房间 ]\n" + Convert.ToString(Config.FunGame_Roomid);
} }
else else
Room.Text = "暂未进入房间"; Room.Text = "暂未进入房间";
@ -389,7 +388,7 @@ namespace Milimoe.FunGame.Desktop.UI
// 显示:匹配、创建房间 // 显示:匹配、创建房间
// 隐藏:退出房间、房间设定 // 隐藏:退出房间、房间设定
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 离开房间"); WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 离开房间");
WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已离开房间 -> [ " + Others.Config.FunGame_Roomid + " ]"); WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已离开房间 -> [ " + Config.FunGame_Roomid + " ]");
SetRoomid("-1"); SetRoomid("-1");
QuitRoom.Visible = false; QuitRoom.Visible = false;
StartMatch.Visible = true; StartMatch.Visible = true;
@ -419,15 +418,15 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
case ClientState.Online: case ClientState.Online:
PresetText.Items.Clear(); PresetText.Items.Clear();
PresetText.Items.AddRange(Others.Constant.PresetOnineItems); PresetText.Items.AddRange(Constant.PresetOnineItems);
break; break;
case ClientState.WaitConnect: case ClientState.WaitConnect:
PresetText.Items.Clear(); PresetText.Items.Clear();
PresetText.Items.AddRange(Others.Constant.PresetNoConnectItems); PresetText.Items.AddRange(Constant.PresetNoConnectItems);
break; break;
case ClientState.WaitLogin: case ClientState.WaitLogin:
PresetText.Items.Clear(); PresetText.Items.Clear();
PresetText.Items.AddRange(Others.Constant.PresetNoLoginItems); PresetText.Items.AddRange(Constant.PresetNoLoginItems);
break; break;
} }
this.PresetText.SelectedIndex = 0; this.PresetText.SelectedIndex = 0;
@ -454,7 +453,7 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
if (CheckRoomIDExist(roomid)) if (CheckRoomIDExist(roomid))
{ {
if (Others.Config.FunGame_Roomid.Equals("-1")) if (Config.FunGame_Roomid.Equals("-1"))
{ {
if (ShowMessage.YesNoMessage("已找到房间 -> [ " + roomid + " ]\n是否加入", "已找到房间") == MessageResult.Yes) if (ShowMessage.YesNoMessage("已找到房间 -> [ " + roomid + " ]\n是否加入", "已找到房间") == MessageResult.Yes)
{ {
@ -482,7 +481,7 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
if (CheckRoomIDExist(roomid)) if (CheckRoomIDExist(roomid))
{ {
if (Others.Config.FunGame_Roomid.Equals("-1")) if (Config.FunGame_Roomid.Equals("-1"))
{ {
if (ShowMessage.YesNoMessage("已找到房间 -> [ " + roomid + " ]\n是否加入", "已找到房间") == MessageResult.Yes) if (ShowMessage.YesNoMessage("已找到房间 -> [ " + roomid + " ]\n是否加入", "已找到房间") == MessageResult.Yes)
{ {
@ -513,7 +512,7 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
case (int)StartMatchState.Matching: case (int)StartMatchState.Matching:
// 开始匹配 // 开始匹配
Others.Config.FunGame_isMatching = true; Config.FunGame_isMatching = true;
int loop = 0; int loop = 0;
string roomid = Convert.ToString(new Random().Next(1, 10000)); string roomid = Convert.ToString(new Random().Next(1, 10000));
// 匹配中 匹配成功返回房间号 // 匹配中 匹配成功返回房间号
@ -521,7 +520,7 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
// 创建新线程,防止主界面阻塞 // 创建新线程,防止主界面阻塞
Thread.Sleep(3000); Thread.Sleep(3000);
while (loop < 10000 && Others.Config.FunGame_isMatching) while (loop < 10000 && Config.FunGame_isMatching)
{ {
loop++; loop++;
if (loop == Convert.ToInt32(roomid)) if (loop == Convert.ToInt32(roomid))
@ -545,7 +544,7 @@ namespace Milimoe.FunGame.Desktop.UI
}); });
break; break;
case (int)StartMatchState.Success: case (int)StartMatchState.Success:
Others.Config.FunGame_isMatching = false; Config.FunGame_isMatching = false;
// 匹配成功返回房间号 // 匹配成功返回房间号
roomid = "-1"; roomid = "-1";
if (objs != null) roomid = (string)objs[0]; if (objs != null) roomid = (string)objs[0];
@ -591,7 +590,7 @@ namespace Milimoe.FunGame.Desktop.UI
case (int)StartMatchState.Cancel: case (int)StartMatchState.Cancel:
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 终止匹配"); WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 终止匹配");
WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已终止匹配。"); WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已终止匹配。");
Others.Config.FunGame_isMatching = false; Config.FunGame_isMatching = false;
StartMatch_Action = (i, objs) => StartMatch_Action = (i, objs) =>
{ {
StartMatch_Method(i, objs); StartMatch_Method(i, objs);
@ -709,7 +708,7 @@ namespace Milimoe.FunGame.Desktop.UI
/// <param name="objs">可传多个参数</param> /// <param name="objs">可传多个参数</param>
private void CreateRoom_Method(int i, object[]? objs = null) private void CreateRoom_Method(int i, object[]? objs = null)
{ {
if (!Others.Config.FunGame_Roomid.Equals("-1")) if (!Config.FunGame_Roomid.Equals("-1"))
{ {
ShowMessage.WarningMessage("已在房间中,无法创建房间。"); ShowMessage.WarningMessage("已在房间中,无法创建房间。");
return; return;
@ -787,7 +786,7 @@ namespace Milimoe.FunGame.Desktop.UI
/// </summary> /// </summary>
private void ShowFunGameInfo() private void ShowFunGameInfo()
{ {
WritelnGameInfo(FunGameInfo.GetInfo((FunGameInfo.FunGame)Others.Constant.FunGameType)); WritelnGameInfo(FunGameInfo.GetInfo((FunGameInfo.FunGame)Constant.FunGameType));
} }
#endregion #endregion
@ -805,7 +804,7 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
if (MainController != null) if (MainController != null)
{ {
MainController.Do<bool>(MainControllerSet.Close); MainController.Close();
MainController = null; MainController = null;
} }
Environment.Exit(0); Environment.Exit(0);
@ -854,11 +853,11 @@ namespace Milimoe.FunGame.Desktop.UI
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 开始匹配"); WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 开始匹配");
WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 开始匹配"); WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 开始匹配");
WriteGameInfo(">> 匹配参数:"); WriteGameInfo(">> 匹配参数:");
if (!Others.Config.Match_Mix && !Others.Config.Match_Team && !Others.Config.Match_HasPass) if (!Config.Match_Mix && !Config.Match_Team && !Config.Match_HasPass)
WritelnGameInfo("无"); WritelnGameInfo("无");
else else
{ {
WriteGameInfo((Others.Config.Match_Mix ? " 混战房间 " : "") + (Others.Config.Match_Team ? " 团队房间 " : "") + (Others.Config.Match_HasPass ? " 密码房间 " : "")); WriteGameInfo((Config.Match_Mix ? " 混战房间 " : "") + (Config.Match_Team ? " 团队房间 " : "") + (Config.Match_HasPass ? " 密码房间 " : ""));
WritelnGameInfo(); WritelnGameInfo();
} }
// 显示停止匹配按钮 // 显示停止匹配按钮
@ -894,26 +893,26 @@ namespace Milimoe.FunGame.Desktop.UI
private void CreateRoom_Click(object sender, EventArgs e) private void CreateRoom_Click(object sender, EventArgs e)
{ {
string roomtype = ""; string roomtype = "";
if (Others.Config.Match_Mix && Others.Config.Match_Team) if (Config.Match_Mix && Config.Match_Team)
{ {
ShowMessage.WarningMessage("创建房间不允许同时勾选混战和团队!"); ShowMessage.WarningMessage("创建房间不允许同时勾选混战和团队!");
return; return;
} }
else if (Others.Config.Match_Mix && !Others.Config.Match_Team && !Others.Config.Match_HasPass) else if (Config.Match_Mix && !Config.Match_Team && !Config.Match_HasPass)
{ {
roomtype = Others.Constant.GameMode_Mix; roomtype = Constant.GameMode_Mix;
} }
else if (!Others.Config.Match_Mix && Others.Config.Match_Team && !Others.Config.Match_HasPass) else if (!Config.Match_Mix && Config.Match_Team && !Config.Match_HasPass)
{ {
roomtype = Others.Constant.GameMode_Team; roomtype = Constant.GameMode_Team;
} }
else if (Others.Config.Match_Mix && !Others.Config.Match_Team && Others.Config.Match_HasPass) else if (Config.Match_Mix && !Config.Match_Team && Config.Match_HasPass)
{ {
roomtype = Others.Constant.GameMode_MixHasPass; roomtype = Constant.GameMode_MixHasPass;
} }
else if (!Others.Config.Match_Mix && Others.Config.Match_Team && Others.Config.Match_HasPass) else if (!Config.Match_Mix && Config.Match_Team && Config.Match_HasPass)
{ {
roomtype = Others.Constant.GameMode_TeamHasPass; roomtype = Constant.GameMode_TeamHasPass;
} }
if (roomtype.Equals("")) if (roomtype.Equals(""))
{ {
@ -973,7 +972,7 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
if (ShowMessage.OKCancelMessage("你确定要退出登录吗?", "退出登录") == MessageResult.OK) if (ShowMessage.OKCancelMessage("你确定要退出登录吗?", "退出登录") == MessageResult.OK)
{ {
if (MainController == null || !MainController.Do<bool>(MainControllerSet.LogOut)) if (MainController == null || !MainController.LogOut())
ShowMessage.WarningMessage("请求无效:退出登录失败!"); ShowMessage.WarningMessage("请求无效:退出登录失败!");
} }
} }
@ -985,7 +984,7 @@ namespace Milimoe.FunGame.Desktop.UI
/// <param name="e"></param> /// <param name="e"></param>
private void Login_Click(object sender, EventArgs e) private void Login_Click(object sender, EventArgs e)
{ {
if (MainController != null && Others.Config.FunGame_isConnected) if (MainController != null && Config.FunGame_isConnected)
new Login().ShowDialog(); new Login().ShowDialog();
else else
ShowMessage.WarningMessage("请先连接服务器!"); ShowMessage.WarningMessage("请先连接服务器!");
@ -1030,8 +1029,8 @@ namespace Milimoe.FunGame.Desktop.UI
/// <param name="e"></param> /// <param name="e"></param>
private void CheckMix_CheckedChanged(object sender, EventArgs e) private void CheckMix_CheckedChanged(object sender, EventArgs e)
{ {
if (CheckMix.Checked) Others.Config.Match_Mix = true; if (CheckMix.Checked) Config.Match_Mix = true;
else Others.Config.Match_Mix = false; else Config.Match_Mix = false;
} }
/// <summary> /// <summary>
@ -1041,8 +1040,8 @@ namespace Milimoe.FunGame.Desktop.UI
/// <param name="e"></param> /// <param name="e"></param>
private void CheckTeam_CheckedChanged(object sender, EventArgs e) private void CheckTeam_CheckedChanged(object sender, EventArgs e)
{ {
if (CheckTeam.Checked) Others.Config.Match_Team = true; if (CheckTeam.Checked) Config.Match_Team = true;
else Others.Config.Match_Team = false; else Config.Match_Team = false;
} }
/// <summary> /// <summary>
@ -1052,8 +1051,8 @@ namespace Milimoe.FunGame.Desktop.UI
/// <param name="e"></param> /// <param name="e"></param>
private void CheckHasPass_CheckedChanged(object sender, EventArgs e) private void CheckHasPass_CheckedChanged(object sender, EventArgs e)
{ {
if (CheckHasPass.Checked) Others.Config.Match_HasPass = true; if (CheckHasPass.Checked) Config.Match_HasPass = true;
else Others.Config.Match_HasPass = false; else Config.Match_HasPass = false;
} }
/// <summary> /// <summary>
@ -1205,81 +1204,81 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
switch (s) switch (s)
{ {
case Others.Constant.FunGame_SignIn: case Constant.FunGame_SignIn:
break; break;
case Others.Constant.FunGame_ShowCredits: case Constant.FunGame_ShowCredits:
break; break;
case Others.Constant.FunGame_ShowStock: case Constant.FunGame_ShowStock:
break; break;
case Others.Constant.FunGame_ShowStore: case Constant.FunGame_ShowStore:
break; break;
case Others.Constant.FunGame_CreateMix: case Constant.FunGame_CreateMix:
CreateRoom_Action = (i, objs) => CreateRoom_Action = (i, objs) =>
{ {
CreateRoom_Method(i, objs); CreateRoom_Method(i, objs);
}; };
if (InvokeRequired) if (InvokeRequired)
{ {
Invoke(CreateRoom_Action, (int)CreateRoomState.Creating, new object[] { Others.Constant.GameMode_Mix }); Invoke(CreateRoom_Action, (int)CreateRoomState.Creating, new object[] { Constant.GameMode_Mix });
} }
else else
{ {
CreateRoom_Action((int)CreateRoomState.Creating, new object[] { Others.Constant.GameMode_Mix }); CreateRoom_Action((int)CreateRoomState.Creating, new object[] { Constant.GameMode_Mix });
} }
break; break;
case Others.Constant.FunGame_CreateTeam: case Constant.FunGame_CreateTeam:
CreateRoom_Action = (i, objs) => CreateRoom_Action = (i, objs) =>
{ {
CreateRoom_Method(i, objs); CreateRoom_Method(i, objs);
}; };
if (InvokeRequired) if (InvokeRequired)
{ {
Invoke(CreateRoom_Action, (int)CreateRoomState.Creating, new object[] { Others.Constant.GameMode_Team }); Invoke(CreateRoom_Action, (int)CreateRoomState.Creating, new object[] { Constant.GameMode_Team });
} }
else else
{ {
CreateRoom_Action((int)CreateRoomState.Creating, new object[] { Others.Constant.GameMode_Team }); CreateRoom_Action((int)CreateRoomState.Creating, new object[] { Constant.GameMode_Team });
} }
break; break;
case Others.Constant.FunGame_StartGame: case Constant.FunGame_StartGame:
break; break;
case Others.Constant.FunGame_AutoRetryOn: case Constant.FunGame_AutoRetryOn:
WritelnGameInfo(">> 自动重连开启"); WritelnGameInfo(">> 自动重连开启");
Others.Config.FunGame_isAutoRetry = true; Config.FunGame_isAutoRetry = true;
break; break;
case Others.Constant.FunGame_AutoRetryOff: case Constant.FunGame_AutoRetryOff:
WritelnGameInfo(">> 自动重连关闭"); WritelnGameInfo(">> 自动重连关闭");
Others.Config.FunGame_isAutoRetry = false; Config.FunGame_isAutoRetry = false;
break; break;
case Others.Constant.FunGame_Retry: case Constant.FunGame_Retry:
if (!Others.Config.FunGame_isRetrying) if (!Config.FunGame_isRetrying)
{ {
CurrentRetryTimes = -1; CurrentRetryTimes = -1;
MainController?.Do<object>(MainControllerSet.Connect); MainController?.Connect();
} }
else else
WritelnGameInfo(">> 你不能在连接服务器的同时重试连接!"); WritelnGameInfo(">> 你不能在连接服务器的同时重试连接!");
break; break;
case Others.Constant.FunGame_Connect: case Constant.FunGame_Connect:
if (!Others.Config.FunGame_isConnected) if (!Config.FunGame_isConnected)
{ {
CurrentRetryTimes = -1; CurrentRetryTimes = -1;
MainController?.Do<bool>(MainControllerSet.GetServerConnection); MainController?.GetServerConnection();
} }
break; break;
case Others.Constant.FunGame_Disconnect: case Constant.FunGame_Disconnect:
if (Others.Config.FunGame_isConnected && MainController != null) if (Config.FunGame_isConnected && MainController != null)
{ {
MainController?.Do<bool>(MainControllerSet.Disconnect); MainController?.Disconnect();
} }
break; break;
case Others.Constant.FunGame_DisconnectWhenNotLogin: case Constant.FunGame_DisconnectWhenNotLogin:
if (Others.Config.FunGame_isConnected && MainController != null) if (Config.FunGame_isConnected && MainController != null)
{ {
MainController?.Do<object>(MainControllerSet.Disconnect); MainController?.Disconnect();
} }
break; break;
case Others.Constant.FunGame_ConnectTo: case Constant.FunGame_ConnectTo:
string msg = ShowMessage.InputMessage("请输入服务器IP地址和端口号如: 127.0.0.1:22222。", "连接指定服务器"); string msg = ShowMessage.InputMessage("请输入服务器IP地址和端口号如: 127.0.0.1:22222。", "连接指定服务器");
if (msg.Equals("")) return; if (msg.Equals("")) return;
string[] addr = msg.Split(':'); string[] addr = msg.Split(':');
@ -1303,10 +1302,10 @@ namespace Milimoe.FunGame.Desktop.UI
ErrorType ErrorType = NetworkUtility.IsServerAddress(ip, port); ErrorType ErrorType = NetworkUtility.IsServerAddress(ip, port);
if (ErrorType == Core.Library.Constant.ErrorType.None) if (ErrorType == Core.Library.Constant.ErrorType.None)
{ {
Others.Constant.SERVER_IPADRESS = ip; Constant.Server_Address = ip;
Others.Constant.SERVER_PORT = port; Constant.Server_Port = port;
CurrentRetryTimes = -1; CurrentRetryTimes = -1;
MainController?.Do<object>(MainControllerSet.Connect); MainController?.Connect();
} }
else if (ErrorType == Core.Library.Constant.ErrorType.IsNotIP) ShowMessage.ErrorMessage("这不是一个IP地址"); else if (ErrorType == Core.Library.Constant.ErrorType.IsNotIP) ShowMessage.ErrorMessage("这不是一个IP地址");
else if (ErrorType == Core.Library.Constant.ErrorType.IsNotPort) ShowMessage.ErrorMessage("这不是一个端口号!\n正确范围1~65535"); else if (ErrorType == Core.Library.Constant.ErrorType.IsNotPort) ShowMessage.ErrorMessage("这不是一个端口号!\n正确范围1~65535");

View File

@ -1,21 +1,6 @@
using System; using Milimoe.FunGame.Core.Api.Utility;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.Net.NetworkInformation;
using Milimoe.FunGame.Core.Entity;
using Milimoe.FunGame.Desktop.Others;
using Milimoe.FunGame.Desktop.UI;
using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Core.Api.Factory;
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Desktop.Library.Component; using Milimoe.FunGame.Desktop.UI;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Milimoe.FunGame.Desktop.Utility namespace Milimoe.FunGame.Desktop.Utility
{ {
@ -23,50 +8,11 @@ namespace Milimoe.FunGame.Desktop.Utility
{ {
public static void SingleForm(FormType type, OpenFormType opentype = OpenFormType.General) public static void SingleForm(FormType type, OpenFormType opentype = OpenFormType.General)
{ {
string formtype = ""; Form form = new();
switch(type)
{
case FormType.Register:
formtype = FormSet.Register;
break;
case FormType.Login:
formtype = FormSet.Login;
break;
case FormType.Inventory:
formtype = FormSet.Inventory;
break;
case FormType.RoomSetting:
formtype = FormSet.RoomSetting;
break;
case FormType.Store:
formtype = FormSet.Store;
break;
case FormType.UserCenter:
formtype = FormSet.UserCenter;
break;
case FormType.Main:
formtype = FormSet.Main;
break;
default:
break;
}
if (!Singleton.IsExist(formtype))
{
NewSingleForm(type, opentype);
}
else
{
OpenSingleForm(formtype, opentype);
}
}
private static void NewSingleForm(FormType type, OpenFormType opentype)
{
System.Windows.Forms.Form form = new();
switch (type) switch (type)
{ {
case FormType.Register: case FormType.Register:
form = new Register(); form = new Register();
break; break;
case FormType.Login: case FormType.Login:
form = new Login(); form = new Login();
@ -85,6 +31,18 @@ namespace Milimoe.FunGame.Desktop.Utility
default: default:
break; break;
} }
if (!Singleton.IsExist(form))
{
NewSingleForm(form, opentype);
}
else
{
throw new Exception("目标窗口可能已处于打开状态。");
}
}
private static void NewSingleForm(Form form, OpenFormType opentype)
{
if (Singleton.Add(form)) if (Singleton.Add(form))
{ {
if (opentype == OpenFormType.Dialog) form.ShowDialog(); if (opentype == OpenFormType.Dialog) form.ShowDialog();
@ -92,39 +50,5 @@ namespace Milimoe.FunGame.Desktop.Utility
} }
else throw new Exception("无法打开指定窗口。"); else throw new Exception("无法打开指定窗口。");
} }
private static void OpenSingleForm(string key, OpenFormType opentype)
{
System.Windows.Forms.Form form = new();
object? obj = Singleton.Get(key);
if (obj != null)
{
switch (key)
{
case FormSet.Register:
form = (Register)obj;
break;
case FormSet.Login:
form = (Login)obj;
break;
case FormSet.Inventory:
break;
case FormSet.RoomSetting:
break;
case FormSet.Store:
break;
case FormSet.UserCenter:
break;
case FormSet.Main:
form = (Main)obj;
break;
default:
break;
}
if (opentype == OpenFormType.Dialog) form.ShowDialog();
else form.Show();
}
else throw new Exception("无法打开指定窗口。");
}
} }
} }