Beispiel #1
0
        public void _Deserialize(LobbyHostIntroductionPacket pkt, MemoryStream m)
        {
            pkt.myPlayerId = Data_serializers_const.ser_M_liteIntSerializer.Deserialize(m);
            int length_activePlayerIds = m.ReadByte();

            pkt.activePlayerIds = new Int32[length_activePlayerIds];
            int i_activePlayerIds = 0;

            for (i_activePlayerIds = 0; (i_activePlayerIds < length_activePlayerIds); i_activePlayerIds = (i_activePlayerIds + 1))
            {
                pkt.activePlayerIds[i_activePlayerIds] = Data_serializers_const.ser_M_liteIntSerializer.Deserialize(m);
            }
            int length_preplacedInstanceIds = m.ReadByte();

            pkt.preplacedInstanceIds = new Int64[length_preplacedInstanceIds];
            int i_preplacedInstanceIds = 0;

            for (i_preplacedInstanceIds = 0; (i_preplacedInstanceIds < length_preplacedInstanceIds); i_preplacedInstanceIds = (i_preplacedInstanceIds + 1))
            {
                pkt.preplacedInstanceIds[i_preplacedInstanceIds] = Data_serializers_const.ser_M_liteLongSerializer.Deserialize(m);
            }
            int length_instanceIdToEntity = m.ReadByte();

            pkt.instanceIdToEntity = new Int32[length_instanceIdToEntity];
            int i_instanceIdToEntity = 0;

            for (i_instanceIdToEntity = 0; (i_instanceIdToEntity < length_instanceIdToEntity); i_instanceIdToEntity = (i_instanceIdToEntity + 1))
            {
                pkt.instanceIdToEntity[i_instanceIdToEntity] = Data_serializers_const.ser_M_liteIntSerializer.Deserialize(m);
            }
        }
Beispiel #2
0
        public void _Serialize(LobbyHostIntroductionPacket pkt, MemoryStream m)
        {
            byte[] myPlayerId = Data_serializers_const.ser_M_liteIntSerializer.Serialize(pkt.myPlayerId);
            m.Write(myPlayerId, 0, myPlayerId.Length);
            m.WriteByte(((byte)(pkt.activePlayerIds.Length)));
            int i_activePlayerIds = 0;

            for (i_activePlayerIds = 0; (i_activePlayerIds < pkt.activePlayerIds.Length); i_activePlayerIds = (i_activePlayerIds + 1))
            {
                byte[] byteArr = Data_serializers_const.ser_M_liteIntSerializer.Serialize(pkt.activePlayerIds[i_activePlayerIds]);
                m.Write(byteArr, 0, byteArr.Length);
            }
            m.WriteByte(((byte)(pkt.preplacedInstanceIds.Length)));
            int i_preplacedInstanceIds = 0;

            for (i_preplacedInstanceIds = 0; (i_preplacedInstanceIds < pkt.preplacedInstanceIds.Length); i_preplacedInstanceIds = (i_preplacedInstanceIds + 1))
            {
                byte[] byteArr = Data_serializers_const.ser_M_liteLongSerializer.Serialize(pkt.preplacedInstanceIds[i_preplacedInstanceIds]);
                m.Write(byteArr, 0, byteArr.Length);
            }
            m.WriteByte(((byte)(pkt.instanceIdToEntity.Length)));
            int i_instanceIdToEntity = 0;

            for (i_instanceIdToEntity = 0; (i_instanceIdToEntity < pkt.instanceIdToEntity.Length); i_instanceIdToEntity = (i_instanceIdToEntity + 1))
            {
                byte[] byteArr = Data_serializers_const.ser_M_liteIntSerializer.Serialize(pkt.instanceIdToEntity[i_instanceIdToEntity]);
                m.Write(byteArr, 0, byteArr.Length);
            }
        }
Beispiel #3
0
        public static void SendLobbyHostIntroductionPacket(LobbyHostIntroductionPacket pkt, [Optional()][DefaultParameterValue(-1)] int connectionId)
        {
            MemoryStream m = new MemoryStream();

            m.WriteByte(8);
            LiteNetworking.Networking.localPacketPlayer = LiteNetworking.LobbyConnector.ConvertConnectionToPlayer(connectionId);
            ConstRefs.mirror_LobbyHostIntroductionPacket._Serialize(pkt, m);
            Networking.TransmitPacket(m, connectionId);
        }
Beispiel #4
0
        public static IEnumerator SendPacketsLater(int connectionId)
        {
            yield return(new WaitForSeconds(0.1f));

            Debug.Log("OnPlayerJoined");
            //hostId = connectionId;

            // Send the introduction packet to this client
            Debug.Log("Sending out the intro packet");
            LobbyHostIntroductionPacket introPkt = new LobbyHostIntroductionPacket();

            connectedClients.Add(connectionId);
            introPkt.myPlayerId = nextPlayerIndex++;
            List <int> activePlayers = new List <int>();

            foreach (int i in connectedClients)
            {
                if (i != connectionId)
                {
                    activePlayers.Add(connectionToPlayer[i]);
                }
            }
            introPkt.activePlayerIds         = activePlayers.ToArray();
            connectionToPlayer[connectionId] = nextPlayerIndex - 1;

            SpawnEntityPacket epkt = new SpawnEntityPacket();

            foreach (NetworkedEntity e in EntityManager.ents.Values)
            {
                if (e.GetComponent <LitePlayer>() == null)
                {
                    epkt.authority = e.GetComponent <NetworkAuthority>()?.owner?.id ?? 0;
                    epkt.entityId  = (int)e.EntityIndex;
                    epkt.prefabId  = e.GetComponent <UniqueId>().prefabId;
                    epkt.uniqueId  = e.GetComponent <UniqueId>().uniqueId;
                    epkt.position  = e.transform.position;
                    PacketSender.SendSpawnEntityPacket(epkt, connectionId);
                }
            }


            Debug.Log("Spawining player prefab");
            SpawnPlayerPrefab(false, (nextPlayerIndex - 1));

            Debug.Log("Actually sending the packet now");
            introPkt.instanceIdToEntity   = new int[0];
            introPkt.preplacedInstanceIds = new long[0];
            LiteNetworkingGenerated.PacketSender.SendLobbyHostIntroductionPacket(introPkt, connectionId);
            Debug.Log("Done sending packet");
            // Send the player joined packet to all other clients
            foreach (int i in connectedClients)
            {
                if (i != connectionId)
                {
                    LobbyNewPlayerPacket pkt = new LobbyNewPlayerPacket();
                    pkt.newPlayerId = (nextPlayerIndex - 1);
                    Debug.Log("Sending NP Packet");
                    PacketSender.SendLobbyNewPlayerPacket(pkt, i);
                    Debug.Log("Done Sending NP Packet");
                }
            }
            Debug.Log("Done SendPacketsLater");
        }