public void AnalyzeMessage(CSID messageId, byte[] bodyData) { switch (messageId) { case CSID.UDP_BATTLE_READY: { //接收战斗准备 UdpBattleReady _mes = CSData.DeserializeData <UdpBattleReady> (bodyData); CheckBattleBegin(_mes.battleID); dic_udp [_mes.battleID].RecvClientReady(_mes.uid); } break; case CSID.UDP_UP_PLAYER_OPERATIONS: { UdpUpPlayerOperations pb_ReceiveMes = CSData.DeserializeData <UdpUpPlayerOperations>(bodyData); UpdatePlayerOperation(pb_ReceiveMes.operation, pb_ReceiveMes.mesID); } break; case CSID.UDP_UP_DELTA_FRAMES: { UdpUpDeltaFrames pb_ReceiveMes = CSData.DeserializeData <UdpUpDeltaFrames>(bodyData); UdpDownDeltaFrames _downData = new UdpDownDeltaFrames(); for (int i = 0; i < pb_ReceiveMes.frames.Count; i++) { int framIndex = pb_ReceiveMes.frames [i]; UdpDownFrameOperations _downOp = new UdpDownFrameOperations(); _downOp.frameID = framIndex; _downOp.operations = dic_gameOperation [framIndex]; _downData.framesData.Add(_downOp); } byte[] _data = CSData.GetSendMessage <UdpDownDeltaFrames> (_downData, SCID.UDP_DOWN_DELTA_FRAMES); dic_udp [pb_ReceiveMes.battleID].SendMessage(_data); } break; case CSID.UDP_UP_GAME_OVER: { UdpUpGameOver pb_ReceiveMes = CSData.DeserializeData <UdpUpGameOver>(bodyData); UpdatePlayerGameOver(pb_ReceiveMes.battleID); UdpDownGameOver _downData = new UdpDownGameOver(); byte[] _data = CSData.GetSendMessage <UdpDownGameOver> (_downData, SCID.UDP_DOWN_GAME_OVER); dic_udp [pb_ReceiveMes.battleID].SendMessage(_data); } break; default: break; } }
private void HandleMsg(ServerClientUdp udp, Protocol proto) { switch (proto.ClassName) { case nameof(UdpBattleReadyMessage): { UdpBattleReadyMessage msg = proto.Decode <UdpBattleReadyMessage>(); Debug.Log("客户端完成战斗加载"); // 接收战斗准备 CheckBattleBegin(msg.BattleID); dic_udp[msg.BattleID].RecvClientReady(msg.UID); } break; case nameof(UdpUpPlayerOperation): { UdpUpPlayerOperation msg = proto.Decode <UdpUpPlayerOperation>(); //Debug.Log("服务器接收到玩家的操作信息"); UpdatePlayerOperation(msg.PlayerOperation, msg.MsgID); } break; case nameof(UdpUpDeltaFrames): { UdpUpDeltaFrames msg = proto.Decode <UdpUpDeltaFrames>(); UdpDownDeltaFrames _downData = new UdpDownDeltaFrames(); for (int i = 0; i < msg.Frames.Count; i++) { int frameIndex = msg.Frames[i]; UdpDownFrameOperations _downOps = new UdpDownFrameOperations(); _downOps.FrameID = frameIndex; _downOps.Ops = dic_gameOperation[frameIndex]; _downData.FramesData.Add(_downOps); } dic_udp[msg.BattleID].SendMessage(new Protocol(_downData)); } break; default: { Debug.LogError("未知客户端UDP信息"); } break; } }
public void AnalyzeMessage(SCID messageId, byte[] bodyData) { switch (messageId) { case SCID.UDP_BATTLE_START: { UdpBattleStart pb_ReceiveMes = CSData.DeserializeData <UdpBattleStart>(bodyData); NetGlobal.Instance().AddAction(() => { mes_battle_start(pb_ReceiveMes); }); } break; case SCID.UDP_DOWN_FRAME_OPERATIONS: { UdpDownFrameOperations pb_ReceiveMes = CSData.DeserializeData <UdpDownFrameOperations>(bodyData); NetGlobal.Instance().AddAction(() => { mes_frame_operation(pb_ReceiveMes); }); } break; case SCID.UDP_DOWN_DELTA_FRAMES: { UdpDownDeltaFrames pb_ReceiveMes = CSData.DeserializeData <UdpDownDeltaFrames>(bodyData); NetGlobal.Instance().AddAction(() => { mes_delta_frame_data(pb_ReceiveMes); }); } break; case SCID.UDP_DOWN_GAME_OVER: { UdpDownGameOver pb_ReceiveMes = CSData.DeserializeData <UdpDownGameOver>(bodyData); NetGlobal.Instance().AddAction(() => { mes_down_game_over(pb_ReceiveMes); }); } break; default: break; } }
void Message_Frame_Operation(UdpDownFrameOperations _mes) { BattleData.Instance.AddNewFrameData(_mes.frameID, _mes.operations); BattleData.Instance.netPack++; }
private void Thread_SendFrameData() { //向玩家发送战斗开始 bool isFinishBS = false; while (!isFinishBS) { UdpBattleStart _btData = new UdpBattleStart(); byte[] _data = CSData.GetSendMessage <UdpBattleStart> (_btData, SCID.UDP_BATTLE_START); foreach (var item in dic_udp) { item.Value.SendMessage(_data); } bool _allData = true; for (int i = 0; i < frameOperation.Length; i++) { if (frameOperation[i] == null) { _allData = false; break; } } if (_allData) { LogManage.Instance.AddLog("战斗服务器:收到全部玩家的第一次操作数据...."); frameNum = 1; isFinishBS = true; } Thread.Sleep(500); } LogManage.Instance.AddLog("开始发送帧数据~~~~"); while (_isRun) { UdpDownFrameOperations _dataPb = new UdpDownFrameOperations(); if (oneGameOver) { _dataPb.frameID = lastFrame; _dataPb.operations = dic_gameOperation [lastFrame]; } else { _dataPb.operations = new AllPlayerOperation(); _dataPb.operations.operations.AddRange(frameOperation); _dataPb.frameID = frameNum; dic_gameOperation [frameNum] = _dataPb.operations; lastFrame = frameNum; frameNum++; } byte[] _data = CSData.GetSendMessage <UdpDownFrameOperations> (_dataPb, SCID.UDP_DOWN_FRAME_OPERATIONS); foreach (var item in dic_udp) { int _index = item.Key - 1; if (!playerGameOver [_index]) { item.Value.SendMessage(_data); } } Thread.Sleep(ServerConfig.frameTime); } LogManage.Instance.AddLog("帧数据发送线程结束....................."); }
private void Thread_SendFrameData() { //向玩家发送战斗开始 bool isFinishBS = false; while (!isFinishBS) { UdpBattleStartMessage _bt = new UdpBattleStartMessage(); Protocol protocol = new Protocol(_bt); foreach (var item in dic_udp.Values) { item.SendMessage(protocol); } bool _allData = true; for (int i = 0; i < frameOperation.Length; i++) { if (frameOperation[i] == null) { _allData = false; // 有一个玩家没有发送上来操作,则判断为false break; } } if (_allData) { Debug.Log("战斗服务器:收到全部玩家的第一次操作数据"); frameNum = 1; isFinishBS = true; } Thread.Sleep(500); } Debug.Log("开始发送帧数据"); while (isRun) { UdpDownFrameOperations _ops = new UdpDownFrameOperations(); //Debug.Log("服务器转发帧数据"); if (oneGameOver) { _ops.FrameID = lastFrame; _ops.Ops = dic_gameOperation[lastFrame]; } else { _ops.Ops.Operations.AddRange(frameOperation); _ops.FrameID = frameNum; dic_gameOperation[frameNum] = _ops.Ops; lastFrame = frameNum; frameNum++; Protocol protocol = new Protocol(_ops); foreach (var item in dic_udp) { int _index = item.Key - 1; if (!playerGameOver[_index]) { item.Value.SendMessage(protocol); } } } Thread.Sleep(ServerConfig.FRAME_TIME); } Debug.Log("帧数据发送线程结束....................."); }
void Message_Frame_Operation(UdpDownFrameOperations msg) { //Debug.Log("客户端处理服务器发来的帧操作信息"); BattleData.Instance.AddNewFrameData(msg.FrameID, msg.Ops); }