Exemplo n.º 1
0
        public override bool StoreFriend(UUID PrincipalID, string Friend, int flags)
        {
            IUserAccountService userAccountService = m_registry.RequestModuleInterface <IUserAccountService> ();
            UserAccount         agentAccount       = userAccountService.GetUserAccount(null, PrincipalID);
            UUID FriendUUID;

            if (!UUID.TryParse(Friend, out FriendUUID))
            {
                return(base.StoreFriend(PrincipalID, Friend, flags));//Already set to a UUI
            }
            else
            {
                UserAccount friendAccount = userAccountService.GetUserAccount(null, FriendUUID);
                if (agentAccount == null || friendAccount == null)
                {
                    // remote grid users
                    ICapsService       capsService = m_registry.RequestModuleInterface <ICapsService> ();
                    IClientCapsService FriendCaps  = capsService.GetClientCapsService(UUID.Parse(Friend));
                    if (FriendCaps != null && FriendCaps.GetRootCapsService() != null)
                    {
                        Friend = HGUtil.ProduceUserUniversalIdentifier(FriendCaps.GetRootCapsService().CircuitData);
                    }
                }
                return(base.StoreFriend(PrincipalID, Friend, flags));
            }
        }
Exemplo n.º 2
0
        public void KickUser(UUID avatarID, string message)
        {
            //Get required interfaces
            IAsyncMessagePostService messagePost = m_registry.RequestModuleInterface <IAsyncMessagePostService>();
            ICapsService             capsService = m_registry.RequestModuleInterface <ICapsService>();
            IClientCapsService       client      = capsService.GetClientCapsService(avatarID);

            if (client != null)
            {
                IRegionClientCapsService regionClient = client.GetRootCapsService();
                if (regionClient != null)
                {
                    //Send the message to the client
                    messagePost.Post(regionClient.RegionHandle,
                                     BuildRequest("KickUserMessage", message, regionClient.AgentID.ToString()));
                    IAgentProcessing agentProcessor = m_registry.RequestModuleInterface <IAgentProcessing>();
                    if (agentProcessor != null)
                    {
                        agentProcessor.LogoutAgent(regionClient, true);
                    }
                    MainConsole.Instance.Info("User will be kicked in less than 30 seconds.");
                    return;
                }
            }
            MainConsole.Instance.Info("Could not find user to send message to.");
        }
Exemplo n.º 3
0
        protected void SendGridMessage(string module, string[] cmd)
        {
            //Combine the params and figure out the message
            string user    = CombineParams(cmd, 3, 5);
            string message = CombineParams(cmd, 5);

            //Get required interfaces
            IAsyncMessagePostService messagePost = m_registry.RequestModuleInterface <IAsyncMessagePostService>();
            ICapsService             capsService = m_registry.RequestModuleInterface <ICapsService>();
            IUserAccountService      userService = m_registry.RequestModuleInterface <IUserAccountService>();
            UserAccount account = userService.GetUserAccount(UUID.Zero, user.Split(' ')[0], user.Split(' ')[1]);

            if (account == null)
            {
                m_log.Info("User does not exist.");
                return;
            }
            IClientCapsService client = capsService.GetClientCapsService(account.PrincipalID);

            if (client != null)
            {
                IRegionClientCapsService regionClient = client.GetRootCapsService();
                if (regionClient != null)
                {
                    //Send the message to the client
                    messagePost.Post(regionClient.RegionHandle, BuildRequest("GridWideMessage", message, regionClient.AgentID.ToString()));
                    m_log.Info("Message sent.");
                    return;
                }
            }
            m_log.Info("Could not find user to send message to.");
        }
        public void KickUser(UUID avatarID, string message)
        {
            //Get required interfaces
            IClientCapsService client = m_capsService.GetClientCapsService(avatarID);

            if (client != null)
            {
                IRegionClientCapsService regionClient = client.GetRootCapsService();
                if (regionClient != null)
                {
                    //Send the message to the client
                    m_messagePost.Get(regionClient.Region.ServerURI,
                                      BuildRequest("KickUserMessage", message, regionClient.AgentID.ToString()),
                                      (resp) =>
                    {
                        IAgentProcessing agentProcessor =
                            m_registry.RequestModuleInterface <IAgentProcessing>();
                        if (agentProcessor != null)
                        {
                            agentProcessor.LogoutAgent(regionClient, true);
                        }
                        MainConsole.Instance.Info("User has been kicked.");
                    });

                    return;
                }
            }
            MainConsole.Instance.Info("Could not find user to send message to.");
        }
