コード例 #1
0
        protected override void Disconnect(Event netEvent)
        {
            Debug.Log($"Client disconnected - ID: {netEvent.Peer.ID}, IP: {netEvent.Peer.IP}  Reason: {netEvent.Data}");
            Peer            peer = netEvent.Peer;
            NetworkedObject nobj = null;

            if (m_peers.TryGetValue(peer.ID, out nobj))
            {
                uint id = peer.ID;

                m_peers.Remove(peer.ID);

                Destroy(nobj.gameObject);

                // notify everyone else
                if (m_peers.Count > 0)
                {
                    m_buffer.AddEntityHeader(peer, OpCodes.Destroy);
                    var packet  = m_buffer.GetPacketFromBuffer(PacketFlags.Reliable);
                    var command = GameCommandPool.GetGameCommand();
                    command.Type    = CommandType.BroadcastAll;
                    command.Packet  = packet;
                    command.Channel = 0;
                    m_commandQueue.Enqueue(command);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Only called on the server where the peer is present.
        /// </summary>
        public void UpdateSyncs()
        {
            if (CanUpdate() == false)
            {
                return;
            }

            m_nextUpdate += m_updateRate;

            int dirtyBits = 0;

            for (int i = 0; i < m_syncs.Count; i++)
            {
                if (m_syncs[i].Dirty)
                {
                    dirtyBits = dirtyBits | m_syncs[i].BitFlag;
                }
            }

            if (dirtyBits == 0)
            {
                return;
            }

            m_buffer.AddEntityHeader(m_peer, OpCodes.SyncUpdate);
            m_buffer.AddInt(dirtyBits);

            for (int i = 0; i < m_syncs.Count; i++)
            {
                if (m_syncs[i].Dirty)
                {
                    m_buffer.AddSyncVar(m_syncs[i]);
                }
            }

            var packet  = m_buffer.GetPacketFromBuffer(PacketFlags.Reliable);
            var command = GameCommandPool.GetGameCommand();

            command.Type    = CommandType.BroadcastAll;
            command.Packet  = packet;
            command.Channel = 0;

            Debug.Log($"Sending dirtyBits: {dirtyBits}  Length: {packet.Length}");

            m_network.AddCommandToQueue(command);
        }