Пример #1
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));
            }
        }
Пример #2
0
        /// <summary>
        /// Store the contacts online.
        /// </summary>
        /// <param name="storeKey">The store key value.</param>
        /// <param name="contactsOnline">The contacts online list; else null to get contacts online.</param>
        /// <param name="context">The server context sending the data.</param>
        public void StoreContactsOnline(ActionStoreKey storeKey, string[] contactsOnline,
                                        Nequeo.Net.Sockets.ServerContext context = null)
        {
            lock (_lockContactsOnlineStore)
            {
                if (contactsOnline != null)
                {
                    // Assign the list.
                    _contactsOnline[storeKey.ToString()] = contactsOnline;
                }
                else
                {
                    switch (storeKey)
                    {
                    case ActionStoreKey.ASK1:
                        ExecuteRequest(context, "A1CO", true, "");
                        break;

                    case ActionStoreKey.ASK2:
                        ExecuteRequest(context, "A2CO", true, "");
                        break;
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Store the contacts online hosts.
        /// </summary>
        /// <param name="storeKey">The store key value.</param>
        /// <param name="contactsOnlineHosts">The contacts online list; else null to get contacts online.</param>
        /// <param name="context">The server context sending the data.</param>
        /// <param name="uniqueIdentifiers">The unique client identifiers.</param>
        public void StoreContactsOnlineHosts(ActionStoreKey storeKey, string[] contactsOnlineHosts,
                                             Nequeo.Net.Sockets.ServerContext context = null, string[] uniqueIdentifiers = null)
        {
            lock (_lockContactsOnlineHostsStore)
            {
                if (contactsOnlineHosts != null)
                {
                    // Assign the list.
                    _contactsOnlineHosts[storeKey.ToString()] = contactsOnlineHosts;
                }
                else
                {
                    switch (storeKey)
                    {
                    case ActionStoreKey.ASK1:
                        ExecuteRequest(context, "Z1GS", true, String.Join(";", uniqueIdentifiers));
                        break;

                    case ActionStoreKey.ASK2:
                        ExecuteRequest(context, "Z2GS", true, String.Join(";", uniqueIdentifiers));
                        break;
                    }
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Authenticate the user.
 /// </summary>
 /// <param name="context">The server context sending the data.</param>
 /// <param name="username">The user name.</param>
 /// <param name="password">The password.</param>
 /// <param name="domain">The domain.</param>
 /// <param name="applicationName">The application name.</param>
 public void ValidateUser(Nequeo.Net.Sockets.ServerContext context, string username, string password, string domain = null, string applicationName = "All")
 {
     ExecuteRequest(context, "AUTH", true,
                    username + "|" + password + "|" +
                    (String.IsNullOrEmpty(domain) ? "" : domain) + "|" +
                    (String.IsNullOrEmpty(applicationName) ? "All" : applicationName));
 }
Пример #5
0
 /// <summary>
 /// Add a new client.
 /// </summary>
 /// <param name="context">The server context sending the data.</param>
 /// <param name="hostName">The host machine the client must connect to.</param>
 /// <param name="active">Is the communication currenlty active.</param>
 /// <param name="communicationToken">The common token used for communication.</param>
 /// <remarks>This does not relay back to the client.</remarks>
 public void AddClient(Nequeo.Net.Sockets.ServerContext context, string hostName, bool active = false, string communicationToken = "")
 {
     ExecuteRequest(context, "ZXAC", true,
                    hostName + "|" +
                    active.ToString() + "|" +
                    (String.IsNullOrEmpty(communicationToken) ? "" : communicationToken));
 }
Пример #6
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");
            }
        }
Пример #7
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>
        new 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 "ZORE":
                // Authorise this connection to the server.
                AuthoriseConnection(context, false, data);
                return(true);

            default:
                return(base.ReceiveFromServer(context, command, data));
            }
        }
        /// <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>
        new public bool Receiver(Nequeo.Net.Sockets.ServerContext context, string command, string data)
        {
            // Delay.
            System.Threading.Thread.Sleep(10);

            // Process the command.
            switch (command.ToUpper())
            {
            case "AORE":
                // Authorise this connection to the server.
                AuthoriseConnection(context, true, data);
                return(true);

            case "AUTH":
                // Attempt to autherticate the credentials.
                Authenticate(context, true, data);
                return(true);

            default:
                return(base.Receiver(context, command, data));
            }
        }
Пример #9
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");
             }
         }
     }
 }