Exemplo n.º 5
0
        public static bool GetIsForeign(UUID AgentID, string server, IRegistryCore registry, out string serverURL)
        {
            serverURL = "";
            if (registry == null)
            {
                return(true);
            }
            ICapsService       caps       = registry.RequestModuleInterface <ICapsService>();
            IClientCapsService clientCaps = caps.GetClientCapsService(AgentID);

            if (clientCaps == null)
            {
                return(false);
            }
            IRegionClientCapsService regionClientCaps = clientCaps.GetRootCapsService();

            if (regionClientCaps == null)
            {
                return(false);
            }
            Dictionary <string, object> urls = regionClientCaps.CircuitData.ServiceURLs;

            if (urls != null && urls.Count > 0)
            {
                serverURL = urls[server].ToString();
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
 public bool SendGridMessage(UUID toId, string message, bool goDeep, UUID transactionId)
 {
     try
     {
         if (m_doRemoteCalls)
         {
             return((bool)DoRemote(toId, message, goDeep, transactionId));
         }
         ICapsService       capsService = m_registry.RequestModuleInterface <ICapsService>();
         IClientCapsService client      = capsService.GetClientCapsService(toId);
         if (client != null)
         {
             IRegionClientCapsService regionClient = client.GetRootCapsService();
             if (regionClient != null)
             {
                 regionPostHandler.SendGridMessageRegionPostHandler(regionClient.Region, toId, message,
                                                                    transactionId);
             }
         }
     }
     catch (Exception e)
     {
         MainConsole.Instance.ErrorFormat("[CURRENCY CONNECTOR] UserCurrencyUpdate to m_ServerURI: {0}", e.ToString());
     }
     return(false);
 }
Exemplo n.º 7
0
        private void CloseNeighborAgents(GridRegion oldRegion, GridRegion destination, UUID AgentID)
        {
            Util.FireAndForget(delegate(object o)
            {
                //Sleep for 5 seconds to give the agents a chance to cross and get everything right
                Thread.Sleep(5000);
                //Now do a sanity check on the avatar
                IClientCapsService clientCaps = m_registry.RequestModuleInterface <ICapsService>().GetClientCapsService(AgentID);
                if (clientCaps == null)
                {
                    return;
                }
                IRegionClientCapsService rootRegionCaps = clientCaps.GetRootCapsService();
                if (rootRegionCaps == null)
                {
                    return;
                }
                IRegionClientCapsService ourRegionCaps = clientCaps.GetCapsService(destination.RegionHandle);
                if (ourRegionCaps == null)
                {
                    return;
                }
                //If they handles arn't the same, the agent moved, and we can't be sure that we should close these agents
                if (rootRegionCaps.RegionHandle != ourRegionCaps.RegionHandle)
                {
                    return;
                }

                INeighborService service = m_registry.RequestModuleInterface <INeighborService>();
                if (service != null)
                {
                    List <GridRegion> NeighborsOfOldRegion         = service.GetNeighbors(oldRegion);
                    List <GridRegion> NeighborsOfDestinationRegion = service.GetNeighbors(destination);

                    List <GridRegion> byebyeRegions = new List <GridRegion>(NeighborsOfOldRegion);
                    byebyeRegions.Add(oldRegion); //Add the old region, because it might need closed too

                    byebyeRegions.RemoveAll(delegate(GridRegion r)
                    {
                        if (r.RegionID == destination.RegionID)
                        {
                            return(true);
                        }
                        else if (NeighborsOfDestinationRegion.Contains(r))
                        {
                            return(true);
                        }
                        return(false);
                    });

                    if (byebyeRegions.Count > 0)
                    {
                        m_log.Info("[AgentProcessing]: Closing " + byebyeRegions.Count + " child agents around " + oldRegion.RegionName);
                        SendCloseChildAgent(AgentID, byebyeRegions);
                    }
                }
            });
        }
Exemplo n.º 8
0
        protected object OnGenericEvent(string FunctionName, object parameters)
        {
            if (FunctionName == "UserStatusChange")
            {
                //A user has logged in or out... we need to update friends lists across the grid

                IAsyncMessagePostService asyncPoster    = m_registry.RequestModuleInterface <IAsyncMessagePostService>();
                IFriendsService          friendsService = m_registry.RequestModuleInterface <IFriendsService>();
                ICapsService             capsService    = m_registry.RequestModuleInterface <ICapsService>();
                IGridService             gridService    = m_registry.RequestModuleInterface <IGridService>();
                if (asyncPoster != null && friendsService != null && capsService != null && gridService != null)
                {
                    //Get all friends
                    UserInfo     info          = (UserInfo)parameters;
                    FriendInfo[] friends       = friendsService.GetFriends(UUID.Parse(info.UserID));
                    List <UUID>  OnlineFriends = new List <UUID>();
                    UUID         us            = UUID.Parse(info.UserID);
                    foreach (FriendInfo friend in friends)
                    {
                        UUID FriendToInform = UUID.Parse(friend.Friend);
                        //Now find their caps service so that we can find where they are root (and if they are logged in)
                        IClientCapsService clientCaps = capsService.GetClientCapsService(FriendToInform);
                        if (clientCaps != null)
                        {
                            OnlineFriends.Add(FriendToInform);
                            //Find the root agent
                            IRegionClientCapsService regionClientCaps = clientCaps.GetRootCapsService();
                            if (regionClientCaps != null)
                            {
                                //Post!
                                asyncPoster.Post(regionClientCaps.RegionHandle, SyncMessageHelper.AgentStatusChange(us, FriendToInform, info.IsOnline));
                            }
                        }
                    }
                    //If they are online, send all friends online statuses to them
                    if (info.IsOnline)
                    {
                        GridRegion ourRegion = gridService.GetRegionByUUID(UUID.Zero, info.CurrentRegionID);
                        if (ourRegion != null)
                        {
                            foreach (UUID onlineFriend in OnlineFriends)
                            {
                                asyncPoster.Post(ourRegion.RegionHandle, SyncMessageHelper.AgentStatusChange(onlineFriend, us, info.IsOnline));
                            }
                        }
                    }
                }
            }
            return(null);
        }
        public void MessageUser(UUID avatarID, string message)
        {
            //Get required interfaces
            IClientCapsService client = m_capsService.GetClientCapsService(avatarID);

            if (client != null)
            {
                IRegionClientCapsService regionClient = client.GetRootCapsService();
                if (regionClient != null)
                {
                    //Send the message to the client
                    m_messagePost.Post(regionClient.Region.ServerURI,
                                       BuildRequest("GridWideMessage", message, regionClient.AgentID.ToString()));
                    MainConsole.Instance.Info("Message sent to the user.");
                    return;
                }
            }
            MainConsole.Instance.Info("Could not find user to send message to.");
        }
Exemplo n.º 10
0
        protected void KickUserMessage(string module, string[] cmd)
        {
            //Combine the params and figure out the message
            string user = CombineParams(cmd, 2, 4);

            if (user.EndsWith(" "))
            {
                user = user.Remove(user.Length - 1);
            }
            string message = CombineParams(cmd, 5);

            //Get required interfaces
            IAsyncMessagePostService messagePost = m_registry.RequestModuleInterface <IAsyncMessagePostService>();
            ICapsService             capsService = m_registry.RequestModuleInterface <ICapsService>();
            IUserAccountService      userService = m_registry.RequestModuleInterface <IUserAccountService>();
            UserAccount account = userService.GetUserAccount(UUID.Zero, user);

            if (account == null)
            {
                m_log.Info("User does not exist.");
                return;
            }
            IClientCapsService client = capsService.GetClientCapsService(account.PrincipalID);

            if (client != null)
            {
                IRegionClientCapsService regionClient = client.GetRootCapsService();
                if (regionClient != null)
                {
                    //Send the message to the client
                    messagePost.Post(regionClient.RegionHandle, BuildRequest("KickUserMessage", message, regionClient.AgentID.ToString()));
                    IAgentProcessing agentProcessor = m_registry.RequestModuleInterface <IAgentProcessing>();
                    if (agentProcessor != null)
                    {
                        agentProcessor.LogoutAgent(regionClient);
                    }
                    m_log.Info("User Kicked sent.");
                    return;
                }
            }
            m_log.Info("Could not find user to send message to.");
        }
Exemplo n.º 11
0
        public void MessageUser(UUID avatarID, string message)
        {
            //Get required interfaces
            IAsyncMessagePostService messagePost = m_registry.RequestModuleInterface <IAsyncMessagePostService> ();
            ICapsService             capsService = m_registry.RequestModuleInterface <ICapsService> ();
            IClientCapsService       client      = capsService.GetClientCapsService(avatarID);

            if (client != null)
            {
                IRegionClientCapsService regionClient = client.GetRootCapsService();
                if (regionClient != null)
                {
                    //Send the message to the client
                    messagePost.Post(regionClient.RegionHandle, BuildRequest("GridWideMessage", message, regionClient.AgentID.ToString()));
                    m_log.Info("Message sent.");
                    return;
                }
            }
            m_log.Info("Could not find user to send message to.");
        }
Exemplo n.º 12
0
 public OSDMap GetParcelDetails(UUID agentId)
 {
     try
     {
         ICapsService       capsService = m_registry.RequestModuleInterface <ICapsService>();
         IClientCapsService client      = capsService.GetClientCapsService(agentId);
         if (client != null)
         {
             IRegionClientCapsService regionClient = client.GetRootCapsService();
             if (regionClient != null)
             {
                 LandData land = regionPostHandler.ParcelDetailsRegionPostHandler(regionClient.Region, client.AgentID);
                 return(land.ToOSD());
             }
         }
     }
     catch (Exception e)
     {
         MainConsole.Instance.ErrorFormat("[CURRENCY CONNECTOR] UserCurrencyUpdate to m_ServerURI: {0}", e.ToString());
     }
     return(null);
 }
Exemplo n.º 13
0
        protected OSDMap OnMessageReceived(OSDMap message)
        {
            if (!message.ContainsKey("Method"))
            {
                return(null);
            }

            UUID         AgentID          = message["AgentID"].AsUUID();
            ulong        requestingRegion = message["RequestingRegion"].AsULong();
            ICapsService capsService      = m_registry.RequestModuleInterface <ICapsService>();

            if (capsService == null)
            {
                //m_log.Info("[AgentProcessing]: Failed OnMessageReceived ICapsService is null");
                return(new OSDMap());
            }
            IClientCapsService clientCaps = capsService.GetClientCapsService(AgentID);

            IRegionClientCapsService regionCaps = null;

            if (clientCaps != null)
            {
                regionCaps = clientCaps.GetCapsService(requestingRegion);
            }
            if (message["Method"] == "LogoutRegionAgents")
            {
                LogOutAllAgentsForRegion(requestingRegion);
            }
            else if (message["Method"] == "RegionIsOnline") //This gets fired when the scene is fully finished starting up
            {
                //Log out all the agents first, then add any child agents that should be in this region
                LogOutAllAgentsForRegion(requestingRegion);
                IGridService GridService = m_registry.RequestModuleInterface <IGridService>();
                if (GridService != null)
                {
                    int x, y;
                    Util.UlongToInts(requestingRegion, out x, out y);
                    GridRegion requestingGridRegion = GridService.GetRegionByPosition(UUID.Zero, x, y);
                    if (requestingGridRegion != null)
                    {
                        EnableChildAgentsForRegion(requestingGridRegion);
                    }
                }
            }
            else if (message["Method"] == "DisableSimulator")
            {
                //KILL IT!
                if (regionCaps == null || clientCaps == null)
                {
                    return(null);
                }
                regionCaps.Close();
                clientCaps.RemoveCAPS(requestingRegion);
            }
            else if (message["Method"] == "ArrivedAtDestination")
            {
                if (regionCaps == null || clientCaps == null)
                {
                    return(null);
                }
                //Recieved a callback
                if (clientCaps.InTeleport) //Only set this if we are in a teleport,
                //  otherwise (such as on login), this won't check after the first tp!
                {
                    clientCaps.CallbackHasCome = true;
                }

                regionCaps.Disabled = false;

                //The agent is getting here for the first time (eg. login)
                OSDMap body = ((OSDMap)message["Message"]);

                //Parse the OSDMap
                int DrawDistance = body["DrawDistance"].AsInteger();

                AgentCircuitData circuitData = new AgentCircuitData();
                circuitData.UnpackAgentCircuitData((OSDMap)body["Circuit"]);

                //Now do the creation
                EnableChildAgents(AgentID, requestingRegion, DrawDistance, circuitData);
            }
            else if (message["Method"] == "CancelTeleport")
            {
                if (regionCaps == null || clientCaps == null)
                {
                    return(null);
                }
                //Only the region the client is root in can do this
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService();
                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    //The user has requested to cancel the teleport, stop them.
                    clientCaps.RequestToCancelTeleport = true;
                    regionCaps.Disabled = false;
                }
            }
            else if (message["Method"] == "AgentLoggedOut")
            {
                //ONLY if the agent is root do we even consider it
                if (regionCaps != null)
                {
                    if (regionCaps.RootAgent)
                    {
                        LogoutAgent(regionCaps);
                    }
                }
            }
            else if (message["Method"] == "SendChildAgentUpdate")
            {
                if (regionCaps == null || clientCaps == null)
                {
                    return(null);
                }
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService();
                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    OSDMap body = ((OSDMap)message["Message"]);

                    AgentPosition pos = new AgentPosition();
                    pos.Unpack((OSDMap)body["AgentPos"]);

                    SendChildAgentUpdate(pos, regionCaps);
                    regionCaps.Disabled = false;
                }
            }
            else if (message["Method"] == "TeleportAgent")
            {
                if (regionCaps == null || clientCaps == null)
                {
                    return(null);
                }
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService();
                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    OSDMap body = ((OSDMap)message["Message"]);

                    GridRegion destination = new GridRegion();
                    destination.FromOSD((OSDMap)body["Region"]);

                    uint TeleportFlags = body["TeleportFlags"].AsUInteger();
                    int  DrawDistance  = body["DrawDistance"].AsInteger();

                    AgentCircuitData Circuit = new AgentCircuitData();
                    Circuit.UnpackAgentCircuitData((OSDMap)body["Circuit"]);

                    AgentData AgentData = new AgentData();
                    AgentData.Unpack((OSDMap)body["AgentData"]);
                    regionCaps.Disabled = false;

                    OSDMap result = new OSDMap();
                    string reason = "";
                    result["Success"] = TeleportAgent(destination, TeleportFlags, DrawDistance,
                                                      Circuit, AgentData, AgentID, requestingRegion, out reason);
                    result["Reason"] = reason;
                    return(result);
                }
            }
            else if (message["Method"] == "CrossAgent")
            {
                if (regionCaps == null || clientCaps == null)
                {
                    return(null);
                }
                if (clientCaps.GetRootCapsService().RegionHandle == regionCaps.RegionHandle)
                {
                    //This is a simulator message that tells us to cross the agent
                    OSDMap body = ((OSDMap)message["Message"]);

                    Vector3    pos    = body["Pos"].AsVector3();
                    Vector3    Vel    = body["Vel"].AsVector3();
                    GridRegion Region = new GridRegion();
                    Region.FromOSD((OSDMap)body["Region"]);
                    AgentCircuitData Circuit = new AgentCircuitData();
                    Circuit.UnpackAgentCircuitData((OSDMap)body["Circuit"]);
                    AgentData AgentData = new AgentData();
                    AgentData.Unpack((OSDMap)body["AgentData"]);
                    regionCaps.Disabled = false;

                    OSDMap result = new OSDMap();
                    string reason = "";
                    result["Success"] = CrossAgent(Region, pos, Vel, Circuit, AgentData,
                                                   AgentID, requestingRegion, out reason);
                    result["Reason"] = reason;
                    return(result);
                }
            }
            return(null);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Async component for informing client of which neighbors exist
        /// </summary>
        /// <remarks>
        /// This needs to run asynchronously, as a network timeout may block the thread for a long while
        /// </remarks>
        /// <param name="remoteClient"></param>
        /// <param name="a"></param>
        /// <param name="regionHandle"></param>
        /// <param name="endPoint"></param>
        private bool InformClientOfNeighbor(UUID AgentID, ulong requestingRegion, AgentCircuitData circuitData, GridRegion neighbor,
                                            uint TeleportFlags, AgentData agentData, out string reason)
        {
            if (neighbor == null)
            {
                reason = "Could not find neighbor to inform";
                return(false);
            }
            m_log.Info("[AgentProcessing]: Starting to inform client about neighbor " + neighbor.RegionName);

            //Notes on this method
            // 1) the SimulationService.CreateAgent MUST have a fixed CapsUrl for the region, so we have to create (if needed)
            //       a new Caps handler for it.
            // 2) Then we can call the methods (EnableSimulator and EstatablishAgentComm) to tell the client the new Urls
            // 3) This allows us to make the Caps on the grid server without telling any other regions about what the
            //       Urls are.

            ISimulationService SimulationService = m_registry.RequestModuleInterface <ISimulationService>();

            if (SimulationService != null)
            {
                ICapsService       capsService = m_registry.RequestModuleInterface <ICapsService>();
                IClientCapsService clientCaps  = capsService.GetClientCapsService(AgentID);

                IRegionClientCapsService oldRegionService = clientCaps.GetCapsService(neighbor.RegionHandle);

                //If its disabled, it should be removed, so kill it!
                if (oldRegionService != null && oldRegionService.Disabled)
                {
                    clientCaps.RemoveCAPS(neighbor.RegionHandle);
                    oldRegionService = null;
                }

                bool newAgent = oldRegionService == null;
                IRegionClientCapsService otherRegionService = clientCaps.GetOrCreateCapsService(neighbor.RegionHandle,
                                                                                                CapsUtil.GetCapsSeedPath(CapsUtil.GetRandomCapsObjectPath()), circuitData);

                if (!newAgent)
                {
                    //Note: if the agent is already there, send an agent update then
                    bool result = true;
                    if (agentData != null)
                    {
                        result = SimulationService.UpdateAgent(neighbor, agentData);
                        if (result)
                        {
                            oldRegionService.Disabled = false;
                        }
                    }
                    reason = "";
                    return(result);
                }

                ICommunicationService commsService = m_registry.RequestModuleInterface <ICommunicationService>();
                if (commsService != null)
                {
                    circuitData.OtherInformation["UserUrls"] = commsService.GetUrlsForUser(neighbor, circuitData.AgentID);
                }

                #region OpenSim teleport compatibility!

                if (!m_useCallbacks)
                {
                    circuitData.CapsPath    = CapsUtil.GetRandomCapsObjectPath();
                    circuitData.startpos.X += (neighbor.RegionLocX - clientCaps.GetRootCapsService().RegionX);
                    circuitData.startpos.Y += (neighbor.RegionLocY - clientCaps.GetRootCapsService().RegionY);
                }

                #endregion

                bool regionAccepted = SimulationService.CreateAgent(neighbor, circuitData,
                                                                    TeleportFlags, agentData, out reason);
                if (regionAccepted)
                {
                    string otherRegionsCapsURL;
                    //If the region accepted us, we should get a CAPS url back as the reason, if not, its not updated or not an Aurora region, so don't touch it.
                    if (reason != "")
                    {
                        OSDMap responseMap = (OSDMap)OSDParser.DeserializeJson(reason);
                        OSDMap SimSeedCaps = (OSDMap)responseMap["CapsUrls"];
                        otherRegionService.AddCAPS(SimSeedCaps);
                        otherRegionsCapsURL = otherRegionService.CapsUrl;
                    }
                    else
                    {
                        //We are assuming an OpenSim region now!
                        #region OpenSim teleport compatibility!

                        otherRegionsCapsURL = "http://" + otherRegionService.Region.ExternalEndPoint.ToString() +
                                              CapsUtil.GetCapsSeedPath(circuitData.CapsPath);
                        otherRegionService.CapsUrl = otherRegionsCapsURL;

                        #endregion
                    }

                    IEventQueueService EQService = m_registry.RequestModuleInterface <IEventQueueService>();

                    EQService.EnableSimulator(neighbor.RegionHandle,
                                              neighbor.ExternalEndPoint.Address.GetAddressBytes(),
                                              neighbor.ExternalEndPoint.Port, AgentID,
                                              neighbor.RegionSizeX, neighbor.RegionSizeY, requestingRegion);

                    // EnableSimulator makes the client send a UseCircuitCode message to the destination,
                    // which triggers a bunch of things there.
                    // So let's wait
                    Thread.Sleep(300);
                    EQService.EstablishAgentCommunication(AgentID, neighbor.RegionHandle,
                                                          neighbor.ExternalEndPoint.Address.GetAddressBytes(),
                                                          neighbor.ExternalEndPoint.Port, otherRegionsCapsURL, neighbor.RegionSizeX,
                                                          neighbor.RegionSizeY,
                                                          requestingRegion);

                    if (!m_useCallbacks)
                    {
                        Thread.Sleep(3000);  //Give it a bit of time
                    }
                    m_log.Info("[AgentProcessing]: Completed inform client about neighbor " + neighbor.RegionName);
                }
                else
                {
                    m_log.Error("[AgentProcessing]: Failed to inform client about neighbor " + neighbor.RegionName + ", reason: " + reason);
                    return(false);
                }
                return(true);
            }
            reason = "SimulationService does not exist";
            m_log.Error("[AgentProcessing]: Failed to inform client about neighbor " + neighbor.RegionName + ", reason: " + reason + "!");
            return(false);
        }
