Example #1
0
        /// <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 virtual void Authenticate(Nequeo.Net.Sockets.ServerContext context, bool request, string data)
        {
            if (!String.IsNullOrEmpty(data))
            {
                // Get the intentity.
                string uniqueClientIdentifier = data.Trim();

                // Assign the client data.
                context.UniqueIdentifier = uniqueClientIdentifier;

                // If an identifier exists.
                if (!String.IsNullOrEmpty(context.UniqueIdentifier))
                {
                    // The client has been authenticated.
                    context.SetAuthenticated();

                    // Send a message to the client
                    // indicating that the client
                    // is allowed to join the conversation.
                    context.Send("JOIN 200 " + uniqueClientIdentifier + "\r\n");
                }
                else
                {
                    // Send a message to the client
                    // indicating that the credentials
                    // are invalid.
                    context.Send("REJD 402 Credentials have been suspended or invalid." + "\r\n");
                }
            }
            else
            {
                // Send an error to the client.
                context.Send("ERRO 500 No data" + "\r\n");
            }
        }
Example #2
0
        /// <summary>
        /// Data sent from the server context to the server.
        /// </summary>
        /// <param name="context">The server context sending the data.</param>
        /// <param name="command">The command sent from the server context to the server.</param>
        /// <param name="data">The data sent from the server context to the server.</param>
        /// <returns>True if the command was found and executed; else false.</returns>
        public bool ReceiveFromServer(Nequeo.Net.Sockets.ServerContext context, string command, string data)
        {
            // Delay.
            System.Threading.Thread.Sleep(10);

            // Process the command.
            switch (command.ToUpper())
            {
            case "AUTH":
                // Send a message to the client
                // indicating that the credentials
                // are valid.
                Authenticate(context, false, data);
                return(true);

            case "AREJ":
                // Send a message to the client
                // indicating that the credentials
                // are invalid.
                context.Send("REJD 401 Credentials are invalid." + "\r\n");
                return(true);

            case "ERRO":
                // Send an error to the client.
                context.Send("ERRO 500" + (String.IsNullOrEmpty(data) ? "" : " " + data) + "\r\n");
                return(true);

            default:
                return(ExecuteCommand(context, command, false, data));
            }
        }
Example #3
0
 /// <summary>
 /// Execute the request.
 /// </summary>
 /// <param name="context">The server context sending the data.</param>
 /// <param name="command">The command sent from the server context to the server.</param>
 /// <param name="request">Is in request mode; else returning data.</param>
 /// <param name="data">The data from the client.</param>
 /// <param name="isDirectServerRequest">Is the request direct from the server.</param>
 private void ExecuteRequest(Nequeo.Net.Sockets.ServerContext context, string command, bool request, string data, bool isDirectServerRequest = false)
 {
     // Has the credentials been authenticated.
     if (_isAuthenticated)
     {
         // If in request mode.
         if (request)
         {
             // Send a message to the server.
             context.SendToServer(Encoding.ASCII.GetBytes(command + (String.IsNullOrEmpty(data) ? "" : " " + data) + "\r\n"));
         }
         else
         {
             // If not direct from server.
             if (!isDirectServerRequest)
             {
                 // Send a message to the client.
                 context.Send(command + " 200" + (String.IsNullOrEmpty(data) ? "" : " " + data) + "\r\n");
             }
         }
     }
 }