Пример #10
0
 /// <summary>
 /// Get the host details for the identity.
 /// </summary>
 /// <param name="context">The server context sending the data.</param>
 /// <remarks>This does not relay back to the client.</remarks>
 public void GetHost(Nequeo.Net.Sockets.ServerContext context)
 {
     ExecuteRequest(context, "ZXGH", true, "");
 }
Пример #11
0
 /// <summary>
 /// Set the online status of the client, no callback.
 /// </summary>
 /// <param name="context">The server context sending the data.</param>
 /// <param name="status">The status of the client.</param>
 public void SetClientOnlineStatusNoCallback(Nequeo.Net.Sockets.ServerContext context, string status)
 {
     ExecuteRequest(context, "AXXS", true, status);
 }
Пример #12
0
 /// <summary>
 /// Set the online status of the client.
 /// </summary>
 /// <param name="context">The server context sending the data.</param>
 /// <param name="status">The status of the client.</param>
 public void SetClientOnlineStatus(Nequeo.Net.Sockets.ServerContext context, OnlineStatus status)
 {
     ExecuteRequest(context, "AXSO", true, status.ToString());
 }
Пример #13
0
 /// <summary>
 /// Logoff the client.
 /// </summary>
 /// <param name="context">The server context sending the data.</param>
 /// <remarks>This does not relay back to the client.</remarks>
 public void LogOff(Nequeo.Net.Sockets.ServerContext context)
 {
     ExecuteRequest(context, "AXLO", true, "");
 }
Пример #14
0
 /// <summary>
 /// Get all the current client contacts that are currently online.
 /// </summary>
 /// <param name="context">The server context sending the data.</param>
 /// <remarks>This does not relay back to the client.</remarks>
 public void GetClientContactsOnline(Nequeo.Net.Sockets.ServerContext context)
 {
     ExecuteRequest(context, "AXCO", true, "");
 }
Пример #15
0
 /// <summary>
 /// Remove a new client.
 /// </summary>
 /// <param name="context">The server context sending the data.</param>
 /// <param name="hostName">The host machine the client must connect to.</param>
 /// <param name="activeConnections">The number of active connection using this client.</param>
 /// <remarks>This does not relay back to the client.</remarks>
 public void RemoveClient(Nequeo.Net.Sockets.ServerContext context, string hostName, int activeConnections = 0)
 {
     ExecuteRequest(context, "ZXCR", true,
                    hostName + "|" +
                    activeConnections);
 }
Пример #16
0
        /// <summary>
        /// Execute the command.
        /// </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.</param>
        /// <param name="data">The data from the client.</param>
        /// <returns>True if the command was found and executed; else false.</returns>
        private bool ExecuteCommand(Nequeo.Net.Sockets.ServerContext context, string command, bool request, string data)
        {
            // Delay.
            System.Threading.Thread.Sleep(10);

            // Process the command.
            switch (command.ToUpper())
            {
            case "AXCO":
                // Attempt to get all the current client contacts
                // that are currently online.
                ExecuteRequest(context, command, request, data, true);
                return(true);

            case "ACOO":
                // Attempt to get all the current client contacts
                // that are currently online.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ACLD":
                // Get all the client contacts that are online and logged on
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ASUS":
                // Client suspended.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "AACO":
                // Add a new contact for this client.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "AACL":
                // Add a new client.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ACEX":
                // Does the client exist.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "AFDP":
                // Find a person that could potentally be a contact.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ACAC":
                // Get the client active connections count.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ACAN":
                // Get the client application name.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "AXCL":
                // Get all the client contacts.
                ExecuteRequest(context, command, request, data, true);
                return(true);

            case "ACLC":
                // Get all the client contacts.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ACEA":
                // Get the client email address.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ACNM":
                // Get the client name.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ACOS":
                // Get the client online and available status.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ACUN":
                // Get the client username.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "AICO":
                // Is the client contact online and available.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "AICL":
                // Is the client currently logged-on.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "AXLO":
                // Logoff the client, direct server request.
                ExecuteRequest(context, command, request, data, true);
                return(true);

            case "ALOF":
                // Logoff the client.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ARCL":
                // Remove an existing client.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ARCC":
                // Remove a contact from this client.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ASAC":
                // Set the client active connections count for the same client.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ASAN":
                // Set the client application name.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ASED":
                // Set the client application name.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ASLS":
                // Set the client logged-on state.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ASCN":
                // Set the client name.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "AXXS":
            case "AXSO":
                // Set the online status of the client.
                ExecuteRequest(context, command, request, data, true);
                return(true);

            case "ASOS":
                // Set the online status of the client.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ASCP":
                // Set the client password.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ASSS":
                // Set the client suspended state.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ASUN":
                // Set the client username.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "AGCA":
                // Get all the clients.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "AGOC":
                // Get all the clients online.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "A1CO":
                // Attempt to get all the current client contacts
                // that are currently online.
                ExecuteRequest(context, command, request, data, true);

                // If result mode.
                if (!request)
                {
                    // Store the result.
                    StoreContactsOnline(ActionStoreKey.ASK1, data.Split('|'));
                }
                return(true);

            case "A2CO":
                // Attempt to get all the current client contacts
                // that are currently online.
                ExecuteRequest(context, command, request, data, true);

                // If result mode.
                if (!request)
                {
                    // Store the result.
                    StoreContactsOnline(ActionStoreKey.ASK2, data.Split('|'));
                }
                return(true);

            default:
                return(false);
            }
        }
