robust: add login block by ID0. Note that like by mac this may even block wrong users; cosmetics

This commit is contained in:
UbitUmarov
2023-01-09 12:39:42 +00:00
parent 8d16d0b0ba
commit c821ef25cb
4 changed files with 410 additions and 337 deletions

View File

@@ -46,9 +46,7 @@ namespace OpenSim.Services.HypergridService
{
public class GatekeeperService : IGatekeeperService
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static bool m_Initialized = false;
@@ -60,12 +58,13 @@ namespace OpenSim.Services.HypergridService
private static IGridUserService m_GridUserService;
private static IBansService m_BansService;
private static string m_AllowedClients = string.Empty;
private static string m_DeniedClients = string.Empty;
private static Regex m_AllowedClientsRegex = null;
private static Regex m_DeniedClientsRegex = null;
private static string m_DeniedMacs = string.Empty;
private static string m_DeniedID0s = string.Empty;
private static bool m_ForeignAgentsAllowed = true;
private static List<string> m_ForeignsAllowedExceptions = new List<string>();
private static List<string> m_ForeignsDisallowedExceptions = new List<string>();
private static readonly List<string> m_ForeignsAllowedExceptions = new();
private static readonly List<string> m_ForeignsDisallowedExceptions = new();
private static UUID m_ScopeID;
private static bool m_AllowTeleportsToAnyRegion;
@@ -85,7 +84,7 @@ namespace OpenSim.Services.HypergridService
m_Initialized = true;
IConfig serverConfig = config.Configs["GatekeeperService"];
if (serverConfig == null)
if (serverConfig is null)
throw new Exception(String.Format("No section GatekeeperService in config file"));
string accountService = serverConfig.GetString("UserAccountService", string.Empty);
@@ -124,11 +123,10 @@ namespace OpenSim.Services.HypergridService
string[] alias = gatekeeperURIAlias.Split(',');
for (int i = 0; i < alias.Length; ++i)
{
OSHHTPHost tmp = new OSHHTPHost(alias[i].Trim(), false);
OSHHTPHost tmp = new(alias[i].Trim(), false);
if (tmp.IsValidHost)
{
if (m_gateKeeperAlias == null)
m_gateKeeperAlias = new HashSet<OSHHTPHost>();
m_gateKeeperAlias ??= new HashSet<OSHHTPHost>();
m_gateKeeperAlias.Add(tmp);
}
}
@@ -138,43 +136,68 @@ namespace OpenSim.Services.HypergridService
m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
if (accountService != string.Empty)
if (!string.IsNullOrEmpty(accountService))
m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args);
if (homeUsersService != string.Empty)
if (!string.IsNullOrEmpty(homeUsersService))
m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(homeUsersService, args);
if (gridUserService != string.Empty)
if (!string.IsNullOrEmpty(gridUserService))
m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args);
if (bansService != string.Empty)
if (!string.IsNullOrEmpty(bansService))
m_BansService = ServerUtils.LoadPlugin<IBansService>(bansService, args);
if (simService != null)
if (simService is not null)
m_SimulationService = simService;
else if (simulationService != string.Empty)
m_SimulationService = ServerUtils.LoadPlugin<ISimulationService>(simulationService, args);
string[] possibleAccessControlConfigSections = new string[] { "AccessControl", "GatekeeperService" };
m_AllowedClients = Util.GetConfigVarFromSections<string>(
config, "AllowedClients", possibleAccessControlConfigSections, string.Empty);
m_DeniedClients = Util.GetConfigVarFromSections<string>(
config, "DeniedClients", possibleAccessControlConfigSections, string.Empty);
m_DeniedMacs = Util.GetConfigVarFromSections<string>(
config, "DeniedMacs", possibleAccessControlConfigSections, string.Empty);
string AllowedClients = Util.GetConfigVarFromSections<string>(config, "AllowedClients", possibleAccessControlConfigSections, string.Empty);
if (!string.IsNullOrEmpty(AllowedClients))
{
try
{
m_AllowedClientsRegex = new Regex(AllowedClients, RegexOptions.Compiled | RegexOptions.IgnoreCase);
}
catch
{
m_AllowedClientsRegex = null;
m_log.Error("[GATEKEEPER SERVICE]: failed to parse AllowedClients");
}
}
string DeniedClients = Util.GetConfigVarFromSections<string>(config, "DeniedClients", possibleAccessControlConfigSections, string.Empty);
if (!string.IsNullOrEmpty(DeniedClients))
{
try
{
m_DeniedClientsRegex = new Regex(DeniedClients, RegexOptions.Compiled | RegexOptions.IgnoreCase);
}
catch
{
m_DeniedClientsRegex = null;
m_log.Error("[GATEKEEPER SERVICE]: failed to parse DeniedClients");
}
}
m_DeniedMacs = Util.GetConfigVarFromSections<string>(config, "DeniedMacs", possibleAccessControlConfigSections, string.Empty);
m_DeniedID0s = Util.GetConfigVarFromSections<string>(config, "DeniedID0s", possibleAccessControlConfigSections, string.Empty);
m_ForeignAgentsAllowed = serverConfig.GetBoolean("ForeignAgentsAllowed", true);
LoadDomainExceptionsFromConfig(serverConfig, "AllowExcept", m_ForeignsAllowedExceptions);
LoadDomainExceptionsFromConfig(serverConfig, "DisallowExcept", m_ForeignsDisallowedExceptions);
if (m_GridService == null || m_PresenceService == null || m_SimulationService == null)
if (m_GridService is null || m_PresenceService is null || m_SimulationService is null)
throw new Exception("Unable to load a required plugin, Gatekeeper Service cannot function.");
IConfig presenceConfig = config.Configs["PresenceService"];
if (presenceConfig != null)
if (presenceConfig is not null)
{
m_allowDuplicatePresences = presenceConfig.GetBoolean("AllowDuplicatePresences", m_allowDuplicatePresences);
}
IConfig messagingConfig = config.Configs["Messaging"];
if (messagingConfig != null)
if (messagingConfig is not null)
m_messageKey = messagingConfig.GetString("MessageKey", String.Empty);
m_log.Debug("[GATEKEEPER SERVICE]: Starting...");
}
@@ -190,8 +213,13 @@ namespace OpenSim.Services.HypergridService
string value = config.GetString(variable, string.Empty);
string[] parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in parts)
exceptions.Add(s.Trim());
foreach (string ps in parts)
{
string s = ps.Trim();
if(!s.EndsWith("/"))
s += '/';
exceptions.Add(s);
}
}
public bool LinkRegion(string regionName, out UUID regionID, out ulong regionHandle, out string externalName, out string imageURL, out string reason, out int sizeX, out int sizeY)
@@ -203,13 +231,13 @@ namespace OpenSim.Services.HypergridService
externalName = m_gatekeeperURL + ((regionName != string.Empty) ? " " + regionName : "");
imageURL = string.Empty;
reason = string.Empty;
GridRegion region = null;
GridRegion region;
//m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to link to {0}", (regionName.Length == 0)? "default region" : regionName);
if (!m_AllowTeleportsToAnyRegion || regionName.Length == 0)
{
List<GridRegion> defs = m_GridService.GetDefaultHypergridRegions(m_ScopeID);
if (defs != null && defs.Count > 0)
if (defs is not null && defs.Count > 0)
{
region = defs[0];
m_DefaultGatewayRegion = region;
@@ -224,7 +252,7 @@ namespace OpenSim.Services.HypergridService
else
{
region = m_GridService.GetRegionByName(m_ScopeID, regionName);
if (region == null)
if (region is null)
{
reason = "Region not found";
return false;
@@ -256,7 +284,7 @@ namespace OpenSim.Services.HypergridService
m_DefaultGatewayRegion.RegionID,
m_DefaultGatewayRegion.ServerURI,
agentID,
agentHomeURI == null ? "" : " @ " + agentHomeURI);
agentHomeURI is null ? "" : " @ " + agentHomeURI);
message = "Teleporting to the default region.";
return m_DefaultGatewayRegion;
@@ -268,7 +296,7 @@ namespace OpenSim.Services.HypergridService
{
m_log.DebugFormat(
"[GATEKEEPER SERVICE]: Could not find region with ID {0} as requested by user {1}{2}. Returning null.",
regionID, agentID, (agentHomeURI == null) ? "" : " @ " + agentHomeURI);
regionID, agentID, (agentHomeURI is null) ? "" : " @ " + agentHomeURI);
message = "The teleport destination could not be found.";
return null;
@@ -280,7 +308,7 @@ namespace OpenSim.Services.HypergridService
region.RegionID,
region.ServerURI,
agentID,
agentHomeURI == null ? "" : " @ " + agentHomeURI);
agentHomeURI is null ? "" : " @ " + agentHomeURI);
return region;
}
@@ -306,35 +334,39 @@ namespace OpenSim.Services.HypergridService
//
// Check client
//
if (!String.IsNullOrWhiteSpace(m_AllowedClients))
if (m_AllowedClientsRegex is not null)
{
Regex arx = new Regex(m_AllowedClients);
Match am = arx.Match(curViewer);
if (!am.Success)
lock(m_AllowedClientsRegex)
{
reason = "Login failed: client " + curViewer + " is not allowed";
m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is not allowed", curViewer);
return false;
Match am = m_AllowedClientsRegex.Match(curViewer);
if (!am.Success)
{
reason = "Login failed: client " + curViewer + " is not allowed";
m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is not allowed", curViewer);
return false;
}
}
}
if (!String.IsNullOrWhiteSpace(m_DeniedClients))
if (m_DeniedClientsRegex is not null)
{
Regex drx = new Regex(m_DeniedClients);
Match dm = drx.Match(curViewer);
if (dm.Success)
lock(m_DeniedClientsRegex)
{
reason = "Login failed: client " + curViewer + " is denied";
m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is denied", curViewer);
return false;
Match dm = m_DeniedClientsRegex.Match(curViewer);
if (dm.Success)
{
reason = "Login failed: client " + curViewer + " is denied";
m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is denied", curViewer);
return false;
}
}
}
if (!String.IsNullOrWhiteSpace(m_DeniedMacs))
{
m_log.InfoFormat("[GATEKEEPER SERVICE]: Checking users Mac {0} against list of denied macs {1} ...", curMac, m_DeniedMacs);
//m_log.InfoFormat("[GATEKEEPER SERVICE]: Checking users Mac {0} against list of denied macs {1} ...", curMac, m_DeniedMacs);
if (m_DeniedMacs.Contains(curMac))
{
reason = "Login failed: client with Mac " + curMac + " is denied";
@@ -343,6 +375,17 @@ namespace OpenSim.Services.HypergridService
}
}
if (!string.IsNullOrWhiteSpace(m_DeniedID0s))
{
//m_log.InfoFormat("[GATEKEEPER SERVICE]: Checking users Mac {0} against list of denied macs {1} ...", curMac, m_DeniedMacs);
if (m_DeniedID0s.Contains(aCircuit.Id0))
{
reason = "Login failed: client with id0 " + aCircuit.Id0 + " is denied";
m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client with mac {0} is denied", aCircuit.Id0);
return false;
}
}
//
// Authenticate the user
//
@@ -358,14 +401,14 @@ namespace OpenSim.Services.HypergridService
// Check for impersonations
//
UserAccount account = null;
if (m_UserAccountService != null)
if (m_UserAccountService is not null)
{
// Check to see if we have a local user with that UUID
account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID);
if (account != null)
if (account is not null)
{
// Make sure this is the user coming home, and not a foreign user with same UUID as a local user
if (m_UserAgentService != null)
if (m_UserAgentService is not null)
{
if (!m_UserAgentService.IsAgentComingHome(aCircuit.SessionID, m_gatekeeperURL))
{
@@ -383,7 +426,7 @@ namespace OpenSim.Services.HypergridService
//
// Foreign agents allowed? Exceptions?
//
if (account == null)
if (account is null)
{
bool allowed = m_ForeignAgentsAllowed;
@@ -406,8 +449,8 @@ namespace OpenSim.Services.HypergridService
// Is the user banned?
// This uses a Ban service that's more powerful than the configs
//
string uui = (account != null ? aCircuit.AgentID.ToString() : Util.ProduceUserUniversalIdentifier(aCircuit));
if (m_BansService != null && m_BansService.IsBanned(uui, aCircuit.IPAddress, aCircuit.Id0, authURL))
string uui = (account is not null ? aCircuit.AgentID.ToString() : Util.ProduceUserUniversalIdentifier(aCircuit));
if (m_BansService is not null && m_BansService.IsBanned(uui, aCircuit.IPAddress, aCircuit.Id0, authURL))
{
reason = "You are banned from this world";
m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: user {0} is banned", uui);
@@ -415,32 +458,33 @@ namespace OpenSim.Services.HypergridService
}
UUID agentID = aCircuit.AgentID;
if(agentID == new UUID("6571e388-6218-4574-87db-f9379718315e"))
if(agentID.Equals(Constants.servicesGodAgentID))
{
// really?
reason = "Invalid account ID";
return false;
}
if(m_GridUserService != null)
if(m_GridUserService is not null)
{
string PrincipalIDstr = agentID.ToString();
GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(PrincipalIDstr);
if(!m_allowDuplicatePresences)
GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(uui);
if (guinfo is not null)
{
if(guinfo != null && guinfo.Online && guinfo.LastRegionID != UUID.Zero)
if (!m_allowDuplicatePresences)
{
if(SendAgentGodKillToRegion(UUID.Zero, agentID, guinfo))
if (guinfo.Online && !guinfo.LastRegionID.IsZero())
{
if(account != null)
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 the destination 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;
if (SendAgentGodKillToRegion(UUID.Zero, agentID, uui, guinfo))
{
if (account is not null)
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 the destination 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;
}
}
}
}
@@ -453,7 +497,7 @@ namespace OpenSim.Services.HypergridService
// Login the presence, if it's not there yet (by the login service)
//
PresenceInfo presence = m_PresenceService.GetAgent(aCircuit.SessionID);
if (presence != null) // it has been placed there by the login service
if (presence is not null) // it has been placed there by the login service
isFirstLogin = true;
else
@@ -472,7 +516,7 @@ namespace OpenSim.Services.HypergridService
// Get the region
//
destination = m_GridService.GetRegionByUUID(m_ScopeID, destination.RegionID);
if (destination == null)
if (destination is null)
{
reason = "Destination region not found";
return false;
@@ -484,18 +528,18 @@ namespace OpenSim.Services.HypergridService
//
// Adjust the visible name
//
if (account != null)
if (account is not null)
{
aCircuit.firstname = account.FirstName;
aCircuit.lastname = account.LastName;
}
if (account == null)
if (account is null)
{
if (!aCircuit.lastname.StartsWith("@"))
aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname;
try
{
Uri uri = new Uri(aCircuit.ServiceURLs["HomeURI"].ToString());
Uri uri = new(aCircuit.ServiceURLs["HomeURI"].ToString());
aCircuit.lastname = "@" + uri.Authority;
}
catch
@@ -515,7 +559,7 @@ namespace OpenSim.Services.HypergridService
m_log.DebugFormat("[GATEKEEPER SERVICE]: Launching {0}, Teleport Flags: {1}", aCircuit.Name, loginFlag);
EntityTransferContext ctx = new EntityTransferContext();
EntityTransferContext ctx = new();
if (!m_SimulationService.QueryAccess(
destination, aCircuit.AgentID, aCircuit.ServiceURLs["HomeURI"].ToString(),
@@ -528,7 +572,7 @@ namespace OpenSim.Services.HypergridService
{
m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence {0} is ok", aCircuit.Name);
if(!isFirstLogin && m_GridUserService != null && account == null)
if(!isFirstLogin && m_GridUserService is not null && account is null)
{
// Also login foreigners with GridUser service
string userId = aCircuit.AgentID.ToString();
@@ -566,7 +610,7 @@ namespace OpenSim.Services.HypergridService
if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
userURL = aCircuit.ServiceURLs["HomeURI"].ToString();
OSHHTPHost userHomeHost = new OSHHTPHost(userURL, true);
OSHHTPHost userHomeHost = new(userURL, true);
if(!userHomeHost.IsResolvedHost)
{
m_log.DebugFormat("[GATEKEEPER SERVICE]: Agent did not provide an authentication server URL");
@@ -601,7 +645,7 @@ namespace OpenSim.Services.HypergridService
if (parts.Length < 2)
return false;
OSHHTPHost reqGrid = new OSHHTPHost(parts[0], false);
OSHHTPHost reqGrid = new(parts[0], false);
if(!reqGrid.IsValidHost)
{
m_log.DebugFormat("[GATEKEEPER SERVICE]: Visitor provided malformed gird address {0}", parts[0]);
@@ -624,31 +668,30 @@ namespace OpenSim.Services.HypergridService
private bool IsException(AgentCircuitData aCircuit, List<string> exceptions)
{
bool exception = false;
if (exceptions.Count > 0) // we have exceptions
{
// Retrieve the visitor's origin
string userURL = aCircuit.ServiceURLs["HomeURI"].ToString();
string userURL = aCircuit.ServiceURLs["HomeURI"].ToString().Trim();
if (string.IsNullOrEmpty(userURL))
return false;
if (!userURL.EndsWith("/"))
userURL += "/";
if (exceptions.Find(delegate(string s)
{
if (!s.EndsWith("/"))
s += "/";
return s == userURL;
}) != null)
exception = true;
if(userURL.Equals(s))
return true;
}
}
return exception;
return false;
}
private bool SendAgentGodKillToRegion(UUID scopeID, UUID agentID , GridUserInfo guinfo)
private bool SendAgentGodKillToRegion(UUID scopeID, UUID agentID, string uui, GridUserInfo guinfo)
{
UUID regionID = guinfo.LastRegionID;
GridRegion regInfo = m_GridService.GetRegionByUUID(scopeID, regionID);
if(regInfo == null)
if(regInfo is null)
return false;
string regURL = regInfo.ServerURI;
@@ -671,7 +714,7 @@ namespace OpenSim.Services.HypergridService
msg.binaryBucket = new byte[1] {0};
InstantMessageServiceConnector.SendInstantMessage(regURL,msg, m_messageKey);
m_GridUserService.LoggedOut(agentID.ToString(),
m_GridUserService.LoggedOut(uui,
UUID.Zero, guinfo.LastRegionID, guinfo.LastPosition, guinfo.LastLookAt);
return true;

View File

@@ -53,9 +53,7 @@ namespace OpenSim.Services.HypergridService
/// </summary>
public class UserAgentService : UserAgentServiceBase, IUserAgentService
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// This will need to go into a DB table
//static Dictionary<UUID, TravelingAgentInfo> m_Database = new Dictionary<UUID, TravelingAgentInfo>();
@@ -80,9 +78,9 @@ namespace OpenSim.Services.HypergridService
protected static bool m_BypassClientVerification;
private static Dictionary<int, bool> m_ForeignTripsAllowed = new Dictionary<int, bool>();
private static Dictionary<int, List<string>> m_TripsAllowedExceptions = new Dictionary<int, List<string>>();
private static Dictionary<int, List<string>> m_TripsDisallowedExceptions = new Dictionary<int, List<string>>();
private static readonly Dictionary<int, bool> m_ForeignTripsAllowed = new();
private static readonly Dictionary<int, List<string>> m_TripsAllowedExceptions = new();
private static readonly Dictionary<int, List<string>> m_TripsDisallowedExceptions = new();
public UserAgentService(IConfigSource config) : this(config, null)
{
@@ -93,7 +91,7 @@ namespace OpenSim.Services.HypergridService
{
// Let's set this always, because we don't know the sequence
// of instantiations
if (friendsConnector != null)
if (friendsConnector is not null)
m_FriendsLocalSimConnector = friendsConnector;
if (!m_Initialized)
@@ -105,7 +103,7 @@ namespace OpenSim.Services.HypergridService
m_FriendsSimConnector = new FriendsSimConnector();
IConfig serverConfig = config.Configs["UserAgentService"];
if (serverConfig == null)
if (serverConfig is null)
throw new Exception(String.Format("No section UserAgentService in config file"));
string gridService = serverConfig.GetString("GridService", String.Empty);
@@ -152,13 +150,12 @@ namespace OpenSim.Services.HypergridService
{
m_GridName = m_GridName.ToLowerInvariant();
if (!m_GridName.EndsWith("/"))
m_GridName = m_GridName + "/";
Uri gateURI;
if(!Uri.TryCreate(m_GridName, UriKind.Absolute, out gateURI))
m_GridName += "/";
if (!Uri.TryCreate(m_GridName, UriKind.Absolute, out Uri gateURI))
throw new Exception(String.Format("[UserAgentService] could not parse gatekeeper uri"));
string host = gateURI.DnsSafeHost;
IPAddress ip = Util.GetHostFromDNS(host);
if(ip == null)
if(ip is null)
throw new Exception(String.Format("[UserAgentService] failed to resolve gatekeeper host"));
m_MyExternalIP = ip.ToString();
}
@@ -174,8 +171,7 @@ namespace OpenSim.Services.HypergridService
{
if (keyName.StartsWith(variable + "_Level_"))
{
int level = 0;
if (Int32.TryParse(keyName.Replace(variable + "_Level_", ""), out level))
if (Int32.TryParse(keyName.Replace(variable + "_Level_", ""), out int level))
m_ForeignTripsAllowed.Add(level, config.GetBoolean(keyName, true));
}
}
@@ -187,15 +183,19 @@ namespace OpenSim.Services.HypergridService
{
if (keyName.StartsWith(variable + "_Level_"))
{
int level = 0;
if (Int32.TryParse(keyName.Replace(variable + "_Level_", ""), out level) && !exceptions.ContainsKey(level))
if (Int32.TryParse(keyName.Replace(variable + "_Level_", ""), out int level) && !exceptions.ContainsKey(level))
{
exceptions.Add(level, new List<string>());
string value = config.GetString(keyName, string.Empty);
string[] parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in parts)
exceptions[level].Add(s.Trim());
{
string ss = s.Trim();
if(!ss.EndsWith("/"))
ss += '/';
exceptions[level].Add(ss);
}
}
}
}
@@ -209,18 +209,18 @@ namespace OpenSim.Services.HypergridService
GridRegion home = null;
GridUserInfo uinfo = m_GridUserService.GetGridUserInfo(userID.ToString());
if (uinfo != null)
if (uinfo is not null)
{
if (!uinfo.HomeRegionID.IsZero())
if (uinfo.HomeRegionID.IsNotZero())
{
home = m_GridService.GetRegionByUUID(UUID.Zero, uinfo.HomeRegionID);
position = uinfo.HomePosition;
lookAt = uinfo.HomeLookAt;
}
if (home == null)
if (home is null)
{
List<GridRegion> defs = m_GridService.GetDefaultRegions(UUID.Zero);
if (defs != null && defs.Count > 0)
if (defs is not null && defs.Count > 0)
home = defs[0];
}
}
@@ -236,7 +236,7 @@ namespace OpenSim.Services.HypergridService
string gridName = gatekeeper.ServerURI.ToLowerInvariant();
UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, agentCircuit.AgentID);
if (account == null)
if (account is null)
{
m_log.WarnFormat("[USER AGENT SERVICE]: Someone attempted to lauch a foreign user from here {0} {1}", agentCircuit.firstname, agentCircuit.lastname);
reason = "Forbidden to launch your agents from here";
@@ -266,27 +266,28 @@ 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;
region.ExternalHostName = finalDestination.ExternalHostName;
region.InternalEndPoint = finalDestination.InternalEndPoint;
region.RegionName = finalDestination.RegionName;
region.RegionID = finalDestination.RegionID;
region.RegionLocX = finalDestination.RegionLocX;
region.RegionLocY = finalDestination.RegionLocY;
GridRegion region = new(gatekeeper)
{
ServerURI = gatekeeper.ServerURI,
ExternalHostName = finalDestination.ExternalHostName,
InternalEndPoint = finalDestination.InternalEndPoint,
RegionName = finalDestination.RegionName,
RegionID = finalDestination.RegionID,
RegionLocX = finalDestination.RegionLocX,
RegionLocY = finalDestination.RegionLocY
};
// Generate a new service session
agentCircuit.ServiceSessionID = region.ServerURI + ";" + UUID.Random();
TravelingAgentInfo old = null;
TravelingAgentInfo travel = CreateTravelInfo(agentCircuit, region, fromLogin, out old);
TravelingAgentInfo travel = CreateTravelInfo(agentCircuit, region, fromLogin, out TravelingAgentInfo old);
if(!fromLogin && old != null && !string.IsNullOrEmpty(old.ClientIPAddress))
if(!fromLogin && old is not null && !string.IsNullOrEmpty(old.ClientIPAddress))
{
m_log.DebugFormat("[USER AGENT SERVICE]: stored IP = {0}. Old circuit IP: {1}", old.ClientIPAddress, agentCircuit.IPAddress);
agentCircuit.IPAddress = old.ClientIPAddress;
}
bool success = false;
bool success;
m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}, desired region: {2}", m_GridName, gridName, region.RegionID);
@@ -297,7 +298,7 @@ namespace OpenSim.Services.HypergridService
else
{
//TODO: Should there not be a call to QueryAccess here?
EntityTransferContext ctx = new EntityTransferContext();
EntityTransferContext ctx = new();
success = m_GatekeeperConnector.CreateAgent(source, region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, ctx, out reason);
}
@@ -306,7 +307,7 @@ namespace OpenSim.Services.HypergridService
m_log.DebugFormat("[USER AGENT SERVICE]: Unable to login user {0} {1} to grid {2}, reason: {3}",
agentCircuit.firstname, agentCircuit.lastname, region.ServerURI, reason);
if (old != null)
if (old is not null)
StoreTravelInfo(old);
else
m_Database.Delete(agentCircuit.SessionID);
@@ -323,7 +324,6 @@ namespace OpenSim.Services.HypergridService
public bool LoginAgentToGrid(GridRegion source, AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, out string reason)
{
reason = string.Empty;
return LoginAgentToGrid(source, agentCircuit, gatekeeper, finalDestination, false, out reason);
}
@@ -332,7 +332,7 @@ namespace OpenSim.Services.HypergridService
HGTravelingData hgt = m_Database.Get(agentCircuit.SessionID);
existing = null;
if (hgt != null)
if (hgt is not null)
{
// Very important! Override whatever this agent comes with.
// UserAgentService always sets the IP for every new agent
@@ -341,11 +341,13 @@ namespace OpenSim.Services.HypergridService
agentCircuit.IPAddress = existing.ClientIPAddress;
}
TravelingAgentInfo travel = new TravelingAgentInfo(existing);
travel.SessionID = agentCircuit.SessionID;
travel.UserID = agentCircuit.AgentID;
travel.GridExternalName = region.ServerURI;
travel.ServiceToken = agentCircuit.ServiceSessionID;
TravelingAgentInfo travel = new(existing)
{
SessionID = agentCircuit.SessionID,
UserID = agentCircuit.AgentID,
GridExternalName = region.ServerURI,
ServiceToken = agentCircuit.ServiceSessionID
};
if (fromLogin)
travel.ClientIPAddress = agentCircuit.IPAddress;
@@ -362,7 +364,7 @@ namespace OpenSim.Services.HypergridService
m_Database.Delete(sessionID);
GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(userID.ToString());
if (guinfo != null)
if (guinfo is not null)
m_GridUserService.LoggedOut(userID.ToString(), sessionID, guinfo.LastRegionID, guinfo.LastPosition, guinfo.LastLookAt);
}
@@ -370,12 +372,11 @@ namespace OpenSim.Services.HypergridService
public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName)
{
HGTravelingData hgt = m_Database.Get(sessionID);
if (hgt == null)
if (hgt is null || hgt.Data is null)
return false;
TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
return travel.GridExternalName.ToLower() == thisGridExternalName.ToLower();
if(!hgt.Data.TryGetValue("GridExternalName", out string htgGrid))
return false;
return htgGrid.Equals(thisGridExternalName, StringComparison.InvariantCultureIgnoreCase);
}
public bool VerifyClient(UUID sessionID, string reportedIP)
@@ -387,10 +388,10 @@ namespace OpenSim.Services.HypergridService
sessionID, reportedIP);
HGTravelingData hgt = m_Database.Get(sessionID);
if (hgt == null)
if (hgt is null)
return false;
TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
TravelingAgentInfo travel = new(hgt);
bool result = travel.ClientIPAddress == reportedIP;
if(!result && !string.IsNullOrEmpty(m_MyExternalIP))
@@ -405,7 +406,7 @@ namespace OpenSim.Services.HypergridService
public bool VerifyAgent(UUID sessionID, string token)
{
HGTravelingData hgt = m_Database.Get(sessionID);
if (hgt == null)
if (hgt is null)
{
m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID);
return false;
@@ -425,18 +426,16 @@ namespace OpenSim.Services.HypergridService
return new List<UUID>();
}
List<UUID> localFriendsOnline = new List<UUID>();
List<UUID> localFriendsOnline = new();
m_log.DebugFormat("[USER AGENT SERVICE]: Status notification: foreign user {0} wants to notify {1} local friends", foreignUserID, friends.Count);
// First, let's double check that the reported friends are, indeed, friends of that user
// And let's check that the secret matches
List<string> usersToBeNotified = new List<string>();
List<string> usersToBeNotified = new();
foreach (string uui in friends)
{
UUID localUserID;
string secret = string.Empty, tmp = string.Empty;
if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret))
if (Util.ParseUniversalUserIdentifier(uui, out UUID localUserID, out _, out _, out _, out string secret))
{
FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID);
foreach (FriendInfo finfo in friendInfos)
@@ -459,18 +458,18 @@ namespace OpenSim.Services.HypergridService
{
PresenceInfo friendSession = null;
foreach (PresenceInfo pinfo in friendSessions)
if (!pinfo.RegionID.IsZero()) // let's guard against traveling agents
{
if (pinfo.RegionID.IsNotZero()) // let's guard against traveling agents
{
friendSession = pinfo;
break;
}
if (friendSession != null)
}
if (friendSession is not null)
{
ForwardStatusNotificationToSim(friendSession.RegionID, foreignUserID, friendSession.UserID, online);
usersToBeNotified.Remove(friendSession.UserID.ToString());
UUID id;
if (UUID.TryParse(friendSession.UserID, out id))
if (UUID.TryParse(friendSession.UserID, out UUID id))
localFriendsOnline.Add(id);
}
@@ -500,10 +499,9 @@ namespace OpenSim.Services.HypergridService
[Obsolete]
protected void ForwardStatusNotificationToSim(UUID regionID, UUID foreignUserID, string user, bool online)
{
UUID userID;
if (UUID.TryParse(user, out userID))
if (UUID.TryParse(user, out UUID userID))
{
if (m_FriendsLocalSimConnector != null)
if (m_FriendsLocalSimConnector is not null)
{
m_log.DebugFormat("[USER AGENT SERVICE]: Local Notify, user {0} is {1}", foreignUserID, (online ? "online" : "offline"));
m_FriendsLocalSimConnector.StatusNotify(foreignUserID, userID, online);
@@ -511,7 +509,7 @@ namespace OpenSim.Services.HypergridService
else
{
GridRegion region = m_GridService.GetRegionByUUID(UUID.Zero /* !!! */, regionID);
if (region != null)
if (region is not null)
{
m_log.DebugFormat("[USER AGENT SERVICE]: Remote Notify to region {0}, user {1} is {2}", region.RegionName, foreignUserID, (online ? "online" : "offline"));
m_FriendsSimConnector.StatusNotify(region, foreignUserID, userID.ToString(), online);
@@ -522,9 +520,9 @@ namespace OpenSim.Services.HypergridService
public List<UUID> GetOnlineFriends(UUID foreignUserID, List<string> friends)
{
List<UUID> online = new List<UUID>();
List<UUID> online = new();
if (m_FriendsService == null || m_PresenceService == null)
if (m_FriendsService is null || m_PresenceService is null)
{
m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get online friends because friends or presence services are missing");
return online;
@@ -534,12 +532,10 @@ namespace OpenSim.Services.HypergridService
// First, let's double check that the reported friends are, indeed, friends of that user
// And let's check that the secret matches and the rights
List<string> usersToBeNotified = new List<string>();
List<string> usersToBeNotified = new();
foreach (string uui in friends)
{
UUID localUserID;
string secret = string.Empty, tmp = string.Empty;
if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret))
if (Util.ParseUniversalUserIdentifier(uui, out UUID localUserID, out _, out _, out _, out string secret))
{
FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID);
foreach (FriendInfo finfo in friendInfos)
@@ -559,12 +555,11 @@ namespace OpenSim.Services.HypergridService
// First, let's send notifications to local users who are online in the home grid
PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray());
if (friendSessions != null && friendSessions.Length > 0)
if (friendSessions is not null && friendSessions.Length > 0)
{
foreach (PresenceInfo pi in friendSessions)
{
UUID presenceID;
if (UUID.TryParse(pi.UserID, out presenceID))
if (UUID.TryParse(pi.UserID, out UUID presenceID))
online.Add(presenceID);
}
}
@@ -574,9 +569,9 @@ namespace OpenSim.Services.HypergridService
public Dictionary<string, object> GetUserInfo(UUID userID)
{
Dictionary<string, object> info = new Dictionary<string, object>();
Dictionary<string, object> info = new();
if (m_UserAccountService == null)
if (m_UserAccountService is null)
{
m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get user flags because user account service is missing");
info["result"] = "fail";
@@ -611,7 +606,7 @@ namespace OpenSim.Services.HypergridService
public Dictionary<string, object> GetServerURLs(UUID userID)
{
if (m_UserAccountService == null)
if (m_UserAccountService is null)
{
m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get server URLs because user account service is missing");
return new Dictionary<string, object>();
@@ -640,21 +635,21 @@ namespace OpenSim.Services.HypergridService
{
// Let's see if it's a local user
UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, targetUserID);
if (account != null)
if (account is not null)
return targetUserID.ToString() + ";" + m_GridName + ";" + account.FirstName + " " + account.LastName ;
// Let's try the list of friends
if(m_FriendsService != null)
if(m_FriendsService is not null)
{
FriendInfo[] friends = m_FriendsService.GetFriends(userID);
if (friends != null && friends.Length > 0)
if (friends is not null && friends.Length > 0)
{
foreach (FriendInfo f in friends)
if (f.Friend.StartsWith(targetUserID.ToString()))
{
// Let's remove the secret
UUID id; string tmp = string.Empty, secret = string.Empty;
if (Util.ParseUniversalUserIdentifier(f.Friend, out id, out tmp, out tmp, out tmp, out secret))
if (Util.ParseUniversalUserIdentifier(f.Friend, out _,
out _, out _, out _, out string secret))
return f.Friend.Replace(secret, "0");
}
}
@@ -666,7 +661,7 @@ namespace OpenSim.Services.HypergridService
{
// Let's see if it's a local user
UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, first, last);
if (account != null)
if (account is not null)
{
// check user level
if (account.UserLevel < m_LevelOutsideContacts)
@@ -682,40 +677,37 @@ namespace OpenSim.Services.HypergridService
private bool IsException(string dest, int level, Dictionary<int, List<string>> exceptions)
{
if (!exceptions.ContainsKey(level))
if (string.IsNullOrEmpty(dest))
return false;
if (!exceptions.TryGetValue(level, out List<string> excep) || excep.Count == 0)
return false;
bool exception = false;
if (exceptions[level].Count > 0) // we have exceptions
{
string destination = dest;
if (!destination.EndsWith("/"))
destination += "/";
if (exceptions[level].Find(delegate(string s)
{
if (!s.EndsWith("/"))
s += "/";
return s == destination;
}) != null)
exception = true;
if (destination.Equals(s))
return true;
}
return exception;
return false;
}
private void StoreTravelInfo(TravelingAgentInfo travel)
{
if (travel == null)
if (travel is null)
return;
HGTravelingData hgt = new HGTravelingData();
hgt.SessionID = travel.SessionID;
hgt.UserID = travel.UserID;
hgt.Data = new Dictionary<string, string>();
hgt.Data["GridExternalName"] = travel.GridExternalName;
hgt.Data["ServiceToken"] = travel.ServiceToken;
hgt.Data["ClientIPAddress"] = travel.ClientIPAddress;
HGTravelingData hgt = new()
{
SessionID = travel.SessionID,
UserID = travel.UserID,
Data = new Dictionary<string, string>
{
["GridExternalName"] = travel.GridExternalName,
["ServiceToken"] = travel.ServiceToken,
["ClientIPAddress"] = travel.ClientIPAddress
}
};
m_Database.Store(hgt);
}
@@ -733,7 +725,7 @@ namespace OpenSim.Services.HypergridService
public TravelingAgentInfo(HGTravelingData t)
{
if (t.Data != null)
if (t.Data is not null)
{
SessionID = new UUID(t.SessionID);
UserID = new UUID(t.UserID);
@@ -745,7 +737,7 @@ namespace OpenSim.Services.HypergridService
public TravelingAgentInfo(TravelingAgentInfo old)
{
if (old != null)
if (old is not null)
{
SessionID = old.SessionID;
UserID = old.UserID;

View File

@@ -26,11 +26,8 @@
*/
using System;
using System.Reflection;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Data;
using OpenSim.Services.Interfaces;
using OpenSim.Services.Base;
namespace OpenSim.Services.HypergridService
@@ -50,7 +47,7 @@ namespace OpenSim.Services.HypergridService
// Try reading the [DatabaseService] section, if it exists
//
IConfig dbConfig = config.Configs["DatabaseService"];
if (dbConfig != null)
if (dbConfig is not null)
{
if (dllName.Length == 0)
dllName = dbConfig.GetString("StorageProvider", String.Empty);
@@ -62,7 +59,7 @@ namespace OpenSim.Services.HypergridService
// [UserAgentService] section overrides [DatabaseService], if it exists
//
IConfig gridConfig = config.Configs["UserAgentService"];
if (gridConfig != null)
if (gridConfig is not null)
{
dllName = gridConfig.GetString("StorageProvider", dllName);
connString = gridConfig.GetString("ConnectionString", connString);
@@ -76,7 +73,7 @@ namespace OpenSim.Services.HypergridService
throw new Exception("No StorageProvider configured");
m_Database = LoadPlugin<IHGTravelingData>(dllName, new Object[] { connString, realm });
if (m_Database == null)
if (m_Database is null)
throw new Exception("Could not find a storage interface in the given module");
}