Beispiel #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);
        }
Beispiel #2
0
        public void OnClientsWantsToLeave(VNetMessageLeaveSession leaveRequest)
        {
            VNetMessageLeaveSessionConfirm confirm = new VNetMessageLeaveSessionConfirm();
            VNetClient client = leaveRequest._client;

            confirm.clientUID = client.GetUID();
            client.SendNetMessage(confirm, false);
            client.SendPacketToClient();
            RemoveClient(client);
        }
Beispiel #3
0
        public void OnClientJoinRequest(VNetMessageJoinSession joinRequest)
        {
            // If i'm not the host, ignore this
            if (LocalIsHost() == false)
            {
                return;
            }

            // If this is for a separate session, ignore
            UInt64 sessionUID = VNetSession.Inst.GetSessionUID();

            if (joinRequest.sessionUID != sessionUID)
            {
                return;
            }

            // Could be a dup, ignore if if that's the case
            if (VNetSession.Inst.GetClientByUID(joinRequest._packet.header.clientUID) != null)
            {
                return;
            }

            // Add this client
            VNetMessageNewClient nmc = new VNetMessageNewClient();

            nmc.clientData        = new VNetSimpleClientData();
            nmc.clientData.active = 1;
            nmc.clientData.ip     = joinRequest._packet.IP_Port.Address;
            nmc.clientData.port   = joinRequest._packet.IP_Port.Port;
            nmc.clientData.uid    = joinRequest._packet.header.clientUID;
            nmc.clientData.name   = joinRequest.userName;
            nmc.clientData.role   = joinRequest.role;

            nmc.sessionUID = sessionUID;
            VNet.Inst.SendToLobby(nmc, true);

            // Add the client to the local list
            VNetClient client = VNetSession.Inst.AddClient(joinRequest._packet.header.clientUID, joinRequest._packet.IP_Port);

            client.SetName(joinRequest.userName);
            client.SetRole(joinRequest.role);

            // Accept this client
            VNetMessageAcceptClient ac = new VNetMessageAcceptClient();

            ac.clientUID  = client.GetUID();
            ac.sessionUID = sessionUID;
            ac.role       = joinRequest.role;
            client.SendNetMessage(ac, true);
        }
Beispiel #4
0
        // Functions
        public void CheckForHostLeft(VNetClient client)
        {
            if (client.GetUID() == m_hostUID)
            {
                if (VNetCommon.SHOW_LOGS)
                {
                    UnityEngine.Debug.Log("VNet: The host left the session.");
                }

                // In the future, become the host based on some internal value
                Disconnect();
                VNetSession.Inst.DisconnectAll();
            }
        }
Beispiel #5
0
        public void UpdateClients()
        {
            List <VNetClient> disconnectedClients = new List <VNetClient>();

            foreach (KeyValuePair <UInt64, VNetClient> kvp in m_clientsByUID)
            {
                VNetClient client = kvp.Value;
                client.Update();
                if (client.CheckForTimeout())
                {
                    disconnectedClients.Add(client);
                }
            }

            foreach (VNetClient client in disconnectedClients)
            {
                m_clientsByUID.Remove(client.GetUID());
            }
        }