From 1184baf3a0345ab3f9dc7adefe1a4d4f28ea7a7c Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Fri, 8 Nov 2024 09:41:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=88=BF=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AxibugEmuOnline.Client/Assets/Script/App.cs | 7 +++ .../Assets/Script/Event/EEvent.cs | 1 + .../Assets/Script/Manager/AppRoom.cs | 14 ++++-- .../Assets/Script/MonoCom/TickLoop.cs | 4 +- .../Manager/ClientManager.cs | 2 + AxibugEmuOnline.Server/Manager/RoomManager.cs | 43 ++++++++++++++++--- 6 files changed, 60 insertions(+), 11 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/App.cs b/AxibugEmuOnline.Client/Assets/Script/App.cs index c4bb8dfa..aaeb8c66 100644 --- a/AxibugEmuOnline.Client/Assets/Script/App.cs +++ b/AxibugEmuOnline.Client/Assets/Script/App.cs @@ -101,6 +101,13 @@ namespace AxibugEmuOnline.Client.ClientCore yield break; int platform = 0; + bool bTest = true; + if (bTest) + { + yield return null; + Connect("192.168.0.47", 10492); + yield break; + } UnityWebRequest request = UnityWebRequest.Get($"{App.httpAPI.WebSiteApi}/CheckStandInfo?platform={platform}&version={Application.version}"); yield return request.SendWebRequest(); diff --git a/AxibugEmuOnline.Client/Assets/Script/Event/EEvent.cs b/AxibugEmuOnline.Client/Assets/Script/Event/EEvent.cs index d4096492..40c69001 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Event/EEvent.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Event/EEvent.cs @@ -7,6 +7,7 @@ OnRoomListAllUpdate,//房间列表全量刷新 + OnRoomListSingleAdd,//房间列表中新增房间 OnRoomListSingleUpdate,//房间列表中单个更新 OnRoomListSingleClose,//房间关闭 OnRoomGetRoomScreen,//获取到房间数据 diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs index ec0f1033..83145e79 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs @@ -55,9 +55,11 @@ namespace AxibugEmuOnline.Client.Manager } #region 房间列表管理 - void AddOrUpdateRoomList(Protobuf_Room_MiniInfo roomInfo) + bool AddOrUpdateRoomList(Protobuf_Room_MiniInfo roomInfo) { + bool bNew = !dictRoomListID2Info.ContainsKey(roomInfo.RoomID); dictRoomListID2Info[roomInfo.RoomID] = roomInfo; + return bNew; } bool RemoveRoomList(int roomId) { @@ -203,8 +205,14 @@ namespace AxibugEmuOnline.Client.Manager Protobuf_Room_Update_RESP msg = ProtoBufHelper.DeSerizlize(reqData); if (msg.UpdateType == 0) { - AddOrUpdateRoomList(msg.RoomMiniInfo); - Eventer.Instance.PostEvent(EEvent.OnRoomListSingleUpdate, msg.RoomMiniInfo.RoomID); + if (AddOrUpdateRoomList(msg.RoomMiniInfo)) + { + Eventer.Instance.PostEvent(EEvent.OnRoomListSingleAdd, msg.RoomMiniInfo.RoomID); + } + else + { + Eventer.Instance.PostEvent(EEvent.OnRoomListSingleUpdate, msg.RoomMiniInfo.RoomID); + } } else { diff --git a/AxibugEmuOnline.Client/Assets/Script/MonoCom/TickLoop.cs b/AxibugEmuOnline.Client/Assets/Script/MonoCom/TickLoop.cs index bcbd3b56..80d5a0c6 100644 --- a/AxibugEmuOnline.Client/Assets/Script/MonoCom/TickLoop.cs +++ b/AxibugEmuOnline.Client/Assets/Script/MonoCom/TickLoop.cs @@ -90,7 +90,7 @@ namespace AxibugEmuOnline.Client public void OnCmdPing(byte[] reqData) { - App.log.Debug($"OnCmdPing"); + //App.log.Debug($"OnCmdPing"); Protobuf_Ping msg = ProtoBufHelper.DeSerizlize(reqData); Protobuf_Pong resp = new Protobuf_Pong() { @@ -101,7 +101,7 @@ namespace AxibugEmuOnline.Client public void OnCmdPong(byte[] reqData) { - App.log.Debug($"OnCmdPong"); + //App.log.Debug($"OnCmdPong"); Protobuf_Pong msg = ProtoBufHelper.DeSerizlize(reqData); if (LastPingSeed == msg.Seed) diff --git a/AxibugEmuOnline.Server/Manager/ClientManager.cs b/AxibugEmuOnline.Server/Manager/ClientManager.cs index 13822bbb..0a084634 100644 --- a/AxibugEmuOnline.Server/Manager/ClientManager.cs +++ b/AxibugEmuOnline.Server/Manager/ClientManager.cs @@ -221,6 +221,8 @@ namespace AxibugEmuOnline.Server.Manager Console.WriteLine("标记玩家UID" + cinfo.UID + "为离线"); cinfo.IsOffline = true; cinfo.LogOutDT = DateTime.Now; + + AppSrv.g_Room.LeaveRoom(cinfo, cinfo.RoomState.RoomID); } public void RemoveClientForSocket(Socket sk) diff --git a/AxibugEmuOnline.Server/Manager/RoomManager.cs b/AxibugEmuOnline.Server/Manager/RoomManager.cs index b15c886e..5794d621 100644 --- a/AxibugEmuOnline.Server/Manager/RoomManager.cs +++ b/AxibugEmuOnline.Server/Manager/RoomManager.cs @@ -131,7 +131,7 @@ namespace AxibugEmuOnline.Server List temp = GetRoomList(); foreach (var room in temp) resp.RoomMiniInfoList.Add(GetProtoDataRoom(room)); - AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdChatmsg, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp)); + AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomList, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp)); } public void CmdRoomGetScreen(Socket sk, byte[] reqData) { @@ -196,6 +196,8 @@ namespace AxibugEmuOnline.Server if (joinErrcode == ErrorCode.ErrorOk && bHadRoomStateChange) SendRoomStateChange(newRoom); + + SendRoomUpdateToAll(newRoom.RoomID, 0); } public void OnCmdRoomJoin(Socket sk, byte[] reqData) @@ -233,6 +235,33 @@ namespace AxibugEmuOnline.Server AppSrv.g_Log.Debug($"OnCmdRoomLeave "); ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk); Protobuf_Room_Leave msg = ProtoBufHelper.DeSerizlize(reqData); + LeaveRoom(_c, msg.RoomID); + //Protobuf_Room_Leave_RESP resp = new Protobuf_Room_Leave_RESP(); + //ErrorCode errcode; + //Data_RoomData room = GetRoomData(_c.RoomState.RoomID); + //bool bHadRoomStateChange = false; + //if (room == null) + // errcode = ErrorCode.ErrorRoomNotFound; + //else + //{ + // if (room.Leave(_c, out errcode, out bHadRoomStateChange)) + // { + // resp.RoomID = msg.RoomID; + // } + //} + //AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomLeave, (int)errcode, ProtoBufHelper.Serizlize(resp)); + //Protobuf_Room_MyRoom_State_Change(msg.RoomID); + + //if (errcode == ErrorCode.ErrorOk && bHadRoomStateChange) + // SendRoomStateChange(room); + + //SendRoomUpdateToAll(room.RoomID, 1); + //if (room.GetPlayerCount() < 1) + // RemoveRoom(room.RoomID); + } + + public void LeaveRoom(ClientInfo _c,int RoomID) + { Protobuf_Room_Leave_RESP resp = new Protobuf_Room_Leave_RESP(); ErrorCode errcode; Data_RoomData room = GetRoomData(_c.RoomState.RoomID); @@ -243,20 +272,22 @@ namespace AxibugEmuOnline.Server { if (room.Leave(_c, out errcode, out bHadRoomStateChange)) { - resp.RoomID = msg.RoomID; + resp.RoomID = RoomID; } } AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomLeave, (int)errcode, ProtoBufHelper.Serizlize(resp)); - Protobuf_Room_MyRoom_State_Change(msg.RoomID); + Protobuf_Room_MyRoom_State_Change(RoomID); if (errcode == ErrorCode.ErrorOk && bHadRoomStateChange) SendRoomStateChange(room); - SendRoomUpdateToAll(room.RoomID, 1); if (room.GetPlayerCount() < 1) + { RemoveRoom(room.RoomID); - - + SendRoomUpdateToAll(room.RoomID, 1); + } + else + SendRoomUpdateToAll(room.RoomID, 0); } public void OnHostPlayerUpdateStateRaw(Socket sk, byte[] reqData) From 2bec46bed42f2c76f9556724e10f339b9a6ab605 Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Fri, 8 Nov 2024 09:59:35 +0800 Subject: [PATCH 2/3] fix --- .../Assets/Script/Manager/AppRoom.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs index 83145e79..b59b5ade 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs @@ -425,5 +425,25 @@ namespace AxibugEmuOnline.Client.Manager //解压 byte[] data = Helper.DecompressByteArray(msg.RawBitmap.ToArray()); } - } + } + + public static class RoomEX + { + /// + /// 获取房间空闲席位下标 (返回True表示由余位) + /// + /// + /// + /// + public static bool GetFreeSlot(this Protobuf_Room_MiniInfo roomMiniInfo,out int[] freeSlots) + { + List temp = new List(); + if (roomMiniInfo.Player1UID > 0) temp.Add(0); + if (roomMiniInfo.Player2UID > 1) temp.Add(1); + if (roomMiniInfo.Player3UID > 2) temp.Add(2); + if (roomMiniInfo.Player4UID > 3) temp.Add(3); + freeSlots = temp.ToArray(); + return freeSlots.Length > 0; + } + } } \ No newline at end of file From cb309e4ab086872c2098d32c42b32c07ff769a96 Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Fri, 8 Nov 2024 10:00:57 +0800 Subject: [PATCH 3/3] test flag --- AxibugEmuOnline.Client/Assets/Script/App.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/App.cs b/AxibugEmuOnline.Client/Assets/Script/App.cs index aaeb8c66..8232c2fe 100644 --- a/AxibugEmuOnline.Client/Assets/Script/App.cs +++ b/AxibugEmuOnline.Client/Assets/Script/App.cs @@ -101,7 +101,7 @@ namespace AxibugEmuOnline.Client.ClientCore yield break; int platform = 0; - bool bTest = true; + bool bTest = false; if (bTest) { yield return null;