Exemplo n.º 15
0
        protected OSDMap OnMessageReceived(OSDMap message)
        {
            IAsyncMessagePostService asyncPost = m_registry.RequestModuleInterface <IAsyncMessagePostService>();

            //We need to check and see if this is an AgentStatusChange
            if (message.ContainsKey("Method") && message["Method"] == "AgentStatusChange")
            {
                OSDMap innerMessage = (OSDMap)message["Message"];
                //We got a message, now pass it on to the clients that need it
                UUID AgentID          = innerMessage["AgentID"].AsUUID();
                UUID FriendToInformID = innerMessage["FriendToInformID"].AsUUID();
                bool NewStatus        = innerMessage["NewStatus"].AsBoolean();

                //Do this since IFriendsModule is a scene module, not a ISimulationBase module (not interchangable)
                ISceneManager manager = m_registry.RequestModuleInterface <ISceneManager>();
                if (manager != null && manager.GetAllScenes().Count > 0)
                {
                    IFriendsModule friendsModule = manager.GetCurrentOrFirstScene().RequestModuleInterface <IFriendsModule>();
                    if (friendsModule != null)
                    {
                        //Send the message
                        friendsModule.SendFriendsStatusMessage(FriendToInformID, AgentID, NewStatus);
                    }
                }
            }
            else if (message.ContainsKey("Method") && message["Method"] == "FriendGrantRights")
            {
                OSDMap             body          = (OSDMap)message["Message"];
                UUID               targetID      = body["Target"].AsUUID();
                IClientCapsService friendSession =
                    m_registry.RequestModuleInterface <ICapsService>().GetClientCapsService(targetID);
                if (friendSession != null && friendSession.GetRootCapsService() != null)
                {
                    //Forward the message
                    asyncPost.Post(friendSession.GetRootCapsService().RegionHandle, message);
                }
            }
            else if (message.ContainsKey("Method") && message["Method"] == "FriendshipOffered")
            {
                OSDMap             body          = (OSDMap)message["Message"];
                UUID               targetID      = body["Friend"].AsUUID();
                IClientCapsService friendSession =
                    m_registry.RequestModuleInterface <ICapsService>().GetClientCapsService(targetID);
                if (friendSession != null && friendSession.GetRootCapsService() != null)
                {
                    //Forward the message
                    asyncPost.Post(friendSession.GetRootCapsService().RegionHandle, message);
                }
            }
            else if (message.ContainsKey("Method") && message["Method"] == "FriendTerminated")
            {
                OSDMap             body          = (OSDMap)message["Message"];
                UUID               targetID      = body["ExFriend"].AsUUID();
                IClientCapsService friendSession =
                    m_registry.RequestModuleInterface <ICapsService>().GetClientCapsService(targetID);
                if (friendSession != null && friendSession.GetRootCapsService() != null)
                {
                    //Forward the message
                    asyncPost.Post(friendSession.GetRootCapsService().RegionHandle, message);
                }
            }
            else if (message.ContainsKey("Method") && message["Method"] == "FriendshipDenied")
            {
                OSDMap             body          = (OSDMap)message["Message"];
                UUID               targetID      = body["FriendID"].AsUUID();
                IClientCapsService friendSession =
                    m_registry.RequestModuleInterface <ICapsService>().GetClientCapsService(targetID);
                if (friendSession != null && friendSession.GetRootCapsService() != null)
                {
                    //Forward the message
                    asyncPost.Post(friendSession.GetRootCapsService().RegionHandle, message);
                }
            }
            else if (message.ContainsKey("Method") && message["Method"] == "FriendshipApproved")
            {
                OSDMap             body          = (OSDMap)message["Message"];
                UUID               targetID      = body["FriendID"].AsUUID();
                IClientCapsService friendSession =
                    m_registry.RequestModuleInterface <ICapsService>().GetClientCapsService(targetID);
                if (friendSession != null && friendSession.GetRootCapsService() != null)
                {
                    //Forward the message
                    asyncPost.Post(friendSession.GetRootCapsService().RegionHandle, message);
                }
            }
            return(null);
        }
