Ejemplo n.º 1
0
 private void RaiseOnAgentConnectedEvent(object sender, ConnectionStatusEventArgs e)
 {
     if (OnConnected != null)
     {
         OnConnected(this, e);
     }
 }
Ejemplo n.º 2
0
 private void RaiseAgentOnDisconnectingEvent(object sender, ConnectionStatusEventArgs e)
 {
     if (OnDisconnecting != null)
     {
         OnDisconnecting(this, e);
     }
 }
Ejemplo n.º 3
0
        private void Agent_OnConnectionEstablished(object sender, ConnectionStatusEventArgs e)
        {
            Model.LogMessages.Add("Connection requested: " + e.Connection.RemoteEndPoint.Address + ":" + e.Connection.RemoteEndPoint.Port);

            // Send a request for the user's username.
            RequestPacket packet = new RequestPacket(PacketRequestTypeEnum.Username);
            Agent.SendPacket(packet, e.Connection, NetDeliveryMethod.ReliableUnordered);
        }
Ejemplo n.º 4
0
 private void Agent_OnDisconnected(object sender, ConnectionStatusEventArgs e)
 {
     Model.ConnectionUsernamesDictionary.Remove(e.Connection);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Reads every message in the queue and returns a list of data messages.
        /// Other message types just write a Console note.
        /// </summary>
        /// <returns></returns>
        private List<NetIncomingMessage> CheckForMessages()
        {
            _incomingMessages.Clear();
            NetIncomingMessage incomingMessage;

            while ((incomingMessage = _peer.ReadMessage()) != null)
            {
                switch (incomingMessage.MessageType)
                {
                    case NetIncomingMessageType.DiscoveryRequest:
                        _peer.SendDiscoveryResponse(null, incomingMessage.SenderEndPoint);
                        break;
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.ErrorMessage:
                        break;
                    case NetIncomingMessageType.StatusChanged:
                    {

                        NetConnectionStatus status = (NetConnectionStatus)incomingMessage.ReadByte();
                        ConnectionStatusEventArgs e = new ConnectionStatusEventArgs
                        {
                            Connection = incomingMessage.SenderConnection
                        };

                        if (status == NetConnectionStatus.Connected)
                        {
                            if (!Object.ReferenceEquals(OnConnected, null))
                            {
                                OnConnected(this, e);
                            }
                        }
                        else if (status == NetConnectionStatus.Disconnecting)
                        {
                            if (!Object.ReferenceEquals(OnDisconnecting, null))
                            {
                                OnDisconnecting(this, e);
                            }
                        }
                        else if (status == NetConnectionStatus.Disconnected)
                        {
                            if (!Object.ReferenceEquals(OnDisconnected, null))
                            {
                                OnDisconnected(this, e);
                            }
                        }

                        break;
                    }
                    case NetIncomingMessageType.Data:
                        incomingMessage.Decrypt(Encryption);
                        _incomingMessages.Add(incomingMessage);
                        break;
                    default:
                        // unknown message type
                        break;
                }
            }
            return _incomingMessages;
        }