public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) { try { //if (m_IsLog) Log("OnNetworkReceive " + peer.EndPoint + " method=" + deliveryMethod); var player = m_Players.GetPlayerByPeer(peer); if (player == null) { return; } var state = ReaderGameHelper.GetClientState(reader); //var prevState = player.State; //TODO: добавить действия которые присылает клиент(как ответы на команды от сервера) if (state == ClientState.Verification) { player.PlayerName = reader.GetString(); player.TypeUnit = (TypeUnit)reader.GetByte(); m_Players.ResolveDublicateName(player); } if (state != ClientState.Connected) { Log("OnNetworkReceive " + player + " setState=" + state + " frame=" + Time.frameCount); } player.State = state; //if (m_IsLog) Log("OnNetworkReceive " + player); if (player.IsConnected) { player.AddData(reader); } //if (MiscHelper.CheckIncludeInMask(state, MiscHelper.MASK_REGISTRY_OR_CONNECTED)) //{ // player.AddData(reader); //} } catch (System.Exception e) { if (m_IsLog) { Log("OnNetworkReceive bad data from " + (peer == null ? "Empty" : peer.EndPoint.ToString()) + " error=" + e, true); } return; } }
void UpdatePlayer(NetPacketReader reader) { //if (m_IsLog) Log(string.Format("UpdatePlayer ID={0} StartInd={1} DataLen={2}", peer.EndPoint, reader.Position, reader.AvailableBytes)); if (!MiscHelper.CheckIncludeInMask(m_ClientPlayer.State, MiscHelper.MASK_REGISTRY_OR_CONNECTED)) { return; } var state = ReaderGameHelper.GetClientState(reader); var id = GetIDPlayer(reader); if (m_IsLog) { PeriodLog(string.Format("UpdatePlayer={0} state={1}", id, state)); } bool isClient = m_ClientPlayer.ID == id; if (isClient && state == ClientState.Disconnected) { //CallConnectEvents(new Args() { Event = ProcessConnection.Disconnected, Reason = "Server kicked out" }); return; } if (isClient && m_ClientPlayer.State != ClientState.Connected) { return; } var playerName = reader.GetString(); var player = m_Players.GetPlayer(id); var typeUnit = (TypeUnit)reader.GetByte(); if (player == null) { player = AddNewPlayer(id); } player.TypeUnit = typeUnit; player.PlayerName = playerName; player.State = state; player.AddData(reader); }