示例#1
0
 /// <summary>
 /// Use this method to recieve packets from other clients
 /// </summary>
 public void ReadPackets()
 {
     if (SteamNetworking.IsP2PPacketAvailable())
     {
         var nullableP2Packet = SteamNetworking.ReadP2PPacket();
         if (nullableP2Packet != null)
         {
             var p2PPacket = nullableP2Packet.Value;
             var playerId  = p2PPacket.SteamId.Value;
             if (Client.steamID != playerId)
             {
                 var packetData       = p2PPacket.Data;
                 var packetsToExecute = PacketGetter.GetPacketsByData(packetData, _protocol, playerId);
                 var packetsCount     = packetsToExecute.Length;
                 for (var i = 0; i < packetsCount; i++)
                 {
                     PacketExecutor.ExecutePacket(packetsToExecute[i], false);
                 }
             }
         }
     }
 }
示例#2
0
        /// <summary>
        /// Use this method to send packets to other clients
        /// WARNING! Be careful in sending packets with variables, be sure that you pass the right type values
        /// </summary>
        public void SendPacket <T>(params object[] packetVariables) where T : Packet
        {
            var packet = _protocol.GetPacketByType(typeof(T));

            packet.SetPlayer(Client.steamID);

            if (packetVariables.Length > 0)
            {
                PacketBinder.SetVariablesToPacket(packet, packetVariables);
            }

            PacketExecutor.ExecutePacket(packet, true);

            switch (packet.SendType)
            {
            case SendType.Unreliable:
                PacketSetter.SetPacketToCollection(packet, _unreliablePackets);
                break;

            case SendType.Reliable:
                PacketSetter.SetPacketToCollection(packet, _reliablePackets);
                break;
            }
        }