Example #1
0
        public override VNetMessage Clone()
        {
            VNetMessageAcceptClient clone = (VNetMessageAcceptClient)base.Clone();

            clone.sessionUID = sessionUID;
            clone.clientUID  = clientUID;
            clone.role       = role;
            return(clone);
        }
Example #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());
            }
        }
Example #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);
        }