FreeMoney.FreeMoneyModule.FirstRegionLoaded C# (CSharp) Method

FirstRegionLoaded() public method

public FirstRegionLoaded ( ) : void
return void
        public void FirstRegionLoaded()
        {
            m_log.Info ("[FreeMoney] Loading predefined users and groups.");

            // Users
            IConfig users = m_config.Configs["PayPal Users"];

            if (null == users) {
                m_log.Warn ("[FreeMoney] No users specified in local ini file.");
            } else {
                IUserAccountService userAccountService = m_scenes[0].UserAccountService;

                // This aborts at the slightest provocation
                // We realise this may be inconvenient for you,
                // however it is important when dealing with
                // financial matters to error check everything.

                foreach (string user in users.GetKeys ()) {
                    UUID tmp;
                    if (UUID.TryParse (user, out tmp)) {
                        m_log.Debug ("[FreeMoney] User is UUID, skipping lookup...");
                        string email = users.GetString (user);
                        m_usersemail[tmp] = email;
                        continue;
                    }

                    m_log.Debug ("[FreeMoney] Looking up UUID for user " + user);
                    string[] username = user.Split (new[] { ' ' }, 2);
                    UserAccount ua = userAccountService.GetUserAccount (UUID.Zero, username[0], username[1]);

                    if (ua != null) {
                        m_log.Debug ("[FreeMoney] Found user, " + user + " = " + ua.PrincipalID);
                        string email = users.GetString (user);

                        if (string.IsNullOrEmpty (email)) {
                            m_log.Error ("[FreeMoney] FreeMoney email address not set for user " + user +
                                         " in [FreeMoney Users] config section. Skipping.");
                            m_usersemail[ua.PrincipalID] = "";
                        } else {
                            if (!FreeMoneyHelpers.IsValidEmail (email)) {
                                m_log.Error ("[FreeMoney] FreeMoney email address not valid for user " + user +
                                             " in [FreeMoney Users] config section. Skipping.");
                                m_usersemail[ua.PrincipalID] = "";
                            } else {
                                m_usersemail[ua.PrincipalID] = email;
                            }
                        }
                    // UserProfileData was null
                    } else {
                        m_log.Error ("[FreeMoney] Error, User Profile not found for user " + user +
                                     ". Check the spelling and/or any associated grid services.");
                    }
                }
            }

            // Groups
            IConfig groups = m_config.Configs["PayPal Groups"];

            if (!m_allowGroups || null == groups) {
                m_log.Warn ("[FreeMoney] Groups disabled or no groups specified in local ini file.");
            } else {
                // This aborts at the slightest provocation
                // We realise this may be inconvenient for you,
                // however it is important when dealing with
                // financial matters to error check everything.

                foreach (string @group in groups.GetKeys ()) {
                    m_log.Debug ("[FreeMoney] Defining email address for UUID for group " + @group);
                    UUID groupID = new UUID (@group);
                    string email = groups.GetString (@group);

                    if (string.IsNullOrEmpty (email)) {
                        m_log.Error ("[FreeMoney] FreeMoney email address not set for group " +
                                     @group + " in [FreeMoney Groups] config section. Skipping.");
                        m_usersemail[groupID] = "";
                    } else {
                        if (!FreeMoneyHelpers.IsValidEmail (email)) {
                            m_log.Error ("[FreeMoney] FreeMoney email address not valid for group " +
                                         @group + " in [FreeMoney Groups] config section. Skipping.");
                            m_usersemail[groupID] = "";
                        } else {
                            m_usersemail[groupID] = email;
                        }
                    }
                }
            }

            // Add HTTP Handlers (user, then PP-IPN)
            MainServer.Instance.AddHTTPHandler ("/pp/", UserPage);
            MainServer.Instance.AddHTTPHandler ("/ppipn/", IPN);

            // For now Bitcoin uses the same IPN as FreeMoney. But we'll give it a different URL to make it clear what's going on.
            MainServer.Instance.AddHTTPHandler ("/register_addresses/", HandleBitcoinRegistrationRequest);
            MainServer.Instance.AddHTTPHandler ("/btcgo/", BitcoinInitializePaymentPage);
            MainServer.Instance.AddHTTPHandler ("/btcping/", HandleBitcoinConfirmationPing);

            // Allow the Bitcoin server to ask us for the email and UUID of the buyer.
            MainServer.Instance.AddHTTPHandler ("/btcbuyerinfo/", BuyerInfo);

            // XMLRPC Handlers for Standalone
            MainServer.Instance.AddXmlRPCHandler ("getCurrencyQuote", quote_func);
            MainServer.Instance.AddXmlRPCHandler ("buyCurrency", buy_func);

            m_active = true;
        }