Example #1
0
        /// <summary>
        /// Registers the packet.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="type">The type.</param>
        public static void RegisterPacket(PacketIDs id, Type type) {
            if ( type == null )
                throw new ArgumentNullException("type", "type is null");

            if ( type != typeof(Packet) && !type.IsAbstract )
                throw new ArgumentException("Type must be a packet");

            if ( PacketMap.ContainsKey(id) )
                throw new ArgumentException("Packet " + id + " is already registered");

            PacketMap.Add(id, type);
        }
Example #2
0
        /// <summary>
        /// Gets the packet from the packet id.
        /// </summary>
        /// <param name="packetId">The packet id.</param>
        /// <returns>A packet if the packetid is registered. If anything goes wrong nothing will be returned.</returns> (badpokerface)
        public static Packet GetPacket(PacketIDs packetId) {

            if ( !PacketMap.ContainsKey(packetId) )
                throw new ArgumentException("Packet id is not registered");

            Type type = PacketMap[packetId];

            try {
                return Activator.CreateInstance(type) as Packet;
            }
            catch {
                return null;
            }
        }
Example #3
0
        /// <summary>
        /// Gets the packet from the packet id.
        /// </summary>
        /// <param name="packetId">The packet id.</param>
        /// <returns>A packet if the packetid is registered. If anything goes wrong nothing will be returned.</returns> (badpokerface)
        public static Packet GetPacket(PacketIDs packetId)
        {
            if (!PacketMap.ContainsKey(packetId))
            {
                throw new ArgumentException("Packet id is not registered");
            }

            Type type = PacketMap[packetId];

            try {
                return(Activator.CreateInstance(type) as Packet);
            }
            catch {
                return(null);
            }
        }
Example #4
0
        /// <summary>
        /// Registers the packet.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="type">The type.</param>
        public static void RegisterPacket(PacketIDs id, Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type", "type is null");
            }

            if (type != typeof(Packet) && !type.IsAbstract)
            {
                throw new ArgumentException("Type must be a packet");
            }

            if (PacketMap.ContainsKey(id))
            {
                throw new ArgumentException("Packet " + id + " is already registered");
            }

            PacketMap.Add(id, type);
        }
Example #5
0
    /// <summary>
    /// Method is called when data is received from the client
    /// </summary>
    /// connection - client's native network id
    /// data - received data from client
    /// data[0] - packet id
    public override void OnReceivedData(ulong connection_guid, ArraySegment <byte> data)
    {
        PacketIDs packet_id = (PacketIDs)data.Array[0];

        switch (packet_id)
        {
        case PacketIDs.CLIENT_DATA:

            packet_ClientData.Unpack(server_peer, data);
            OnReceivedClientData(connection_guid, packet_ClientData);


            server_peer.GetPingAverage(connection_guid);
            server_peer.GetPingLast(connection_guid);
            server_peer.GetPingLowest(connection_guid);


            break;
        }
    }
    public override void OnReceivedData(ArraySegment <byte> data)
    {
        PacketIDs packet_id = (PacketIDs)data.Array[0];

        switch (packet_id)
        {
        case PacketIDs.CLIENT_DATA_REQUEST:


            packet_ClientData.CreatePacket(client_peer, (byte)PacketIDs.CLIENT_DATA);
            packet_ClientData.BeginWritePacket();
            packet_ClientData.username = UserNameField.text;
            packet_ClientData.version  = Application.version;
            packet_ClientData.EndWritePacket();
            packet_ClientData.SendToServer();

            break;

        case PacketIDs.CLIENT_DATA:
            packet_ClientData.Unpack(client_peer, data);
            Debug.Log("Client data processed by server :)  username=" + packet_ClientData.username);
            break;
        }
    }
Example #7
0
 public PacketBase(PacketIDs ids)
 {
     messageID = (short)ids;
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Packet"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 public Packet(PacketIDs id) {
     PacketID = id;
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Packet"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 public Packet(PacketIDs id)
 {
     PacketID = id;
 }