void SendRegisterData(Player player) { Log("SendRegisterData on " + player.IPInfo); var writer = m_Server.m_Writer; var players = m_Server.m_Players; writer.Reset(); ReaderGameHelper.AddCommand(writer, ServerCommands.Register); var playerID = player.ID; //players.AddPlayer(player); writer.Put(playerID); writer.Put(player.PlayerName); writer.Put(players.Count - 1); for (int i = players.Count - 1; i >= 0; i--) { var otherPlayer = players[i]; if (!otherPlayer.IsConnected) { continue; } var id = otherPlayer.ID; if (id == playerID) { continue; } writer.Put(id); //writer.Put(otherPlayer.PlayerName); } player.Peer.Send(writer, DeliveryMethod.ReliableUnordered); }
void SendVerificationData(Player player) { Log("SendVerificationData on " + player.IPInfo); var writer = m_Server.m_Writer; writer.Reset(); ReaderGameHelper.AddCommand(writer, ServerCommands.Verify); //writer.Put(player.ID); player.Peer.Send(writer, DeliveryMethod.ReliableUnordered); }
bool GetHitsData() { if (!NetworkHitsController.Can) { return(false); } m_Writer.Reset(); ReaderGameHelper.AddCommand(m_Writer, ServerCommands.UpdateWorld); ReaderGameHelper.AddWorldUpdate(m_Writer, TypeWorldUpdate.Hits); bool res = NetworkHitsController.I.GetData(m_Writer); return(res); }
void SendSyncPlayers() { //Log("SendSyncPlayers"); m_Writer.Reset(); ReaderGameHelper.AddCommand(m_Writer, ServerCommands.UpdateWorld); ReaderGameHelper.AddWorldUpdate(m_Writer, TypeWorldUpdate.SyncPlayersInfo); int count = m_Players.Count; m_Writer.Put(count); for (int i = 0; i < count; i++) { //Log("Sync " + m_Players[i]); m_Writer.Put(m_Players[i].ID); } SendToAllWithState(m_Writer, DeliveryMethod.Unreliable, MiscHelper.MASK_REGISTRY_OR_CONNECTED); }
private void FixedUpdate() { if (Tick()) { return; } //обработка событий m_Server.PollEvents(); if (!IsStarted) { return; } //синхронизируем игроков на клиентах SendSyncPlayers(); //данные игрока for (int i = m_Players.Count - 1; i >= 0; i--) { var pl = m_Players[i]; if (!pl.IsConnected) { continue; } m_Writer.Reset(); ReaderGameHelper.AddCommand(m_Writer, ServerCommands.UpdateWorld); if (!pl.GetData(m_Writer)) { continue; } //if (m_IsLog) Log(string.Format("SendData ID={0} DataLen={1}", pl.ID, m_Writer.Length)); SendToAllWithState(m_Writer, DeliveryMethod.Unreliable, MiscHelper.MASK_REGISTRY_OR_CONNECTED); } //данные о зарегистрированных попаданиях if (GetHitsData()) { SendToAllWithState(m_Writer, DeliveryMethod.Unreliable, MiscHelper.MASK_REGISTRY_OR_CONNECTED); } //if (m_ClientPlayer != null) m_ClientPlayer.Update(m_Writer); }