mirror of
https://github.com/project-redbud/FunGame-Desktop.git
synced 2025-04-23 13:39:36 +08:00
添加了退出房间和创建房间相关 (#2)
* Add QuitRoom * 添加加入房间时与服务器的通信,修复无法接收房间聊天信息的问题 * Add CreateRoom * 添加一定操作时刷新房间列表 * 刷新房间列表前需要先清空
This commit is contained in:
parent
b573adc215
commit
841ab3b3d1
@ -4,6 +4,7 @@ using Milimoe.FunGame.Core.Library.Constant;
|
|||||||
using Milimoe.FunGame.Desktop.Model;
|
using Milimoe.FunGame.Desktop.Model;
|
||||||
using Milimoe.FunGame.Desktop.UI;
|
using Milimoe.FunGame.Desktop.UI;
|
||||||
using Milimoe.FunGame.Core.Library.Exception;
|
using Milimoe.FunGame.Core.Library.Exception;
|
||||||
|
using Milimoe.FunGame.Desktop.Library;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Desktop.Controller
|
namespace Milimoe.FunGame.Desktop.Controller
|
||||||
{
|
{
|
||||||
@ -32,6 +33,11 @@ namespace Milimoe.FunGame.Desktop.Controller
|
|||||||
GeneralEventArgs EventArgs = new();
|
GeneralEventArgs EventArgs = new();
|
||||||
if (Main.OnBeforeLogoutEvent(EventArgs) == EventResult.Fail) return result;
|
if (Main.OnBeforeLogoutEvent(EventArgs) == EventResult.Fail) return result;
|
||||||
|
|
||||||
|
if (Config.FunGame_Roomid != "-1")
|
||||||
|
{
|
||||||
|
await MainModel.QuitRoom(Config.FunGame_Roomid);
|
||||||
|
}
|
||||||
|
|
||||||
result = await MainModel.LogOut();
|
result = await MainModel.LogOut();
|
||||||
|
|
||||||
if (result) Main.OnSucceedLogoutEvent(EventArgs);
|
if (result) Main.OnSucceedLogoutEvent(EventArgs);
|
||||||
@ -74,7 +80,7 @@ namespace Milimoe.FunGame.Desktop.Controller
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool QuitRoom(string roomid)
|
public async Task<bool> QuitRoom(string roomid)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
@ -83,7 +89,7 @@ namespace Milimoe.FunGame.Desktop.Controller
|
|||||||
RoomEventArgs EventArgs = new(roomid);
|
RoomEventArgs EventArgs = new(roomid);
|
||||||
if (Main.OnBeforeQuitRoomEvent(EventArgs) == EventResult.Fail) return result;
|
if (Main.OnBeforeQuitRoomEvent(EventArgs) == EventResult.Fail) return result;
|
||||||
|
|
||||||
result = MainModel.QuitRoom(roomid);
|
result = await MainModel.QuitRoom(roomid);
|
||||||
|
|
||||||
if (result) Main.OnSucceedQuitRoomEvent(EventArgs);
|
if (result) Main.OnSucceedQuitRoomEvent(EventArgs);
|
||||||
else Main.OnFailedQuitRoomEvent(EventArgs);
|
else Main.OnFailedQuitRoomEvent(EventArgs);
|
||||||
@ -97,18 +103,18 @@ namespace Milimoe.FunGame.Desktop.Controller
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CreateRoom()
|
public async Task<string> CreateRoom(string RoomType, string Password = "")
|
||||||
{
|
{
|
||||||
bool result = false;
|
string result = "";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RoomEventArgs EventArgs = new();
|
RoomEventArgs EventArgs = new();
|
||||||
if (Main.OnBeforeCreateRoomEvent(EventArgs) == EventResult.Fail) return result;
|
if (Main.OnBeforeCreateRoomEvent(EventArgs) == EventResult.Fail) return result;
|
||||||
|
|
||||||
result = MainModel.CreateRoom();
|
result = await MainModel.CreateRoom(RoomType, Password);
|
||||||
|
|
||||||
if (result) Main.OnSucceedCreateRoomEvent(EventArgs);
|
if (result.Trim() != "") Main.OnSucceedCreateRoomEvent(EventArgs);
|
||||||
else Main.OnFailedCreateRoomEvent(EventArgs);
|
else Main.OnFailedCreateRoomEvent(EventArgs);
|
||||||
Main.OnAfterCreateRoomEvent(EventArgs);
|
Main.OnAfterCreateRoomEvent(EventArgs);
|
||||||
}
|
}
|
||||||
@ -120,7 +126,7 @@ namespace Milimoe.FunGame.Desktop.Controller
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> Chat(string msg)
|
public bool Chat(string msg)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
@ -131,7 +137,7 @@ namespace Milimoe.FunGame.Desktop.Controller
|
|||||||
|
|
||||||
if (msg.Trim() != "")
|
if (msg.Trim() != "")
|
||||||
{
|
{
|
||||||
result = await MainModel.Chat(msg);
|
result = MainModel.Chat(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) Main.OnSucceedSendTalkEvent(EventArgs);
|
if (result) Main.OnSucceedSendTalkEvent(EventArgs);
|
||||||
|
@ -17,7 +17,7 @@ namespace Milimoe.FunGame.Desktop.Controller
|
|||||||
public RegisterController(Register reg)
|
public RegisterController(Register reg)
|
||||||
{
|
{
|
||||||
Register = reg;
|
Register = reg;
|
||||||
RegModel = new RegisterModel(reg);
|
RegModel = new RegisterModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
|
@ -20,11 +20,6 @@ namespace Milimoe.FunGame.Desktop.Library
|
|||||||
/**
|
/**
|
||||||
* FunGame Configs
|
* FunGame Configs
|
||||||
*/
|
*/
|
||||||
public const string GameMode_Mix = "混战模式";
|
|
||||||
public const string GameMode_Team = "团队模式";
|
|
||||||
public const string GameMode_MixHasPass = "带密码的混战模式";
|
|
||||||
public const string GameMode_TeamHasPass = "带密码的团队模式";
|
|
||||||
|
|
||||||
public const string FunGame_PresetMessage = "- 快捷消息 -";
|
public const string FunGame_PresetMessage = "- 快捷消息 -";
|
||||||
public const string FunGame_SignIn = "签到";
|
public const string FunGame_SignIn = "签到";
|
||||||
public const string FunGame_ShowCredits = "积分";
|
public const string FunGame_ShowCredits = "积分";
|
||||||
|
@ -7,6 +7,7 @@ using Milimoe.FunGame.Desktop.Library;
|
|||||||
using Milimoe.FunGame.Desktop.Library.Component;
|
using Milimoe.FunGame.Desktop.Library.Component;
|
||||||
using Milimoe.FunGame.Desktop.UI;
|
using Milimoe.FunGame.Desktop.UI;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Desktop.Model
|
namespace Milimoe.FunGame.Desktop.Model
|
||||||
{
|
{
|
||||||
@ -99,54 +100,60 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool QuitRoom(string roomid)
|
public async Task<bool> QuitRoom(string roomid)
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SetWorking();
|
SetWorking();
|
||||||
if (RunTime.Socket?.Send(SocketMessageType.QuitRoom, roomid) == SocketResult.Success)
|
if (RunTime.Socket?.Send(SocketMessageType.QuitRoom, roomid) == SocketResult.Success)
|
||||||
return true;
|
{
|
||||||
else throw new QuitRoomException();
|
result = await Task.Factory.StartNew(SocketHandler_QuitRoom);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
Config.FunGame_Roomid = "-1";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new QuitRoomException();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Main.GetMessage(e.GetErrorInfo());
|
Main.GetMessage(e.GetErrorInfo());
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CreateRoom()
|
public async Task<string> CreateRoom(string RoomType, string Password = "")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SetWorking();
|
SetWorking();
|
||||||
if (RunTime.Socket?.Send(SocketMessageType.CreateRoom) == SocketResult.Success)
|
if (RunTime.Socket?.Send(SocketMessageType.CreateRoom, RoomType, Usercfg.LoginUser?.Id ?? 0, Password) == SocketResult.Success)
|
||||||
return true;
|
{
|
||||||
else throw new CreateRoomException();
|
string roomid = await Task.Factory.StartNew(SocketHandler_CreateRoom);
|
||||||
|
if (roomid.Trim() != "")
|
||||||
|
{
|
||||||
|
return roomid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new CreateRoomException();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Main.GetMessage(e.GetErrorInfo());
|
Main.GetMessage(e.GetErrorInfo());
|
||||||
return false;
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> Chat(string msg)
|
public bool Chat(string msg)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SetWorking();
|
|
||||||
if (RunTime.Socket?.Send(SocketMessageType.Chat, msg) == SocketResult.Success)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
throw new CanNotSendTalkException();
|
throw new CanNotSendTalkException();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -162,7 +169,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
{
|
{
|
||||||
// 定义接收的通信类型
|
// 定义接收的通信类型
|
||||||
SocketMessageType[] SocketMessageTypes = new SocketMessageType[] { SocketMessageType.GetNotice, SocketMessageType.Logout, SocketMessageType.IntoRoom, SocketMessageType.QuitRoom,
|
SocketMessageType[] SocketMessageTypes = new SocketMessageType[] { SocketMessageType.GetNotice, SocketMessageType.Logout, SocketMessageType.IntoRoom, SocketMessageType.QuitRoom,
|
||||||
SocketMessageType.Chat, SocketMessageType.UpdateRoom };
|
SocketMessageType.Chat, SocketMessageType.UpdateRoom, SocketMessageType.CreateRoom };
|
||||||
if (SocketObject.SocketType == SocketMessageType.HeartBeat)
|
if (SocketObject.SocketType == SocketMessageType.HeartBeat)
|
||||||
{
|
{
|
||||||
// 心跳包单独处理
|
// 心跳包单独处理
|
||||||
@ -183,6 +190,17 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
Main.UpdateUI(MainInvokeType.LogOut, msg ?? "");
|
Main.UpdateUI(MainInvokeType.LogOut, msg ?? "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (SocketObject.SocketType == SocketMessageType.Chat)
|
||||||
|
{
|
||||||
|
// 收到房间聊天信息
|
||||||
|
string? user = "", msg = "";
|
||||||
|
if (SocketObject.Length > 0) user = SocketObject.GetParam<string>(0);
|
||||||
|
if (SocketObject.Length > 1) msg = SocketObject.GetParam<string>(1);
|
||||||
|
if (user != Usercfg.LoginUserName)
|
||||||
|
{
|
||||||
|
Main.GetMessage(msg, TimeType.None);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (SocketMessageTypes.Contains(SocketObject.SocketType))
|
else if (SocketMessageTypes.Contains(SocketObject.SocketType))
|
||||||
{
|
{
|
||||||
Work = SocketObject;
|
Work = SocketObject;
|
||||||
@ -234,6 +252,37 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
return roomid;
|
return roomid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string SocketHandler_CreateRoom()
|
||||||
|
{
|
||||||
|
string? roomid = "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
WaitForWorkDone();
|
||||||
|
if (Work.Length > 0) roomid = Work.GetParam<string>(0);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Main.GetMessage(e.GetErrorInfo());
|
||||||
|
}
|
||||||
|
roomid ??= "";
|
||||||
|
return roomid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool SocketHandler_QuitRoom()
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
WaitForWorkDone();
|
||||||
|
if (Work.Length > 0) result = Work.GetParam<bool>(0);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Main.GetMessage(e.GetErrorInfo());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private List<string> SocketHandler_UpdateRoom()
|
private List<string> SocketHandler_UpdateRoom()
|
||||||
{
|
{
|
||||||
List<string>? list = null;
|
List<string>? list = null;
|
||||||
@ -250,24 +299,6 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private (string, string) SocketHandler_Chat()
|
|
||||||
{
|
|
||||||
string? user = "", msg = "";
|
|
||||||
try
|
|
||||||
{
|
|
||||||
WaitForWorkDone();
|
|
||||||
if (Work.Length > 0) user = Work.GetParam<string>(0);
|
|
||||||
if (Work.Length > 1) msg = Work.GetParam<string>(1);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Main.GetMessage(e.GetErrorInfo());
|
|
||||||
}
|
|
||||||
user ??= "";
|
|
||||||
msg ??= "";
|
|
||||||
return (user, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,9 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
{
|
{
|
||||||
public class RegisterModel : BaseModel
|
public class RegisterModel : BaseModel
|
||||||
{
|
{
|
||||||
private readonly Register Register;
|
public RegisterModel() : base(RunTime.Socket)
|
||||||
|
|
||||||
public RegisterModel(Register reg) : base(RunTime.Socket)
|
|
||||||
{
|
{
|
||||||
Register = reg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SocketHandler(SocketObject SocketObject)
|
public override void SocketHandler(SocketObject SocketObject)
|
||||||
|
@ -8,6 +8,7 @@ using Milimoe.FunGame.Desktop.Controller;
|
|||||||
using Milimoe.FunGame.Desktop.Library;
|
using Milimoe.FunGame.Desktop.Library;
|
||||||
using Milimoe.FunGame.Desktop.Library.Base;
|
using Milimoe.FunGame.Desktop.Library.Base;
|
||||||
using Milimoe.FunGame.Desktop.Library.Component;
|
using Milimoe.FunGame.Desktop.Library.Component;
|
||||||
|
using Milimoe.FunGame.Desktop.Model;
|
||||||
using Milimoe.FunGame.Desktop.Utility;
|
using Milimoe.FunGame.Desktop.Utility;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Desktop.UI
|
namespace Milimoe.FunGame.Desktop.UI
|
||||||
@ -18,23 +19,21 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
#region 变量定义
|
#region 变量定义
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定义全局变量
|
* 属性
|
||||||
*/
|
*/
|
||||||
public int MaxRetryTimes { get; } = SocketSet.MaxRetryTimes; // 最大重试连接次数
|
public int MaxRetryTimes { get; } = SocketSet.MaxRetryTimes; // 最大重试连接次数
|
||||||
public int CurrentRetryTimes { get; set; } = -1; // 当前重试连接次数
|
public int CurrentRetryTimes { get; set; } = -1; // 当前重试连接次数
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定义全局对象
|
* 变量
|
||||||
*/
|
*/
|
||||||
private Task? MatchFunGame = null; // 匹配线程
|
private Task? MatchFunGame = null; // 匹配线程
|
||||||
private MainController? MainController = null;
|
private MainController? MainController = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定义委托
|
* 委托【即将删除】
|
||||||
* 子线程操作窗体控件时,先实例化Action,然后Invoke传递出去。
|
|
||||||
*/
|
*/
|
||||||
Action<int, object[]?>? StartMatch_Action = null;
|
Action<int, object[]?>? StartMatch_Action = null;
|
||||||
Action<int, object[]?>? CreateRoom_Action = null;
|
|
||||||
|
|
||||||
public Main()
|
public Main()
|
||||||
{
|
{
|
||||||
@ -205,6 +204,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
case MainInvokeType.UpdateRoom:
|
case MainInvokeType.UpdateRoom:
|
||||||
if (objs != null && objs.Length > 0)
|
if (objs != null && objs.Length > 0)
|
||||||
{
|
{
|
||||||
|
RoomList.Items.Clear();
|
||||||
List<string> list = (List<string>)objs[0];
|
List<string> list = (List<string>)objs[0];
|
||||||
RoomList.Items.AddRange(list.ToArray());
|
RoomList.Items.AddRange(list.ToArray());
|
||||||
}
|
}
|
||||||
@ -443,30 +443,13 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="isDouble"></param>
|
/// <param name="isDouble"></param>
|
||||||
/// <param name="roomid"></param>
|
/// <param name="roomid"></param>
|
||||||
private void JoinRoom(bool isDouble, string roomid)
|
private async Task<bool> JoinRoom(bool isDouble, string roomid)
|
||||||
{
|
{
|
||||||
if (!isDouble)
|
if (!isDouble)
|
||||||
|
{
|
||||||
if (!RoomText.Text.Equals("") && !RoomText.ForeColor.Equals(Color.DarkGray))
|
if (!RoomText.Text.Equals("") && !RoomText.ForeColor.Equals(Color.DarkGray))
|
||||||
{
|
{
|
||||||
if (CheckRoomIDExist(roomid))
|
return await JoinRoom_Handler(roomid);
|
||||||
{
|
|
||||||
if (Config.FunGame_Roomid.Equals("-1"))
|
|
||||||
{
|
|
||||||
if (ShowMessage.YesNoMessage("已找到房间 -> [ " + roomid + " ]\n是否加入?", "已找到房间") == MessageResult.Yes)
|
|
||||||
{
|
|
||||||
SetRoomid(roomid);
|
|
||||||
InRoom();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ShowMessage.TipMessage("你需要先退出房间才可以加入新的房间。");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ShowMessage.WarningMessage("未找到此房间!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -474,29 +457,48 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
ShowMessage.TipMessage("请输入房间号。");
|
ShowMessage.TipMessage("请输入房间号。");
|
||||||
RoomText.Enabled = true;
|
RoomText.Enabled = true;
|
||||||
RoomText.Focus();
|
RoomText.Focus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
return await JoinRoom_Handler(roomid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重复处理加入房间的方法
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roomid"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<bool> JoinRoom_Handler(string roomid)
|
||||||
|
{
|
||||||
|
if (MainController != null)
|
||||||
|
{
|
||||||
|
await MainController.UpdateRoom();
|
||||||
if (CheckRoomIDExist(roomid))
|
if (CheckRoomIDExist(roomid))
|
||||||
{
|
{
|
||||||
if (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)
|
||||||
|
{
|
||||||
|
if (MainController != null && await MainController.IntoRoom(roomid))
|
||||||
{
|
{
|
||||||
SetRoomid(roomid);
|
SetRoomid(roomid);
|
||||||
InRoom();
|
InRoom();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ShowMessage.TipMessage("你需要先退出房间才可以加入新的房间。");
|
ShowMessage.TipMessage("你需要先退出房间才可以加入新的房间。");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ShowMessage.WarningMessage("未找到此房间!");
|
ShowMessage.WarningMessage("未找到此房间!");
|
||||||
}
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -667,7 +669,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
/// 发送消息实现
|
/// 发送消息实现
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="isLeave">是否离开焦点</param>
|
/// <param name="isLeave">是否离开焦点</param>
|
||||||
private async void SendTalkText_Click(bool isLeave)
|
private async Task SendTalkText_Click(bool isLeave)
|
||||||
{
|
{
|
||||||
// 向消息队列发送消息
|
// 向消息队列发送消息
|
||||||
string text = TalkText.Text;
|
string text = TalkText.Text;
|
||||||
@ -685,7 +687,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
WritelnGameInfo(msg);
|
WritelnGameInfo(msg);
|
||||||
if (Usercfg.LoginUser != null && !await SwitchTalkMessage(text))
|
if (Usercfg.LoginUser != null && !await SwitchTalkMessage(text))
|
||||||
{
|
{
|
||||||
_ = MainController?.Chat(" [ " + Usercfg.LoginUserName + " ] 说: " + text);
|
MainController?.Chat(" [ " + Usercfg.LoginUserName + " ] 说: " + text);
|
||||||
}
|
}
|
||||||
TalkText.Text = "";
|
TalkText.Text = "";
|
||||||
if (isLeave) TalkText_Leave(); // 回车不离开焦点
|
if (isLeave) TalkText_Leave(); // 回车不离开焦点
|
||||||
@ -699,6 +701,35 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建房间的处理方法
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="RoomType"></param>
|
||||||
|
/// <param name="Password"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task CreateRoom_Handler(string RoomType, string Password = "")
|
||||||
|
{
|
||||||
|
if (Config.FunGame_Roomid != "-1")
|
||||||
|
{
|
||||||
|
ShowMessage.WarningMessage("已在房间中,无法创建房间。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MainController != null)
|
||||||
|
{
|
||||||
|
string roomid = (await MainController.CreateRoom(RoomType)).Trim();
|
||||||
|
if (roomid != "" && roomid != "-1" && await MainController.IntoRoom(roomid))
|
||||||
|
{
|
||||||
|
SetRoomid(roomid);
|
||||||
|
InRoom();
|
||||||
|
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 创建" + RoomType + "房间");
|
||||||
|
WritelnGameInfo(">> 创建" + RoomType + "房间成功!房间号: " + roomid);
|
||||||
|
ShowMessage.Message("创建" + RoomType + "房间成功!\n房间号是 -> [ " + roomid + " ]", "创建成功");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ShowMessage.Message("创建" + RoomType + "房间失败!", "创建失败");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送消息实现,往消息队列发送消息
|
/// 发送消息实现,往消息队列发送消息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -721,47 +752,17 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 这里实现创建房间相关的方法
|
/// 登录成功后的处理
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="i">主要参数:触发方法的哪一个分支</param>
|
/// <returns></returns>
|
||||||
/// <param name="objs">可传多个参数</param>
|
private async Task SucceedLoginEvent_Handler()
|
||||||
private void CreateRoom_Method(int i, object[]? objs = null)
|
|
||||||
{
|
{
|
||||||
if (!Config.FunGame_Roomid.Equals("-1"))
|
if (MainController != null)
|
||||||
{
|
{
|
||||||
ShowMessage.WarningMessage("已在房间中,无法创建房间。");
|
// 接入-1号房间聊天室
|
||||||
return;
|
await MainController.IntoRoom("-1");
|
||||||
}
|
// 获取在线的房间列表
|
||||||
string roomid = "";
|
await MainController.UpdateRoom();
|
||||||
string roomtype = "";
|
|
||||||
if (objs != null)
|
|
||||||
{
|
|
||||||
roomtype = (string)objs[0];
|
|
||||||
}
|
|
||||||
switch (i)
|
|
||||||
{
|
|
||||||
case (int)CreateRoomState.Creating:
|
|
||||||
CreateRoom_Action = (i, objs) =>
|
|
||||||
{
|
|
||||||
CreateRoom_Method(i, objs);
|
|
||||||
};
|
|
||||||
if (InvokeRequired)
|
|
||||||
{
|
|
||||||
Invoke(CreateRoom_Action, (int)CreateRoomState.Success, new object[] { roomtype });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CreateRoom_Action((int)CreateRoomState.Success, new object[] { roomtype });
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (int)CreateRoomState.Success:
|
|
||||||
roomid = Convert.ToString(new Random().Next(1, 10000));
|
|
||||||
SetRoomid(roomid);
|
|
||||||
InRoom();
|
|
||||||
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 创建" + roomtype + "房间");
|
|
||||||
WritelnGameInfo(">> 创建" + roomtype + "房间成功!房间号: " + roomid);
|
|
||||||
ShowMessage.Message("创建" + roomtype + "房间成功!\n房间号是 -> [ " + roomid + " ]", "创建成功");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,6 +822,14 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
RunTime.UserCenter?.Close();
|
RunTime.UserCenter?.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 退出游戏时处理
|
||||||
|
/// </summary>
|
||||||
|
private void ExitFunGame()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 事件
|
#region 事件
|
||||||
@ -834,6 +843,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
{
|
{
|
||||||
if (ShowMessage.OKCancelMessage("你确定关闭游戏?", "退出") == (int)MessageResult.OK)
|
if (ShowMessage.OKCancelMessage("你确定关闭游戏?", "退出") == (int)MessageResult.OK)
|
||||||
{
|
{
|
||||||
|
_ = MainController?.LogOut();
|
||||||
RunTime.Connector?.Close();
|
RunTime.Connector?.Close();
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
@ -887,9 +897,10 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void CreateRoom_Click(object sender, EventArgs e)
|
private async void CreateRoom_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string roomtype = "";
|
string roomtype = "";
|
||||||
|
string password = "";
|
||||||
if (Config.Match_Mix && Config.Match_Team)
|
if (Config.Match_Mix && Config.Match_Team)
|
||||||
{
|
{
|
||||||
ShowMessage.WarningMessage("创建房间不允许同时勾选混战和团队!");
|
ShowMessage.WarningMessage("创建房间不允许同时勾选混战和团队!");
|
||||||
@ -897,37 +908,36 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
}
|
}
|
||||||
else if (Config.Match_Mix && !Config.Match_Team && !Config.Match_HasPass)
|
else if (Config.Match_Mix && !Config.Match_Team && !Config.Match_HasPass)
|
||||||
{
|
{
|
||||||
roomtype = Constant.GameMode_Mix;
|
roomtype = GameMode.GameMode_Mix;
|
||||||
}
|
}
|
||||||
else if (!Config.Match_Mix && Config.Match_Team && !Config.Match_HasPass)
|
else if (!Config.Match_Mix && Config.Match_Team && !Config.Match_HasPass)
|
||||||
{
|
{
|
||||||
roomtype = Constant.GameMode_Team;
|
roomtype = GameMode.GameMode_Team;
|
||||||
}
|
}
|
||||||
else if (Config.Match_Mix && !Config.Match_Team && Config.Match_HasPass)
|
else if (Config.Match_Mix && !Config.Match_Team && Config.Match_HasPass)
|
||||||
{
|
{
|
||||||
roomtype = Constant.GameMode_MixHasPass;
|
roomtype = GameMode.GameMode_MixHasPass;
|
||||||
}
|
}
|
||||||
else if (!Config.Match_Mix && Config.Match_Team && Config.Match_HasPass)
|
else if (!Config.Match_Mix && Config.Match_Team && Config.Match_HasPass)
|
||||||
{
|
{
|
||||||
roomtype = Constant.GameMode_TeamHasPass;
|
roomtype = GameMode.GameMode_TeamHasPass;
|
||||||
|
}
|
||||||
|
if (Config.Match_HasPass)
|
||||||
|
{
|
||||||
|
password = ShowMessage.InputMessage("请输入该房间的密码:", "创建密码房间").Trim();
|
||||||
|
if (password == "" || password.Length > 10)
|
||||||
|
{
|
||||||
|
ShowMessage.WarningMessage("密码无效!密码不能为空或大于10个字符。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (roomtype.Equals(""))
|
if (roomtype.Equals(""))
|
||||||
{
|
{
|
||||||
ShowMessage.WarningMessage("请勾选你要创建的房间类型!");
|
ShowMessage.WarningMessage("请勾选你要创建的房间类型!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CreateRoom_Action = (i, objs) =>
|
await CreateRoom_Handler(roomtype, password);
|
||||||
{
|
_ = MainController?.UpdateRoom();
|
||||||
CreateRoom_Method(i, objs);
|
|
||||||
};
|
|
||||||
if (InvokeRequired)
|
|
||||||
{
|
|
||||||
Invoke(CreateRoom_Action, (int)CreateRoomState.Creating, new object[] { roomtype });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CreateRoom_Action((int)CreateRoomState.Creating, new object[] { roomtype });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -935,11 +945,21 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void QuitRoom_Click(object sender, EventArgs e)
|
private async void QuitRoom_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (MainController != null)
|
||||||
|
{
|
||||||
|
string roomid = Config.FunGame_Roomid;
|
||||||
|
if (await MainController.QuitRoom(roomid))
|
||||||
{
|
{
|
||||||
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 离开房间");
|
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 离开房间");
|
||||||
WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已离开房间 -> [ " + Config.FunGame_Roomid + " ]");
|
WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已离开房间 -> [ " + roomid + " ]");
|
||||||
InMain();
|
InMain();
|
||||||
|
_ = MainController.UpdateRoom();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ShowMessage.ErrorMessage("无法退出房间!", "退出房间");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -957,9 +977,9 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void QueryRoom_Click(object sender, EventArgs e)
|
private async void QueryRoom_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
JoinRoom(false, RoomText.Text);
|
await JoinRoom(false, RoomText.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -1004,11 +1024,12 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void RoomList_MouseDoubleClick(object sender, MouseEventArgs e)
|
private async void RoomList_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
#pragma warning disable CS8600, CS8604
|
|
||||||
if (RoomList.SelectedItem != null)
|
if (RoomList.SelectedItem != null)
|
||||||
JoinRoom(true, RoomList.SelectedItem.ToString());
|
{
|
||||||
|
await JoinRoom(true, RoomList.SelectedItem.ToString() ?? "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -1016,9 +1037,9 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void SendTalkText_Click(object sender, EventArgs e)
|
private async void SendTalkText_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SendTalkText_Click(true);
|
await SendTalkText_Click(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -1087,13 +1108,13 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void RoomText_KeyUp(object sender, KeyEventArgs e)
|
private async void RoomText_KeyUp(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
RoomText.ForeColor = Color.Black;
|
RoomText.ForeColor = Color.Black;
|
||||||
if (e.KeyCode.Equals(Keys.Enter))
|
if (e.KeyCode.Equals(Keys.Enter))
|
||||||
{
|
{
|
||||||
// 按下回车加入房间
|
// 按下回车加入房间
|
||||||
JoinRoom(false, RoomText.Text);
|
await JoinRoom(false, RoomText.Text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1126,13 +1147,13 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void TalkText_KeyUp(object sender, KeyEventArgs e)
|
private async void TalkText_KeyUp(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
TalkText.ForeColor = Color.Black;
|
TalkText.ForeColor = Color.Black;
|
||||||
if (e.KeyCode.Equals(Keys.Enter))
|
if (e.KeyCode.Equals(Keys.Enter))
|
||||||
{
|
{
|
||||||
// 按下回车发送
|
// 按下回车发送
|
||||||
SendTalkText_Click(false);
|
await SendTalkText_Click(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1157,13 +1178,18 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
// 发送快捷消息并执行功能
|
// 发送快捷消息并执行功能
|
||||||
if (PresetText.SelectedIndex != 0)
|
if (PresetText.SelectedIndex != 0)
|
||||||
{
|
{
|
||||||
string s = PresetText.SelectedItem.ToString();
|
string s = PresetText.SelectedItem.ToString() ?? "";
|
||||||
SendTalkText_Click(s);
|
SendTalkText_Click(s);
|
||||||
await SwitchTalkMessage(s);
|
await SwitchTalkMessage(s);
|
||||||
PresetText.SelectedIndex = 0;
|
PresetText.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 关闭主界面
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
private void Main_Disposed(object? sender, EventArgs e)
|
private void Main_Disposed(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
MainController?.Dispose();
|
MainController?.Dispose();
|
||||||
@ -1217,10 +1243,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private EventResult SucceedLoginEvent(object sender, GeneralEventArgs e)
|
private EventResult SucceedLoginEvent(object sender, GeneralEventArgs e)
|
||||||
{
|
{
|
||||||
// 接入-1号房间聊天室
|
_ = SucceedLoginEvent_Handler();
|
||||||
_ = MainController?.IntoRoom("-1");
|
|
||||||
// 获取在线的房间列表
|
|
||||||
_ = MainController?.UpdateRoom();
|
|
||||||
return EventResult.Success;
|
return EventResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1262,32 +1285,10 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
case Constant.FunGame_ShowStore:
|
case Constant.FunGame_ShowStore:
|
||||||
break;
|
break;
|
||||||
case Constant.FunGame_CreateMix:
|
case Constant.FunGame_CreateMix:
|
||||||
CreateRoom_Action = (i, objs) =>
|
await CreateRoom_Handler(GameMode.GameMode_Mix);
|
||||||
{
|
|
||||||
CreateRoom_Method(i, objs);
|
|
||||||
};
|
|
||||||
if (InvokeRequired)
|
|
||||||
{
|
|
||||||
Invoke(CreateRoom_Action, (int)CreateRoomState.Creating, new object[] { Constant.GameMode_Mix });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CreateRoom_Action((int)CreateRoomState.Creating, new object[] { Constant.GameMode_Mix });
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Constant.FunGame_CreateTeam:
|
case Constant.FunGame_CreateTeam:
|
||||||
CreateRoom_Action = (i, objs) =>
|
await CreateRoom_Handler(GameMode.GameMode_Team);
|
||||||
{
|
|
||||||
CreateRoom_Method(i, objs);
|
|
||||||
};
|
|
||||||
if (InvokeRequired)
|
|
||||||
{
|
|
||||||
Invoke(CreateRoom_Action, (int)CreateRoomState.Creating, new object[] { Constant.GameMode_Team });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CreateRoom_Action((int)CreateRoomState.Creating, new object[] { Constant.GameMode_Team });
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Constant.FunGame_StartGame:
|
case Constant.FunGame_StartGame:
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user