Пример #17
0
 /// <summary>
 /// Get the host details for the identities.
 /// </summary>
 /// <param name="context">The server context sending the data.</param>
 /// <param name="uniqueIdentifiers">The unique client identifiers.</param>
 /// <remarks>This does not relay back to the client.</remarks>
 public void GetHosts(Nequeo.Net.Sockets.ServerContext context, string[] uniqueIdentifiers)
 {
     ExecuteRequest(context, "ZXGS", true, String.Join(";", uniqueIdentifiers));
 }
Пример #18
0
        /// <summary>
        /// Execute the command.
        /// </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.</param>
        /// <param name="data">The data from the client.</param>
        /// <returns>True if the command was found and executed; else false.</returns>
        private bool ExecuteCommand(Nequeo.Net.Sockets.ServerContext context, string command, bool request, string data)
        {
            // Delay.
            System.Threading.Thread.Sleep(10);

            // Process the command.
            switch (command.ToUpper())
            {
            case "ZURL":
                // Get the host manage URL for a type.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZAMU":
                // Adds new manage URLs.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZRME":
                // Removes a manage URLs.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZRMU":
                // Removes a manage URLs.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZHHT":
                // Get the host type.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZHTS":
                // Set the host type.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZXAC":
                // Add a new client.
                ExecuteRequest(context, command, request, data, true);
                return(true);

            case "ZACL":
                // Add a new client.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZAHN":
                // Add a new host.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZCEX":
                // Does the client exist.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZCAC":
                // Get the communication active state.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZCCT":
                // Get the communication token.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZCHN":
                // Get the client host name.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZHAC":
                // Get the number of active connections.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZHPT":
                // Get the host index number.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZHEX":
                // Does the host exist.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZXCR":
                // Remove the client.
                ExecuteRequest(context, command, request, data, true);
                return(true);

            case "ZCRM":
                // Remove the client.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZHRM":
                // Remove the host.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZXGH":
                // Get the host details for the identity.
                ExecuteRequest(context, command, request, data, true);
                return(true);

            case "ZHST":
                // Get the host details for the identity.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZXGS":
                // Get the host details for the identities.
                ExecuteRequest(context, command, request, data, true);
                return(true);

            case "ZHSS":
                // Get the host details for the identities.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZCSA":
                // Set the client communication active state.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZCST":
                // Set the communication token.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZCSH":
                // Set the client host name.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZHSC":
                // Set the number of active connections.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZHSP":
                // Set the host index number.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZHSD":
                // Set the host domain.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZHGD":
                // Get the host domain.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZAPT":
                // Add a new port range.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZRPT":
                // Remove the port.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZRPX":
                // Remove the port.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZRSN":
                // Sets the port number.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "ZGPT":
                // Get the ports.
                ExecuteRequest(context, command, request, data);
                return(true);

            case "Z1GS":
                // Get the host details for the identities.
                ExecuteRequest(context, command, request, data, true);

                // If result mode.
                if (!request)
                {
                    // Store the result.
                    StoreContactsOnlineHosts(ActionStoreKey.ASK1, data.Split('|'));
                }
                return(true);

            case "Z2GS":
                // Get the host details for the identities.
                ExecuteRequest(context, command, request, data, true);

                // If result mode.
                if (!request)
                {
                    // Store the result.
                    StoreContactsOnlineHosts(ActionStoreKey.ASK2, data.Split('|'));
                }
                return(true);

            default:
                return(false);
            }
        }
Пример #19
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 Receiver(Nequeo.Net.Sockets.ServerContext context, string command, string data)
 {
     return(ExecuteCommand(context, command, true, data));
 }