房间系统优化;添加准备和取消准备功能 (#23)

* 房间列表添加显示房间名称

* 添加了准备和取消准备

* 释放DataRequest

* 修复准备提示文本问题

* 添加了房间相关命令的使用限制

* 添加了玩家是否在房间中的标记

* set button to correct enable

* fix ready&cancelready bug

* 开始游戏/提醒玩家准备/提醒房主开始游戏
This commit is contained in:
milimoe 2023-11-21 10:52:13 +08:00 committed by GitHub
parent 2fbb511ea7
commit d3ac188fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 298 additions and 65 deletions

View File

@ -20,6 +20,7 @@ namespace Milimoe.FunGame.Desktop.Controller
private readonly DataRequest UpdateRoomRequest; private readonly DataRequest UpdateRoomRequest;
private readonly DataRequest IntoRoomRequest; private readonly DataRequest IntoRoomRequest;
private readonly DataRequest QuitRoomRequest; private readonly DataRequest QuitRoomRequest;
private readonly DataRequest StartGameRequest;
public MainController(Main main) public MainController(Main main)
{ {
@ -31,6 +32,7 @@ namespace Milimoe.FunGame.Desktop.Controller
UpdateRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_UpdateRoom); UpdateRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_UpdateRoom);
IntoRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_IntoRoom); IntoRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_IntoRoom);
QuitRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_QuitRoom); QuitRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_QuitRoom);
StartGameRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_StartGame);
} }
#region #region
@ -43,6 +45,7 @@ namespace Milimoe.FunGame.Desktop.Controller
UpdateRoomRequest.Dispose(); UpdateRoomRequest.Dispose();
IntoRoomRequest.Dispose(); IntoRoomRequest.Dispose();
QuitRoomRequest.Dispose(); QuitRoomRequest.Dispose();
StartGameRequest.Dispose();
} }
public async Task<bool> LogOutAsync() public async Task<bool> LogOutAsync()
@ -135,6 +138,70 @@ namespace Milimoe.FunGame.Desktop.Controller
return 0; return 0;
} }
} }
public async Task<bool> SetReadyAsync(string roomid)
{
try
{
bool result = true;
DataRequest request = RunTime.NewDataRequest(DataRequestType.Main_Ready);
request.AddRequestData("roomid", roomid);
await request.SendRequestAsync();
if (request.Result == RequestResult.Success)
{
result = request.GetResult<bool>("result");
if (result)
{
Config.FunGame_isInRoom = true;
Main.GetMessage("[ " + Usercfg.LoginUser.Username + " ] 准备完毕。");
}
List<User> ReadyPlayerList = request.GetResult<List<User>>("ready") ?? new();
if (ReadyPlayerList.Count > 0) Main.GetMessage("已准备的玩家:" + string.Join(", ", ReadyPlayerList.Select(u => u.Username)));
List<User> NotReadyPlayerList = request.GetResult<List<User>>("notready") ?? new();
if (NotReadyPlayerList.Count > 0) Main.GetMessage("仍未准备的玩家:" + string.Join(", ", NotReadyPlayerList.Select(u => u.Username)));
}
request.Dispose();
return result;
}
catch (Exception e)
{
Main.GetMessage(e.GetErrorInfo(), TimeType.None);
return false;
}
}
public async Task<bool> CancelReadyAsync(string roomid)
{
try
{
bool result = true;
DataRequest request = RunTime.NewDataRequest(DataRequestType.Main_CancelReady);
request.AddRequestData("roomid", roomid);
await request.SendRequestAsync();
if (request.Result == RequestResult.Success)
{
result = request.GetResult<bool>("result");
if (result)
{
Config.FunGame_isInRoom = false;
Main.GetMessage("[ " + Usercfg.LoginUser.Username + " ] 已取消准备。");
}
List<User> ReadyPlayerList = request.GetResult<List<User>>("ready") ?? new();
if (ReadyPlayerList.Count > 0) Main.GetMessage("已准备的玩家:" + string.Join(", ", ReadyPlayerList.Select(u => u.Username)));
List<User> NotReadyPlayerList = request.GetResult<List<User>>("notready") ?? new();
if (NotReadyPlayerList.Count > 0) Main.GetMessage("仍未准备的玩家:" + string.Join(", ", NotReadyPlayerList.Select(u => u.Username)));
}
request.Dispose();
return result;
}
catch (Exception e)
{
Main.GetMessage(e.GetErrorInfo(), TimeType.None);
return false;
}
}
public async Task<bool> QuitRoomAsync(string roomid, bool isMaster) public async Task<bool> QuitRoomAsync(string roomid, bool isMaster)
{ {
@ -227,6 +294,26 @@ namespace Milimoe.FunGame.Desktop.Controller
return false; return false;
} }
} }
public async Task<bool> StartGameAsync(string roomid, bool isMaster)
{
try
{
StartGameRequest.AddRequestData("roomid", roomid);
StartGameRequest.AddRequestData("isMaster", isMaster);
await StartGameRequest.SendRequestAsync();
if (StartGameRequest.Result == RequestResult.Success)
{
return true;
}
}
catch (Exception e)
{
Main.GetMessage(e.GetErrorInfo(), TimeType.None);
}
return false;
}
#endregion #endregion
} }

