Compare commits

..

No commits in common. "3e919523301fedf54df747ed853351e457eafd98" and "e5f0816061ffdd44a1a02153db325ec7b52d4210" have entirely different histories.

12 changed files with 1532 additions and 3298 deletions

View File

@ -67,6 +67,6 @@
/// <summary>
/// 当房间中手柄位信息发生任何变化时触发,进入房间后也应该触发
/// </summary>
OnRoomSlotDataChanged,
OnRoomSlotDataChanged, //todo : 实现这个事件
}
}

View File

@ -72,5 +72,18 @@ namespace AxibugEmuOnline.Client.Manager
#endif
}
#region
void TestCreate()
{
App.roomMgr.SendCreateRoom(1, 0, string.Empty);
}
long TestFrameID = 0;
void TestEmuUpdate()
{
}
#endregion
}
}

View File

@ -18,6 +18,7 @@ namespace AxibugEmuOnline.Client.Manager
public bool IsHost => mineRoomMiniInfo?.HostPlayerUID == App.user.userdata.UID;
public bool IsScreenProviderUID => mineRoomMiniInfo?.ScreenProviderUID == App.user.userdata.UID;
public RoomGameState RoomState => mineRoomMiniInfo.GameState;
public int MinePlayerIdx => GetMinePlayerIndex();
public int WaitStep { get; private set; } = -1;
public byte[] RawData { get; private set; } = null;
public NetReplay netReplay { get; private set; }
@ -109,31 +110,64 @@ namespace AxibugEmuOnline.Client.Manager
#endregion
#region
List<Protobuf_Room_GamePlaySlot> GetMinePlayerSlotInfo()
int GetMinePlayerIndex()
{
if (mineRoomMiniInfo == null)
return null;
return mineRoomMiniInfo.GamePlaySlotList.Where(w => w.PlayerUID == App.user.userdata.UID).ToList();
return -1;
if (mineRoomMiniInfo.Player1UID == App.user.userdata.UID)
return 0;
if (mineRoomMiniInfo.Player2UID == App.user.userdata.UID)
return 1;
if (mineRoomMiniInfo.Player3UID == App.user.userdata.UID)
return 2;
if (mineRoomMiniInfo.Player4UID == App.user.userdata.UID)
return 3;
return -1;
}
long[] GetRoom4PlayerUIDs()
{
if (mineRoomMiniInfo == null)
return null;
long[] result = new long[mineRoomMiniInfo.GamePlaySlotList.Count];
for (int i = 0; i < mineRoomMiniInfo.GamePlaySlotList.Count; i++)
{
if (mineRoomMiniInfo.GamePlaySlotList[i].PlayerUID > 0)
result[i] = mineRoomMiniInfo.GamePlaySlotList[i].PlayerUID;
}
long[] result = new long[4];
if (mineRoomMiniInfo.Player1UID > 0)
result[0] = mineRoomMiniInfo.Player1UID;
if (mineRoomMiniInfo.Player2UID > 0)
result[1] = mineRoomMiniInfo.Player2UID;
if (mineRoomMiniInfo.Player3UID > 0)
result[2] = mineRoomMiniInfo.Player3UID;
if (mineRoomMiniInfo.Player4UID > 0)
result[3] = mineRoomMiniInfo.Player4UID;
return result;
}
Protobuf_Room_GamePlaySlot[] GetRoom4GameSlotMiniInfos()
S_PlayerMiniInfo[] GetRoom4PlayerMiniInfos()
{
if (mineRoomMiniInfo == null)
return null;
return mineRoomMiniInfo.GamePlaySlotList.ToArray();
S_PlayerMiniInfo[] result = new S_PlayerMiniInfo[4];
if (mineRoomMiniInfo.Player1UID > 0)
{
result[0].UID = mineRoomMiniInfo.Player1UID;
result[0].NickName = mineRoomMiniInfo.Player1NickName;
}
if (mineRoomMiniInfo.Player2UID > 0)
{
result[1].UID = mineRoomMiniInfo.Player2UID;
result[1].NickName = mineRoomMiniInfo.Player2NickName;
}
if (mineRoomMiniInfo.Player3UID > 0)
{
result[2].UID = mineRoomMiniInfo.Player3UID;
result[2].NickName = mineRoomMiniInfo.Player3NickName;
}
if (mineRoomMiniInfo.Player4UID > 0)
{
result[3].UID = mineRoomMiniInfo.Player4UID;
result[3].NickName = mineRoomMiniInfo.Player4NickName;
}
return result;
}
#endregion
@ -217,8 +251,9 @@ namespace AxibugEmuOnline.Client.Manager
/// <param name="GameRomID"></param>
/// <param name="JoinPlayerIdx"></param>
/// <param name="GameRomHash"></param>
public void SendCreateRoom(int GameRomID, string GameRomHash = null)
public void SendCreateRoom(int GameRomID, int JoinPlayerIdx, string GameRomHash = null)
{
_Protobuf_Room_Create.JoinPlayerIdx = JoinPlayerIdx;
_Protobuf_Room_Create.GameRomID = GameRomID;
_Protobuf_Room_Create.GameRomHash = GameRomHash;
App.log.Info($"创建房间");
@ -243,12 +278,13 @@ namespace AxibugEmuOnline.Client.Manager
/// <summary>
/// 创建房间
/// </summary>
/// <param name="RoomID"></param>
/// <param name="JoinSlotIdx">加入时所在SlotIdx</param>
/// <param name="LocalJoyIdx">加入时候本地对应JoyIdx</param>
public void SendJoinRoom(int RoomID)
/// <param name="GameRomID"></param>
/// <param name="JoinPlayerIdx"></param>
/// <param name="GameRomHash"></param>
public void SendJoinRoom(int RoomID, int JoinPlayerIdx)
{
_Protobuf_Room_Join.RoomID = RoomID;
_Protobuf_Room_Join.PlayerNum = JoinPlayerIdx;
App.log.Info($"加入房间");
App.network.SendToServer((int)CommandID.CmdRoomJoin, ProtoBufHelper.Serizlize(_Protobuf_Room_Join));
}
@ -300,105 +336,35 @@ namespace AxibugEmuOnline.Client.Manager
{
Protobuf_Room_MyRoom_State_Change msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_MyRoom_State_Change>(reqData);
long[] oldRoomPlayer = GetRoom4PlayerUIDs();
Protobuf_Room_GamePlaySlot[] oldslotArr = GetRoom4GameSlotMiniInfos();
mineRoomMiniInfo = msg.RoomMiniInfo;
long[] newRoomPlayer = GetRoom4PlayerUIDs();
Protobuf_Room_GamePlaySlot[] newslotArr = GetRoom4GameSlotMiniInfos();
oldRoomPlayer = oldRoomPlayer.Where(w => w > 0).Distinct().ToArray();
newRoomPlayer = newRoomPlayer.Where(w => w > 0).Distinct().ToArray();
//离开用户
foreach (var leavn in oldRoomPlayer.Where(w => !newRoomPlayer.Contains(w)))
{
UserDataBase oldplayer = App.user.GetUserByUid(leavn);
string oldPlayName = oldplayer != null ? oldplayer.NickName : "Player";
OverlayManager.PopTip($"[{oldPlayName}]离开房间");
Eventer.Instance.PostEvent(EEvent.OnOtherPlayerLeavnRoom, leavn);
}
//新加入用户
foreach (var newJoin in newRoomPlayer.Where(w => !oldRoomPlayer.Contains(w)))
{
UserDataBase newplayer = App.user.GetUserByUid(newJoin);
string newplayerName = newplayer != null ? newplayer.NickName : "Player";
OverlayManager.PopTip($"[{newplayer}]进入房间");
Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, newJoin);
}
bool bChangeSlot = false;
for (int i = 0; i < 4; i++)
{
var oldSlot = oldslotArr[i];
var newSlot = newslotArr[i];
if (oldSlot.PlayerUID <= 0 && newSlot.PlayerUID <= 0)
long OldPlayer = oldRoomPlayer[i];
long NewPlayer = newRoomPlayer[i];
if (OldPlayer == NewPlayer)
continue;
if (
oldSlot.PlayerUID != newSlot.PlayerUID
||
oldSlot.PlayerLocalJoyIdx != newSlot.PlayerLocalJoyIdx
)
//位置之前有人,但是离开了
if (OldPlayer > 0)
{
bChangeSlot = true;
if (newSlot.PlayerUID > 0)
Eventer.Instance.PostEvent(EEvent.OnOtherPlayerLeavnRoom, i, OldPlayer);
UserDataBase oldplayer = App.user.GetUserByUid(OldPlayer);
string oldPlayName = oldplayer != null ? oldplayer.NickName : "Player";
OverlayManager.PopTip($"[{oldPlayName}]离开房间,手柄位:P{i}");
if (NewPlayer > 0)//而且害换了一个玩家
{
OverlayManager.PopTip($"[{newSlot.PlayerNickName}]使用:P{i}");
Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer);
mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName);
OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}");
}
}
else //之前没人
{
Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer);
mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName);
OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}");
}
}
if (bChangeSlot)
{
Eventer.Instance.PostEvent(EEvent.OnRoomSlotDataChanged);
}
//for (int i = 0; i < 4; i++)
//{
// long OldPlayer = oldRoomPlayer[i];
// long NewPlayer = newRoomPlayer[i];
// if (OldPlayer == NewPlayer)
// continue;
// //位置之前有人,但是离开了
// if (OldPlayer > 0)
// {
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerLeavnRoom, i, OldPlayer);
// UserDataBase oldplayer = App.user.GetUserByUid(OldPlayer);
// string oldPlayName = oldplayer != null ? oldplayer.NickName : "Player";
// OverlayManager.PopTip($"[{oldPlayName}]离开房间,手柄位:P{i}");
// if (NewPlayer > 0)//而且害换了一个玩家
// {
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer);
// mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName);
// OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}");
// }
// }
// else //之前没人
// {
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer);
// mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName);
// OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}");
// }
// //位置之前有人,但是离开了
// if (OldPlayer > 0)
// {
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerLeavnRoom, i, OldPlayer);
// UserDataBase oldplayer = App.user.GetUserByUid(OldPlayer);
// string oldPlayName = oldplayer != null ? oldplayer.NickName : "Player";
// OverlayManager.PopTip($"[{oldPlayName}]离开房间,手柄位:P{i}");
// if (NewPlayer > 0)//而且害换了一个玩家
// {
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer);
// mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName);
// OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}");
// }
// }
// else //之前没人
// {
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer);
// mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName);
// OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}");
// }
//}
}
/// <summary>
@ -495,11 +461,14 @@ namespace AxibugEmuOnline.Client.Manager
if (mineRoomMiniInfo == null)
{
foreach (var gameslot in mineRoomMiniInfo.GamePlaySlotList)
{
if (gameslot.PlayerUID == uid)
gameslot.PlayerNickName = userdata.NickName;
}
if (mineRoomMiniInfo.Player1UID == uid)
mineRoomMiniInfo.Player1NickName = userdata.NickName;
else if (mineRoomMiniInfo.Player2UID == uid)
mineRoomMiniInfo.Player2NickName = userdata.NickName;
else if (mineRoomMiniInfo.Player3UID == uid)
mineRoomMiniInfo.Player3NickName = userdata.NickName;
else if (mineRoomMiniInfo.Player4UID == uid)
mineRoomMiniInfo.Player4NickName = userdata.NickName;
}
}
}
@ -515,38 +484,34 @@ namespace AxibugEmuOnline.Client.Manager
public static bool GetFreeSlot(this Protobuf_Room_MiniInfo roomMiniInfo, out int[] freeSlots)
{
List<int> temp = new List<int>();
for (int i = 0; i < roomMiniInfo.GamePlaySlotList.Count; i++)
{
if (roomMiniInfo.GamePlaySlotList[i].PlayerUID <= 0)
temp.Add(i);
}
if (roomMiniInfo.Player1UID <= 0) temp.Add(0);
if (roomMiniInfo.Player2UID <= 0) temp.Add(1);
if (roomMiniInfo.Player3UID <= 0) temp.Add(2);
if (roomMiniInfo.Player4UID <= 0) temp.Add(3);
freeSlots = temp.ToArray();
return freeSlots.Length > 0;
}
/// <summary>
/// 指定uid和该uid的本地手柄序号,获取占用的手柄位
/// </summary>
public static bool GetPlayerSlotIdxByUid(this Protobuf_Room_MiniInfo roomMiniInfo, long uid, int joyIdx, out uint? slotIdx)
public static bool GetPlayerSlotIdxByUid(this Protobuf_Room_MiniInfo roomMiniInfo, long uid ,int controllerIndex, out uint? slotID)
{
slotIdx = null;
//joyIdx取值返回[0,3],这个序号代表玩家本地的手柄编号
slotID = null;
//controllerIndex取值返回[0,3],这个序号代表玩家本地的手柄编号
//todo : 根据uid和controllerIndex 返回占用的位置
//目前未实现,所有非0号位置的手柄,都返回false
for (int i = 0; i < roomMiniInfo.GamePlaySlotList.Count; i++)
{
if (roomMiniInfo.GamePlaySlotList[i].PlayerUID == uid)
{
slotIdx = (uint)i;
return true;
}
}
return false;
if (controllerIndex != 0) return false;
if (roomMiniInfo.Player1UID == uid) slotID = 0;
if (roomMiniInfo.Player2UID == uid) slotID = 1;
if (roomMiniInfo.Player3UID == uid) slotID = 2;
if (roomMiniInfo.Player4UID == uid) slotID = 3;
return true;
}
/// <summary>
/// 按照房间玩家下标获取昵称
/// </summary>
@ -554,11 +519,16 @@ namespace AxibugEmuOnline.Client.Manager
/// <param name="PlayerIndex"></param>
/// <param name="PlayerName"></param>
/// <returns></returns>
public static bool GetPlayerNameByPlayerIdx(this Protobuf_Room_MiniInfo roomMiniInfo, uint GameSlotIdx, out string PlayerName)
public static bool GetPlayerNameByPlayerIdx(this Protobuf_Room_MiniInfo roomMiniInfo,uint PlayerIndex, out string PlayerName)
{
PlayerName = string.Empty;
if (roomMiniInfo.GamePlaySlotList[(int)GameSlotIdx].PlayerUID > 0)
PlayerName = roomMiniInfo.GamePlaySlotList[(int)GameSlotIdx].PlayerNickName;
switch (PlayerIndex)
{
case 0: PlayerName = roomMiniInfo.Player1UID > 0 ? roomMiniInfo.Player1NickName : null; break;
case 1: PlayerName = roomMiniInfo.Player2UID > 0 ? roomMiniInfo.Player2NickName : null; break;
case 2: PlayerName = roomMiniInfo.Player3UID > 0 ? roomMiniInfo.Player3NickName : null; break;
case 3: PlayerName = roomMiniInfo.Player4UID > 0 ? roomMiniInfo.Player4NickName : null; break;
}
return string.IsNullOrEmpty(PlayerName);
}
}

