This commit is contained in:
sin365 2024-11-11 19:21:35 +08:00
parent 73f1f858fd
commit 5c0730c8f9
9 changed files with 135 additions and 52 deletions

View File

@ -60,6 +60,7 @@ namespace AxiReplay
inputDiff = true; inputDiff = true;
mNextReplay = mNetReplayQueue.Dequeue(); mNextReplay = mNetReplayQueue.Dequeue();
} }
bFrameDiff = mRemoteFrameIdx - mCurrClientFrameIdx; bFrameDiff = mRemoteFrameIdx - mCurrClientFrameIdx;
data = mCurrReplay; data = mCurrReplay;
} }

View File

@ -404,10 +404,15 @@ namespace AxibugEmuOnline.Client.Manager
App.network.SendToServer((int)CommandID.CmdRoomSingelPlayerInput, ProtoBufHelper.Serizlize(_Protobuf_Room_SinglePlayerInputData)); App.network.SendToServer((int)CommandID.CmdRoomSingelPlayerInput, ProtoBufHelper.Serizlize(_Protobuf_Room_SinglePlayerInputData));
} }
ulong TestAllData = 0;
void RecvHostSyn_RoomFrameAllInputData(byte[] reqData) void RecvHostSyn_RoomFrameAllInputData(byte[] reqData)
{ {
Protobuf_Room_Syn_RoomFrameAllInputData msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Syn_RoomFrameAllInputData>(reqData); Protobuf_Room_Syn_RoomFrameAllInputData msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Syn_RoomFrameAllInputData>(reqData);
//App.log.Debug($"ServerFrameID->{msg.ServerFrameID} FrameID->{msg.FrameID} ClientFrame->{netReplay.mCurrClientFrameIdx} InputData->{msg.InputData}"); if (TestAllData != msg.InputData)
{
TestAllData = msg.InputData;
App.log.Debug($"ServerFrameID->{msg.ServerFrameID} FrameID->{msg.FrameID} ClientFrame->{netReplay.mCurrClientFrameIdx} InputData->{msg.InputData}");
}
netReplay.InData(new ReplayStep() { FrameStartID = (int)msg.FrameID, InPut = msg.InputData }, (int)msg.ServerFrameID); netReplay.InData(new ReplayStep() { FrameStartID = (int)msg.FrameID, InPut = msg.InputData }, (int)msg.ServerFrameID);
} }

View File

