diff --git a/FunGame.Core/Api/Factory/RoomFactory.cs b/FunGame.Core/Api/Factory/RoomFactory.cs index 70128da..4ab36a1 100644 --- a/FunGame.Core/Api/Factory/RoomFactory.cs +++ b/FunGame.Core/Api/Factory/RoomFactory.cs @@ -5,9 +5,9 @@ namespace Milimoe.FunGame.Core.Api.Factory { internal class RoomFactory { - internal static Room GetInstance(DataRow? DrRoom, DataRow? DrUser) + internal static Room GetInstance(DataSet? DsRoom, DataSet? DsUser, int Index) { - return new Room(DrRoom, DrUser); + return new Room(DsRoom, DsUser, Index); } } } diff --git a/FunGame.Core/Api/Factory/SkillFactory.cs b/FunGame.Core/Api/Factory/SkillFactory.cs index e475516..ad1d761 100644 --- a/FunGame.Core/Api/Factory/SkillFactory.cs +++ b/FunGame.Core/Api/Factory/SkillFactory.cs @@ -6,12 +6,12 @@ namespace Milimoe.FunGame.Core.Api.Factory { internal class SkillFactory { - internal static Skill GetInstance(DataRow? DataRow, SkillType type = SkillType.Passive) + internal static Skill GetInstance(DataSet? DataSet, SkillType type = SkillType.Passive, int Index = 0) { Skill skill = type switch { - SkillType.Active => new ActiveSkill(DataRow), - _ => new PassiveSkill(DataRow) + SkillType.Active => new ActiveSkill(DataSet, Index), + _ => new PassiveSkill(DataSet, Index) }; return skill; } diff --git a/FunGame.Core/Api/Factory/UserFactory.cs b/FunGame.Core/Api/Factory/UserFactory.cs index 28d3e3c..3017219 100644 --- a/FunGame.Core/Api/Factory/UserFactory.cs +++ b/FunGame.Core/Api/Factory/UserFactory.cs @@ -5,9 +5,9 @@ namespace Milimoe.FunGame.Core.Api.Factory { internal class UserFactory { - internal static User GetInstance(DataRow? DataRow) + internal static User GetInstance(DataSet? DataSet, int Index = 0) { - return new User(DataRow); + return new User(DataSet, Index); } } } diff --git a/FunGame.Core/Api/Utility/Factory.cs b/FunGame.Core/Api/Utility/Factory.cs index d56ae61..2341c31 100644 --- a/FunGame.Core/Api/Utility/Factory.cs +++ b/FunGame.Core/Api/Utility/Factory.cs @@ -13,30 +13,30 @@ namespace Milimoe.FunGame.Core.Api.Utility /// RoomRow /// UserRow(RoomMaster) /// - public static Room GetRoom(DataRow? DrRoom, DataRow? DrUser) + public static Room GetRoom(DataSet? DsRoom, DataSet? DsUser, int Index = 0) { - return RoomFactory.GetInstance(DrRoom, DrUser); + return RoomFactory.GetInstance(DsRoom, DsUser, Index); } /// /// 获取Skill实例,默认返回PassiveSkill /// - /// SkillRow + /// SkillRow /// Skill类型 /// - public static Skill GetSkill(DataRow? DataRow, SkillType SkillType = SkillType.Passive) + public static Skill GetSkill(DataSet? DataSet, SkillType SkillType = SkillType.Passive, int Index = 0) { - return SkillFactory.GetInstance(DataRow, SkillType); + return SkillFactory.GetInstance(DataSet, SkillType, Index); } /// /// 获取User实例 - /// - /// UserRow + /// awaa + /// UserRow /// - public static User GetUser(DataRow? DataRow) + public static User GetUser(DataSet? DataSet, int Index = 0) { - return UserFactory.GetInstance(DataRow); + return UserFactory.GetInstance(DataSet, Index); } /// @@ -46,27 +46,27 @@ namespace Milimoe.FunGame.Core.Api.Utility /// 若无法找到T,返回唯一的空对象 /// /// Entity类 - /// 使用DataRow构造对象 + /// 使用DataSets构造对象 /// T - public static T GetInstance(params DataRow?[] DataRows) + public static T GetInstance(params DataSet?[] DataSets) { - if (DataRows is null || DataRows.Length == 0) throw new GetInstanceException(); + if (DataSets is null || DataSets.Length == 0) throw new GetInstanceException(); object instance = General.EntityInstance; if (typeof(T) == typeof(User)) { - instance = GetUser(DataRows[0]); + instance = GetUser(DataSets[0]); } else if (typeof(T) == typeof(Skill) || typeof(T) == typeof(PassiveSkill)) { - instance = GetSkill(DataRows[0]); + instance = GetSkill(DataSets[0]); } else if (typeof(T) == typeof(ActiveSkill)) { - instance = GetSkill(DataRows[0], SkillType.Active); + instance = GetSkill(DataSets[0], SkillType.Active); } else if (typeof(T) == typeof(Room)) { - instance = GetRoom(DataRows[0], DataRows[1]); + instance = GetRoom(DataSets[0], DataSets[1]); } return (T)instance; } @@ -89,9 +89,9 @@ namespace Milimoe.FunGame.Core.Api.Utility DataSet? ds = DataSets[0]; if (ds != null && ds.Tables[0].Rows.Count > 0) { - foreach (DataRow? row in ds.Tables[0].Rows) + for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { - object entity = GetUser(row); + object entity = GetUser(ds, i); list.Add((T)entity); } } @@ -101,9 +101,9 @@ namespace Milimoe.FunGame.Core.Api.Utility DataSet? ds = DataSets[0]; if (ds != null && ds.Tables[0].Rows.Count > 0) { - foreach (DataRow? row in ds.Tables[0].Rows) + for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { - object entity = GetSkill(row); + object entity = GetSkill(ds, SkillType.Passive, i); list.Add((T)entity); } } @@ -113,33 +113,27 @@ namespace Milimoe.FunGame.Core.Api.Utility DataSet? ds = DataSets[0]; if (ds != null && ds.Tables[0].Rows.Count > 0) { - foreach (DataRow? row in ds.Tables[0].Rows) + for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { - object entity = GetSkill(row, SkillType.Active); + object entity = GetSkill(ds, SkillType.Active, i); list.Add((T)entity); } } } else if (typeof(T) == typeof(Room)) { - DataSet? ds = DataSets[0]; - if (ds != null && ds.Tables[0].Rows.Count > 0) + DataSet? DsRoom = DataSets[0]; + DataSet? DsUser = DataSets[1]; + if (DsRoom != null && DsRoom.Tables[0].Rows.Count > 0) { - foreach (DataRow? row in ds.Tables[0].Rows) + for (int i = 0; i < DsRoom.Tables[0].Rows.Count; i++) { - if (row != null) - { - DataRow[] rows = ds.Tables[1].Select($"{Library.SQLScript.Entity.UserQuery.Column_Username} = '{row[Library.SQLScript.Entity.RoomQuery.Column_RoomMasterName]}'"); - if (rows != null && rows.Length > 0) - { - object entity = GetRoom(row, rows[0]); - list.Add((T)entity); - } - } + object entity = GetRoom(DsRoom, DsUser, i); + list.Add((T)entity); } } } - return new List(); + return list; } } } diff --git a/FunGame.Core/Entity/Skill/ActiveSkill.cs b/FunGame.Core/Entity/Skill/ActiveSkill.cs index 96f6c07..83ff263 100644 --- a/FunGame.Core/Entity/Skill/ActiveSkill.cs +++ b/FunGame.Core/Entity/Skill/ActiveSkill.cs @@ -17,7 +17,7 @@ namespace Milimoe.FunGame.Core.Entity public decimal Reference9 { get; set; } = 0; public decimal Reference10 { get; set; } = 0; - internal ActiveSkill(DataRow? DataRow) + internal ActiveSkill(DataSet? DataSet, int Index = 0) { Active = true; } diff --git a/FunGame.Core/Entity/Skill/PassiveSkill.cs b/FunGame.Core/Entity/Skill/PassiveSkill.cs index 6024144..b6a1d79 100644 --- a/FunGame.Core/Entity/Skill/PassiveSkill.cs +++ b/FunGame.Core/Entity/Skill/PassiveSkill.cs @@ -15,7 +15,7 @@ namespace Milimoe.FunGame.Core.Entity public decimal Reference9 { get; set; } = 0; public decimal Reference10 { get; set; } = 0; - internal PassiveSkill(DataRow? DataRow) + internal PassiveSkill(DataSet? DataSet, int Index = 0) { Active = false; } diff --git a/FunGame.Core/Entity/System/Room.cs b/FunGame.Core/Entity/System/Room.cs index d940192..98b8573 100644 --- a/FunGame.Core/Entity/System/Room.cs +++ b/FunGame.Core/Entity/System/Room.cs @@ -3,6 +3,7 @@ using System.Collections; using Milimoe.FunGame.Core.Interface.Entity; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.SQLScript.Entity; +using System.Linq; namespace Milimoe.FunGame.Core.Entity { @@ -27,14 +28,15 @@ namespace Milimoe.FunGame.Core.Entity public string Password { get; set; } = ""; public GameStatistics? Statistics { get; set; } = null; - internal Room(DataRow? DrRoom, DataRow? DrUser) + internal Room(DataSet? DsRoom, DataSet? DsUser, int Index) { - if (DrRoom != null) + if (DsRoom != null && DsRoom.Tables[0].Rows.Count > 0) { + DataRow DrRoom = DsRoom.Tables[0].Rows[Index]; Id = (long)DrRoom[RoomQuery.Column_ID]; Roomid = (string)DrRoom[RoomQuery.Column_RoomID]; CreateTime = (DateTime)DrRoom[RoomQuery.Column_CreateTime]; - RoomMaster = Api.Utility.Factory.GetInstance(DrUser); + RoomMaster = Api.Utility.Factory.GetUser(DsUser, GetUserRowIndex(DsUser, (long)DrRoom[RoomQuery.Column_RoomMaster])); RoomType = (RoomType)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomType]); RoomState = (RoomState)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomState]); Password = (string)DrRoom[RoomQuery.Column_Password]; @@ -55,5 +57,20 @@ namespace Milimoe.FunGame.Core.Entity { return Equals(other); } + + private static int GetUserRowIndex(DataSet? DsUser, long UID) + { + if (DsUser != null) + { + for (int i = 0; i < DsUser.Tables[0].Rows.Count; i++) + { + if (DsUser.Tables[0].Rows[i][UserQuery.Column_UID].Equals(UID)) + { + return i; + } + } + } + return 0; + } } } diff --git a/FunGame.Core/Entity/User/User.cs b/FunGame.Core/Entity/User/User.cs index e1c38f9..9c55430 100644 --- a/FunGame.Core/Entity/User/User.cs +++ b/FunGame.Core/Entity/User/User.cs @@ -28,10 +28,11 @@ namespace Milimoe.FunGame.Core.Entity } - internal User(DataRow? DataRow) + internal User(DataSet? DataSet, int Index = 0) { - if (DataRow != null) + if (DataSet != null && DataSet.Tables[0].Rows.Count > 0) { + DataRow DataRow = DataSet.Tables[0].Rows[Index]; Id = (long)DataRow[UserQuery.Column_UID]; Username = (string)DataRow[UserQuery.Column_Username]; Password = (string)DataRow[UserQuery.Column_Password]; diff --git a/FunGame.Core/Library/Constant/General.cs b/FunGame.Core/Library/Constant/General.cs index a2fbe34..01478ce 100644 --- a/FunGame.Core/Library/Constant/General.cs +++ b/FunGame.Core/Library/Constant/General.cs @@ -15,7 +15,7 @@ namespace Milimoe.FunGame.Core.Library.Constant public const int MaxThread_General = 20; public const int MaxTask_4C4G = 40; - public const int SocketByteSize = 20480; + public const int SocketByteSize = 512 * 1024; public const int StreamByteSize = 2048; } } diff --git a/FunGame.Desktop/Model/LoginModel.cs b/FunGame.Desktop/Model/LoginModel.cs index e094554..14ba8de 100644 --- a/FunGame.Desktop/Model/LoginModel.cs +++ b/FunGame.Desktop/Model/LoginModel.cs @@ -130,9 +130,9 @@ namespace Milimoe.FunGame.Desktop.Model object[] objs = SocketObject.Parameters; if (objs != null && objs.Length > 0) { - DataRow? row = SocketObject.GetParam(0); + DataSet? DataSet = SocketObject.GetParam(0); // 创建User对象并返回到Main - RunTime.Main?.UpdateUI(MainInvokeType.SetUser, new object[] { Factory.GetInstance(row) }); + RunTime.Main?.UpdateUI(MainInvokeType.SetUser, new object[] { Factory.GetInstance(DataSet) }); RunTime.Login?.OnSucceedLoginEvent(Login.EventArgs); RunTime.Login?.OnAfterLoginEvent(Login.EventArgs); return; diff --git a/FunGame.Desktop/Model/MainModel.cs b/FunGame.Desktop/Model/MainModel.cs index 341468b..eb19ce2 100644 --- a/FunGame.Desktop/Model/MainModel.cs +++ b/FunGame.Desktop/Model/MainModel.cs @@ -227,7 +227,9 @@ namespace Milimoe.FunGame.Desktop.Model private void SocketHandler_UpdateRoom(SocketObject SocketObject) { - Main.UpdateUI(MainInvokeType.UpdateRoom, SocketObject.Parameters); + List? list = SocketObject.GetParam>(0); + list ??= new List(); + Main.UpdateUI(MainInvokeType.UpdateRoom, list); } private void SocketHandler_Chat(SocketObject SocketObject) diff --git a/FunGame.Desktop/UI/Main/Main.cs b/FunGame.Desktop/UI/Main/Main.cs index 4bf12b2..9ad5f8e 100644 --- a/FunGame.Desktop/UI/Main/Main.cs +++ b/FunGame.Desktop/UI/Main/Main.cs @@ -1216,8 +1216,10 @@ namespace Milimoe.FunGame.Desktop.UI private EventResult SucceedLoginEvent(object sender, GeneralEventArgs e) { // 接入-1号房间聊天室 - if (MainController?.IntoRoom("-1") ?? false) return EventResult.Success; - else return EventResult.Fail; + MainController?.IntoRoom("-1"); + // 获取在线的房间列表 + MainController?.UpdateRoom(); + return EventResult.Success; } #endregion