View File

@ -149,12 +149,15 @@ namespace Milimoe.FunGame.Desktop.Controller
protected override void SocketHandler_System(SocketObject ServerMessage) protected override void SocketHandler_System(SocketObject ServerMessage)
{ {
// 收到系统消息,直接发送弹窗 // 收到系统消息,可输出消息或弹窗
string msg = ""; string msg = "";
ShowMessageType type = ShowMessageType.General; ShowMessageType type = ShowMessageType.None;
int autoclose = 60;
if (ServerMessage.Parameters.Length > 0) msg = ServerMessage.GetParam<string>(0) ?? ""; if (ServerMessage.Parameters.Length > 0) msg = ServerMessage.GetParam<string>(0) ?? "";
if (ServerMessage.Parameters.Length > 1) type = ServerMessage.GetParam<ShowMessageType>(1); if (ServerMessage.Parameters.Length > 1) type = ServerMessage.GetParam<ShowMessageType>(1);
Main.ShowMessage(type, msg, "系统消息", 60); if (ServerMessage.Parameters.Length > 2) autoclose = ServerMessage.GetParam<int>(2);
if (type == ShowMessageType.None) Main.GetMessage(msg);
else Main.ShowMessage(type, msg, "系统消息", autoclose);
} }
protected override void SocketHandler_HeartBeat(SocketObject ServerMessage) protected override void SocketHandler_HeartBeat(SocketObject ServerMessage)

View File

@ -57,6 +57,15 @@ namespace Milimoe.FunGame.Desktop.Library
get => RunTime.Config.FunGame_isAutoRetry; get => RunTime.Config.FunGame_isAutoRetry;
set => RunTime.Config.FunGame_isAutoRetry = value; set => RunTime.Config.FunGame_isAutoRetry = value;
} }
/// <summary>
/// 是否在房间中
/// </summary>
public static bool FunGame_isInRoom
{
get => RunTime.Config.FunGame_isInRoom;
set => RunTime.Config.FunGame_isInRoom = value;
}
/// <summary> /// <summary>
/// 当前游戏模式 /// 当前游戏模式

View File

