コード例 #1
0
ファイル: ClientWorker.cs プロジェクト: nalamar/GaMan4
 /// <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
ファイル: Server.cs プロジェクト: nalamar/GaMan4
 /// <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
ファイル: Client.cs プロジェクト: nalamar/GaMan4
        /// <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);
                }
            }
        }