Ejemplo n.º 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");
            }
        }