@ -98,17 +98,27 @@ namespace AxibugEmuOnline.Client
return m_sampledState; return m_sampledState;
} }
uint LastTestInput = 0;
public void SampleInput() public void SampleInput()
{ {
if (InGameUI.Instance.IsNetPlay) if (InGameUI.Instance.IsNetPlay)
{ {
if (App.roomMgr.netReplay.TryGetNextFrame(out var replayData, out int frameDiff, out bool inputDiff)) if (App.roomMgr.netReplay.TryGetNextFrame(out var replayData, out int frameDiff, out bool inputDiff))
{ {
App.log.Debug($"TryGetNextFrame remoteFrame->{App.roomMgr.netReplay.mRemoteFrameIdx} diff->{frameDiff} " + if (inputDiff)
{
App.log.Debug($"{DateTime.Now.ToString("hh:mm:ss.fff")} TryGetNextFrame remoteFrame->{App.roomMgr.netReplay.mRemoteFrameIdx} diff->{frameDiff} " +
$"frame=>{replayData.FrameStartID} InPut=>{replayData.InPut}"); $"frame=>{replayData.FrameStartID} InPut=>{replayData.InPut}");
}
m_sampledState = FromNet(replayData); m_sampledState = FromNet(replayData);
var localState = NesControllerMapper.Get().CreateState(); var localState = NesControllerMapper.Get().CreateState();
var rawData = ToNet(localState); var rawData = ToNet(localState);
if (LastTestInput != rawData)
{
LastTestInput = rawData;
App.log.Debug($"{DateTime.Now.ToString("hh:mm:ss.fff")} Input F:{App.roomMgr.netReplay.mCurrClientFrameIdx} | I:{rawData}");
}
App.roomMgr.SendRoomSingelPlayerInput((uint)App.roomMgr.netReplay.mCurrClientFrameIdx, rawData); App.roomMgr.SendRoomSingelPlayerInput((uint)App.roomMgr.netReplay.mCurrClientFrameIdx, rawData);
} }
else else

View File

@ -66,7 +66,7 @@ namespace AxibugEmuOnline.Client.Network
public void DequeueNesMsg() public void DequeueNesMsg()
{ {
if (queueNetMsg.Count > 0) while (queueNetMsg.Count > 0)
{ {
(int, int, byte[]) msgData = queueNetMsg.Dequeue(); (int, int, byte[]) msgData = queueNetMsg.Dequeue();
PostNetMsgEvent(msgData.Item1, msgData.Item2, msgData.Item3); PostNetMsgEvent(msgData.Item1, msgData.Item2, msgData.Item3);

View File

@ -82,7 +82,6 @@ namespace AxibugEmuOnline.Client.Network
try try
{ {
//抛出网络数据 //抛出网络数据
//网络线程直接抛 //网络线程直接抛
if (CMDID == (int)CommandID.CmdPing || CMDID == (int)CommandID.CmdPong) if (CMDID == (int)CommandID.CmdPing || CMDID == (int)CommandID.CmdPong)
NetMsg.Instance.PostNetMsgEvent(CMDID, ERRCODE, data); NetMsg.Instance.PostNetMsgEvent(CMDID, ERRCODE, data);

View File

@ -26,7 +26,7 @@ namespace AxibugEmuOnline.Server
g_Log = new LogManager(); g_Log = new LogManager();
g_Login = new LoginManager(); g_Login = new LoginManager();
g_Chat = new ChatManager(); g_Chat = new ChatManager();
g_SocketMgr = new IOCPNetWork(1024, 4096); g_SocketMgr = new IOCPNetWork(1024, 4096*2);
g_Room = new RoomManager(); g_Room = new RoomManager();
g_SocketMgr.Init(); g_SocketMgr.Init();

View File

@ -91,10 +91,10 @@ namespace AxibugEmuOnline.Server.Manager
DateTime CheckDT = DateTime.Now.AddMinutes(-1 * _RemoveOfflineCacheMin); DateTime CheckDT = DateTime.Now.AddMinutes(-1 * _RemoveOfflineCacheMin);
ClientInfo[] OfflineClientlist = ClientList.Where(w => w.IsOffline == true && w.LogOutDT < CheckDT).ToArray(); ClientInfo[] OfflineClientlist = ClientList.Where(w => w.IsOffline == true && w.LogOutDT < CheckDT).ToArray();
Console.WriteLine("开始清理离线过久的玩家的缓存");
for (int i = 0; i < OfflineClientlist.Length; i++) for (int i = 0; i < OfflineClientlist.Length; i++)
{ {
//to do 掉线处理 Console.WriteLine($"清理离线过久玩家 UID->{OfflineClientlist[i].UID} Name->{OfflineClientlist[i].NickName}");
//掉线处理
RemoveClient(OfflineClientlist[i]); RemoveClient(OfflineClientlist[i]);
} }
GC.Collect(); GC.Collect();

View File

@ -6,9 +6,17 @@
{ {
Console.WriteLine(str); Console.WriteLine(str);
} }
public void DebugCmd(string str)
{
ConsoleColor srcColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"[{DateTime.Now.ToString("hh:mm:ss.fff")}][{str}]");
Console.ForegroundColor = srcColor;
}
public void Debug(string str) public void Debug(string str)
{ {
Console.WriteLine(str); Console.WriteLine($"[{DateTime.Now.ToString("hh:mm:ss.fff")}][{str}]");
//Console.WriteLine(str);
} }
public void Warning(string str) public void Warning(string str)

View File

@ -31,9 +31,15 @@ namespace AxibugEmuOnline.Server
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdScreen, OnCmdScreen); NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdScreen, OnCmdScreen);
roomTickARE = AppSrv.g_Tick.AddNewARE(TickManager.TickType.Interval_16MS); //roomTickARE = AppSrv.g_Tick.AddNewARE(TickManager.TickType.Interval_16MS);
threadRoomTick = new Thread(UpdateLoopTick); //threadRoomTick = new Thread(UpdateLoopTick);
threadRoomTick.Start(); //threadRoomTick.Start();
System.Timers.Timer mTimer16ms = new System.Timers.Timer(16);//实例化Timer类
mTimer16ms.Elapsed += new System.Timers.ElapsedEventHandler((source, e) => { UpdateAllRoomLogic(); });//到达时间的时候执行事件;
mTimer16ms.AutoReset = true;//设置是执行一次false还是一直执行(true)
mTimer16ms.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件
mTimer16ms.Start();
} }
#region #region
@ -123,7 +129,7 @@ namespace AxibugEmuOnline.Server
public void OnCmdRoomList(Socket sk, byte[] reqData) public void OnCmdRoomList(Socket sk, byte[] reqData)
{ {
AppSrv.g_Log.Debug($"OnCmdRoomList "); AppSrv.g_Log.DebugCmd($"OnCmdRoomList");
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk); ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk);
Protobuf_Room_List msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_List>(reqData); Protobuf_Room_List msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_List>(reqData);
@ -135,7 +141,7 @@ namespace AxibugEmuOnline.Server
} }
public void CmdRoomGetScreen(Socket sk, byte[] reqData) public void CmdRoomGetScreen(Socket sk, byte[] reqData)
{ {
AppSrv.g_Log.Debug($"OnCmdRoomList "); AppSrv.g_Log.DebugCmd($"CmdRoomGetScreen");
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk); ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk);
Protobuf_Room_Get_Screen msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Get_Screen>(reqData); Protobuf_Room_Get_Screen msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Get_Screen>(reqData);
@ -177,7 +183,7 @@ namespace AxibugEmuOnline.Server
public void OnCmdRoomCreate(Socket sk, byte[] reqData) public void OnCmdRoomCreate(Socket sk, byte[] reqData)
{ {
AppSrv.g_Log.Debug($"OnCmdRoomCreate "); AppSrv.g_Log.DebugCmd($"OnCmdRoomCreate");
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk); ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk);
Protobuf_Room_Create msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Create>(reqData); Protobuf_Room_Create msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Create>(reqData);
Protobuf_Room_Create_RESP resp = new Protobuf_Room_Create_RESP(); Protobuf_Room_Create_RESP resp = new Protobuf_Room_Create_RESP();
@ -202,16 +208,21 @@ namespace AxibugEmuOnline.Server
public void OnCmdRoomJoin(Socket sk, byte[] reqData) public void OnCmdRoomJoin(Socket sk, byte[] reqData)
{ {
AppSrv.g_Log.Debug($"OnCmdRoomJoin "); AppSrv.g_Log.DebugCmd($"OnCmdRoomJoin");
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk); ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk);
Protobuf_Room_Join msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Join>(reqData); Protobuf_Room_Join msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Join>(reqData);
Protobuf_Room_Create_RESP resp = new Protobuf_Room_Create_RESP(); Protobuf_Room_Create_RESP resp = new Protobuf_Room_Create_RESP();
ErrorCode joinErrcode; ErrorCode joinErrcode;
Data_RoomData room = GetRoomData(_c.RoomState.RoomID); Data_RoomData room = GetRoomData(msg.RoomID);
bool bHadRoomStateChange = false; bool bHadRoomStateChange = false;
if (room == null) if (room == null)
{
joinErrcode = ErrorCode.ErrorRoomNotFound; joinErrcode = ErrorCode.ErrorRoomNotFound;
else
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomJoin, (int)joinErrcode, ProtoBufHelper.Serizlize(resp));
return;
}
lock (room)
{ {
//加入 //加入
if (room.Join(msg.PlayerNum, _c, out joinErrcode, out bHadRoomStateChange)) if (room.Join(msg.PlayerNum, _c, out joinErrcode, out bHadRoomStateChange))
@ -219,7 +230,6 @@ namespace AxibugEmuOnline.Server
Data_RoomData roomData = GetRoomData(msg.RoomID); Data_RoomData roomData = GetRoomData(msg.RoomID);
resp.RoomMiniInfo = GetProtoDataRoom(roomData); resp.RoomMiniInfo = GetProtoDataRoom(roomData);
} }
}
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomJoin, (int)joinErrcode, ProtoBufHelper.Serizlize(resp)); AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomJoin, (int)joinErrcode, ProtoBufHelper.Serizlize(resp));
Protobuf_Room_MyRoom_State_Change(msg.RoomID); Protobuf_Room_MyRoom_State_Change(msg.RoomID);
@ -227,12 +237,15 @@ namespace AxibugEmuOnline.Server
if (joinErrcode == ErrorCode.ErrorOk && bHadRoomStateChange) if (joinErrcode == ErrorCode.ErrorOk && bHadRoomStateChange)
SendRoomStateChange(room); SendRoomStateChange(room);
if (room != null)
{
SendRoomUpdateToAll(room.RoomID, 0); SendRoomUpdateToAll(room.RoomID, 0);
} }
}
}
public void OnCmdRoomLeave(Socket sk, byte[] reqData) public void OnCmdRoomLeave(Socket sk, byte[] reqData)
{ {
AppSrv.g_Log.Debug($"OnCmdRoomLeave "); AppSrv.g_Log.DebugCmd($"OnCmdRoomLeave");
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk); ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk);
Protobuf_Room_Leave msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Leave>(reqData); Protobuf_Room_Leave msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Leave>(reqData);
LeaveRoom(_c, msg.RoomID); LeaveRoom(_c, msg.RoomID);
@ -262,19 +275,24 @@ namespace AxibugEmuOnline.Server
public void LeaveRoom(ClientInfo _c, int RoomID) public void LeaveRoom(ClientInfo _c, int RoomID)
{ {
AppSrv.g_Log.Debug($"LeaveRoom");
if (RoomID < 0)
return;
Protobuf_Room_Leave_RESP resp = new Protobuf_Room_Leave_RESP(); Protobuf_Room_Leave_RESP resp = new Protobuf_Room_Leave_RESP();
ErrorCode errcode; ErrorCode errcode;
Data_RoomData room = GetRoomData(_c.RoomState.RoomID); Data_RoomData room = GetRoomData(_c.RoomState.RoomID);
bool bHadRoomStateChange = false; bool bHadRoomStateChange = false;
if (room == null) if (room == null)
errcode = ErrorCode.ErrorRoomNotFound;
else
{ {
errcode = ErrorCode.ErrorRoomNotFound;
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomLeave, (int)errcode, ProtoBufHelper.Serizlize(resp));
return;
}
if (room.Leave(_c, out errcode, out bHadRoomStateChange)) if (room.Leave(_c, out errcode, out bHadRoomStateChange))
{ {
resp.RoomID = RoomID; resp.RoomID = RoomID;
} }
}
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomLeave, (int)errcode, ProtoBufHelper.Serizlize(resp)); AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdRoomLeave, (int)errcode, ProtoBufHelper.Serizlize(resp));
Protobuf_Room_MyRoom_State_Change(RoomID); Protobuf_Room_MyRoom_State_Change(RoomID);
@ -293,6 +311,7 @@ namespace AxibugEmuOnline.Server
public void OnHostPlayerUpdateStateRaw(Socket sk, byte[] reqData) public void OnHostPlayerUpdateStateRaw(Socket sk, byte[] reqData)
{ {
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk); ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk);
AppSrv.g_Log.DebugCmd($"OnHostPlayerUpdateStateRaw 上报即时存档 UID->{_c.UID}");
Protobuf_Room_HostPlayer_UpdateStateRaw msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_HostPlayer_UpdateStateRaw>(reqData); Protobuf_Room_HostPlayer_UpdateStateRaw msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_HostPlayer_UpdateStateRaw>(reqData);
Protobuf_Room_HostPlayer_UpdateStateRaw_RESP resp = new Protobuf_Room_HostPlayer_UpdateStateRaw_RESP(); Protobuf_Room_HostPlayer_UpdateStateRaw_RESP resp = new Protobuf_Room_HostPlayer_UpdateStateRaw_RESP();
ErrorCode errcode = ErrorCode.ErrorOk; ErrorCode errcode = ErrorCode.ErrorOk;
@ -307,7 +326,6 @@ namespace AxibugEmuOnline.Server
if (errcode == ErrorCode.ErrorOk) if (errcode == ErrorCode.ErrorOk)
{ {
room.SetLoadRaw(msg.LoadStateRaw, out bool bHadRoomStateChange); room.SetLoadRaw(msg.LoadStateRaw, out bool bHadRoomStateChange);
if (bHadRoomStateChange) if (bHadRoomStateChange)
SendRoomStateChange(room); SendRoomStateChange(room);
} }
@ -316,14 +334,24 @@ namespace AxibugEmuOnline.Server
public void OnRoomPlayerReady(Socket sk, byte[] reqData) public void OnRoomPlayerReady(Socket sk, byte[] reqData)
{ {
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk); ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk);
AppSrv.g_Log.DebugCmd($"OnRoomPlayerReady _c->{_c.UID}");
Protobuf_Room_Player_Ready msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Player_Ready>(reqData); Protobuf_Room_Player_Ready msg = ProtoBufHelper.DeSerizlize<Protobuf_Room_Player_Ready>(reqData);
ErrorCode errcode = ErrorCode.ErrorOk; ErrorCode errcode = ErrorCode.ErrorOk;
Data_RoomData room = GetRoomData(_c.RoomState.RoomID); Data_RoomData room = GetRoomData(_c.RoomState.RoomID);
if (room == null) if (room == null)
return; return;
lock (room)
{
AppSrv.g_Log.Debug($"SetRePlayerReady RoomID->{room.RoomID},UID->{_c.UID}, PlayerIdx->{_c.RoomState.PlayerIdx}");
room.SetRePlayerReady(_c.RoomState.PlayerIdx, out errcode, out bool bHadRoomStateChange);
if (bHadRoomStateChange)
{
SendRoomStateChange(room);
}
}
} }
ulong LastTestRecv = 0;
public void OnSingelPlayerInput(Socket sk, byte[] reqData) public void OnSingelPlayerInput(Socket sk, byte[] reqData)
{ {
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk); ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk);
@ -336,13 +364,19 @@ namespace AxibugEmuOnline.Server
//取玩家操作数据中的第一个 //取玩家操作数据中的第一个
ServerInputSnapShot temp = new ServerInputSnapShot(); ServerInputSnapShot temp = new ServerInputSnapShot();
temp.all = msg.InputData; temp.all = msg.InputData;
room.SetPlayerInput(_c.RoomState.PlayerIdx, msg.FrameID, temp);
if (LastTestRecv != room.mCurrInputData.all)
{
LastTestRecv = room.mCurrInputData.all;
AppSrv.g_Log.Debug($" {DateTime.Now.ToString("hh:mm:ss.fff")} SynTestRecv=> UID->{_c.UID} roomId->{room.mCurrFrameId} input->{msg.InputData}");
}
room.SetPlayerInput(_c.RoomState.PlayerIdx, msg.FrameID, temp.p1_byte);
} }
public void OnCmdScreen(Socket sk, byte[] reqData) public void OnCmdScreen(Socket sk, byte[] reqData)
{ {
AppSrv.g_Log.Debug($"OnCmdScreen lenght:{reqData.Length}"); AppSrv.g_Log.DebugCmd($"OnCmdScreen lenght:{reqData.Length}");
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk); ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk);
Protobuf_Screnn_Frame msg = ProtoBufHelper.DeSerizlize<Protobuf_Screnn_Frame>(reqData); Protobuf_Screnn_Frame msg = ProtoBufHelper.DeSerizlize<Protobuf_Screnn_Frame>(reqData);
Data_RoomData room = AppSrv.g_Room.GetRoomData(msg.RoomID); Data_RoomData room = AppSrv.g_Room.GetRoomData(msg.RoomID);
@ -383,6 +417,7 @@ namespace AxibugEmuOnline.Server
{ {
WaitStep = 0 WaitStep = 0
}; };
AppSrv.g_Log.Debug($"Step=>{0} WaitRawUpdate 广播等待主机上报即时存档");
AppSrv.g_ClientMgr.ClientSend(roomClient, (int)CommandID.CmdRoomWaitStep, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp)); AppSrv.g_ClientMgr.ClientSend(roomClient, (int)CommandID.CmdRoomWaitStep, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp));
} }
break; break;
@ -393,6 +428,8 @@ namespace AxibugEmuOnline.Server
WaitStep = 1, WaitStep = 1,
LoadStateRaw = room.NextStateRaw LoadStateRaw = room.NextStateRaw
}; };
AppSrv.g_Log.Debug($"Step=>{1} WaitReady 广播即时存档");
AppSrv.g_ClientMgr.ClientSend(roomClient, (int)CommandID.CmdRoomWaitStep, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp)); AppSrv.g_ClientMgr.ClientSend(roomClient, (int)CommandID.CmdRoomWaitStep, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp));
} }
break; break;
@ -402,6 +439,8 @@ namespace AxibugEmuOnline.Server
{ {
WaitStep = 2, WaitStep = 2,
}; };
AppSrv.g_Log.Debug($"Step=>{2} 广播开始游戏");
AppSrv.g_ClientMgr.ClientSend(roomClient, (int)CommandID.CmdRoomWaitStep, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp)); AppSrv.g_ClientMgr.ClientSend(roomClient, (int)CommandID.CmdRoomWaitStep, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp));
} }
break; break;
@ -421,12 +460,12 @@ namespace AxibugEmuOnline.Server
} }
void UpdateAllRoomLogic() void UpdateAllRoomLogic()
{ {
if (mKeyRoomList.Count < 1)
return;
for (int i = 0; i < mKeyRoomList.Count; i++) for (int i = 0; i < mKeyRoomList.Count; i++)
{ {
int roomid = mKeyRoomList[i]; int roomid = mKeyRoomList[i];
if (!mDictRoom.TryGetValue(roomid, out Data_RoomData room)) if (!mDictRoom.TryGetValue(roomid, out Data_RoomData room) || room.GameState < RoomGameState.InOnlineGame)
continue;
if (room.GameState < RoomGameState.InOnlineGame)
continue; continue;
//更新帧 //更新帧
room.TakeFrame(); room.TakeFrame();
@ -531,6 +570,7 @@ namespace AxibugEmuOnline.Server
if (oldUID >= 0) if (oldUID >= 0)
SynUIDs.Remove(oldUID); SynUIDs.Remove(oldUID);
SynUIDs.Add(_c.UID); SynUIDs.Add(_c.UID);
AppSrv.g_Log.Debug($"SetPlayerUID RoomID->{RoomID} _c.UID->{_c.UID} PlayerIdx->{PlayerIdx}");
_c.RoomState.SetRoomData(this.RoomID, PlayerIdx); _c.RoomState.SetRoomData(this.RoomID, PlayerIdx);
} }
@ -607,14 +647,14 @@ namespace AxibugEmuOnline.Server
return list; return list;
} }
public void SetPlayerInput(int PlayerIdx, long mFrameID, byte input) public void SetPlayerInput(int PlayerIdx, long mFrameID, ServerInputSnapShot allinput)
{ {
switch (PlayerIdx) switch (PlayerIdx)
{ {
case 0: mCurrInputData.p1_byte = input; break; case 0: mCurrInputData.p1_byte = allinput.p1_byte; break;
case 1: mCurrInputData.p2_byte = input; break; case 1: mCurrInputData.p2_byte = allinput.p2_byte; break;
case 2: mCurrInputData.p3_byte = input; break; case 2: mCurrInputData.p3_byte = allinput.p3_byte; break;
case 3: mCurrInputData.p4_byte = input; break; case 3: mCurrInputData.p4_byte = allinput.p4_byte; break;
} }
} }
@ -651,10 +691,14 @@ namespace AxibugEmuOnline.Server
ClientInfo player = playerlist[i]; ClientInfo player = playerlist[i];
maxNetDelay = Math.Max(maxNetDelay, player.AveNetDelay); maxNetDelay = Math.Max(maxNetDelay, player.AveNetDelay);
} }
mCurrFrameId = 0; mCurrFrameId = 0;
mCurrInputData.all = 1;
int TaskFrameCount = (int)((maxNetDelay / 0.016f) + 5f); int TaskFrameCount = (int)((maxNetDelay / 0.016f) + 5f);
AppSrv.g_Log.Debug($"服务器提前跑帧数:({maxNetDelay} / {0.016f}) + {5f} = {TaskFrameCount}");
TaskFrameCount = 0;
for (int i = 0; i < TaskFrameCount; i++) for (int i = 0; i < TaskFrameCount; i++)
{ {
TakeFrame(); TakeFrame();
@ -667,6 +711,7 @@ namespace AxibugEmuOnline.Server
mCurrFrameId++; mCurrFrameId++;
} }
ulong LastTestSend = 0;
/// <summary> /// <summary>
/// 广播数据 /// 广播数据
/// </summary> /// </summary>
@ -681,11 +726,16 @@ namespace AxibugEmuOnline.Server
InputData = data.inputdata.all, InputData = data.inputdata.all,
ServerFrameID = mCurrFrameId ServerFrameID = mCurrFrameId
}; };
if (LastTestSend != data.inputdata.all)
{
LastTestSend = data.inputdata.all;
AppSrv.g_Log.Debug($" {DateTime.Now.ToString("hh:mm:ss.fff")} SynInput=> RoomID->{RoomID} ServerFrameID->{mCurrFrameId} SynUIDs=>{string.Join(",", SynUIDs)} ");
}
AppSrv.g_ClientMgr.ClientSend(SynUIDs, (int)CommandID.CmdRoomSynPlayerInput, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp)); AppSrv.g_ClientMgr.ClientSend(SynUIDs, (int)CommandID.CmdRoomSynPlayerInput, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp));
} }
} }
#region #region
/// <summary> /// <summary>
/// 进入房间 /// 进入房间
@ -704,6 +754,7 @@ namespace AxibugEmuOnline.Server
errcode = ErrorCode.ErrorRoomSlotReadlyHadPlayer; errcode = ErrorCode.ErrorRoomSlotReadlyHadPlayer;
return false; return false;
} }
AppSrv.g_Log.Debug($"Join _c.UID->{_c.UID} RoomID->{RoomID}");
SetPlayerUID(PlayerNum, _c); SetPlayerUID(PlayerNum, _c);
int newPlayerCount = GetPlayerCount(); int newPlayerCount = GetPlayerCount();
errcode = ErrorCode.ErrorOk; errcode = ErrorCode.ErrorOk;
@ -730,6 +781,16 @@ namespace AxibugEmuOnline.Server
} }
#endregion #endregion
public bool SetRePlayerReady(int PlayerIdx, out ErrorCode errcode, out bool bHadRoomStateChange)
{
int oldPlayerCount = GetPlayerCount();
PlayerReadyState[PlayerIdx] = true;
int newPlayerCount = GetPlayerCount();
errcode = ErrorCode.ErrorOk;
bHadRoomStateChange = CheckRoomStateChange(oldPlayerCount, newPlayerCount);
return true;
}
bool CheckRoomStateChange(int oldPlayerCount, int newPlayerCount) bool CheckRoomStateChange(int oldPlayerCount, int newPlayerCount)
{ {
bool bChanged = false; bool bChanged = false;
@ -773,14 +834,13 @@ namespace AxibugEmuOnline.Server
bChanged = true; bChanged = true;
break; break;
} }
//没有准备的 //没有准备的
bool bAllReady = IsAllReady(); bool bAllReady = IsAllReady();
if (bAllReady) if (bAllReady)
{ {
this.GameState = RoomGameState.InOnlineGame;
//新开Tick //新开Tick
StartNewTick(); StartNewTick();
this.GameState = RoomGameState.InOnlineGame;
bChanged = true; bChanged = true;
break; break;
} }
@ -797,7 +857,6 @@ namespace AxibugEmuOnline.Server
if (bMorePlayer)//加入更多玩家 if (bMorePlayer)//加入更多玩家
{ {
this.GameState = RoomGameState.WaitRawUpdate; this.GameState = RoomGameState.WaitRawUpdate;
//TODO 服务器Tick提前跑帧
bChanged = true; bChanged = true;
break; break;
} }
@ -809,6 +868,7 @@ namespace AxibugEmuOnline.Server
public void SetLoadRaw(Google.Protobuf.ByteString NextStateRaw, out bool bHadRoomStateChange) public void SetLoadRaw(Google.Protobuf.ByteString NextStateRaw, out bool bHadRoomStateChange)
{ {
int oldPlayerCount = GetPlayerCount(); int oldPlayerCount = GetPlayerCount();
AppSrv.g_Log.Debug($"SetLoadRaw proto Lenght->{NextStateRaw.Length}");
this.NextStateRaw = NextStateRaw; this.NextStateRaw = NextStateRaw;
int newPlayerCount = GetPlayerCount(); int newPlayerCount = GetPlayerCount();
bHadRoomStateChange = CheckRoomStateChange(oldPlayerCount, newPlayerCount); bHadRoomStateChange = CheckRoomStateChange(oldPlayerCount, newPlayerCount);