Esempio n. 1
0
        /// <summary>
        ///     Invoked when we recieve a world state from the superpeers controlling our zone.
        /// </summary>
        /// <param name="state">World state recieved.</param>
        internal void RecievedWorldState(SuperPeerWorldStatePacket state)
        {
            if (m_currentZone == null)
            {
                return;
            }
            
            // Check packet comes from a superpeer simulating our current zone.
            int lowest_id = 0;
            foreach (ZoneSuperPeer p in m_currentZone.SuperPeers)
            {
                if (p.ID < lowest_id || lowest_id == 0)
                {
                    lowest_id = p.ID;
                }
            }

            // If it dosen't then ignore it, as its probably a left over from a superpeer we are
            // currently unregistering from.
            if (lowest_id != state.SuperPeerID)
            {
                return;
            }

            // Check for jumps.
            /*
            if (m_worldState != null)
            {
                foreach (SuperPeerWorldStatePlayerInfo newInfo in state.Peers)
                {
                    foreach (SuperPeerWorldStatePlayerInfo oldInfo in m_worldState.Peers)
                    {
                        if (newInfo.ClientID == oldInfo.ClientID)
                        {
                            float dx = Math.Abs(newInfo.Account.PeristentState.X - oldInfo.Account.PeristentState.X);
                            float dy = Math.Abs(newInfo.Account.PeristentState.Y - oldInfo.Account.PeristentState.Y);

                            if (dx > 26.0f || dy > 26.0f)
                            {
                                System.Console.WriteLine("WUT!");
                            }
                        }
                    }
                }
            }
            */

            m_worldState = state;

            foreach (SuperPeerWorldStatePlayerInfo peer in state.Peers)
            {
                if (peer.ClientID == m_clientID)
                {
                    m_account = peer.Account;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Broadcasts the current state of the world to all clients connected to this super peer.
        /// </summary>
        public void BroadcastWorldState()
        {
            SuperPeerWorldStatePacket packet = new SuperPeerWorldStatePacket();
            packet.SuperPeerID = m_superpeer_id;

            // Count peer states we will send.
            int count = 0;
            foreach (SuperPeerToClientConnection peer in m_registeredPeers)
            {
                if (peer.Account != null)
                    count++;
            }

            // Insert peer state information.
            packet.Peers = new SuperPeerWorldStatePlayerInfo[count];

            int index = 0;
            foreach (SuperPeerToClientConnection peer in m_registeredPeers)
            {
                if (peer.Account == null)
                {
                    continue;
                }

                packet.Peers[index].ClientID = peer.ClientID;
                packet.Peers[index].Account = peer.Account.Clone();
                packet.Peers[index].Account.Email = "";
                packet.Peers[index].Account.Password = "";
                index++;
            }

            // Send to all registered peers!
            foreach (SuperPeerToClientConnection peer in m_registeredPeers)
            {
                peer.Connection.SendPacket(packet);
            }
        }