Пример #1
0
 /// <summary>
 /// This method triggers an event, when we receive a new packet.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnPacketReceived(PacketEventArgs e)
 {
     // Invoke the event; called whenever we receive a packet
     if (PacketReceivedEvent != null)
         PacketReceivedEvent(this, e);
 }
Пример #2
0
 /// <summary>
 /// Always called, when the server reveives a new packet.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void PacketReceived(object sender, PacketEventArgs e)
 {
     // Switch on message types
     switch (e.Packet.Type)
     {
         case PacketType.ClientLoginInformation:
             // On login
             SetClientData(e.Packet);
             break;
         case PacketType.ContactListRequest:
             // Send a partial contact list
             SendContactList(e.Packet);
             break;
         case PacketType.ContactRequest:
             // Send detailled contact information
             SendContact(e.Packet);
             break;
         case PacketType.Route:
             // Route a message
             Send(e.Packet);
             break;
         case PacketType.Broadcast:
             // Broadcast to all
             BroadCast(e.Packet);
             break;
         default:
             // Unknown type
             LogConsole("unknown message type.", e.Packet.Source);
             break;
     }
 }
Пример #3
0
        /// <summary>
        /// This method triggers an event, when we receive a new packet. On
        /// Windows Forms we maybe have to invoke.
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnPacketReceived(PacketEventArgs e)
        {
            if (PacketReceivedEvent != null)
            {
                Control target = PacketReceivedEvent.Target as Control;
                if (target != null && target.InvokeRequired)
                {
                    target.Invoke(PacketReceivedEvent, new object[] { this, e });

                }
                else
                {
                    PacketReceivedEvent(this, e);
                }
            }
        }