Пример #1
0
        public bool RemoveClient(VNetClient client)
        {
            if (client == null)
            {
                return(false);
            }
            if (VNetCommon.SHOW_LOGS)
            {
                UnityEngine.Debug.Log("VNet: Removing client " + client.GetName());
            }

            // Callback when clietns are removed
            ClientRemovedCallback(client);

            // Check if we need to do a host migration
            m_netHost.CheckForHostLeft(client);

            // Remove from the client list and delete
            m_clientsByUID.Remove(client.GetUID());

            // disconnect it
            client.Disconnect();

            return(true);
        }
Пример #2
0
        // Listeners
        public void OnAcceptClientJoinRequest(VNetMessageAcceptClient accept)
        {
            // Not us
            if (accept.clientUID != VNet.Inst.GetUID())
            {
                return;
            }

            // Different session?
            if (accept.sessionUID != m_attemptingToJoinSession.sessionUID)
            {
                return;
            }

            // We aren't trying to join..
            if (m_sessionState != VNetSessionState.Connecting)
            {
                return;
            }

            // joined
            m_sessionState = VNetSessionState.InSession;

            // Add the host
            VNetSimpleClientData sc = m_attemptingToJoinSession.host;

            m_netHost.SetHostInfo(sc.uid, sc.role);

            VNetClient hostClient = GetClientByUID(sc.uid);

            hostClient.SetName(m_attemptingToJoinSession.host.name);
            hostClient.SetRole(sc.role);

            // add remaining clients
            for (SByte i = 0; i < m_attemptingToJoinSession.numClients; i++)
            {
                sc = m_attemptingToJoinSession.clients[i];

                // skip yourself
                if (sc.uid == VNet.Inst.GetUID())
                {
                    continue;
                }

                VNetClient client = AddClient(sc.uid, new IPEndPoint(sc.ip, sc.port));
                client.SetName(sc.name);
                client.SetRole(sc.role);
            }

            if (VNetCommon.SHOW_LOGS)
            {
                UnityEngine.Debug.Log("VNet: Joined session hosted by " + hostClient.GetName());
            }
        }