@ -28,7 +28,9 @@ namespace Milimoe.FunGame.Desktop.Library
public const string FunGame_Retry = "重新连接"; public const string FunGame_Retry = "重新连接";
public const string FunGame_AutoRetryOn = "开启自动重连"; public const string FunGame_AutoRetryOn = "开启自动重连";
public const string FunGame_AutoRetryOff = "关闭自动重连"; public const string FunGame_AutoRetryOff = "关闭自动重连";
public static readonly object[] PresetOnineItems = public const string FunGame_Ready = "准备就绪";
public const string FunGame_CancelReady = "取消准备";
public static readonly object[] PresetOnlineItems =
{ {
FunGame_PresetMessage, FunGame_PresetMessage,
FunGame_SignIn, FunGame_SignIn,
@ -38,11 +40,23 @@ namespace Milimoe.FunGame.Desktop.Library
FunGame_ClearGameInfo, FunGame_ClearGameInfo,
FunGame_CreateMix, FunGame_CreateMix,
FunGame_CreateTeam, FunGame_CreateTeam,
FunGame_StartGame,
FunGame_Disconnect, FunGame_Disconnect,
FunGame_AutoRetryOn, FunGame_AutoRetryOn,
FunGame_AutoRetryOff FunGame_AutoRetryOff
}; };
public static readonly object[] PresetInRoomItems =
{
FunGame_PresetMessage,
FunGame_SignIn,
FunGame_ShowCredits,
FunGame_ShowStock,
FunGame_ShowStore,
FunGame_ClearGameInfo,
FunGame_Ready,
FunGame_CancelReady,
FunGame_StartGame,
FunGame_Disconnect
};
public static readonly object[] PresetNoLoginItems = public static readonly object[] PresetNoLoginItems =
{ {
FunGame_PresetMessage, FunGame_PresetMessage,
@ -63,6 +77,7 @@ namespace Milimoe.FunGame.Desktop.Library
public enum ShowMessageType public enum ShowMessageType
{ {
None,
General, General,
Tip, Tip,
Warning, Warning,

View File

@ -101,23 +101,25 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
case MainInvokeType.SetGreen: case MainInvokeType.SetGreen:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Green); SetServerStatusLight(LightType.Green);
SetButtonEnableIfLogon(true, ClientState.Online); if (Usercfg.InRoom.Roomid != "-1") SetButtonEnableIfLogon(true, ClientState.InRoom);
else SetButtonEnableIfLogon(true, ClientState.Online);
Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case MainInvokeType.SetGreenAndPing: case MainInvokeType.SetGreenAndPing:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(RunTime.Session.Server_IP)); SetServerStatusLight(LightType.Green, ping: NetworkUtility.GetServerPing(RunTime.Session.Server_IP));
SetButtonEnableIfLogon(true, ClientState.Online); if (Usercfg.InRoom.Roomid != "-1") SetButtonEnableIfLogon(true, ClientState.InRoom);
else SetButtonEnableIfLogon(true, ClientState.Online);
Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case MainInvokeType.SetYellow: case MainInvokeType.SetYellow:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow); SetServerStatusLight(LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
@ -125,7 +127,7 @@ namespace Milimoe.FunGame.Desktop.UI
case MainInvokeType.WaitConnectAndSetYellow: case MainInvokeType.WaitConnectAndSetYellow:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow); SetServerStatusLight(LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
@ -138,14 +140,14 @@ namespace Milimoe.FunGame.Desktop.UI
case MainInvokeType.WaitLoginAndSetYellow: case MainInvokeType.WaitLoginAndSetYellow:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow, true); SetServerStatusLight(LightType.Yellow, true);
SetButtonEnableIfLogon(false, ClientState.WaitLogin); SetButtonEnableIfLogon(false, ClientState.WaitLogin);
Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case MainInvokeType.SetRed: case MainInvokeType.SetRed:
SetServerStatusLight((int)LightType.Red); SetServerStatusLight(LightType.Red);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
Config.FunGame_isConnected = false; Config.FunGame_isConnected = false;
break; break;
@ -155,7 +157,7 @@ namespace Milimoe.FunGame.Desktop.UI
RoomList.Items.Clear(); RoomList.Items.Clear();
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
Config.FunGame_isConnected = false; Config.FunGame_isConnected = false;
SetServerStatusLight((int)LightType.Red); SetServerStatusLight(LightType.Red);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
LogoutAccount(); LogoutAccount();
MainController?.MainController_Disposed(); MainController?.MainController_Disposed();
@ -170,7 +172,7 @@ namespace Milimoe.FunGame.Desktop.UI
Config.FunGame_isAutoConnect = false; Config.FunGame_isAutoConnect = false;
Config.FunGame_isAutoLogin = false; Config.FunGame_isAutoLogin = false;
Config.FunGame_isConnected = false; Config.FunGame_isConnected = false;
SetServerStatusLight((int)LightType.Yellow); SetServerStatusLight(LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
LogoutAccount(); LogoutAccount();
MainController?.MainController_Disposed(); MainController?.MainController_Disposed();
@ -182,7 +184,7 @@ namespace Milimoe.FunGame.Desktop.UI
case MainInvokeType.LogOut: case MainInvokeType.LogOut:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
Config.FunGame_isAutoLogin = false; Config.FunGame_isAutoLogin = false;
SetServerStatusLight((int)LightType.Yellow, true); SetServerStatusLight(LightType.Yellow, true);
SetButtonEnableIfLogon(false, ClientState.WaitLogin); SetButtonEnableIfLogon(false, ClientState.WaitLogin);
LogoutAccount(); LogoutAccount();
if (objs != null && objs.Length > 0) if (objs != null && objs.Length > 0)
@ -211,10 +213,19 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
RoomList.Items.Clear(); RoomList.Items.Clear();
Rooms.Clear(); Rooms.Clear();
Rooms.AddRooms((List<Room>)objs[0]); List<Room> list = (List<Room>)objs[0];
foreach (string roomid in Rooms.ListRoomID) Rooms.AddRooms(list);
foreach (Room r in list)
{ {
if (roomid != "-1") RoomList.Items.Add(roomid); if (r.Roomid != "-1")
{
string item = r.Roomid;
if (r.Name.Trim() != "")
{
item += " [ " + r.Name + " ]";
}
RoomList.Items.Add(item);
}
} }
} }
break; break;
@ -432,6 +443,8 @@ namespace Milimoe.FunGame.Desktop.UI
RoomSetting.Visible = true; RoomSetting.Visible = true;
NowRoomID.Visible = true; NowRoomID.Visible = true;
CopyRoomID.Visible = true; CopyRoomID.Visible = true;
// 禁用和激活按钮,并切换预设快捷消息
SetButtonEnableIfLogon(true, ClientState.InRoom);
} }
/// <summary> /// <summary>
@ -444,10 +457,6 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
switch (status) switch (status)
{ {
case ClientState.Online:
PresetText.Items.Clear();
PresetText.Items.AddRange(Constant.PresetOnineItems);
break;
case ClientState.WaitConnect: case ClientState.WaitConnect:
PresetText.Items.Clear(); PresetText.Items.Clear();
PresetText.Items.AddRange(Constant.PresetNoConnectItems); PresetText.Items.AddRange(Constant.PresetNoConnectItems);
@ -456,11 +465,16 @@ namespace Milimoe.FunGame.Desktop.UI
PresetText.Items.Clear(); PresetText.Items.Clear();
PresetText.Items.AddRange(Constant.PresetNoLoginItems); PresetText.Items.AddRange(Constant.PresetNoLoginItems);
break; break;
case ClientState.Online:
PresetText.Items.Clear();
PresetText.Items.AddRange(Constant.PresetOnlineItems);
break;
case ClientState.InRoom:
PresetText.Items.Clear();
PresetText.Items.AddRange(Constant.PresetInRoomItems);
break;
} }
this.PresetText.SelectedIndex = 0; this.PresetText.SelectedIndex = 0;
CheckMix.Enabled = isLogon;
CheckTeam.Enabled = isLogon;
CheckHasPass.Enabled = isLogon;
StartMatch.Enabled = isLogon; StartMatch.Enabled = isLogon;
AccountSetting.Enabled = isLogon; AccountSetting.Enabled = isLogon;
Stock.Enabled = isLogon; Stock.Enabled = isLogon;
@ -471,6 +485,9 @@ namespace Milimoe.FunGame.Desktop.UI
RoomBox.Enabled = isLogon; RoomBox.Enabled = isLogon;
CreateRoom.Enabled = isLogon; CreateRoom.Enabled = isLogon;
RefreshRoomList.Enabled = isLogon; RefreshRoomList.Enabled = isLogon;
CheckMix.Enabled = isLogon;
CheckTeam.Enabled = isLogon;
CheckHasPass.Enabled = isLogon;
} }
} }
@ -810,19 +827,19 @@ namespace Milimoe.FunGame.Desktop.UI
/// </summary> /// </summary>
/// <param name="light"></param> /// <param name="light"></param>
/// <param name="ping"></param> /// <param name="ping"></param>
private void SetServerStatusLight(int light, bool waitlogin = false, int ping = 0) private void SetServerStatusLight(LightType light, bool waitlogin = false, int ping = 0)
{ {
switch (light) switch (light)
{ {
case (int)LightType.Green: case LightType.Green:
Connection.Text = "服务器连接成功"; Connection.Text = "服务器连接成功";
this.Light.Image = Properties.Resources.green; this.Light.Image = Properties.Resources.green;
break; break;
case (int)LightType.Yellow: case LightType.Yellow:
Connection.Text = waitlogin ? "等待登录账号" : "等待连接服务器"; Connection.Text = waitlogin ? "等待登录账号" : "等待连接服务器";
this.Light.Image = Properties.Resources.yellow; this.Light.Image = Properties.Resources.yellow;
break; break;
case (int)LightType.Red: case LightType.Red:
default: default:
Connection.Text = "服务器连接失败"; Connection.Text = "服务器连接失败";
this.Light.Image = Properties.Resources.red; this.Light.Image = Properties.Resources.red;
@ -1335,8 +1352,6 @@ namespace Milimoe.FunGame.Desktop.UI
/// <param name="e"></param> /// <param name="e"></param>
private void SucceedCreateRoomEvent(object sender, RoomEventArgs e) private void SucceedCreateRoomEvent(object sender, RoomEventArgs e)
{ {
SetRoomid(e.Room);
InRoom();
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 创建" + e.RoomTypeString + "房间"); WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 创建" + e.RoomTypeString + "房间");
WritelnGameInfo(">> 创建" + e.RoomTypeString + "房间成功!房间号: " + e.RoomID); WritelnGameInfo(">> 创建" + e.RoomTypeString + "房间成功!房间号: " + e.RoomID);
ShowMessage(ShowMessageType.General, "创建" + e.RoomTypeString + "房间成功!\n房间号是 -> [ " + e.RoomID + " ]", "创建成功"); ShowMessage(ShowMessageType.General, "创建" + e.RoomTypeString + "房间成功!\n房间号是 -> [ " + e.RoomID + " ]", "创建成功");
@ -1384,12 +1399,65 @@ namespace Milimoe.FunGame.Desktop.UI
GameInfo.Clear(); GameInfo.Clear();
break; break;
case Constant.FunGame_CreateMix: case Constant.FunGame_CreateMix:
TaskUtility.NewTask(() => CreateRoom_Handler(GameMode.Mix)); if (Usercfg.InRoom.Roomid == "-1")
{
TaskUtility.NewTask(() => CreateRoom_Handler(GameMode.Mix));
}
else WritelnGameInfo(">> 先退出当前房间才可以创建房间。");
break; break;
case Constant.FunGame_CreateTeam: case Constant.FunGame_CreateTeam:
TaskUtility.NewTask(() => CreateRoom_Handler(GameMode.Team)); if (Usercfg.InRoom.Roomid == "-1")
{
TaskUtility.NewTask(() => CreateRoom_Handler(GameMode.Team));
}
else WritelnGameInfo(">> 先退出当前房间才可以创建房间。");
break;
case Constant.FunGame_Ready:
case ".r":
case ".ready":
if (MainController != null)
{
if (Usercfg.InRoom.Roomid != "-1")
{
TaskUtility.NewTask(async () =>
{
if (await MainController.SetReadyAsync(Usercfg.InRoom.Roomid))
{
await InvokeController_SendTalk(" [ " + Usercfg.LoginUser.Username + " ] 已准备。");
}
});
}
else WritelnGameInfo(">> 不在房间中无法使用此命令。");
}
break;
case Constant.FunGame_CancelReady:
case ".cr":
case ".ready -c":
case ".cancelready":
if (MainController != null)
{
if (Usercfg.InRoom.Roomid != "-1")
{
TaskUtility.NewTask(async () =>
{
if (await MainController.CancelReadyAsync(Usercfg.InRoom.Roomid))
{
await InvokeController_SendTalk(" [ " + Usercfg.LoginUser.Username + " ] 已取消准备。");
}
});
}
else WritelnGameInfo(">> 不在房间中无法使用此命令。");
}
break; break;
case Constant.FunGame_StartGame: case Constant.FunGame_StartGame:
if (MainController != null)
{
if (Usercfg.InRoom.Roomid != "-1")
{
TaskUtility.NewTask(async () => await InvokeController_StartGame(Usercfg.InRoom.Roomid, Usercfg.InRoom.RoomMaster?.Id == Usercfg.LoginUser.Id));
}
else WritelnGameInfo(">> 不在房间中无法使用此命令。");
}
break; break;
case Constant.FunGame_AutoRetryOn: case Constant.FunGame_AutoRetryOn:
WritelnGameInfo(">> 自动重连开启"); WritelnGameInfo(">> 自动重连开启");
@ -1438,38 +1506,41 @@ namespace Milimoe.FunGame.Desktop.UI
} }
break; break;
case Constant.FunGame_ConnectTo: case Constant.FunGame_ConnectTo:
string msg = ShowInputMessage("请输入服务器IP地址和端口号如: 127.0.0.1:22222。", "连接指定服务器"); if (!Config.FunGame_isConnected)
if (msg.Equals("")) return true;
string[] addr = msg.Split(':');
string ip;
int port;
if (addr.Length < 2)
{ {
ip = addr[0]; string msg = ShowInputMessage("请输入服务器IP地址和端口号如: 127.0.0.1:22222。", "连接指定服务器");
port = 22222; if (msg.Equals("")) return true;
string[] addr = msg.Split(':');
string ip;
int port;
if (addr.Length < 2)
{
ip = addr[0];
port = 22222;
}
else if (addr.Length < 3)
{
ip = addr[0];
port = Convert.ToInt32(addr[1]);
}
else
{
ShowMessage(ShowMessageType.Error, "格式错误!\n这不是一个服务器地址。");
return true;
}
ErrorIPAddressType ErrorType = NetworkUtility.IsServerAddress(ip, port);
if (ErrorType == ErrorIPAddressType.None)
{
RunTime.Session.Server_IP = ip;
RunTime.Session.Server_Port = port;
CurrentRetryTimes = -1;
Config.FunGame_isAutoRetry = true;
InvokeController_Connect();
}
else if (ErrorType == ErrorIPAddressType.IsNotIP) ShowMessage(ShowMessageType.Error, "这不是一个IP地址");
else if (ErrorType == ErrorIPAddressType.IsNotPort) ShowMessage(ShowMessageType.Error, "这不是一个端口号!\n正确范围1~65535");
else ShowMessage(ShowMessageType.Error, "格式错误!\n这不是一个服务器地址。");
} }
else if (addr.Length < 3)
{
ip = addr[0];
port = Convert.ToInt32(addr[1]);
}
else
{
ShowMessage(ShowMessageType.Error, "格式错误!\n这不是一个服务器地址。");
return true;
}
ErrorIPAddressType ErrorType = NetworkUtility.IsServerAddress(ip, port);
if (ErrorType == ErrorIPAddressType.None)
{
RunTime.Session.Server_IP = ip;
RunTime.Session.Server_Port = port;
CurrentRetryTimes = -1;
Config.FunGame_isAutoRetry = true;
InvokeController_Connect();
}
else if (ErrorType == ErrorIPAddressType.IsNotIP) ShowMessage(ShowMessageType.Error, "这不是一个IP地址");
else if (ErrorType == ErrorIPAddressType.IsNotPort) ShowMessage(ShowMessageType.Error, "这不是一个端口号!\n正确范围1~65535");
else ShowMessage(ShowMessageType.Error, "格式错误!\n这不是一个服务器地址。");
break; break;
default: default:
break; break;
@ -1725,6 +1796,8 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
OnSucceedQuitRoomEvent(this, EventArgs); OnSucceedQuitRoomEvent(this, EventArgs);
RunTime.PluginLoader?.OnSucceedQuitRoomEvent(this, EventArgs); RunTime.PluginLoader?.OnSucceedQuitRoomEvent(this, EventArgs);
// 禁用和激活按钮,并切换预设快捷消息
SetButtonEnableIfLogon(true, ClientState.Online);
} }
else else
{ {
@ -1741,6 +1814,8 @@ namespace Milimoe.FunGame.Desktop.UI
RunTime.PluginLoader?.OnFailedQuitRoomEvent(this, EventArgs); RunTime.PluginLoader?.OnFailedQuitRoomEvent(this, EventArgs);
OnAfterQuitRoomEvent(this, EventArgs); OnAfterQuitRoomEvent(this, EventArgs);
RunTime.PluginLoader?.OnAfterQuitRoomEvent(this, EventArgs); RunTime.PluginLoader?.OnAfterQuitRoomEvent(this, EventArgs);
// 禁用和激活按钮,并切换预设快捷消息
SetButtonEnableIfLogon(true, ClientState.Online);
} }
return result; return result;
@ -1796,6 +1871,50 @@ namespace Milimoe.FunGame.Desktop.UI
return result; return result;
} }
/// <summary>
/// 开始游戏/提醒玩家准备/提醒房主开始游戏
/// </summary>
/// <param name="roomid"></param>
/// <param name="isMaster"></param>
/// <returns></returns>
public async Task<bool> InvokeController_StartGame(string roomid, bool isMaster)
{
GeneralEventArgs EventArgs = new();
bool result = false;
try
{
OnBeforeStartGameEvent(this, EventArgs);
RunTime.PluginLoader?.OnBeforeStartGameEvent(this, EventArgs);
if (EventArgs.Cancel) return result;
result = MainController is not null && await MainController.StartGameAsync(roomid, isMaster);
if (result)
{
OnSucceedStartGameEvent(this, EventArgs);
RunTime.PluginLoader?.OnSucceedStartGameEvent(this, EventArgs);
}
else
{
OnFailedStartGameEvent(this, EventArgs);
RunTime.PluginLoader?.OnFailedStartGameEvent(this, EventArgs);
}
OnAfterStartGameEvent(this, EventArgs);
RunTime.PluginLoader?.OnAfterStartGameEvent(this, EventArgs);
}
catch (Exception e)
{
GetMessage(e.GetErrorInfo(), TimeType.None);
OnFailedStartGameEvent(this, EventArgs);
RunTime.PluginLoader?.OnFailedStartGameEvent(this, EventArgs);
OnAfterStartGameEvent(this, EventArgs);
RunTime.PluginLoader?.OnAfterStartGameEvent(this, EventArgs);
}
return result;
}
#endregion #endregion
} }
} }