/// <summary>
 /// Sends a packet to the currently connected server.
 /// </summary>
 /// <param name="packet"></param>
 /// <param name="deliveryMethod"></param>
 public void SendPacket(PacketBase packet, NetDeliveryMethod deliveryMethod)
 {
     Agent.SendPacket(packet, ServerConnection, deliveryMethod);
 }
 public PacketReceivedEventArgs(PacketBase packet)
 {
     this.Packet = packet;
 }
Exemple #3
0
 /// <summary>
 /// Writes a packet's properties to an outgoing message.
 /// </summary>
 /// <param name="packet"></param>
 private void WriteMessage(PacketBase packet)
 {
     MemoryStream stream = new MemoryStream();
     Serializer.Serialize<PacketBase>(stream, packet); // Protobuf serialization
     _outgoingMessage.Write(stream.ToArray());
 }
        /// <summary>
        /// Handles processing packets depending on their type.
        /// If a packet recieved does not match one of the supported types,
        /// it will be dropped.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="factory"></param>
        private void ProcessPacket(PacketBase packet)
        {
            Type packetType = packet.GetType();

            if (packetType == typeof(RequestPacket))
            {
                ProcessRequest(packet as RequestPacket);
            }
            else if (packetType == typeof(FileRequestPacket))
            {
                ProcessFileTransferRequest(packet as FileRequestPacket);
            }
            else if (packetType == typeof(UsernamePacket))
            {
                ProcessUsernamePacket(packet as UsernamePacket);
            }
            else if (packetType == typeof(DeleteCharacterPacket))
            {
                ProcessDeleteCharacterRequest(packet as DeleteCharacterPacket);
            }
            else if (packetType == typeof(NewCharacterPacket))
            {
                ProcessCharacterCreationRequest(packet as NewCharacterPacket);
            }
        }
Exemple #5
0
 /// <summary>
 /// Sends a packet to the specified connection using the specified delivery method.
 /// </summary>
 /// <param name="packet">The packet to send.</param>
 /// <param name="connection">The connection to send the packet to.</param>
 /// <param name="deliveryMethod">The delivery method used for the delivery.</param>
 public void SendPacket(PacketBase packet, NetConnection connection, NetDeliveryMethod deliveryMethod)
 {
     WriteMessage(packet);
     SendMessage(connection, deliveryMethod);
 }