示例#1
0
 /// <summary>
 ///     Invoked when a game peer connected to us un-registers (or disconnects) its interest in this super peer.
 /// </summary>
 public void PeerUnregistered(SuperPeerToClientConnection peer)
 {
     if (!m_registeredPeers.Contains(peer))
     {
         throw new InvalidOperationException("Invalid peer, could not unregister. Peer is already unregistered.");
     }
     m_registeredPeers.Remove(peer);
     Logger.Info("Client #{0} unregistered from SuperPeer #{1}.", LoggerVerboseLevel.High, peer.ClientID, m_superpeer_id);
 }
示例#2
0
        /// <summary>
        ///     Processes a packet that has been recieved from a peer.
        /// </summary>
        /// <param name="packet">Packet that we recieved.</param>
        private void ProcessIncomingPacket(Packet packet)
        {
            // Peer is registering for events from a superpeer.
            if (packet is SuperPeerRegisterPacket)
            {
                SuperPeerRegisterPacket specificPacket = packet as SuperPeerRegisterPacket;

                SuperPeer peer = m_gameClient.FindSuperPeerByID(specificPacket.SuperPeerID);

                // Wait on arbitrator until we get information about the super-peer.
                while (peer == null)
                {
                    if (m_gameClient.ConnectedToArbitrator == false)
                    {
                        return;
                    }
                    m_gameClient.PollArbitrator();
                    peer = m_gameClient.FindSuperPeerByID(specificPacket.SuperPeerID);
                }

                if (peer != null)
                {
                    /*
                    foreach (SuperPeerToClientConnection p in m_superPeerConnections)
                    {
                        if (p.SuperPeer.ID == peer.ID &&
                            p.ClientID == specificPacket.ClientID)
                        {
                            p.BeginRegister();
                            return;
                        }
                    }*/

                    SuperPeerToClientConnection conn = new SuperPeerToClientConnection(m_gameClient, peer, m_connection);
                    conn.ClientID = specificPacket.ClientID;
                    m_superPeerConnections.Add(conn);

                    conn.BeginRegister();

                    return;
                }

                throw new Exception("Attempt to register to non-existing superpeer.");
            }

            // Peer is unregistering for events from a superpeer.
            else if (packet is SuperPeerUnregisterPacket)
            {
                SuperPeerUnregisterPacket specificPacket = packet as SuperPeerUnregisterPacket;

                bool found = false;
                foreach (SuperPeerToClientConnection conn in m_superPeerConnections)
                {
                    if (conn.SuperPeer.ID == specificPacket.SuperPeerID)
                    {
                        conn.BeginUnregister(specificPacket.ChangeZoneSuperPeerCount);
                        found = true;

                        // Do not break out of this loop, we may need to send packet to lingering connections as well!
                    }
                }

                if (found == false)
                {
                    throw new Exception("Attempt to unregister from non-existing superpeer.");
                }
            }

            // Peer is sending a super peer a message.
            else if ((packet as SuperPeerPacket) != null)
            {
                SuperPeerPacket specificPacket = packet as SuperPeerPacket;

                bool found = false;
                foreach (SuperPeerToClientConnection peer in m_superPeerConnections)
                {
                    if (peer.SuperPeer.ID == specificPacket.SuperPeerID)
                    {
                        peer.RecievedPacket(specificPacket);
                        found = true;

                        // Do not break out of this loop, we may need to send packet to lingering connections as well!
                    }
                }

                if (found == false)
                {
                    throw new Exception("Attempt to send-packet to non-existing superpeer.");
                }
            }
        }
示例#3
0
 /// <summary>
 ///     Invoked when a game peer connected to us registers its interest in this super peer.
 /// </summary>
 public void PeerRegistered(SuperPeerToClientConnection peer)
 {
     if (peer.Account == null ||
         m_registeredPeers.Contains(peer))
     {
         throw new InvalidOperationException("Invalid peer, could not register. Either account is null or peer is already registered.");
     }
     m_registeredPeers.Add(peer);
     Logger.Info("New client #{0} registered to SuperPeer #{1}.", LoggerVerboseLevel.High, peer.ClientID, m_superpeer_id);
 }