/// <summary>
 /// Authenticate the client to the server.
 /// </summary>
 /// <param name="context">The server context sending the data.</param>
 /// <param name="request">Is in request mode.</param>
 /// <param name="data">The data from the client.</param>
 protected override void Authenticate(Net.Sockets.ServerContext context, bool request, string data)
 {
     // Has the credentials been Authorised.
     if (base.IsAuthenticated)
     {
         // If in request mode.
         if (request)
         {
             // Send a message to the server asking
             // to authenticate the credentials.
             context.SendToServer(Encoding.ASCII.GetBytes("AUTH" + (String.IsNullOrEmpty(data) ? "" : " " + data) + "\r\n"));
         }
         else
         {
             // If no data has been passed then
             // not authenticated.
             if (String.IsNullOrEmpty(data))
             {
                 // Send a message to the client.
                 context.Send("AUTH 400" + "\r\n");
             }
             else
             {
                 // Send a message to the client.
                 context.Send("AUTH 200" + (String.IsNullOrEmpty(data) ? "" : " " + data) + "\r\n");
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Authorise this connection to the server.
        /// </summary>
        /// <param name="context">The server context sending the data.</param>
        /// <param name="request">Is in request mode.</param>
        /// <param name="data">The data from the client.</param>
        private void AuthoriseConnection(Net.Sockets.ServerContext context, bool request, string data)
        {
            // If in request mode.
            if (request)
            {
                // If more attempts exits then send invalid credentials.
                if (_connectionAttempts <= MaxNumberOfConnectionAttempts)
                {
                    // Send a message to the server asking
                    // to authorise the connection.
                    context.SendToServer(Encoding.ASCII.GetBytes("ZORE" + (String.IsNullOrEmpty(data) ? "" : " " + data) + "\r\n"));
                }
                else
                {
                    // Sent to the server context a close command,
                    // too many authorise connection attempts.
                    context.SentFromServer(Encoding.ASCII.GetBytes("CLOS" + "\r\n"));
                }

                if (!base.IsAuthenticated)
                {
                    // Increment the connection attempt count.
                    _connectionAttempts++;
                }
            }
            else
            {
                // If data exists.
                if (!String.IsNullOrEmpty(data))
                {
                    // The client has been authenticated.
                    base.IsAuthenticated = true;
                    context.SetAuthenticated();

                    // Send a message to the client
                    // indicating that the client
                    // is allowed to join the conversation.
                    context.Send("JOIN 200" + "\r\n");
                }
                else
                {
                    // Send a message to the client
                    // indicating that the credentials
                    // are invalid.
                    context.Send("REJD 402 Authorise connection credentials are invalid." + "\r\n");
                }
            }
        }