View File

@ -1,5 +1,4 @@
using AxibugEmuOnline.Client.ClientCore;
using AxibugProtobuf;
using System;
using System.Collections.Generic;
@ -84,12 +83,6 @@ namespace AxibugEmuOnline.Client.Network
public void PostNetMsgEvent(int cmd, int ERRCODE, byte[] arg)
{
ErrorCode err = ((ErrorCode)ERRCODE);
if (err != ErrorCode.ErrorOk)
{
OverlayManager.PopTip("错误:"+err.ToString());
}
List<Delegate> eventList = GetNetEventDicList(cmd);
if (eventList != null)
{

View File

@ -83,7 +83,7 @@ namespace AxibugEmuOnline.Client
{
if (App.user.IsLoggedIn)
{
App.roomMgr.SendCreateRoom(RomFile.ID, RomFile.Hash);
App.roomMgr.SendCreateRoom(RomFile.ID, 0, RomFile.Hash);
}
else
{
@ -116,7 +116,7 @@ namespace AxibugEmuOnline.Client
private void OnLoggedIn()
{
if (m_delayCreateRoom) App.roomMgr.SendCreateRoom(RomFile.ID, RomFile.Hash);
if (m_delayCreateRoom) App.roomMgr.SendCreateRoom(RomFile.ID, 0, RomFile.Hash);
}
private void OnServerStepUpdate(int step)

View File

@ -39,7 +39,7 @@ namespace AxibugEmuOnline.Client
public void SetData(object data)
{
Debug.Assert(data is Protobuf_Room_MiniInfo);
var roomInfo = (Protobuf_Room_MiniInfo)data;
RoomID = roomInfo.RoomID;
@ -69,7 +69,7 @@ namespace AxibugEmuOnline.Client
return false;
}
App.roomMgr.SendJoinRoom(RoomID);
App.roomMgr.SendJoinRoom(RoomID, freeSlots[0]);
return true;
}
}

View File

@ -2,7 +2,6 @@ using AxibugEmuOnline.Client.ClientCore;
using AxibugProtobuf;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace AxibugEmuOnline.Client
@ -20,17 +19,21 @@ namespace AxibugEmuOnline.Client
public static string GetHostNickName(this Protobuf_Room_MiniInfo roomInfo)
{
var hostUID = roomInfo.HostPlayerUID;
Protobuf_Room_GamePlaySlot slotdata = roomInfo.GamePlaySlotList.FirstOrDefault(w => w.PlayerUID == hostUID);
if (slotdata != null)
return slotdata.PlayerNickName;
else
return string.Empty;
if (hostUID == roomInfo.Player1UID) return roomInfo.Player1NickName;
else if (hostUID == roomInfo.Player2UID) return roomInfo.Player2NickName;
else if (hostUID == roomInfo.Player3UID) return roomInfo.Player3NickName;
else if (hostUID == roomInfo.Player4UID) return roomInfo.Player4NickName;
else return string.Empty;
}
public static void GetRoomPlayers(this Protobuf_Room_MiniInfo roomInfo, out int current, out int max)
{
current = 0; max = 4;
current = roomInfo.GamePlaySlotList.Count(w => w.PlayerUID > 0);
if (roomInfo.Player1UID > 0) current++;
if (roomInfo.Player2UID > 0) current++;
if (roomInfo.Player3UID > 0) current++;
if (roomInfo.Player4UID > 0) current++;
}
private static Dictionary<int, RomFile> s_RomFileCahcesInRoomInfo = new Dictionary<int, RomFile>();

View File

@ -235,7 +235,7 @@ namespace AxibugEmuOnline.Server
AddRoom(newRoom);
ErrorCode joinErrcode = ErrorCode.ErrorOk;
//加入
if (newRoom.Join(0, 0, _c, out joinErrcode, out bool bHadRoomStateChange))
if (newRoom.Join((uint)msg.PlayerSlotIdx, (uint)msg.PlayerLocalJoyIdx, _c, out joinErrcode, out bool bHadRoomStateChange))
{
//创建成功下行
resp.RoomMiniInfo = GetProtoDataRoom(newRoom);
@ -266,20 +266,10 @@ namespace AxibugEmuOnline.Server
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomJoin, (int)joinErrcode, ProtoBufHelper.Serizlize(resp));
return;
}
lock (room)
lock (room)
{
if (!room.GetFreeSlot(out uint SlotIdx))
{
joinErrcode = ErrorCode.ErrorRoomSlotAlreadlyHadPlayer;
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomJoin, (int)joinErrcode, ProtoBufHelper.Serizlize(resp));
return;
}
//加入
if (room.Join(SlotIdx, (uint)0, _c, out joinErrcode, out bHadRoomStateChange))
//加入
if (room.Join((uint)msg.PlayerSlotIdx, (uint)msg.PlayerLocalJoyIdx, _c, out joinErrcode, out bHadRoomStateChange))
{
Data_RoomData roomData = GetRoomData(msg.RoomID);
resp.RoomMiniInfo = GetProtoDataRoom(roomData);
@ -364,6 +354,7 @@ namespace AxibugEmuOnline.Server
RoomLog(_c.UID, 1, room.RoomID, room.GameRomID, RoomLogType.Leave);
}
public void OnCmdRoomChangePlayerWithJoy(Socket sk, byte[] reqData)
{
AppSrv.g_Log.DebugCmd($"OnCmdRoomChangePlayerjoySlot");
@ -396,6 +387,7 @@ namespace AxibugEmuOnline.Server
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomMyRoomStateChanged, (int)errcode, ProtoBufHelper.Serizlize(resp));
}
public void OnHostPlayerUpdateStateRaw(Socket sk, byte[] reqData)
{
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk);
@ -838,19 +830,6 @@ namespace AxibugEmuOnline.Server
}
return UID > 0;
}
public bool GetFreeSlot(out uint SlotIdx)
{
for (uint i = 0; i < PlayerSlot.Length; i++)
{
if (PlayerSlot[i].UID < 0)
{
SlotIdx = i;
return true;
}
}
SlotIdx = 0;
return false;
}
public bool GetPlayerClientByIdx(uint Idx, out ClientInfo _c)
{
_c = null;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -300,6 +300,8 @@ message Protobuf_Room_Create
{
int32 GameRomID = 1;
string GameRomHash = 2;
int32 PlayerSlotIdx = 3;//P1~P4编号
int32 PlayerLocalJoyIdx = 4;//Joy编号
}
message Protobuf_Room_Create_RESP
@ -310,6 +312,8 @@ message Protobuf_Room_Create_RESP
message Protobuf_Room_Join
{
int32 RoomID = 1;//ID
int32 PlayerSlotIdx = 2;//P1~P4编号
int32 PlayerLocalJoyIdx = 3;//Joy编号
}
message Protobuf_Room_Join_RESP