Exemplo n.º 16
0
        protected object OnGenericEvent(string FunctionName, object parameters)
        {
            if (FunctionName == "UserStatusChange")
            {
                //A user has logged in or out... we need to update friends lists across the grid

                IAsyncMessagePostService asyncPoster    = m_registry.RequestModuleInterface <IAsyncMessagePostService>();
                IFriendsService          friendsService = m_registry.RequestModuleInterface <IFriendsService>();
                ICapsService             capsService    = m_registry.RequestModuleInterface <ICapsService>();
                IGridService             gridService    = m_registry.RequestModuleInterface <IGridService>();
                if (asyncPoster != null && friendsService != null && capsService != null && gridService != null)
                {
                    //Get all friends
                    object[] info     = (object[])parameters;
                    UUID     us       = UUID.Parse(info[0].ToString());
                    bool     isOnline = bool.Parse(info[1].ToString());

                    List <FriendInfo> friends                 = friendsService.GetFriends(us);
                    List <UUID>       OnlineFriends           = new List <UUID>();
                    List <string>     previouslyContactedURLs = new List <string>();
                    foreach (FriendInfo friend in friends)
                    {
                        if (friend.TheirFlags == -1 || friend.MyFlags == -1)
                        {
                            continue; //Not validiated yet!
                        }
                        UUID   FriendToInform = UUID.Zero;
                        string url, first, last, secret;
                        if (!UUID.TryParse(friend.Friend, out FriendToInform))
                        {
                            HGUtil.ParseUniversalUserIdentifier(friend.Friend, out FriendToInform, out url, out first,
                                                                out last, out secret);
                        }
                        //Now find their caps service so that we can find where they are root (and if they are logged in)
                        IClientCapsService clientCaps = capsService.GetClientCapsService(FriendToInform);
                        if (clientCaps != null)
                        {
                            //Find the root agent
                            IRegionClientCapsService regionClientCaps = clientCaps.GetRootCapsService();
                            if (regionClientCaps != null)
                            {
                                OnlineFriends.Add(FriendToInform);
                                //Post!
                                asyncPoster.Post(regionClientCaps.RegionHandle,
                                                 SyncMessageHelper.AgentStatusChange(us, FriendToInform, isOnline));
                            }
                            else
                            {
                                //If they don't have a root agent, wtf happened?
                                capsService.RemoveCAPS(clientCaps.AgentID);
                            }
                        }
                        else
                        {
                            IAgentInfoService agentInfoService = m_registry.RequestModuleInterface <IAgentInfoService>();
                            if (agentInfoService != null)
                            {
                                UserInfo friendinfo = agentInfoService.GetUserInfo(FriendToInform.ToString());
                                if (friendinfo != null && friendinfo.IsOnline)
                                {
                                    OnlineFriends.Add(FriendToInform);
                                    //Post!
                                    GridRegion r = gridService.GetRegionByUUID(UUID.Zero, friendinfo.CurrentRegionID);
                                    if (r != null)
                                    {
                                        asyncPoster.Post(r.RegionHandle,
                                                         SyncMessageHelper.AgentStatusChange(us, FriendToInform,
                                                                                             isOnline));
                                    }
                                }
                                else
                                {
                                    IUserAgentService uas = m_registry.RequestModuleInterface <IUserAgentService>();
                                    if (uas != null)
                                    {
                                        bool online = uas.RemoteStatusNotification(friend, us, isOnline);
                                        if (online)
                                        {
                                            OnlineFriends.Add(FriendToInform);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //If the user is coming online, send all their friends online statuses to them
                    if (isOnline)
                    {
                        GridRegion ourRegion = gridService.GetRegionByUUID(UUID.Zero, UUID.Parse(info[2].ToString()));
                        if (ourRegion != null)
                        {
                            foreach (UUID onlineFriend in OnlineFriends)
                            {
                                asyncPoster.Post(ourRegion.RegionHandle,
                                                 SyncMessageHelper.AgentStatusChange(onlineFriend, us, isOnline));
                            }
                        }
                    }
                }
            }
            return(null);
        }
        public byte[] HandleMap(OSDMap args)
        {
            if (args.ContainsKey("Method"))
            {
                string method = args["Method"].AsString();
                try
                {
                    MethodImplementation methodInfo;
                    if (GetMethodInfo(method, args.Count - 1, out methodInfo))
                    {
                        if (m_SessionID == "")
                        {
                            if (methodInfo.Attribute.ThreatLevel != ThreatLevel.None)
                            {
                                return(MainServer.BadRequest);
                            }
                        }
                        else if (!m_urlModule.CheckThreatLevel(m_SessionID, method, methodInfo.Attribute.ThreatLevel))
                        {
                            return(MainServer.BadRequest);
                        }
                        if (methodInfo.Attribute.UsePassword)
                        {
                            if (!methodInfo.Reference.CheckPassword(args["Password"].AsString()))
                            {
                                return(MainServer.BadRequest);
                            }
                        }
                        if (methodInfo.Attribute.OnlyCallableIfUserInRegion)
                        {
                            UUID userID = args["UserID"].AsUUID();
                            IClientCapsService clientCaps = m_capsService.GetClientCapsService(userID);
                            if (userID == UUID.Zero || clientCaps == null || clientCaps.GetRootCapsService().RegionHandle != ulong.Parse(m_SessionID))
                            {
                                return(MainServer.BadRequest);
                            }
                        }

                        ParameterInfo[] paramInfo  = methodInfo.Method.GetParameters();
                        object[]        parameters = new object[paramInfo.Length];
                        int             paramNum   = 0;
                        foreach (ParameterInfo param in paramInfo)
                        {
                            if (args[param.Name].Type == OSDType.Unknown)
                            {
                                parameters[paramNum++] = null;
                            }
                            else if (param.ParameterType == typeof(OSD))
                            {
                                parameters[paramNum++] = args[param.Name];
                            }
                            else
                            {
                                parameters[paramNum++] = Util.OSDToObject(args[param.Name], param.ParameterType);
                            }
                        }

                        object o        = methodInfo.Method.FastInvoke(paramInfo, methodInfo.Reference, parameters);
                        OSDMap response = new OSDMap();
                        if (o == null)//void method
                        {
                            response["Value"] = "null";
                        }
                        else
                        {
                            response["Value"] = Util.MakeOSD(o, methodInfo.Method.ReturnType);
                        }
                        response["Success"] = true;
                        return(Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(response, true)));
                    }
                }
                catch (Exception ex)
                {
                    MainConsole.Instance.WarnFormat("[ServerHandler]: Error occured for method {0}: {1}", method, ex.ToString());
                }
            }
            else
            {
                MainConsole.Instance.Warn("[ServerHandler]: Post did not have a method block");
            }

            return(MainServer.BadRequest);
        }
Exemplo n.º 18
0
        public Dictionary <string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
                                                OSHttpResponse httpResponse, Dictionary <string, object> requestParameters, ITranslator translator, out string response)
        {
            response = null;
            var vars = new Dictionary <string, object>();

            string      username = filename.Split('/').LastOrDefault();
            UserAccount account  = null;

            if (httpRequest.Query.ContainsKey("userid"))
            {
                string userid = httpRequest.Query["userid"].ToString();

                account = webInterface.Registry.RequestModuleInterface <IUserAccountService>().
                          GetUserAccount(null, UUID.Parse(userid));
            }
            else if (httpRequest.Query.ContainsKey("name"))
            {
                string name = httpRequest.Query.ContainsKey("name") ? httpRequest.Query["name"].ToString() : username;
                name    = name.Replace('.', ' ');
                name    = name.Replace("%20", " ");
                account = webInterface.Registry.RequestModuleInterface <IUserAccountService>().
                          GetUserAccount(null, name);
            }
            else
            {
                username = username.Replace("%20", " ");
                webInterface.Redirect(httpResponse, "/webprofile/?name=" + username);
                return(vars);
            }

            if (account == null)
            {
                return(vars);
            }

            vars.Add("UserName", account.Name);
            vars.Add("UserBorn", Util.ToDateTime(account.Created).ToShortDateString());
            vars.Add("UserType", account.UserTitle == "" ? "Resident" : account.UserTitle);

            IUserProfileInfo profile = Aurora.DataManager.DataManager.RequestPlugin <IProfileConnector>().
                                       GetUserProfile(account.PrincipalID);

            if (profile != null)
            {
                if (profile.Partner != UUID.Zero)
                {
                    account = webInterface.Registry.RequestModuleInterface <IUserAccountService>().
                              GetUserAccount(null, profile.Partner);
                    vars.Add("UserPartner", account.Name);
                }
                else
                {
                    vars.Add("UserPartner", "No partner");
                }
                vars.Add("UserAboutMe", profile.AboutText == "" ? "Nothing here" : profile.AboutText);
                string url = "../images/icons/no_picture.jpg";
                IWebHttpTextureService webhttpService = webInterface.Registry.RequestModuleInterface <IWebHttpTextureService>();
                if (webhttpService != null && profile.Image != UUID.Zero)
                {
                    url = webhttpService.GetTextureURL(profile.Image);
                }
                vars.Add("UserPictureURL", url);
            }
            UserAccount ourAccount = Authenticator.GetAuthentication(httpRequest);

            if (ourAccount != null)
            {
                IFriendsService friendsService = webInterface.Registry.RequestModuleInterface <IFriendsService>();
                var             friends        = friendsService.GetFriends(account.PrincipalID);
                UUID            friendID       = UUID.Zero;
                if (friends.Any(f => UUID.TryParse(f.Friend, out friendID) && friendID == ourAccount.PrincipalID))
                {
                    ICapsService       capsService = webInterface.Registry.RequestModuleInterface <ICapsService>();
                    IClientCapsService clientCaps  = capsService == null ? null : capsService.GetClientCapsService(account.PrincipalID);
                    if (clientCaps != null)
                    {
                        vars.Add("OnlineLocation", clientCaps.GetRootCapsService().Region.RegionName);
                    }
                    vars.Add("UserIsOnline", clientCaps != null);
                    vars.Add("IsOnline", clientCaps != null ? translator.GetTranslatedString("Online") : translator.GetTranslatedString("Offline"));
                }
                else
                {
                    vars.Add("OnlineLocation", "");
                    vars.Add("UserIsOnline", false);
                    vars.Add("IsOnline", translator.GetTranslatedString("Offline"));
                }
            }
            else
            {
                vars.Add("OnlineLocation", "");
                vars.Add("UserIsOnline", false);
                vars.Add("IsOnline", translator.GetTranslatedString("Offline"));
            }

            // Menu Profile
            vars.Add("MenuProfileTitle", translator.GetTranslatedString("MenuProfileTitle"));
            vars.Add("MenuGroupTitle", translator.GetTranslatedString("MenuGroupTitle"));
            vars.Add("MenuPicksTitle", translator.GetTranslatedString("MenuPicksTitle"));

            vars.Add("UserProfileFor", translator.GetTranslatedString("UserProfileFor"));
            vars.Add("ResidentSince", translator.GetTranslatedString("ResidentSince"));
            vars.Add("AccountType", translator.GetTranslatedString("AccountType"));
            vars.Add("PartnersName", translator.GetTranslatedString("PartnersName"));
            vars.Add("AboutMe", translator.GetTranslatedString("AboutMe"));
            vars.Add("IsOnlineText", translator.GetTranslatedString("IsOnlineText"));
            vars.Add("OnlineLocationText", translator.GetTranslatedString("OnlineLocationText"));

            // Style Switcher
            vars.Add("styles1", translator.GetTranslatedString("styles1"));
            vars.Add("styles2", translator.GetTranslatedString("styles2"));
            vars.Add("styles3", translator.GetTranslatedString("styles3"));
            vars.Add("styles4", translator.GetTranslatedString("styles4"));
            vars.Add("styles5", translator.GetTranslatedString("styles5"));

            vars.Add("StyleSwitcherStylesText", translator.GetTranslatedString("StyleSwitcherStylesText"));
            vars.Add("StyleSwitcherLanguagesText", translator.GetTranslatedString("StyleSwitcherLanguagesText"));
            vars.Add("StyleSwitcherChoiceText", translator.GetTranslatedString("StyleSwitcherChoiceText"));

            // Language Switcher
            vars.Add("en", translator.GetTranslatedString("en"));
            vars.Add("fr", translator.GetTranslatedString("fr"));
            vars.Add("de", translator.GetTranslatedString("de"));
            vars.Add("it", translator.GetTranslatedString("it"));
            vars.Add("es", translator.GetTranslatedString("es"));

            IGenericsConnector generics = Aurora.DataManager.DataManager.RequestPlugin <IGenericsConnector>();
            var settings = generics.GetGeneric <GridSettings>(UUID.Zero, "WebSettings", "Settings");

            vars.Add("ShowLanguageTranslatorBar", !settings.HideLanguageTranslatorBar);
            vars.Add("ShowStyleBar", !settings.HideStyleBar);

            return(vars);
        }
        protected OSDMap OnMessageReceived(OSDMap message)
        {
            //We need to check and see if this is an GroupSessionAgentUpdate
            if (message.ContainsKey("Method") && message["Method"] == "GroupSessionAgentUpdate")
            {
                //COMES IN ON AURORA.SERVER SIDE
                //Send it on to whomever it concerns
                OSDMap innerMessage = (OSDMap)message["Message"];
                if (innerMessage["message"] == "ChatterBoxSessionAgentListUpdates")
                //ONLY forward on this type of message
                {
                    UUID agentID            = message["AgentID"];
                    IEventQueueService eqs  = m_registry.RequestModuleInterface <IEventQueueService>();
                    ICapsService       caps = m_registry.RequestModuleInterface <ICapsService>();
                    if (caps != null)
                    {
                        IClientCapsService clientCaps = caps.GetClientCapsService(agentID);
                        if (clientCaps != null && clientCaps.GetRootCapsService() != null)
                        {
                            eqs.Enqueue(innerMessage, agentID, clientCaps.GetRootCapsService().RegionHandle);
                        }
                    }
                }
            }
            else if (message.ContainsKey("Method") && message["Method"] == "FixGroupRoleTitles")
            {
                //COMES IN ON AURORA.SERVER SIDE FROM REGION
                UUID groupID = message["GroupID"].AsUUID();
                UUID agentID = message["AgentID"].AsUUID();
                UUID roleID  = message["RoleID"].AsUUID();
                byte type    = (byte)message["Type"].AsInteger();
                IGroupsServiceConnector     con     = DataManager.RequestPlugin <IGroupsServiceConnector>();
                List <GroupRoleMembersData> members = con.GetGroupRoleMembers(agentID, groupID);
                List <GroupRolesData>       roles   = con.GetGroupRoles(agentID, groupID);
                GroupRolesData everyone             = null;
#if (!ISWIN)
                foreach (GroupRolesData role in roles)
                {
                    if (role.Name == "Everyone")
                    {
                        everyone = role;
                    }
                }
#else
                foreach (GroupRolesData role in roles.Where(role => role.Name == "Everyone"))
                {
                    everyone = role;
                }
#endif

                List <ulong> regionsToBeUpdated = new List <ulong>();
                foreach (GroupRoleMembersData data in members)
                {
                    if (data.RoleID == roleID)
                    {
                        //They were affected by the change
                        switch ((GroupRoleUpdate)type)
                        {
                        case GroupRoleUpdate.Create:
                        case GroupRoleUpdate.NoUpdate:
                            //No changes...
                            break;

                        case GroupRoleUpdate.UpdatePowers:     //Possible we don't need to send this?
                        case GroupRoleUpdate.UpdateAll:
                        case GroupRoleUpdate.UpdateData:
                        case GroupRoleUpdate.Delete:
                            if (type == (byte)GroupRoleUpdate.Delete)
                            {
                                //Set them to the most limited role since their role is gone
                                con.SetAgentGroupSelectedRole(data.MemberID, groupID, everyone.RoleID);
                            }
                            //Need to update their title inworld
                            ICapsService caps = m_registry.RequestModuleInterface <ICapsService>();
                            if (caps != null)
                            {
                                IClientCapsService clientCaps = caps.GetClientCapsService(agentID);
                                if (clientCaps != null && clientCaps.GetRootCapsService() != null)
                                {
                                    regionsToBeUpdated.Add(clientCaps.GetRootCapsService().RegionHandle);
                                }
                            }
                            break;
                        }
                    }
                }
                if (regionsToBeUpdated.Count != 0)
                {
                    IAsyncMessagePostService messagePost = m_registry.RequestModuleInterface <IAsyncMessagePostService>();
                    if (messagePost != null)
                    {
                        foreach (ulong regionhandle in regionsToBeUpdated)
                        {
                            OSDMap outgoingMessage = new OSDMap();
                            outgoingMessage["Method"]   = "ForceUpdateGroupTitles";
                            outgoingMessage["GroupID"]  = groupID;
                            outgoingMessage["RoleID"]   = roleID;
                            outgoingMessage["RegionID"] = regionhandle;
                            messagePost.Post(regionhandle, outgoingMessage);
                        }
                    }
                }
            }
            else if (message.ContainsKey("Method") && message["Method"] == "ForceUpdateGroupTitles")
            {
                //COMES IN ON REGION SIDE FROM AURORA.SERVER
                UUID          groupID  = message["GroupID"].AsUUID();
                UUID          roleID   = message["RoleID"].AsUUID();
                ulong         regionID = message["RegionID"].AsULong();
                IGroupsModule gm       = m_registry.RequestModuleInterface <IGroupsModule>();
                if (gm != null)
                {
                    gm.UpdateUsersForExternalRoleUpdate(groupID, roleID, regionID);
                }
            }
            else if (message.ContainsKey("Method") && message["Method"] == "SendGroupNoticeToUsers")
            {
                //COMES IN ON REGION SIDE FROM AURORA.SERVER
                GroupNoticeInfo notice = new GroupNoticeInfo();
                notice.FromOSD((OSDMap)message["Notice"]);
                IGroupsModule gm = m_registry.RequestModuleInterface <IGroupsModule>();
                if (gm != null)
                {
                    gm.SendGroupNoticeToUsers(null, notice, true);
                }
            }
            return(null);
        }
Exemplo n.º 20
0
        public UUID StartPurchaseOrATMTransfer(UUID agentId, uint amountBuying, PurchaseType purchaseType, string gridName)
        {
            bool        success = false;
            UserAccount ua      = Registry.RequestModuleInterface <IUserAccountService>().GetUserAccount(null, agentId);

            if (ua == null)
            {
                return(UUID.Zero);
            }
            string agentName = ua.Name;

            UUID   RegionID   = UUID.Zero;
            string RegionName = "";

            if (purchaseType == PurchaseType.InWorldPurchaseOfCurrency)
            {
                IClientCapsService client = Registry.RequestModuleInterface <ICapsService>().GetClientCapsService(agentId);
                if (client != null)
                {
                    IRegionClientCapsService regionClient = client.GetRootCapsService();
                    RegionID   = regionClient.Region.RegionID;
                    RegionName = regionClient.Region.RegionName;
                }
            }
            else if (purchaseType == PurchaseType.ATMTransferFromAnotherGrid)
            {
                RegionName = "Grid:" + gridName;
            }
            else
            {
                RegionName = "Unknown";
            }


            UUID purchaseID = UUID.Random();

            success = m_database.UserCurrencyBuy(purchaseID, agentId, agentName, amountBuying, m_options.RealCurrencyConversionFactor,
                                                 new RegionTransactionDetails
            {
                RegionID   = RegionID,
                RegionName = RegionName
            }, (int)purchaseType);
            StarDustUserCurrency currency = UserCurrencyInfo(agentId);



            if (m_options.AutoApplyCurrency && success)
            {
                Transaction transaction;
                m_database.UserCurrencyBuyComplete(purchaseID, 1, "AutoComplete",
                                                   m_options
                                                   .AutoApplyCurrency.ToString
                                                       (), "Auto Complete",
                                                   out transaction);

                UserCurrencyTransfer(transaction.ToID,
                                     m_options.
                                     BankerPrincipalID, UUID.Zero, UUID.Zero,
                                     transaction.Amount, "Currency Purchase",
                                     TransactionType.SystemGenerated,
                                     transaction.TransactionID);
                RestrictCurrency(currency, transaction, agentId);
            }
            else if (success && (m_options.AfterCurrencyPurchaseMessage != string.Empty) && (purchaseType == PurchaseType.InWorldPurchaseOfCurrency))
            {
                SendGridMessage(agentId, String.Format(m_options.AfterCurrencyPurchaseMessage, purchaseID.ToString()), false, UUID.Zero);
            }

            if (success)
            {
                return(purchaseID);
            }
            return(UUID.Zero);
        }
Exemplo n.º 21
0
        /// <summary>
        /// This is the function that everythign really happens Grid and Region Side. We build the transaction here.
        /// </summary>
        /// <param name="toID"></param>
        /// <param name="fromID"></param>
        /// <param name="toObjectID"></param>
        /// <param name="fromObjectID"></param>
        /// <param name="amount"></param>
        /// <param name="description"></param>
        /// <param name="type"></param>
        /// <param name="transactionID"></param>
        /// <returns></returns>
        public virtual bool UserCurrencyTransfer(UUID toID, UUID fromID, UUID toObjectID, UUID fromObjectID, uint amount, string description, TransactionType type, UUID transactionID)
        {
            bool isgridServer = false;

            #region Build the transaction



            string transactionPosition = "";
            IScene scene          = null;
            string fromObjectName = "";
            string toObjectName   = "";


            if ((fromObjectID != UUID.Zero) && (StarDustRegionService != null))
            {
                ISceneChildEntity ce = StarDustRegionService.FindObject(fromObjectID, out scene);
                if (ce != null)
                {
                    fromObjectName      = ce.Name;
                    transactionPosition = ce.AbsolutePosition.ToString();
                }
            }

            if ((toObjectID != UUID.Zero) && (StarDustRegionService != null))
            {
                ISceneChildEntity ce = StarDustRegionService.FindObject(toObjectID, out scene);
                if (ce != null)
                {
                    toObjectName        = ce.Name;
                    transactionPosition = ce.AbsolutePosition.ToString();
                }
            }

            if (transactionPosition.Length == 0)
            {
                transactionPosition = scene.GetScenePresence(fromID).AbsolutePosition.ToString();
            }

            if (transactionPosition.Length == 0)
            {
                transactionPosition = scene.GetScenePresence(toID).AbsolutePosition.ToString();
            }

            if (transactionPosition.Length == 0)
            {
                transactionPosition = "Unknown";
            }

            RegionTransactionDetails r = new RegionTransactionDetails();
            ulong regionHandel         = 0;
            if (scene != null)
            {
                r = new RegionTransactionDetails
                {
                    RegionID       = scene.RegionInfo.RegionID,
                    RegionName     = scene.RegionInfo.RegionName,
                    RegionPosition = transactionPosition
                };
            }
            else if (m_registry != null)
            {
                ICapsService capsService = m_registry.RequestModuleInterface <ICapsService>();
                if (capsService != null)
                {
                    IClientCapsService client = capsService.GetClientCapsService(fromID);
                    if (client != null)
                    {
                        IRegionClientCapsService regionClient = client.GetRootCapsService();
                        if (regionClient != null)
                        {
                            regionHandel     = regionClient.Region.RegionHandle;
                            r.RegionName     = regionClient.Region.RegionName;
                            r.RegionPosition = "<128,128,128>";
                            r.RegionID       = regionClient.Region.RegionID;
                            isgridServer     = true;
                        }
                    }
                }
            }
            else
            {
                return(false);
            }


            string fromName = "";
            if (fromID != UUID.Zero)
            {
                if (StarDustRegionService != null)
                {
                    IClientAPI icapiFrom = StarDustRegionService.GetUserClient(fromID);
                    if (icapiFrom != null)
                    {
                        fromName = icapiFrom.Name;
                    }
                }
                if (fromName == "")
                {
                    UserAccount ua = GetUserAccount(fromID);
                    if (ua != null)
                    {
                        fromName = ua.Name;
                    }
                }
                if (fromName == "")
                {
                    if (StarDustRegionService != null)
                    {
                        ISceneChildEntity ce = StarDustRegionService.FindObject(fromID, out scene);
                        if (ce != null)
                        {
                            fromObjectID = fromID;
                            fromID       = ce.OwnerID;
                            UserAccount ua2 = GetUserAccount(fromID);

                            if (ua2 != null)
                            {
                                fromName = ua2.Name;
                            }
                            else
                            {
                                fromID = UUID.Zero;
                            }

                            fromObjectName = ce.Name;
                        }
                        else
                        {
                            fromID = UUID.Zero;
                        }
                    }
                    else
                    {
                        fromID = UUID.Zero;
                    }
                }
            }

            if (fromID == UUID.Zero)
            {
                MainConsole.Instance.Debug("[StarDust MoneyModule.cs] Could not find who the money was coming from.");
                return(false);
            }

            string toName = "";
            if (toID != UUID.Zero)
            {
                if (StarDustRegionService != null)
                {
                    IClientAPI icapiFrom = StarDustRegionService.GetUserClient(toID);
                    if (icapiFrom != null)
                    {
                        toName = icapiFrom.Name;
                    }
                }
                if (toName == "")
                {
                    UserAccount ua = GetUserAccount(toID);
                    if (ua != null)
                    {
                        toName = ua.Name;
                    }
                }
                if (toName == "")
                {
                    if (StarDustRegionService != null)
                    {
                        ISceneChildEntity ce = StarDustRegionService.FindObject(toID, out scene);
                        if (ce != null)
                        {
                            toObjectID = toID;
                            toID       = ce.OwnerID;
                            UserAccount ua3 = GetUserAccount(toID);
                            if (ua3 != null)
                            {
                                toName = ua3.Name;
                            }
                            toObjectName = ce.Name;
                        }
                        else
                        {
                            toName = "Group";
                        }
                    }
                    else
                    {
                        toName = "Group";
                    }
                }
            }
            else
            {
                toID = m_options.BankerPrincipalID;
            }
            //this ensure no matter what theres a place for the money to go
            UserCurrencyInfo(toID);

            if ((description == "") && ((int)type == 5001) && (fromObjectID == UUID.Zero) && (toObjectID == UUID.Zero))
            {
                description = "Gift";
            }
            if (description == "")
            {
                description = Enum.GetName(typeof(TransactionType), type);
            }
            if (description == "")
            {
                description = type.ToString();
            }



            #endregion

            #region Perform transaction

            Transaction transaction =
                UserCurrencyTransfer(new Transaction
            {
                TransactionID  = transactionID,
                Amount         = amount,
                Description    = description,
                FromID         = fromID,
                FromName       = fromName,
                FromObjectID   = fromObjectID,
                FromObjectName = fromObjectName,
                Region         = r,
                ToID           = toID,
                ToName         = toName,
                ToObjectID     = toObjectID,
                ToObjectName   = toObjectName,
                TypeOfTrans    = type
            });
            bool returnvalue = transaction.Complete == 1;

            if (returnvalue)
            {
                m_moneyModule.FireObjectPaid(toObjectID, fromID, (int)amount);
            }

            #endregion

            #region notifications

            if (transaction.Complete == 1)
            {
                if (transaction.ToID != m_options.BankerPrincipalID)
                {
                    if (transaction.TypeOfTrans == TransactionType.Gift)
                    {
                        SendGridMessage(transaction.FromID,
                                        "You Paid " + transaction.ToName + " $" + transaction.Amount.ToString(), !isgridServer, transaction.TransactionID);
                    }
                    else
                    {
                        SendGridMessage(transaction.FromID,
                                        "You Paid $" + transaction.Amount + " to " + transaction.ToName, !isgridServer, transaction.TransactionID);
                    }
                    SendGridMessage(transaction.ToID,
                                    "You Were Paid $" + transaction.Amount + " by " + transaction.FromName, !isgridServer, transaction.TransactionID);
                }
                else if (transaction.TypeOfTrans == TransactionType.UploadCharge)
                {
                    SendGridMessage(transaction.FromID, "You Paid $" + transaction.Amount + " to upload", !isgridServer, transaction.TransactionID);
                }
                else
                {
                    SendGridMessage(transaction.FromID, "You Paid $" + transaction.Amount, !isgridServer, transaction.TransactionID);
                }
            }
            else
            {
                if (transaction.CompleteReason != "")
                {
                    SendGridMessage(transaction.FromID, "Transaction Failed - " + transaction.CompleteReason, !isgridServer, transaction.TransactionID);
                }
                else
                {
                    SendGridMessage(transaction.FromID, "Transaction Failed", !isgridServer, transaction.TransactionID);
                }
            }

            if ((toObjectID != UUID.Zero) && (!isgridServer))
            {
                m_moneyModule.FireObjectPaid(toObjectID, fromID, (int)amount);
            }

            #endregion

            return(returnvalue);
        }