コード例 #1
0
ファイル: VNetMessage.cs プロジェクト: wardinsky/VNet
        public override VNetMessage Clone()
        {
            VNetMessageNewClient clone = (VNetMessageNewClient)base.Clone();

            clone.clientData = VNetSimpleClientData.ComponentCopy(clientData);
            clone.sessionUID = sessionUID;
            clone.role       = role;
            return(clone);
        }
コード例 #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());
            }
        }
コード例 #3
0
ファイル: VNetClient.cs プロジェクト: wardinsky/VNet
        // Identification
        public void SetClientData(VNetSimpleClientData clientData, int clientID)
        {
            if (clientData == null)
            {
                SetClientRaw(0, null);
                SetPlayerIndex(clientID);
                return;
            }

            SetClientRaw(clientData.uid, new IPEndPoint(clientData.ip, clientData.port));
            SetName(clientData.name);
            SetPlayerIndex(clientID);
        }
コード例 #4
0
        public void UpdateData(VNetMessageSessionAvailable netMessage)
        {
            host      = VNetSimpleClientData.ComponentCopy(netMessage.host);
            host.ip   = netMessage._packet.IP_Port.Address;
            host.port = netMessage._packet.IP_Port.Port;

            numClients = netMessage.numClients;

            for (int i = 0; i < numClients; i++)
            {
                clients[i] = VNetSimpleClientData.ComponentCopy(netMessage.client[i]);
            }

            sessionUID     = netMessage.UID;
            discoveredTime = VNetTimer.Inst.GetSystemTimeNow();
        }
コード例 #5
0
        static public VNetSimpleClientData ComponentCopy(VNetSimpleClientData rhs)
        {
            if (rhs == null)
            {
                return(null);
            }

            VNetSimpleClientData data = new VNetSimpleClientData();

            data.uid    = rhs.uid;
            data.ip     = rhs.ip;
            data.port   = rhs.port;
            data.active = rhs.active;
            data.name   = rhs.name;
            data.role   = rhs.role;
            return(data);
        }
コード例 #6
0
ファイル: VNetMessage.cs プロジェクト: wardinsky/VNet
        public override VNetMessage Clone()
        {
            VNetMessageSessionAvailable clone = (VNetMessageSessionAvailable)base.Clone();

            clone.UID = UID;
            clone.sessionAvaliable = sessionAvaliable;
            clone.numClients       = numClients;

            // copy client data
            clone.host = VNetSimpleClientData.ComponentCopy(host);
            for (int i = 0; i < clone.client.Length; i++)
            {
                clone.client[i] = VNetSimpleClientData.ComponentCopy(client[i]);
            }

            return(clone);
        }
コード例 #7
0
ファイル: VNetMessage.cs プロジェクト: wardinsky/VNet
        public override void FromBytes(BinaryReader reader)
        {
            base.FromBytes(reader);

            UID = reader.ReadUInt64();
            sessionAvaliable = reader.ReadInt32();
            numClients       = reader.ReadSByte();

            host = new VNetSimpleClientData();
            host.FromBytes(reader);
            for (int i = 0; i < numClients; i++)
            {
                if (client [i] == null)
                {
                    client [i] = new VNetSimpleClientData();
                }
                client [i].FromBytes(reader);
            }
        }
コード例 #8
0
 public VNetOpenSession()
 {
     clients = new VNetSimpleClientData[VNetCommon.NET_MAX_CLIENTS - 1];
 }
コード例 #9
0
ファイル: VNetMessage.cs プロジェクト: wardinsky/VNet
 public VNetMessageSessionAvailable() : base("VNetMessageSessionAvaliable")
 {
     client = new VNetSimpleClientData[VNetCommon.NET_MAX_CLIENTS - 1];
 }