From 7e8c996d1b13212a65b75393e1a2f96683e9bb2d Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 11 May 2017 17:15:02 +0100 Subject: [PATCH 1/8] add a grid services god account --- .../UserAccountService/UserAccountService.cs | 78 ++++++++++++------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs index a22754feee..48929ee5fd 100644 --- a/OpenSim/Services/UserAccountService/UserAccountService.cs +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs @@ -43,6 +43,7 @@ namespace OpenSim.Services.UserAccountService public class UserAccountService : UserAccountServiceBase, IUserAccountService { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly UUID UUID_GRID_GOD = new UUID("6571e388-6218-4574-87db-f9379718315e"); private static UserAccountService m_RootInstance; /// @@ -85,38 +86,63 @@ namespace OpenSim.Services.UserAccountService m_CreateDefaultAvatarEntries = userConfig.GetBoolean("CreateDefaultAvatarEntries", false); - // In case there are several instances of this class in the same process, - // the console commands are only registered for the root instance - if (m_RootInstance == null && MainConsole.Instance != null) + // create a system grid god account + UserAccount ggod = GetUserAccount(UUID.Zero, UUID_GRID_GOD); + if(ggod == null) + { + UserAccountData d = new UserAccountData(); + + d.FirstName = "GRID"; + d.LastName = "SERVICES"; + d.PrincipalID = UUID_GRID_GOD; + d.ScopeID = UUID.Zero; + d.Data = new Dictionary(); + d.Data["Email"] = string.Empty; + d.Data["Created"] = Util.UnixTimeSinceEpoch().ToString(); + d.Data["UserLevel"] = "240"; + d.Data["UserFlags"] = "0"; + d.Data["ServiceURLs"] = string.Empty; + + m_Database.Store(d); + } + + if (m_RootInstance == null) { m_RootInstance = this; - MainConsole.Instance.Commands.AddCommand("Users", false, - "create user", - "create user [ [ [ [ [ []]]]]]", - "Create a new user", HandleCreateUser); - MainConsole.Instance.Commands.AddCommand("Users", false, - "reset user password", - "reset user password [ [ []]]", - "Reset a user password", HandleResetUserPassword); + // In case there are several instances of this class in the same process, + // the console commands are only registered for the root instance + if (MainConsole.Instance != null) + { + + MainConsole.Instance.Commands.AddCommand("Users", false, + "create user", + "create user [ [ [ [ [ []]]]]]", + "Create a new user", HandleCreateUser); - MainConsole.Instance.Commands.AddCommand("Users", false, - "reset user email", - "reset user email [ [ []]]", - "Reset a user email address", HandleResetUserEmail); + MainConsole.Instance.Commands.AddCommand("Users", false, + "reset user password", + "reset user password [ [ []]]", + "Reset a user password", HandleResetUserPassword); - MainConsole.Instance.Commands.AddCommand("Users", false, - "set user level", - "set user level [ [ []]]", - "Set user level. If >= 200 and 'allow_grid_gods = true' in OpenSim.ini, " - + "this account will be treated as god-moded. " - + "It will also affect the 'login level' command. ", - HandleSetUserLevel); + MainConsole.Instance.Commands.AddCommand("Users", false, + "reset user email", + "reset user email [ [ []]]", + "Reset a user email address", HandleResetUserEmail); - MainConsole.Instance.Commands.AddCommand("Users", false, - "show account", - "show account ", - "Show account details for the given user", HandleShowAccount); + MainConsole.Instance.Commands.AddCommand("Users", false, + "set user level", + "set user level [ [ []]]", + "Set user level. If >= 200 and 'allow_grid_gods = true' in OpenSim.ini, " + + "this account will be treated as god-moded. " + + "It will also affect the 'login level' command. ", + HandleSetUserLevel); + + MainConsole.Instance.Commands.AddCommand("Users", false, + "show account", + "show account ", + "Show account details for the given user", HandleShowAccount); + } } } From 5968c6372a0620a158c88c70b439cb7c3bf256bb Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 11 May 2017 17:30:57 +0100 Subject: [PATCH 2/8] let new regions know about grid services god --- .../CoreModules/Avatar/Gods/GodsModule.cs | 100 +++++++++++++----- 1 file changed, 74 insertions(+), 26 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs b/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs index f699c0c889..6e6974a5c8 100644 --- a/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs @@ -59,21 +59,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods /// Special UUID for actions that apply to all agents private static readonly UUID ALL_AGENTS = new UUID("44e87126-e794-4ded-05b3-7c42da3d5cdb"); + private static readonly UUID UUID_GRID_GOD = new UUID("6571e388-6218-4574-87db-f9379718315e"); protected Scene m_scene; protected IDialogModule m_dialogModule; - protected IDialogModule DialogModule - { - get - { - if (m_dialogModule == null) - m_dialogModule = m_scene.RequestModuleInterface(); - - return m_dialogModule; - } - } - public void Initialise(IConfigSource source) { } @@ -97,6 +87,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods public void RegionLoaded(Scene scene) { + m_dialogModule = m_scene.RequestModuleInterface(); } public void Close() {} @@ -152,7 +143,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods if (god == null || god.ControllingClient.SessionId != godSessionID) return String.Empty; - KickUser(godID, agentID, kickFlags, Util.StringToBytes1024(reason)); + KickUser(godID, agentID, kickFlags, reason); } else { @@ -173,8 +164,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods sp.GrantGodlikePowers(token, godLike); - if (godLike && !sp.IsViewerUIGod && DialogModule != null) - DialogModule.SendAlertToUser(agentID, "Request for god powers denied"); + if (godLike && !sp.IsViewerUIGod && m_dialogModule != null) + m_dialogModule.SendAlertToUser(agentID, "Request for god powers denied"); + } + + public void KickUser(UUID godID, UUID agentID, uint kickflags, byte[] reason) + { + KickUser(godID, agentID, kickflags, Utils.BytesToString(reason)); } /// @@ -184,7 +180,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods /// the person that is being kicked /// Tells what to do to the user /// The message to send to the user after it's been turned into a field - public void KickUser(UUID godID, UUID agentID, uint kickflags, byte[] reason) + public void KickUser(UUID godID, UUID agentID, uint kickflags, string reason) { // assuming automatic god rights on this for fast griefing reaction // this is also needed for kick via message @@ -200,10 +196,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods if(agentID == ALL_AGENTS) { m_scene.ForEachRootScenePresence(delegate(ScenePresence p) + { + if (p.UUID != godID) { - if (p.UUID != godID && godlevel > p.GodController.GodLevel) + if(godlevel > p.GodController.GodLevel) doKickmodes(godID, p, kickflags, reason); - }); + else if(m_dialogModule != null) + m_dialogModule.SendAlertToUser(p.UUID, "Kick from " + godID.ToString() + " ignored, kick reason: " + reason); + } + }); return; } @@ -217,7 +218,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods m_log.DebugFormat("[GODS]: Sending nonlocal kill for agent {0}", agentID); transferModule.SendInstantMessage(new GridInstantMessage( m_scene, godID, "God", agentID, (byte)250, false, - Utils.BytesToString(reason), UUID.Zero, true, + reason, UUID.Zero, true, new Vector3(), new byte[] {(byte)kickflags}, true), delegate(bool success) {} ); } @@ -225,7 +226,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods } if (godlevel <= sp.GodController.GodLevel) // no god wars + { + if(m_dialogModule != null) + m_dialogModule.SendAlertToUser(sp.UUID, "Kick from " + godID.ToString() + " ignored, kick reason: " + reason); return; + } if(sp.UUID == godID) return; @@ -233,29 +238,34 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods doKickmodes(godID, sp, kickflags, reason); } - private void doKickmodes(UUID godID, ScenePresence sp, uint kickflags, byte[] reason) + private void doKickmodes(UUID godID, ScenePresence sp, uint kickflags, string reason) { switch (kickflags) { case 0: - KickPresence(sp, Utils.BytesToString(reason)); + KickPresence(sp, reason); break; case 1: sp.AllowMovement = false; - m_dialogModule.SendAlertToUser(sp.UUID, Utils.BytesToString(reason)); - m_dialogModule.SendAlertToUser(godID, "User Frozen"); + if(m_dialogModule != null) + { + m_dialogModule.SendAlertToUser(sp.UUID, reason); + m_dialogModule.SendAlertToUser(godID, "User Frozen"); + } break; case 2: sp.AllowMovement = true; - m_dialogModule.SendAlertToUser(sp.UUID, Utils.BytesToString(reason)); - m_dialogModule.SendAlertToUser(godID, "User Unfrozen"); + if(m_dialogModule != null) + { + m_dialogModule.SendAlertToUser(sp.UUID, reason); + m_dialogModule.SendAlertToUser(godID, "User Unfrozen"); + } break; default: break; } } - private void KickPresence(ScenePresence sp, string reason) { if(sp.IsDeleted || sp.IsChildAgent) @@ -264,6 +274,41 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods sp.Scene.CloseAgent(sp.UUID, true); } + public void GridKickUser(UUID agentID, string reason) + { + int godlevel = 240; // grid god default + + ScenePresence sp = m_scene.GetScenePresence(agentID); + if (sp == null || sp.IsChildAgent) + { + IMessageTransferModule transferModule = + m_scene.RequestModuleInterface(); + if (transferModule != null) + { + m_log.DebugFormat("[GODS]: Sending nonlocal kill for agent {0}", agentID); + transferModule.SendInstantMessage(new GridInstantMessage( + m_scene, UUID_GRID_GOD, "GRID", agentID, (byte)250, false, + reason, UUID.Zero, true, + new Vector3(), new byte[] {0}, true), + delegate(bool success) {} ); + } + return; + } + + if(sp.IsDeleted) + return; + + if (godlevel <= sp.GodController.GodLevel) // no god wars + { + if(m_dialogModule != null) + m_dialogModule.SendAlertToUser(sp.UUID, "GRID kick detected and ignored, kick reason: " + reason); + return; + } + + sp.ControllingClient.Kick(reason); + sp.Scene.CloseAgent(sp.UUID, true); + } + private void OnIncomingInstantMessage(GridInstantMessage msg) { if (msg.dialog == (uint)250) // Nonlocal kick @@ -273,7 +318,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods UUID godID = new UUID(msg.fromAgentID); uint kickMode = (uint)msg.binaryBucket[0]; - KickUser(godID, agentID, kickMode, Util.StringToBytes1024(reason)); + if(godID == UUID_GRID_GOD) + GridKickUser(agentID, reason); + else + KickUser(godID, agentID, kickMode, reason); } } } From 211a1fe9d413f5571efb2deb1a436ae8639f1c1e Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 11 May 2017 17:59:37 +0100 Subject: [PATCH 3/8] do not allow multiple logins of same avatar. No HG case, that needs work on some paths. option m_allowDuplicatePresences is checked, but is is a total nonsense.. Presences control will get broken if allowed, No one ever added code to suport it correctly. --- .../LLLoginService/LLLoginResponse.cs | 5 +- .../Services/LLLoginService/LLLoginService.cs | 72 ++++++++++++++++++- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/OpenSim/Services/LLLoginService/LLLoginResponse.cs b/OpenSim/Services/LLLoginService/LLLoginResponse.cs index 32e14a1d0a..823fd36470 100644 --- a/OpenSim/Services/LLLoginService/LLLoginResponse.cs +++ b/OpenSim/Services/LLLoginService/LLLoginResponse.cs @@ -82,9 +82,8 @@ namespace OpenSim.Services.LLLoginService "false"); AlreadyLoggedInProblem = new LLFailedLoginResponse("presence", "You appear to be already logged in. " + - "If this is not the case please wait for your session to timeout. " + - "If this takes longer than a few minutes please contact the grid owner. " + - "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.", + "Please wait a a minute or two and retry. " + + "If this takes longer than a few minutes please contact the grid owner. ", "false"); InternalError = new LLFailedLoginResponse("Internal Error", "Error generating Login Response", "false"); } diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs index fc45f86d45..6a289d153f 100644 --- a/OpenSim/Services/LLLoginService/LLLoginService.cs +++ b/OpenSim/Services/LLLoginService/LLLoginService.cs @@ -40,6 +40,7 @@ using OpenMetaverse; using OpenSim.Framework; using OpenSim.Framework.Console; using OpenSim.Server.Base; +using OpenSim.Services.Connectors.InstantMessage; using OpenSim.Services.Interfaces; using GridRegion = OpenSim.Services.Interfaces.GridRegion; using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; @@ -89,6 +90,7 @@ namespace OpenSim.Services.LLLoginService protected string m_DeniedClients; protected string m_MessageUrl; protected string m_DSTZone; + protected bool m_allowDuplicatePresences = false; IConfig m_LoginServerConfig; // IConfig m_ClientsConfig; @@ -140,6 +142,11 @@ namespace OpenSim.Services.LLLoginService if (groupConfig != null) m_MaxAgentGroups = groupConfig.GetInt("MaxAgentGroups", 42); + IConfig presenceConfig = config.Configs["PresenceService"]; + if (presenceConfig != null) + { + m_allowDuplicatePresences = presenceConfig.GetBoolean("AllowDuplicatePresences", m_allowDuplicatePresences); + } // Clean up some of these vars if (m_MapTileURL != String.Empty) @@ -370,6 +377,29 @@ namespace OpenSim.Services.LLLoginService return LLFailedLoginResponse.UserProblem; } + if(account.PrincipalID == new UUID("6571e388-6218-4574-87db-f9379718315e")) + { + // really? + return LLFailedLoginResponse.UserProblem; + } + + string PrincipalIDstr = account.PrincipalID.ToString(); + GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(PrincipalIDstr); + + if(!m_allowDuplicatePresences) + { + if(guinfo != null && guinfo.Online && guinfo.LastRegionID != UUID.Zero) + { + if(SendAgentGodKillToRegion(scopeID, account.PrincipalID, guinfo)) + { + m_log.InfoFormat( + "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: already logged in", + firstName, lastName); + return LLFailedLoginResponse.AlreadyLoggedInProblem; + } + } + } + // // Get the user's inventory // @@ -406,7 +436,7 @@ namespace OpenSim.Services.LLLoginService // if (m_PresenceService != null) { - success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession); + success = m_PresenceService.LoginAgent(PrincipalIDstr, session, secureSession); if (!success) { @@ -421,7 +451,6 @@ namespace OpenSim.Services.LLLoginService // Change Online status and get the home region // GridRegion home = null; - GridUserInfo guinfo = m_GridUserService.LoggedIn(account.PrincipalID.ToString()); // We are only going to complain about no home if the user actually tries to login there, to avoid // spamming the console. @@ -504,6 +533,10 @@ namespace OpenSim.Services.LLLoginService return new LLFailedLoginResponse("key", reason, "false"); } + + // only now we can assume a login + guinfo = m_GridUserService.LoggedIn(PrincipalIDstr); + // Get Friends list FriendInfo[] friendsList = new FriendInfo[0]; if (m_FriendsService != null) @@ -1080,6 +1113,41 @@ namespace OpenSim.Services.LLLoginService break; } } + + private bool SendAgentGodKillToRegion(UUID scopeID, UUID agentID , GridUserInfo guinfo) + { + UUID regionID = guinfo.LastRegionID; + GridRegion regInfo = m_GridService.GetRegionByUUID(scopeID, regionID); + if(regInfo == null) + return false; + + string regURL = regInfo.ServerURI; + if(String.IsNullOrEmpty(regURL)) + return false; + + UUID guuid = new UUID("6571e388-6218-4574-87db-f9379718315e"); + + GridInstantMessage msg = new GridInstantMessage(); + msg.imSessionID = UUID.Zero.Guid; + msg.fromAgentID = guuid.Guid; + msg.toAgentID = agentID.Guid; + msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); + msg.fromAgentName = "GRID"; + msg.message = string.Format("New login detected"); + msg.dialog = 250; // God kick + msg.fromGroup = false; + msg.offline = (byte)0; + msg.ParentEstateID = 0; + msg.Position = Vector3.Zero; + msg.RegionID = scopeID.Guid; + msg.binaryBucket = new byte[1] {0}; + InstantMessageServiceConnector.SendInstantMessage(regURL,msg); + + m_GridUserService.LoggedOut(agentID.ToString(), + UUID.Zero, guinfo.LastRegionID, guinfo.LastPosition, guinfo.LastLookAt); + + return true; + } } #endregion From fb427daa3443794b38c3dd3e5b58610971b35b13 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 11 May 2017 19:06:49 +0100 Subject: [PATCH 4/8] avoid a null ref --- .../Avatar/Friends/FriendsModule.cs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 35b48d9924..91f19e3ced 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -512,18 +512,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if (((fi.MyFlags & (int)FriendRights.CanSeeOnline) != 0) && (fi.TheirFlags != -1)) friendList.Add(fi); } + if(friendList.Count > 0) + { + Util.FireAndForget( + delegate + { +// m_log.DebugFormat( +// "[FRIENDS MODULE]: Notifying {0} friends of {1} of online status {2}", +// friendList.Count, agentID, online); - Util.FireAndForget( - delegate - { -// m_log.DebugFormat( -// "[FRIENDS MODULE]: Notifying {0} friends of {1} of online status {2}", -// friendList.Count, agentID, online); - - // Notify about this user status - StatusNotify(friendList, agentID, online); - }, null, "FriendsModule.StatusChange" - ); + // Notify about this user status + StatusNotify(friendList, agentID, online); + }, null, "FriendsModule.StatusChange" + ); + } } } @@ -552,6 +554,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends // We do this regrouping so that we can efficiently send a single request rather than one for each // friend in what may be a very large friends list. PresenceInfo[] friendSessions = PresenceService.GetAgents(remoteFriendStringIds.ToArray()); + if(friendSessions == null) + return; foreach (PresenceInfo friendSession in friendSessions) { From f09fafff349af9e020871f622130508e882a1b35 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 11 May 2017 20:24:47 +0100 Subject: [PATCH 5/8] some cleanup --- .../Services/LLLoginService/LLLoginService.cs | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs index 6a289d153f..3ccdc9c013 100644 --- a/OpenSim/Services/LLLoginService/LLLoginService.cs +++ b/OpenSim/Services/LLLoginService/LLLoginService.cs @@ -865,6 +865,9 @@ namespace OpenSim.Services.LLLoginService reason = string.Empty; uint circuitCode = 0; AgentCircuitData aCircuit = null; + dest = null; + + bool success = false; if (m_UserAgentService == null) { @@ -875,28 +878,14 @@ namespace OpenSim.Services.LLLoginService simConnector = m_LocalSimulationService; else if (m_RemoteSimulationService != null) simConnector = m_RemoteSimulationService; - } - else // User Agent Service is on - { - if (gatekeeper == null) // login to local grid - { - if (hostName == string.Empty) - SetHostAndPort(m_GatekeeperURL); - gatekeeper = new GridRegion(destination); - gatekeeper.ExternalHostName = hostName; - gatekeeper.HttpPort = (uint)port; - gatekeeper.ServerURI = m_GatekeeperURL; - } - m_log.Debug("[LLLOGIN SERVICE]: no gatekeeper detected..... using " + m_GatekeeperURL); - } + if(simConnector == null) + return null; - bool success = false; - - if (m_UserAgentService == null && simConnector != null) - { circuitCode = (uint)Util.RandomClass.Next(); ; - aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position, clientIP.Address.ToString(), viewer, channel, mac, id0); + aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position, + clientIP.Address.ToString(), viewer, channel, mac, id0); + success = LaunchAgentDirectly(simConnector, destination, aCircuit, flags, out reason); if (!success && m_GridService != null) { @@ -918,10 +907,22 @@ namespace OpenSim.Services.LLLoginService } } - if (m_UserAgentService != null) + else { + if (gatekeeper == null) // login to local grid + { + if (hostName == string.Empty) + SetHostAndPort(m_GatekeeperURL); + + gatekeeper = new GridRegion(destination); + gatekeeper.ExternalHostName = hostName; + gatekeeper.HttpPort = (uint)port; + gatekeeper.ServerURI = m_GatekeeperURL; + } circuitCode = (uint)Util.RandomClass.Next(); ; - aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position, clientIP.Address.ToString(), viewer, channel, mac, id0); + aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position, + clientIP.Address.ToString(), viewer, channel, mac, id0); + aCircuit.teleportFlags |= (uint)flags; success = LaunchAgentIndirectly(gatekeeper, destination, aCircuit, clientIP, out reason); if (!success && m_GridService != null) From cc95b7e2d4d93be36c71c0d72b9b812e161a208f Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 11 May 2017 20:26:06 +0100 Subject: [PATCH 6/8] don't allow multiple presences of same avatar also on HG gatekeeper --- .../HypergridService/GatekeeperService.cs | 121 ++++++++++++++---- .../HypergridService/UserAgentService.cs | 1 - 2 files changed, 99 insertions(+), 23 deletions(-) diff --git a/OpenSim/Services/HypergridService/GatekeeperService.cs b/OpenSim/Services/HypergridService/GatekeeperService.cs index b80700faed..9bf3cf8810 100644 --- a/OpenSim/Services/HypergridService/GatekeeperService.cs +++ b/OpenSim/Services/HypergridService/GatekeeperService.cs @@ -35,8 +35,8 @@ using OpenSim.Framework; using OpenSim.Services.Interfaces; using GridRegion = OpenSim.Services.Interfaces.GridRegion; using OpenSim.Server.Base; +using OpenSim.Services.Connectors.InstantMessage; using OpenSim.Services.Connectors.Hypergrid; - using OpenMetaverse; using Nini.Config; @@ -71,6 +71,7 @@ namespace OpenSim.Services.HypergridService private static string m_ExternalName; private static Uri m_Uri; private static GridRegion m_DefaultGatewayRegion; + private bool m_allowDuplicatePresences = false; public GatekeeperService(IConfigSource config, ISimulationService simService) { @@ -144,6 +145,12 @@ namespace OpenSim.Services.HypergridService if (m_GridService == null || m_PresenceService == null || m_SimulationService == null) throw new Exception("Unable to load a required plugin, Gatekeeper Service cannot function."); + IConfig presenceConfig = config.Configs["PresenceService"]; + if (presenceConfig != null) + { + m_allowDuplicatePresences = presenceConfig.GetBoolean("AllowDuplicatePresences", m_allowDuplicatePresences); + } + m_log.Debug("[GATEKEEPER SERVICE]: Starting..."); } } @@ -369,6 +376,36 @@ namespace OpenSim.Services.HypergridService return false; } + if(account.PrincipalID == new UUID("6571e388-6218-4574-87db-f9379718315e")) + { + // really? + reason = "Invalid account ID"; + return false; + } + + if(m_GridUserService != null) + { + string PrincipalIDstr = account.PrincipalID.ToString(); + GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(PrincipalIDstr); + + if(!m_allowDuplicatePresences) + { + if(guinfo != null && guinfo.Online && guinfo.LastRegionID != UUID.Zero) + { + if(SendAgentGodKillToRegion(UUID.Zero, account.PrincipalID, guinfo)) + { + m_log.InfoFormat( + "[GATEKEEPER SERVICE]: Login failed for {0} {1}, reason: already logged in", + account.FirstName, account.LastName); + reason = "You appear to be already logged in on destiny grid " + + "Please wait a a minute or two and retry. " + + "If this takes longer than a few minutes please contact the grid owner. "; + return false; + } + } + } + } + m_log.DebugFormat("[GATEKEEPER SERVICE]: User {0} is ok", aCircuit.Name); bool isFirstLogin = false; @@ -389,26 +426,6 @@ namespace OpenSim.Services.HypergridService return false; } - m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence {0} is ok", aCircuit.Name); - - // Also login foreigners with GridUser service - if (m_GridUserService != null && account == null) - { - string userId = aCircuit.AgentID.ToString(); - string first = aCircuit.firstname, last = aCircuit.lastname; - if (last.StartsWith("@")) - { - string[] parts = aCircuit.firstname.Split('.'); - if (parts.Length >= 2) - { - first = parts[0]; - last = parts[1]; - } - } - - userId += ";" + aCircuit.ServiceURLs["HomeURI"] + ";" + first + " " + last; - m_GridUserService.LoggedIn(userId); - } } // @@ -465,7 +482,33 @@ namespace OpenSim.Services.HypergridService true, aCircuit.startpos, new List(), ctx, out reason)) return false; - return m_SimulationService.CreateAgent(source, destination, aCircuit, (uint)loginFlag, ctx, out reason); + bool didit = m_SimulationService.CreateAgent(source, destination, aCircuit, (uint)loginFlag, ctx, out reason); + + if(didit) + { + m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence {0} is ok", aCircuit.Name); + + if(!isFirstLogin && m_GridUserService != null && account == null) + { + // Also login foreigners with GridUser service + string userId = aCircuit.AgentID.ToString(); + string first = aCircuit.firstname, last = aCircuit.lastname; + if (last.StartsWith("@")) + { + string[] parts = aCircuit.firstname.Split('.'); + if (parts.Length >= 2) + { + first = parts[0]; + last = parts[1]; + } + } + + userId += ";" + aCircuit.ServiceURLs["HomeURI"] + ";" + first + " " + last; + m_GridUserService.LoggedIn(userId); + } + } + + return didit; } protected bool Authenticate(AgentCircuitData aCircuit) @@ -563,6 +606,40 @@ namespace OpenSim.Services.HypergridService return exception; } + private bool SendAgentGodKillToRegion(UUID scopeID, UUID agentID , GridUserInfo guinfo) + { + UUID regionID = guinfo.LastRegionID; + GridRegion regInfo = m_GridService.GetRegionByUUID(scopeID, regionID); + if(regInfo == null) + return false; + + string regURL = regInfo.ServerURI; + if(String.IsNullOrEmpty(regURL)) + return false; + + UUID guuid = new UUID("6571e388-6218-4574-87db-f9379718315e"); + + GridInstantMessage msg = new GridInstantMessage(); + msg.imSessionID = UUID.Zero.Guid; + msg.fromAgentID = guuid.Guid; + msg.toAgentID = agentID.Guid; + msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); + msg.fromAgentName = "GRID"; + msg.message = string.Format("New login detected"); + msg.dialog = 250; // God kick + msg.fromGroup = false; + msg.offline = (byte)0; + msg.ParentEstateID = 0; + msg.Position = Vector3.Zero; + msg.RegionID = scopeID.Guid; + msg.binaryBucket = new byte[1] {0}; + InstantMessageServiceConnector.SendInstantMessage(regURL,msg); + + m_GridUserService.LoggedOut(agentID.ToString(), + UUID.Zero, guinfo.LastRegionID, guinfo.LastPosition, guinfo.LastLookAt); + + return true; + } #endregion } } diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs index ba3cb2f72d..6f2cdd5e99 100644 --- a/OpenSim/Services/HypergridService/UserAgentService.cs +++ b/OpenSim/Services/HypergridService/UserAgentService.cs @@ -254,7 +254,6 @@ namespace OpenSim.Services.HypergridService } } - // Take the IP address + port of the gatekeeper (reg) plus the info of finalDestination GridRegion region = new GridRegion(gatekeeper); region.ServerURI = gatekeeper.ServerURI; From b8138c37d3382a52f0b58468a0446c018118302f Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 11 May 2017 21:41:33 +0100 Subject: [PATCH 7/8] hide a nonsense option --- bin/Robust.HG.ini.example | 7 ++----- bin/Robust.ini.example | 4 ---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/bin/Robust.HG.ini.example b/bin/Robust.HG.ini.example index 7d13d4382f..e65d13e862 100644 --- a/bin/Robust.HG.ini.example +++ b/bin/Robust.HG.ini.example @@ -288,7 +288,8 @@ LocalServiceModule = "OpenSim.Services.GridService.dll:GridService" ; Realm = "regions" - ; AllowDuplicateNames = "True" + // do not set this to TRUE unless you understand it + ; AllowDuplicateNames = "" ;; Perform distance check for the creation of a linked region ; Check4096 = "True" @@ -444,10 +445,6 @@ ; for the server connector LocalServiceModule = "OpenSim.Services.PresenceService.dll:PresenceService" - ; Set this to true to allow the use of advanced web services and multiple - ; bots using one account - AllowDuplicatePresences = false; - [AvatarService] ; for the server connector LocalServiceModule = "OpenSim.Services.AvatarService.dll:AvatarService" diff --git a/bin/Robust.ini.example b/bin/Robust.ini.example index d33178c461..2ebcef744b 100644 --- a/bin/Robust.ini.example +++ b/bin/Robust.ini.example @@ -390,10 +390,6 @@ [PresenceService] ; for the server connector LocalServiceModule = "OpenSim.Services.PresenceService.dll:PresenceService" - ; Set this to true to allow the use of advanced web services and multiple - ; bots using one account - AllowDuplicatePresences = false; - [AvatarService] ; for the server connector From 97d02ecf32aeb48479bdd730933f91a50cf07291 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 11 May 2017 21:44:57 +0100 Subject: [PATCH 8/8] remove a coment added by mistake --- bin/Robust.HG.ini.example | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/Robust.HG.ini.example b/bin/Robust.HG.ini.example index e65d13e862..2cd189750b 100644 --- a/bin/Robust.HG.ini.example +++ b/bin/Robust.HG.ini.example @@ -287,8 +287,7 @@ [GridService] LocalServiceModule = "OpenSim.Services.GridService.dll:GridService" - ; Realm = "regions" - // do not set this to TRUE unless you understand it + ; Realm = "regions" ; AllowDuplicateNames = "" ;; Perform distance check for the creation of a linked region