mirror of
https://github.com/project-redbud/FunGame-Desktop.git
synced 2025-04-20 12:09:34 +08:00
parent
841ab3b3d1
commit
2cdf40f556
@ -1,10 +1,11 @@
|
||||
using Milimoe.FunGame.Core.Library.Common.Event;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||
using Milimoe.FunGame.Core.Library.Common.Event;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Desktop.Model;
|
||||
using Milimoe.FunGame.Desktop.UI;
|
||||
using Milimoe.FunGame.Core.Library.Exception;
|
||||
using Milimoe.FunGame.Desktop.Library;
|
||||
using Milimoe.FunGame.Desktop.Model;
|
||||
using Milimoe.FunGame.Desktop.UI;
|
||||
|
||||
namespace Milimoe.FunGame.Desktop.Controller
|
||||
{
|
||||
@ -33,9 +34,11 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
GeneralEventArgs EventArgs = new();
|
||||
if (Main.OnBeforeLogoutEvent(EventArgs) == EventResult.Fail) return result;
|
||||
|
||||
if (Config.FunGame_Roomid != "-1")
|
||||
if (Usercfg.LoginUser is null) return result;
|
||||
|
||||
if (Usercfg.InRoom.Roomid != "-1")
|
||||
{
|
||||
await MainModel.QuitRoom(Config.FunGame_Roomid);
|
||||
await MainModel.QuitRoom(Usercfg.InRoom.Roomid);
|
||||
}
|
||||
|
||||
result = await MainModel.LogOut();
|
||||
@ -57,16 +60,16 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
return await MainModel.UpdateRoom();
|
||||
}
|
||||
|
||||
public async Task<bool> IntoRoom(string roomid)
|
||||
public async Task<bool> IntoRoom(Room room)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
try
|
||||
{
|
||||
RoomEventArgs EventArgs = new(roomid);
|
||||
RoomEventArgs EventArgs = new(room);
|
||||
if (Main.OnBeforeIntoRoomEvent(EventArgs) == EventResult.Fail) return result;
|
||||
|
||||
result = await MainModel.IntoRoom(roomid);
|
||||
result = await MainModel.IntoRoom(room);
|
||||
|
||||
if (result) Main.OnSucceedIntoRoomEvent(EventArgs);
|
||||
else Main.OnFailedIntoRoomEvent(EventArgs);
|
||||
@ -80,13 +83,14 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> QuitRoom(string roomid)
|
||||
public async Task<bool> QuitRoom(Room room)
|
||||
{
|
||||
bool result = false;
|
||||
string roomid = room.Roomid;
|
||||
|
||||
try
|
||||
{
|
||||
RoomEventArgs EventArgs = new(roomid);
|
||||
RoomEventArgs EventArgs = new(room);
|
||||
if (Main.OnBeforeQuitRoomEvent(EventArgs) == EventResult.Fail) return result;
|
||||
|
||||
result = await MainModel.QuitRoom(roomid);
|
||||
@ -109,7 +113,7 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
|
||||
try
|
||||
{
|
||||
RoomEventArgs EventArgs = new();
|
||||
RoomEventArgs EventArgs = new(RoomType, Password);
|
||||
if (Main.OnBeforeCreateRoomEvent(EventArgs) == EventResult.Fail) return result;
|
||||
|
||||
result = await MainModel.CreateRoom(RoomType, Password);
|
||||
|
@ -14,7 +14,6 @@
|
||||
public static bool Match_Mix { get; set; } = false; // 混战模式选项
|
||||
public static bool Match_Team { get; set; } = false; // 团队模式选项
|
||||
public static bool Match_HasPass { get; set; } = false; // 密码房间选项
|
||||
public static string FunGame_Roomid { get; set; } = "-1"; // 房间号
|
||||
public static string FunGame_ServerName { get; set; } = ""; // 服务器名称
|
||||
public static string FunGame_Notice { get; set; } = ""; // 公告
|
||||
public static string FunGame_AutoLoginUser { get; set; } = ""; // 自动登录的账号
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Desktop.Library
|
||||
{
|
||||
@ -9,5 +10,6 @@ namespace Milimoe.FunGame.Desktop.Library
|
||||
*/
|
||||
public static User? LoginUser { get; set; } = null; // 已登录的用户
|
||||
public static string LoginUserName { get; set; } = ""; // 已登录用户名
|
||||
public static Room InRoom { get; set; } = General.HallInstance; // 所处的房间
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using Milimoe.FunGame.Core.Library.Common.Event;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||
using Milimoe.FunGame.Core.Library.Common.Network;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
@ -6,8 +8,6 @@ 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;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Milimoe.FunGame.Desktop.Model
|
||||
{
|
||||
@ -53,21 +53,21 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> IntoRoom(string roomid)
|
||||
public async Task<bool> IntoRoom(Room room)
|
||||
{
|
||||
try
|
||||
{
|
||||
SetWorking();
|
||||
if (RunTime.Socket?.Send(SocketMessageType.IntoRoom, roomid) == SocketResult.Success)
|
||||
if (RunTime.Socket?.Send(SocketMessageType.IntoRoom, room.Roomid) == SocketResult.Success)
|
||||
{
|
||||
roomid = await Task.Factory.StartNew(SocketHandler_IntoRoom);
|
||||
string roomid = await Task.Factory.StartNew(SocketHandler_IntoRoom);
|
||||
if (roomid.Trim() != "" && roomid == "-1")
|
||||
{
|
||||
Main.GetMessage($"已连接至公共聊天室。");
|
||||
}
|
||||
else
|
||||
{
|
||||
Config.FunGame_Roomid = roomid;
|
||||
Usercfg.InRoom = room;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -87,7 +87,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
SetWorking();
|
||||
if (RunTime.Socket?.Send(SocketMessageType.UpdateRoom) == SocketResult.Success)
|
||||
{
|
||||
List<string> list = await Task.Factory.StartNew(SocketHandler_UpdateRoom);
|
||||
Hashtable list = await Task.Factory.StartNew(SocketHandler_UpdateRoom);
|
||||
Main.UpdateUI(MainInvokeType.UpdateRoom, list);
|
||||
return true;
|
||||
}
|
||||
@ -111,7 +111,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
result = await Task.Factory.StartNew(SocketHandler_QuitRoom);
|
||||
if (result)
|
||||
{
|
||||
Config.FunGame_Roomid = "-1";
|
||||
Usercfg.InRoom = General.HallInstance;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -283,20 +283,30 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<string> SocketHandler_UpdateRoom()
|
||||
private Hashtable SocketHandler_UpdateRoom()
|
||||
{
|
||||
List<string>? list = null;
|
||||
Hashtable table = new();
|
||||
try
|
||||
{
|
||||
WaitForWorkDone();
|
||||
if (Work.Length > 0) list = Work.GetParam<List<string>>(0);
|
||||
DataSet? DsRoom = new(), DsUser = new();
|
||||
if (Work.Length > 0) DsRoom = Work.GetParam<DataSet>(0);
|
||||
if (Work.Length > 1) DsUser = Work.GetParam<DataSet>(1);
|
||||
if (DsRoom != null && DsUser != null)
|
||||
{
|
||||
List<Room> list = Core.Api.Utility.Factory.GetList<Room>(DsRoom, DsUser);
|
||||
table.Add(General.HallInstance.Roomid, General.HallInstance);
|
||||
foreach (Room room in list)
|
||||
{
|
||||
table.Add(room.Roomid, room);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo());
|
||||
}
|
||||
list ??= new List<string>();
|
||||
return list;
|
||||
return table;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
@ -8,7 +9,6 @@ using Milimoe.FunGame.Desktop.Controller;
|
||||
using Milimoe.FunGame.Desktop.Library;
|
||||
using Milimoe.FunGame.Desktop.Library.Base;
|
||||
using Milimoe.FunGame.Desktop.Library.Component;
|
||||
using Milimoe.FunGame.Desktop.Model;
|
||||
using Milimoe.FunGame.Desktop.Utility;
|
||||
|
||||
namespace Milimoe.FunGame.Desktop.UI
|
||||
@ -29,6 +29,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
*/
|
||||
private Task? MatchFunGame = null; // 匹配线程
|
||||
private MainController? MainController = null;
|
||||
private Hashtable Rooms = new();
|
||||
|
||||
/**
|
||||
* 委托【即将删除】
|
||||
@ -48,7 +49,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
{
|
||||
RunTime.Main = this;
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
|
||||
SetRoomid("-1"); // 房间号初始化
|
||||
SetRoomid(Usercfg.InRoom); // 房间号初始化
|
||||
ShowFunGameInfo(); // 显示FunGame信息
|
||||
GetFunGameConfig(); // 获取FunGame配置
|
||||
// 创建RunTime
|
||||
@ -205,8 +206,11 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
if (objs != null && objs.Length > 0)
|
||||
{
|
||||
RoomList.Items.Clear();
|
||||
List<string> list = (List<string>)objs[0];
|
||||
RoomList.Items.AddRange(list.ToArray());
|
||||
Rooms = (Hashtable)objs[0];
|
||||
foreach (string roomid in Rooms.Keys)
|
||||
{
|
||||
if (roomid != "-1") RoomList.Items.Add(roomid);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -315,14 +319,14 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
/// 设置房间号和显示信息
|
||||
/// </summary>
|
||||
/// <param name="roomid"></param>
|
||||
private void SetRoomid(string roomid)
|
||||
private void SetRoomid(Room room)
|
||||
{
|
||||
Config.FunGame_Roomid = roomid;
|
||||
if (!roomid.Equals("-1"))
|
||||
Usercfg.InRoom = room;
|
||||
if (room.Roomid != "-1")
|
||||
{
|
||||
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 加入房间");
|
||||
WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已加入房间 -> [ " + Config.FunGame_Roomid + " ]");
|
||||
Room.Text = "[ 当前房间 ]\n" + Convert.ToString(Config.FunGame_Roomid);
|
||||
WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已加入房间 -> [ " + room.Roomid + " ]");
|
||||
Room.Text = "[ 当前房间 ]\n" + Convert.ToString(room.Roomid);
|
||||
}
|
||||
else
|
||||
Room.Text = "暂未进入房间";
|
||||
@ -383,7 +387,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
{
|
||||
// 显示:匹配、创建房间
|
||||
// 隐藏:退出房间、房间设定
|
||||
SetRoomid("-1");
|
||||
SetRoomid(Usercfg.InRoom);
|
||||
QuitRoom.Visible = false;
|
||||
StartMatch.Visible = true;
|
||||
RoomSetting.Visible = false;
|
||||
@ -478,17 +482,19 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
await MainController.UpdateRoom();
|
||||
if (CheckRoomIDExist(roomid))
|
||||
{
|
||||
if (Config.FunGame_Roomid.Equals("-1"))
|
||||
if (Usercfg.InRoom.Roomid == "-1")
|
||||
{
|
||||
if (ShowMessage.YesNoMessage("已找到房间 -> [ " + roomid + " ]\n是否加入?", "已找到房间") == MessageResult.Yes)
|
||||
{
|
||||
if (MainController != null && await MainController.IntoRoom(roomid))
|
||||
Room r = GetRoom(roomid);
|
||||
if (MainController != null && await MainController.IntoRoom(r))
|
||||
{
|
||||
SetRoomid(roomid);
|
||||
SetRoomid(r);
|
||||
InRoom();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -552,7 +558,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
{
|
||||
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 匹配成功");
|
||||
WritelnGameInfo(">> 房间号: " + roomid);
|
||||
SetRoomid(roomid);
|
||||
SetRoomid(GetRoom(roomid));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -709,17 +715,20 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
/// <returns></returns>
|
||||
private async Task CreateRoom_Handler(string RoomType, string Password = "")
|
||||
{
|
||||
if (Config.FunGame_Roomid != "-1")
|
||||
if (Usercfg.InRoom.Roomid != "-1")
|
||||
{
|
||||
ShowMessage.WarningMessage("已在房间中,无法创建房间。");
|
||||
return;
|
||||
}
|
||||
if (MainController != null)
|
||||
{
|
||||
string roomid = (await MainController.CreateRoom(RoomType)).Trim();
|
||||
if (roomid != "" && roomid != "-1" && await MainController.IntoRoom(roomid))
|
||||
string roomid = (await MainController.CreateRoom(RoomType, Password)).Trim();
|
||||
if (roomid != "" && roomid != "-1")
|
||||
{
|
||||
SetRoomid(roomid);
|
||||
await MainController.UpdateRoom();
|
||||
Room r = GetRoom(roomid);
|
||||
await MainController.IntoRoom(r);
|
||||
SetRoomid(r);
|
||||
InRoom();
|
||||
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 创建" + RoomType + "房间");
|
||||
WritelnGameInfo(">> 创建" + RoomType + "房间成功!房间号: " + roomid);
|
||||
@ -759,10 +768,10 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
{
|
||||
if (MainController != null)
|
||||
{
|
||||
// 接入-1号房间聊天室
|
||||
await MainController.IntoRoom("-1");
|
||||
// 获取在线的房间列表
|
||||
await MainController.UpdateRoom();
|
||||
// 接入-1号房间聊天室
|
||||
await MainController.IntoRoom((Room)Rooms["-1"]!);
|
||||
}
|
||||
}
|
||||
|
||||
@ -825,9 +834,14 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
/// <summary>
|
||||
/// 退出游戏时处理
|
||||
/// </summary>
|
||||
private void ExitFunGame()
|
||||
private async Task ExitFunGame()
|
||||
{
|
||||
|
||||
if (ShowMessage.OKCancelMessage("你确定关闭游戏?", "退出") == (int)MessageResult.OK)
|
||||
{
|
||||
if (MainController != null) await MainController.LogOut();
|
||||
RunTime.Connector?.Close();
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -839,14 +853,9 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Exit_Click(object sender, EventArgs e)
|
||||
private async void Exit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ShowMessage.OKCancelMessage("你确定关闭游戏?", "退出") == (int)MessageResult.OK)
|
||||
{
|
||||
_ = MainController?.LogOut();
|
||||
RunTime.Connector?.Close();
|
||||
Environment.Exit(0);
|
||||
}
|
||||
await ExitFunGame();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -937,7 +946,6 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
return;
|
||||
}
|
||||
await CreateRoom_Handler(roomtype, password);
|
||||
_ = MainController?.UpdateRoom();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -949,8 +957,8 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
{
|
||||
if (MainController != null)
|
||||
{
|
||||
string roomid = Config.FunGame_Roomid;
|
||||
if (await MainController.QuitRoom(roomid))
|
||||
string roomid = Usercfg.InRoom.Roomid;
|
||||
if (await MainController.QuitRoom(Usercfg.InRoom))
|
||||
{
|
||||
WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 离开房间");
|
||||
WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 已离开房间 -> [ " + roomid + " ]");
|
||||
@ -1256,16 +1264,17 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
/// </summary>
|
||||
/// <param name="roomid"></param>
|
||||
/// <returns></returns>
|
||||
private bool CheckRoomIDExist(string roomid)
|
||||
private bool CheckRoomIDExist(string roomid) => Rooms.ContainsKey(roomid);
|
||||
|
||||
/// <summary>
|
||||
/// 获取房间对象
|
||||
/// </summary>
|
||||
/// <param name="roomid">房间号</param>
|
||||
/// <returns></returns>
|
||||
private Room GetRoom(string roomid)
|
||||
{
|
||||
foreach (string BoxText in RoomList.Items)
|
||||
{
|
||||
if (roomid.Equals(BoxText))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
Room? r = (Room?)Rooms[roomid];
|
||||
return r ?? General.HallInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user