mirror of
https://github.com/project-redbud/FunGame-Desktop.git
synced 2025-04-20 20:19:34 +08:00
重构MainModel 添加服务器强制将玩家下线 (#1)
This commit is contained in:
commit
b573adc215
@ -3,14 +3,12 @@ using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Desktop.Model;
|
||||
using Milimoe.FunGame.Desktop.UI;
|
||||
using Milimoe.FunGame.Desktop.Library;
|
||||
using Milimoe.FunGame.Core.Library.Exception;
|
||||
|
||||
namespace Milimoe.FunGame.Desktop.Controller
|
||||
{
|
||||
public class MainController : BaseController
|
||||
{
|
||||
public bool Connected => Do<bool>(MainInvokeType.Connected);
|
||||
|
||||
private MainModel MainModel { get; }
|
||||
private Main Main { get; }
|
||||
|
||||
@ -25,83 +23,127 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
MainModel.Dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从内部去调用Model的方法,并记录日志。
|
||||
*/
|
||||
private T Do<T>(MainInvokeType DoType, params object[] args)
|
||||
public async Task<bool> LogOut()
|
||||
{
|
||||
object result = new();
|
||||
switch(DoType)
|
||||
bool result = false;
|
||||
|
||||
try
|
||||
{
|
||||
case MainInvokeType.LogOut:
|
||||
if (Main.OnBeforeLogoutEvent(new GeneralEventArgs()) == EventResult.Fail) return (T)result;
|
||||
result = MainModel.LogOut();
|
||||
break;
|
||||
GeneralEventArgs EventArgs = new();
|
||||
if (Main.OnBeforeLogoutEvent(EventArgs) == EventResult.Fail) return result;
|
||||
|
||||
case MainInvokeType.IntoRoom:
|
||||
string roomid = new("-1");
|
||||
if (args != null && args.Length > 0) roomid = (string)args[0];
|
||||
if (Main.OnBeforeIntoRoomEvent(new RoomEventArgs(roomid)) == EventResult.Fail) return (T)result;
|
||||
result = MainModel.IntoRoom(roomid);
|
||||
break;
|
||||
result = await MainModel.LogOut();
|
||||
|
||||
case MainInvokeType.UpdateRoom:
|
||||
result = MainModel.UpdateRoom();
|
||||
break;
|
||||
|
||||
case MainInvokeType.QuitRoom:
|
||||
roomid = new("-1");
|
||||
if (args != null && args.Length > 0) roomid = (string)args[0];
|
||||
if (Main.OnBeforeQuitRoomEvent(new RoomEventArgs(roomid)) == EventResult.Fail) return (T)result;
|
||||
result = MainModel.QuitRoom(roomid);
|
||||
break;
|
||||
|
||||
case MainInvokeType.CreateRoom:
|
||||
if (Main.OnBeforeCreateRoomEvent(new RoomEventArgs()) == EventResult.Fail) return (T)result;
|
||||
result = MainModel.CreateRoom();
|
||||
break;
|
||||
|
||||
case MainInvokeType.Chat:
|
||||
string msg = "";
|
||||
if (args != null && args.Length > 0) msg = (string)args[0];
|
||||
if (Main.OnBeforeSendTalkEvent(new SendTalkEventArgs(msg)) == EventResult.Fail) return (T)result;
|
||||
if (msg.Trim() != "") result = MainModel.Chat(msg);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
if (result) Main.OnSucceedLogoutEvent(EventArgs);
|
||||
else Main.OnFailedLogoutEvent(EventArgs);
|
||||
Main.OnAfterLogoutEvent(EventArgs);
|
||||
}
|
||||
return (T)result;
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo(), TimeType.None);
|
||||
}
|
||||
|
||||
public bool LogOut()
|
||||
{
|
||||
return Do<bool>(MainInvokeType.LogOut);
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool UpdateRoom()
|
||||
public async Task<bool> UpdateRoom()
|
||||
{
|
||||
return Do<bool>(MainInvokeType.UpdateRoom);
|
||||
return await MainModel.UpdateRoom();
|
||||
}
|
||||
|
||||
public bool IntoRoom(string roomid)
|
||||
public async Task<bool> IntoRoom(string roomid)
|
||||
{
|
||||
return Do<bool>(MainInvokeType.IntoRoom, roomid);
|
||||
bool result = false;
|
||||
|
||||
try
|
||||
{
|
||||
RoomEventArgs EventArgs = new(roomid);
|
||||
if (Main.OnBeforeIntoRoomEvent(EventArgs) == EventResult.Fail) return result;
|
||||
|
||||
result = await MainModel.IntoRoom(roomid);
|
||||
|
||||
if (result) Main.OnSucceedIntoRoomEvent(EventArgs);
|
||||
else Main.OnFailedIntoRoomEvent(EventArgs);
|
||||
Main.OnAfterIntoRoomEvent(EventArgs);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo(), TimeType.None);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool QuitRoom(string roomid)
|
||||
{
|
||||
return Do<bool>(MainInvokeType.QuitRoom, roomid);
|
||||
bool result = false;
|
||||
|
||||
try
|
||||
{
|
||||
RoomEventArgs EventArgs = new(roomid);
|
||||
if (Main.OnBeforeQuitRoomEvent(EventArgs) == EventResult.Fail) return result;
|
||||
|
||||
result = MainModel.QuitRoom(roomid);
|
||||
|
||||
if (result) Main.OnSucceedQuitRoomEvent(EventArgs);
|
||||
else Main.OnFailedQuitRoomEvent(EventArgs);
|
||||
Main.OnAfterQuitRoomEvent(EventArgs);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo(), TimeType.None);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool CreateRoom()
|
||||
{
|
||||
return Do<bool>(MainInvokeType.CreateRoom);
|
||||
bool result = false;
|
||||
|
||||
try
|
||||
{
|
||||
RoomEventArgs EventArgs = new();
|
||||
if (Main.OnBeforeCreateRoomEvent(EventArgs) == EventResult.Fail) return result;
|
||||
|
||||
result = MainModel.CreateRoom();
|
||||
|
||||
if (result) Main.OnSucceedCreateRoomEvent(EventArgs);
|
||||
else Main.OnFailedCreateRoomEvent(EventArgs);
|
||||
Main.OnAfterCreateRoomEvent(EventArgs);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo(), TimeType.None);
|
||||
}
|
||||
|
||||
public bool Chat(string msg)
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> Chat(string msg)
|
||||
{
|
||||
return Do<bool>(MainInvokeType.Chat, msg);
|
||||
bool result = false;
|
||||
|
||||
try
|
||||
{
|
||||
SendTalkEventArgs EventArgs = new(msg);
|
||||
if (Main.OnBeforeSendTalkEvent(EventArgs) == EventResult.Fail) return result;
|
||||
|
||||
if (msg.Trim() != "")
|
||||
{
|
||||
result = await MainModel.Chat(msg);
|
||||
}
|
||||
|
||||
if (result) Main.OnSucceedSendTalkEvent(EventArgs);
|
||||
else Main.OnFailedSendTalkEvent(EventArgs);
|
||||
Main.OnAfterSendTalkEvent(EventArgs);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo(), TimeType.None);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,15 +82,15 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool Close(params object[] args)
|
||||
public bool Close(Exception? e = null)
|
||||
{
|
||||
bool result;
|
||||
|
||||
if (Connected) Disconnect();
|
||||
|
||||
if (args != null && args.Length > 0)
|
||||
if (e != null)
|
||||
{
|
||||
RunTimeModel.Error((Exception)args[0]);
|
||||
RunTimeModel.Error(e);
|
||||
result = true;
|
||||
}
|
||||
else result = RunTimeModel.Close();
|
||||
@ -103,12 +103,12 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
return Close(e);
|
||||
}
|
||||
|
||||
public async Task AutoLogin(params object[] objs)
|
||||
public async Task AutoLogin(string Username, string Password, string AutoKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoginController LoginController = new();
|
||||
await LoginController.LoginAccount(objs);
|
||||
await LoginController.LoginAccount(Username, Password, AutoKey);
|
||||
LoginController.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -93,10 +93,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
string? msg = "";
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!Working) break;
|
||||
}
|
||||
WaitForWorkDone();
|
||||
// 返回一个确认登录的Key
|
||||
if (Work.Length > 0) key = Work.GetParam<Guid>(0);
|
||||
if (Work.Length > 1) msg = Work.GetParam<string>(1);
|
||||
@ -118,10 +115,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
DataSet? ds = new();
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!Working) break;
|
||||
}
|
||||
WaitForWorkDone();
|
||||
// 返回构造User对象的DataSet
|
||||
if (Work.Length > 0) ds = Work.GetParam<DataSet>(0);
|
||||
}
|
||||
@ -138,5 +132,13 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
Working = true;
|
||||
Work = default;
|
||||
}
|
||||
|
||||
private static new void WaitForWorkDone()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!Working) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ using Milimoe.FunGame.Core.Library.Exception;
|
||||
using Milimoe.FunGame.Desktop.Library;
|
||||
using Milimoe.FunGame.Desktop.Library.Component;
|
||||
using Milimoe.FunGame.Desktop.UI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Milimoe.FunGame.Desktop.Model
|
||||
{
|
||||
public class MainModel : BaseModel
|
||||
{
|
||||
private readonly Main Main;
|
||||
private string LastSendTalkMessage = "";
|
||||
|
||||
public MainModel(Main main) : base(RunTime.Socket)
|
||||
{
|
||||
@ -21,55 +21,76 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
|
||||
#region 公开方法
|
||||
|
||||
public bool LogOut()
|
||||
public async Task<bool> LogOut()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 需要当时登录给的Key发回去,确定是账号本人在操作才允许登出
|
||||
if (Config.Guid_LoginKey != Guid.Empty)
|
||||
{
|
||||
SetWorking();
|
||||
if (RunTime.Socket?.Send(SocketMessageType.Logout, Config.Guid_LoginKey) == SocketResult.Success)
|
||||
{
|
||||
string msg = "";
|
||||
Guid key = Guid.Empty;
|
||||
(msg, key) = await Task.Factory.StartNew(SocketHandler_LogOut);
|
||||
if (key == Config.Guid_LoginKey)
|
||||
{
|
||||
Config.Guid_LoginKey = Guid.Empty;
|
||||
Main.UpdateUI(MainInvokeType.LogOut, msg ?? "");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else throw new CanNotLogOutException();
|
||||
}
|
||||
throw new CanNotLogOutException();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ShowMessage.ErrorMessage("无法登出您的账号,请联系服务器管理员。", "登出失败", 5);
|
||||
Main.GetMessage(e.GetErrorInfo());
|
||||
Main.OnFailedLogoutEvent(new GeneralEventArgs());
|
||||
Main.OnAfterLogoutEvent(new GeneralEventArgs());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IntoRoom(string roomid)
|
||||
public async Task<bool> IntoRoom(string roomid)
|
||||
{
|
||||
try
|
||||
{
|
||||
SetWorking();
|
||||
if (RunTime.Socket?.Send(SocketMessageType.IntoRoom, roomid) == SocketResult.Success)
|
||||
{
|
||||
roomid = await Task.Factory.StartNew(SocketHandler_IntoRoom);
|
||||
if (roomid.Trim() != "" && roomid == "-1")
|
||||
{
|
||||
Main.GetMessage($"已连接至公共聊天室。");
|
||||
}
|
||||
else
|
||||
{
|
||||
Config.FunGame_Roomid = roomid;
|
||||
}
|
||||
return true;
|
||||
else throw new CanNotIntoRoomException();
|
||||
}
|
||||
throw new CanNotIntoRoomException();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo());
|
||||
RoomEventArgs args = new(roomid);
|
||||
Main.OnFailedIntoRoomEvent(args);
|
||||
Main.OnAfterIntoRoomEvent(args);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdateRoom()
|
||||
public async Task<bool> UpdateRoom()
|
||||
{
|
||||
try
|
||||
{
|
||||
SetWorking();
|
||||
if (RunTime.Socket?.Send(SocketMessageType.UpdateRoom) == SocketResult.Success)
|
||||
{
|
||||
List<string> list = await Task.Factory.StartNew(SocketHandler_UpdateRoom);
|
||||
Main.UpdateUI(MainInvokeType.UpdateRoom, list);
|
||||
return true;
|
||||
else throw new GetRoomListException();
|
||||
}
|
||||
throw new GetRoomListException();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -82,6 +103,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
{
|
||||
try
|
||||
{
|
||||
SetWorking();
|
||||
if (RunTime.Socket?.Send(SocketMessageType.QuitRoom, roomid) == SocketResult.Success)
|
||||
return true;
|
||||
else throw new QuitRoomException();
|
||||
@ -89,9 +111,6 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo());
|
||||
RoomEventArgs args = new(roomid);
|
||||
Main.OnFailedQuitRoomEvent(args);
|
||||
Main.OnAfterQuitRoomEvent(args);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -100,35 +119,39 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
{
|
||||
try
|
||||
{
|
||||
SetWorking();
|
||||
if (RunTime.Socket?.Send(SocketMessageType.CreateRoom) == SocketResult.Success)
|
||||
return true;
|
||||
else throw new QuitRoomException();
|
||||
else throw new CreateRoomException();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo());
|
||||
RoomEventArgs args = new();
|
||||
Main.OnFailedCreateRoomEvent(args);
|
||||
Main.OnAfterCreateRoomEvent(args);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Chat(string msg)
|
||||
public async Task<bool> Chat(string msg)
|
||||
{
|
||||
LastSendTalkMessage = msg;
|
||||
try
|
||||
{
|
||||
SetWorking();
|
||||
if (RunTime.Socket?.Send(SocketMessageType.Chat, msg) == SocketResult.Success)
|
||||
{
|
||||
string user = "";
|
||||
(user, msg) = await Task.Factory.StartNew(SocketHandler_Chat);
|
||||
if (user != Usercfg.LoginUserName)
|
||||
{
|
||||
Main.GetMessage(msg, TimeType.None);
|
||||
return true;
|
||||
else throw new CanNotSendTalkException();
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
throw new CanNotSendTalkException();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo());
|
||||
SendTalkEventArgs SendTalkEventArgs = new(LastSendTalkMessage);
|
||||
Main.OnFailedSendTalkEvent(SendTalkEventArgs);
|
||||
Main.OnAfterSendTalkEvent(SendTalkEventArgs);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -137,39 +160,33 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (SocketObject.SocketType)
|
||||
// 定义接收的通信类型
|
||||
SocketMessageType[] SocketMessageTypes = new SocketMessageType[] { SocketMessageType.GetNotice, SocketMessageType.Logout, SocketMessageType.IntoRoom, SocketMessageType.QuitRoom,
|
||||
SocketMessageType.Chat, SocketMessageType.UpdateRoom };
|
||||
if (SocketObject.SocketType == SocketMessageType.HeartBeat)
|
||||
{
|
||||
case SocketMessageType.GetNotice:
|
||||
SocketHandler_GetNotice(SocketObject);
|
||||
break;
|
||||
|
||||
case SocketMessageType.Logout:
|
||||
SocketHandler_LogOut(SocketObject);
|
||||
break;
|
||||
|
||||
case SocketMessageType.HeartBeat:
|
||||
// 心跳包单独处理
|
||||
if ((RunTime.Socket?.Connected ?? false) && Usercfg.LoginUser != null)
|
||||
Main.UpdateUI(MainInvokeType.SetGreenAndPing);
|
||||
break;
|
||||
|
||||
case SocketMessageType.IntoRoom:
|
||||
SocketHandler_IntoRoom(SocketObject);
|
||||
break;
|
||||
|
||||
case SocketMessageType.QuitRoom:
|
||||
break;
|
||||
|
||||
case SocketMessageType.Chat:
|
||||
SocketHandler_Chat(SocketObject);
|
||||
break;
|
||||
|
||||
case SocketMessageType.UpdateRoom:
|
||||
SocketHandler_UpdateRoom(SocketObject);
|
||||
break;
|
||||
|
||||
case SocketMessageType.Unknown:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
else if (SocketObject.SocketType == SocketMessageType.ForceLogout)
|
||||
{
|
||||
// 服务器强制下线登录
|
||||
Guid key = Guid.Empty;
|
||||
string? msg = "";
|
||||
if (SocketObject.Length > 0) key = SocketObject.GetParam<Guid>(0);
|
||||
if (SocketObject.Length > 1) msg = SocketObject.GetParam<string>(1);
|
||||
msg ??= "";
|
||||
if (key == Config.Guid_LoginKey)
|
||||
{
|
||||
Config.Guid_LoginKey = Guid.Empty;
|
||||
Main.UpdateUI(MainInvokeType.LogOut, msg ?? "");
|
||||
}
|
||||
}
|
||||
else if (SocketMessageTypes.Contains(SocketObject.SocketType))
|
||||
{
|
||||
Work = SocketObject;
|
||||
Working = false;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -182,73 +199,73 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
|
||||
#region SocketHandler
|
||||
|
||||
private void SocketHandler_GetNotice(SocketObject SocketObject)
|
||||
private (string, Guid) SocketHandler_LogOut()
|
||||
{
|
||||
if (SocketObject.Length > 0) Config.FunGame_Notice = SocketObject.GetParam<string>(0)!;
|
||||
}
|
||||
|
||||
private void SocketHandler_LogOut(SocketObject SocketObject)
|
||||
{
|
||||
Guid key = Guid.Empty;
|
||||
string? msg = "";
|
||||
Guid key = Guid.Empty;
|
||||
try
|
||||
{
|
||||
WaitForWorkDone();
|
||||
// 返回一个Key,如果这个Key是空的,登出失败
|
||||
if (SocketObject.Parameters != null && SocketObject.Length > 0) key = SocketObject.GetParam<Guid>(0);
|
||||
if (SocketObject.Parameters != null && SocketObject.Length > 1) msg = SocketObject.GetParam<string>(1);
|
||||
if (key != Guid.Empty)
|
||||
{
|
||||
Config.Guid_LoginKey = Guid.Empty;
|
||||
Main.UpdateUI(MainInvokeType.LogOut, msg ?? "");
|
||||
Main.OnSucceedLogoutEvent(new GeneralEventArgs());
|
||||
if (Work.Length > 0) key = Work.GetParam<Guid>(0);
|
||||
if (Work.Length > 1) msg = Work.GetParam<string>(1);
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
ShowMessage.ErrorMessage("无法登出您的账号,请联系服务器管理员。", "登出失败", 5);
|
||||
Main.OnFailedLogoutEvent(new GeneralEventArgs());
|
||||
Main.GetMessage(e.GetErrorInfo());
|
||||
}
|
||||
Main.OnAfterLogoutEvent(new GeneralEventArgs());
|
||||
msg ??= "";
|
||||
return (msg, key);
|
||||
}
|
||||
|
||||
private void SocketHandler_IntoRoom(SocketObject SocketObject)
|
||||
private string SocketHandler_IntoRoom()
|
||||
{
|
||||
string roomid = "";
|
||||
if (SocketObject.Length > 0) roomid = SocketObject.GetParam<string>(0)!;
|
||||
if (roomid.Trim() != "" && roomid == "-1")
|
||||
string? roomid = "";
|
||||
try
|
||||
{
|
||||
Main.GetMessage($"已连接至公共聊天室。");
|
||||
WaitForWorkDone();
|
||||
if (Work.Length > 0) roomid = Work.GetParam<string>(0);
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
Config.FunGame_Roomid = roomid;
|
||||
Main.GetMessage(e.GetErrorInfo());
|
||||
}
|
||||
RoomEventArgs args = new(roomid);
|
||||
Main.OnSucceedIntoRoomEvent(args);
|
||||
Main.OnAfterIntoRoomEvent(args);
|
||||
roomid ??= "";
|
||||
return roomid;
|
||||
}
|
||||
|
||||
private void SocketHandler_UpdateRoom(SocketObject SocketObject)
|
||||
private List<string> SocketHandler_UpdateRoom()
|
||||
{
|
||||
List<string>? list = SocketObject.GetParam<List<string>>(0);
|
||||
List<string>? list = null;
|
||||
try
|
||||
{
|
||||
WaitForWorkDone();
|
||||
if (Work.Length > 0) list = Work.GetParam<List<string>>(0);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo());
|
||||
}
|
||||
list ??= new List<string>();
|
||||
Main.UpdateUI(MainInvokeType.UpdateRoom, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void SocketHandler_Chat(SocketObject SocketObject)
|
||||
private (string, string) SocketHandler_Chat()
|
||||
{
|
||||
SendTalkEventArgs SendTalkEventArgs = new(LastSendTalkMessage);
|
||||
if (SocketObject.Parameters != null && SocketObject.Length > 1)
|
||||
string? user = "", msg = "";
|
||||
try
|
||||
{
|
||||
string user = SocketObject.GetParam<string>(0)!;
|
||||
string msg = SocketObject.GetParam<string>(1)!;
|
||||
if (user != Usercfg.LoginUserName)
|
||||
{
|
||||
Main.GetMessage(msg, TimeType.None);
|
||||
WaitForWorkDone();
|
||||
if (Work.Length > 0) user = Work.GetParam<string>(0);
|
||||
if (Work.Length > 1) msg = Work.GetParam<string>(1);
|
||||
}
|
||||
Main.OnSucceedSendTalkEvent(SendTalkEventArgs);
|
||||
Main.OnAfterSendTalkEvent(SendTalkEventArgs);
|
||||
return;
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo());
|
||||
}
|
||||
Main.OnFailedSendTalkEvent(SendTalkEventArgs);
|
||||
Main.OnAfterSendTalkEvent(SendTalkEventArgs);
|
||||
user ??= "";
|
||||
msg ??= "";
|
||||
return (user, msg);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -95,10 +95,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
RegInvokeType type = RegInvokeType.None;
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!Working) break;
|
||||
}
|
||||
WaitForWorkDone();
|
||||
if (Work.Length > 0) type = Work.GetParam<RegInvokeType>(0);
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -114,10 +111,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
string? msg = "";
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!Working) break;
|
||||
}
|
||||
WaitForWorkDone();
|
||||
if (Work.Length > 0) success = Work.GetParam<bool>(0);
|
||||
if (Work.Length > 1) msg = Work.GetParam<string>(1) ?? "";
|
||||
}
|
||||
|
@ -667,7 +667,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
/// 发送消息实现
|
||||
/// </summary>
|
||||
/// <param name="isLeave">是否离开焦点</param>
|
||||
private void SendTalkText_Click(bool isLeave)
|
||||
private async void SendTalkText_Click(bool isLeave)
|
||||
{
|
||||
// 向消息队列发送消息
|
||||
string text = TalkText.Text;
|
||||
@ -683,9 +683,9 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
msg = DateTimeUtility.GetNowShortTime() + " [ " + Usercfg.LoginUserName + " ] 说: " + text;
|
||||
}
|
||||
WritelnGameInfo(msg);
|
||||
if (Usercfg.LoginUser != null && !SwitchTalkMessage(text))
|
||||
if (Usercfg.LoginUser != null && !await SwitchTalkMessage(text))
|
||||
{
|
||||
MainController?.Chat(" [ " + Usercfg.LoginUserName + " ] 说: " + text);
|
||||
_ = MainController?.Chat(" [ " + Usercfg.LoginUserName + " ] 说: " + text);
|
||||
}
|
||||
TalkText.Text = "";
|
||||
if (isLeave) TalkText_Leave(); // 回车不离开焦点
|
||||
@ -967,11 +967,11 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Logout_Click(object sender, EventArgs e)
|
||||
private async void Logout_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ShowMessage.OKCancelMessage("你确定要退出登录吗?", "退出登录") == MessageResult.OK)
|
||||
{
|
||||
if (MainController == null || !MainController.LogOut())
|
||||
if (MainController == null || !await MainController.LogOut())
|
||||
ShowMessage.WarningMessage("请求无效:退出登录失败!");
|
||||
}
|
||||
}
|
||||
@ -1152,14 +1152,14 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PresetText_SelectedIndexChanged(object sender, EventArgs e)
|
||||
private async void PresetText_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
// 发送快捷消息并执行功能
|
||||
if (PresetText.SelectedIndex != 0)
|
||||
{
|
||||
string s = PresetText.SelectedItem.ToString();
|
||||
SendTalkText_Click(s);
|
||||
SwitchTalkMessage(s);
|
||||
await SwitchTalkMessage(s);
|
||||
PresetText.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
@ -1218,9 +1218,9 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
private EventResult SucceedLoginEvent(object sender, GeneralEventArgs e)
|
||||
{
|
||||
// 接入-1号房间聊天室
|
||||
MainController?.IntoRoom("-1");
|
||||
_ = MainController?.IntoRoom("-1");
|
||||
// 获取在线的房间列表
|
||||
MainController?.UpdateRoom();
|
||||
_ = MainController?.UpdateRoom();
|
||||
return EventResult.Success;
|
||||
}
|
||||
|
||||
@ -1249,7 +1249,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
/// 判断快捷消息
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
private bool SwitchTalkMessage(string s)
|
||||
private async Task<bool> SwitchTalkMessage(string s)
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
@ -1321,7 +1321,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
if (Config.FunGame_isConnected && MainController != null)
|
||||
{
|
||||
// 先退出登录再断开连接
|
||||
if (MainController?.LogOut() ?? false) RunTime.Connector?.Disconnect();
|
||||
if (MainController != null && await MainController.LogOut()) RunTime.Connector?.Disconnect();
|
||||
}
|
||||
break;
|
||||
case Constant.FunGame_DisconnectWhenNotLogin:
|
||||
|
Loading…
x
Reference in New Issue
Block a user