LLLoginService.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Linq;
  31. using System.Net;
  32. using System.Reflection;
  33. using System.Text.RegularExpressions;
  34. using log4net;
  35. using Nini.Config;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Console;
  39. using OpenSim.Server.Base;
  40. using OpenSim.Services.Connectors.InstantMessage;
  41. using OpenSim.Services.Interfaces;
  42. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  43. using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
  44. using OpenSim.Services.Connectors.Hypergrid;
  45. namespace OpenSim.Services.LLLoginService
  46. {
  47. public class LLLoginService : ILoginService
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. private static readonly string LogHeader = "[LLOGIN SERVICE]";
  51. private static bool Initialized = false;
  52. protected IUserAccountService m_UserAccountService;
  53. protected IGridUserService m_GridUserService;
  54. protected IAuthenticationService m_AuthenticationService;
  55. protected IInventoryService m_InventoryService;
  56. protected IInventoryService m_HGInventoryService;
  57. protected IGridService m_GridService;
  58. protected IPresenceService m_PresenceService;
  59. protected ISimulationService m_LocalSimulationService;
  60. protected ISimulationService m_RemoteSimulationService;
  61. protected ILibraryService m_LibraryService;
  62. protected IFriendsService m_FriendsService;
  63. protected IAvatarService m_AvatarService;
  64. protected IUserAgentService m_UserAgentService;
  65. protected GatekeeperServiceConnector m_GatekeeperConnector;
  66. protected string m_DefaultRegionName;
  67. protected string m_WelcomeMessage;
  68. protected bool m_RequireInventory;
  69. protected int m_MinLoginLevel;
  70. protected string m_GatekeeperURL;
  71. protected bool m_AllowRemoteSetLoginLevel;
  72. protected string m_MapTileURL;
  73. protected string m_ProfileURL;
  74. protected string m_OpenIDURL;
  75. protected string m_SearchURL;
  76. protected string m_Currency;
  77. protected string m_ClassifiedFee;
  78. protected int m_MaxAgentGroups = 42;
  79. protected string m_DestinationGuide;
  80. protected string m_AvatarPicker;
  81. protected string m_AllowedClients;
  82. protected string m_DeniedClients;
  83. protected string m_DeniedMacs;
  84. protected string m_MessageUrl;
  85. protected string m_DSTZone;
  86. protected bool m_allowDuplicatePresences = false;
  87. IConfig m_LoginServerConfig;
  88. // IConfig m_ClientsConfig;
  89. public LLLoginService(IConfigSource config, ISimulationService simService, ILibraryService libraryService)
  90. {
  91. m_LoginServerConfig = config.Configs["LoginService"];
  92. if (m_LoginServerConfig == null)
  93. throw new Exception(String.Format("No section LoginService in config file"));
  94. string accountService = m_LoginServerConfig.GetString("UserAccountService", String.Empty);
  95. string gridUserService = m_LoginServerConfig.GetString("GridUserService", String.Empty);
  96. string agentService = m_LoginServerConfig.GetString("UserAgentService", String.Empty);
  97. string authService = m_LoginServerConfig.GetString("AuthenticationService", String.Empty);
  98. string invService = m_LoginServerConfig.GetString("InventoryService", String.Empty);
  99. string gridService = m_LoginServerConfig.GetString("GridService", String.Empty);
  100. string presenceService = m_LoginServerConfig.GetString("PresenceService", String.Empty);
  101. string libService = m_LoginServerConfig.GetString("LibraryService", String.Empty);
  102. string friendsService = m_LoginServerConfig.GetString("FriendsService", String.Empty);
  103. string avatarService = m_LoginServerConfig.GetString("AvatarService", String.Empty);
  104. string simulationService = m_LoginServerConfig.GetString("SimulationService", String.Empty);
  105. m_DefaultRegionName = m_LoginServerConfig.GetString("DefaultRegion", String.Empty);
  106. m_WelcomeMessage = m_LoginServerConfig.GetString("WelcomeMessage", "Welcome to OpenSim!");
  107. m_RequireInventory = m_LoginServerConfig.GetBoolean("RequireInventory", true);
  108. m_AllowRemoteSetLoginLevel = m_LoginServerConfig.GetBoolean("AllowRemoteSetLoginLevel", false);
  109. m_MinLoginLevel = m_LoginServerConfig.GetInt("MinLoginLevel", 0);
  110. m_GatekeeperURL = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
  111. new string[] { "Startup", "Hypergrid", "LoginService" }, String.Empty);
  112. m_MapTileURL = m_LoginServerConfig.GetString("MapTileURL", string.Empty);
  113. m_ProfileURL = m_LoginServerConfig.GetString("ProfileServerURL", string.Empty);
  114. m_OpenIDURL = m_LoginServerConfig.GetString("OpenIDServerURL", String.Empty);
  115. m_SearchURL = m_LoginServerConfig.GetString("SearchURL", string.Empty);
  116. m_Currency = m_LoginServerConfig.GetString("Currency", string.Empty);
  117. m_ClassifiedFee = m_LoginServerConfig.GetString("ClassifiedFee", string.Empty);
  118. m_DestinationGuide = m_LoginServerConfig.GetString ("DestinationGuide", string.Empty);
  119. m_AvatarPicker = m_LoginServerConfig.GetString ("AvatarPicker", string.Empty);
  120. string[] possibleAccessControlConfigSections = new string[] { "AccessControl", "LoginService" };
  121. m_AllowedClients = Util.GetConfigVarFromSections<string>(
  122. config, "AllowedClients", possibleAccessControlConfigSections, string.Empty);
  123. m_DeniedClients = Util.GetConfigVarFromSections<string>(
  124. config, "DeniedClients", possibleAccessControlConfigSections, string.Empty);
  125. m_DeniedMacs = Util.GetConfigVarFromSections<string>(
  126. config, "DeniedMacs", possibleAccessControlConfigSections, string.Empty);
  127. m_MessageUrl = m_LoginServerConfig.GetString("MessageUrl", string.Empty);
  128. m_DSTZone = m_LoginServerConfig.GetString("DSTZone", "America/Los_Angeles;Pacific Standard Time");
  129. IConfig groupConfig = config.Configs["Groups"];
  130. if (groupConfig != null)
  131. m_MaxAgentGroups = groupConfig.GetInt("MaxAgentGroups", 42);
  132. IConfig presenceConfig = config.Configs["PresenceService"];
  133. if (presenceConfig != null)
  134. {
  135. m_allowDuplicatePresences = presenceConfig.GetBoolean("AllowDuplicatePresences", m_allowDuplicatePresences);
  136. }
  137. // Clean up some of these vars
  138. if (m_MapTileURL != String.Empty)
  139. {
  140. m_MapTileURL = m_MapTileURL.Trim();
  141. if (!m_MapTileURL.EndsWith("/"))
  142. m_MapTileURL = m_MapTileURL + "/";
  143. }
  144. // These are required; the others aren't
  145. if (accountService == string.Empty || authService == string.Empty)
  146. throw new Exception("LoginService is missing service specifications");
  147. // replace newlines in welcome message
  148. m_WelcomeMessage = m_WelcomeMessage.Replace("\\n", "\n");
  149. Object[] args = new Object[] { config };
  150. m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args);
  151. m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args);
  152. Object[] authArgs = new Object[] { config, m_UserAccountService };
  153. m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, authArgs);
  154. m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(invService, args);
  155. if (gridService != string.Empty)
  156. m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
  157. if (presenceService != string.Empty)
  158. m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
  159. if (avatarService != string.Empty)
  160. m_AvatarService = ServerUtils.LoadPlugin<IAvatarService>(avatarService, args);
  161. if (friendsService != string.Empty)
  162. m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(friendsService, args);
  163. if (simulationService != string.Empty)
  164. m_RemoteSimulationService = ServerUtils.LoadPlugin<ISimulationService>(simulationService, args);
  165. if (agentService != string.Empty)
  166. m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(agentService, args);
  167. // Get the Hypergrid inventory service (exists only if Hypergrid is enabled)
  168. string hgInvServicePlugin = m_LoginServerConfig.GetString("HGInventoryServicePlugin", String.Empty);
  169. if (hgInvServicePlugin != string.Empty)
  170. {
  171. // TODO: Remove HGInventoryServiceConstructorArg after 0.9 release
  172. string hgInvServiceArg = m_LoginServerConfig.GetString("HGInventoryServiceConstructorArg", String.Empty);
  173. if (hgInvServiceArg != String.Empty)
  174. {
  175. m_log.Warn("[LLOGIN SERVICE]: You are using HGInventoryServiceConstructorArg, which is deprecated. See example file for correct syntax.");
  176. hgInvServicePlugin = hgInvServiceArg + "@" + hgInvServicePlugin;
  177. }
  178. m_HGInventoryService = ServerUtils.LoadPlugin<IInventoryService>(hgInvServicePlugin, args);
  179. }
  180. //
  181. // deal with the services given as argument
  182. //
  183. m_LocalSimulationService = simService;
  184. if (libraryService != null)
  185. {
  186. m_log.DebugFormat("[LLOGIN SERVICE]: Using LibraryService given as argument");
  187. m_LibraryService = libraryService;
  188. }
  189. else if (libService != string.Empty)
  190. {
  191. m_log.DebugFormat("[LLOGIN SERVICE]: Using instantiated LibraryService");
  192. m_LibraryService = ServerUtils.LoadPlugin<ILibraryService>(libService, args);
  193. }
  194. m_GatekeeperConnector = new GatekeeperServiceConnector();
  195. if (!Initialized)
  196. {
  197. Initialized = true;
  198. RegisterCommands();
  199. }
  200. m_log.DebugFormat("[LLOGIN SERVICE]: Starting...");
  201. }
  202. public LLLoginService(IConfigSource config) : this(config, null, null)
  203. {
  204. }
  205. public Hashtable SetLevel(string firstName, string lastName, string passwd, int level, IPEndPoint clientIP)
  206. {
  207. Hashtable response = new Hashtable();
  208. response["success"] = "false";
  209. if (!m_AllowRemoteSetLoginLevel)
  210. return response;
  211. try
  212. {
  213. UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, firstName, lastName);
  214. if (account == null)
  215. {
  216. m_log.InfoFormat("[LLOGIN SERVICE]: Set Level failed, user {0} {1} not found", firstName, lastName);
  217. return response;
  218. }
  219. if (account.UserLevel < 200)
  220. {
  221. m_log.InfoFormat("[LLOGIN SERVICE]: Set Level failed, reason: user level too low");
  222. return response;
  223. }
  224. //
  225. // Authenticate this user
  226. //
  227. // We don't support clear passwords here
  228. //
  229. string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30);
  230. UUID secureSession = UUID.Zero;
  231. if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession)))
  232. {
  233. m_log.InfoFormat("[LLOGIN SERVICE]: SetLevel failed, reason: authentication failed");
  234. return response;
  235. }
  236. }
  237. catch (Exception e)
  238. {
  239. m_log.Error("[LLOGIN SERVICE]: SetLevel failed, exception " + e.ToString());
  240. return response;
  241. }
  242. m_MinLoginLevel = level;
  243. m_log.InfoFormat("[LLOGIN SERVICE]: Login level set to {0} by {1} {2}", level, firstName, lastName);
  244. response["success"] = true;
  245. return response;
  246. }
  247. public LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, UUID scopeID,
  248. string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP, bool LibOMVclient)
  249. {
  250. bool success = false;
  251. UUID session = UUID.Random();
  252. string processedMessage;
  253. if (clientVersion.Contains("Radegast"))
  254. LibOMVclient = false;
  255. m_log.InfoFormat("[LLOGIN SERVICE]: Login request for {0} {1} at {2} using viewer {3}, channel {4}, IP {5}, Mac {6}, Id0 {7}, Possible LibOMVGridProxy: {8} ",
  256. firstName, lastName, startLocation, clientVersion, channel, clientIP.Address.ToString(), mac, id0, LibOMVclient.ToString());
  257. string curMac = mac.ToString();
  258. try
  259. {
  260. //
  261. // Check client
  262. //
  263. string clientNameToCheck;
  264. if(clientVersion.Contains(" "))
  265. clientNameToCheck = clientVersion;
  266. else
  267. clientNameToCheck = channel + " " + clientVersion;
  268. if (!String.IsNullOrWhiteSpace(m_AllowedClients))
  269. {
  270. Regex arx = new Regex(m_AllowedClients);
  271. Match am = arx.Match(clientNameToCheck);
  272. if (!am.Success)
  273. {
  274. m_log.InfoFormat(
  275. "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: client {2} is not allowed",
  276. firstName, lastName, clientNameToCheck);
  277. return LLFailedLoginResponse.LoginBlockedProblem;
  278. }
  279. }
  280. if (!String.IsNullOrWhiteSpace(m_DeniedClients))
  281. {
  282. Regex drx = new Regex(m_DeniedClients);
  283. Match dm = drx.Match(clientNameToCheck);
  284. if (dm.Success)
  285. {
  286. m_log.InfoFormat(
  287. "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: client {2} is denied",
  288. firstName, lastName, clientNameToCheck);
  289. return LLFailedLoginResponse.LoginBlockedProblem;
  290. }
  291. }
  292. if (!String.IsNullOrWhiteSpace(m_DeniedMacs))
  293. {
  294. m_log.InfoFormat("[LLOGIN SERVICE]: Checking users Mac {0} against list of denied macs {1} ...", curMac, m_DeniedMacs);
  295. if (m_DeniedMacs.Contains(curMac))
  296. {
  297. m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: client with mac {0} is denied", curMac);
  298. return LLFailedLoginResponse.LoginBlockedProblem;
  299. }
  300. }
  301. //
  302. // Get the account and check that it exists
  303. //
  304. UserAccount account = m_UserAccountService.GetUserAccount(scopeID, firstName, lastName);
  305. if (account == null)
  306. {
  307. m_log.InfoFormat(
  308. "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: user not found", firstName, lastName);
  309. return LLFailedLoginResponse.UserProblem;
  310. }
  311. if (account.UserLevel < m_MinLoginLevel)
  312. {
  313. m_log.InfoFormat(
  314. "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: user level is {2} but minimum login level is {3}",
  315. firstName, lastName, account.UserLevel, m_MinLoginLevel);
  316. return LLFailedLoginResponse.LoginBlockedProblem;
  317. }
  318. // If a scope id is requested, check that the account is in
  319. // that scope, or unscoped.
  320. //
  321. if (scopeID != UUID.Zero)
  322. {
  323. if (account.ScopeID != scopeID && account.ScopeID != UUID.Zero)
  324. {
  325. m_log.InfoFormat(
  326. "[LLOGIN SERVICE]: Login failed, reason: user {0} {1} not found", firstName, lastName);
  327. return LLFailedLoginResponse.UserProblem;
  328. }
  329. }
  330. else
  331. {
  332. scopeID = account.ScopeID;
  333. }
  334. //
  335. // Authenticate this user
  336. //
  337. if (!passwd.StartsWith("$1$"))
  338. passwd = "$1$" + Util.Md5Hash(passwd);
  339. passwd = passwd.Remove(0, 3); //remove $1$
  340. UUID realID;
  341. string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30, out realID);
  342. UUID secureSession = UUID.Zero;
  343. if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession)))
  344. {
  345. m_log.InfoFormat(
  346. "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: authentication failed",
  347. firstName, lastName);
  348. return LLFailedLoginResponse.UserProblem;
  349. }
  350. if(account.PrincipalID == new UUID("6571e388-6218-4574-87db-f9379718315e"))
  351. {
  352. // really?
  353. return LLFailedLoginResponse.UserProblem;
  354. }
  355. string PrincipalIDstr = account.PrincipalID.ToString();
  356. GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(PrincipalIDstr);
  357. if(!m_allowDuplicatePresences)
  358. {
  359. if(guinfo != null && guinfo.Online && guinfo.LastRegionID != UUID.Zero)
  360. {
  361. if(SendAgentGodKillToRegion(scopeID, account.PrincipalID, guinfo))
  362. {
  363. m_log.InfoFormat(
  364. "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: already logged in",
  365. firstName, lastName);
  366. return LLFailedLoginResponse.AlreadyLoggedInProblem;
  367. }
  368. }
  369. }
  370. //
  371. // Get the user's inventory
  372. //
  373. if (m_RequireInventory && m_InventoryService == null)
  374. {
  375. m_log.WarnFormat(
  376. "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: inventory service not set up",
  377. firstName, lastName);
  378. return LLFailedLoginResponse.InventoryProblem;
  379. }
  380. if (m_HGInventoryService != null)
  381. {
  382. // Give the Suitcase service a chance to create the suitcase folder.
  383. // (If we're not using the Suitcase inventory service then this won't do anything.)
  384. m_HGInventoryService.GetRootFolder(account.PrincipalID);
  385. }
  386. List<InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID);
  387. if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0)))
  388. {
  389. m_log.InfoFormat(
  390. "[LLOGIN SERVICE]: Login failed, for {0} {1}, reason: unable to retrieve user inventory",
  391. firstName, lastName);
  392. return LLFailedLoginResponse.InventoryProblem;
  393. }
  394. // Get active gestures
  395. List<InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(account.PrincipalID);
  396. // m_log.DebugFormat("[LLOGIN SERVICE]: {0} active gestures", gestures.Count);
  397. //
  398. // Login the presence
  399. //
  400. if (m_PresenceService != null)
  401. {
  402. success = m_PresenceService.LoginAgent(PrincipalIDstr, session, secureSession);
  403. if (!success)
  404. {
  405. m_log.InfoFormat(
  406. "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: could not login presence",
  407. firstName, lastName);
  408. return LLFailedLoginResponse.GridProblem;
  409. }
  410. }
  411. //
  412. // Change Online status and get the home region
  413. //
  414. GridRegion home = null;
  415. // We are only going to complain about no home if the user actually tries to login there, to avoid
  416. // spamming the console.
  417. if (guinfo != null)
  418. {
  419. if (guinfo.HomeRegionID == UUID.Zero && startLocation == "home")
  420. {
  421. m_log.WarnFormat(
  422. "[LLOGIN SERVICE]: User {0} tried to login to a 'home' start location but they have none set",
  423. account.Name);
  424. }
  425. else if (m_GridService != null)
  426. {
  427. home = m_GridService.GetRegionByUUID(scopeID, guinfo.HomeRegionID);
  428. if (home == null && startLocation == "home")
  429. {
  430. m_log.WarnFormat(
  431. "[LLOGIN SERVICE]: User {0} tried to login to a 'home' start location with ID {1} but this was not found.",
  432. account.Name, guinfo.HomeRegionID);
  433. }
  434. }
  435. }
  436. else
  437. {
  438. // something went wrong, make something up, so that we don't have to test this anywhere else
  439. m_log.DebugFormat("{0} Failed to fetch GridUserInfo. Creating empty GridUserInfo as home", LogHeader);
  440. guinfo = new GridUserInfo();
  441. guinfo.LastPosition = guinfo.HomePosition = new Vector3(128, 128, 30);
  442. }
  443. //
  444. // Find the destination region/grid
  445. //
  446. string where = string.Empty;
  447. Vector3 position = Vector3.Zero;
  448. Vector3 lookAt = Vector3.Zero;
  449. GridRegion gatekeeper = null;
  450. TeleportFlags flags;
  451. GridRegion destination = FindDestination(account, scopeID, guinfo, session, startLocation, home, out gatekeeper, out where, out position, out lookAt, out flags);
  452. if (destination == null)
  453. {
  454. m_PresenceService.LogoutAgent(session);
  455. m_log.InfoFormat(
  456. "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: destination not found",
  457. firstName, lastName);
  458. return LLFailedLoginResponse.GridProblem;
  459. }
  460. else
  461. {
  462. m_log.DebugFormat(
  463. "[LLOGIN SERVICE]: Found destination {0}, endpoint {1} for {2} {3}",
  464. destination.RegionName, destination.ExternalEndPoint, firstName, lastName);
  465. }
  466. if (account.UserLevel >= 200)
  467. flags |= TeleportFlags.Godlike;
  468. //
  469. // Get the avatar
  470. //
  471. AvatarAppearance avatar = null;
  472. if (m_AvatarService != null)
  473. {
  474. avatar = m_AvatarService.GetAppearance(account.PrincipalID);
  475. }
  476. //
  477. // Instantiate/get the simulation interface and launch an agent at the destination
  478. //
  479. string reason = string.Empty;
  480. GridRegion dest;
  481. AgentCircuitData aCircuit = LaunchAgentAtGrid(gatekeeper, destination, account, avatar, session, secureSession, position, where,
  482. clientVersion, channel, mac, id0, clientIP, flags, out where, out reason, out dest);
  483. destination = dest;
  484. if (aCircuit == null)
  485. {
  486. m_PresenceService.LogoutAgent(session);
  487. m_log.InfoFormat("[LLOGIN SERVICE]: Login failed for {0} {1}, reason: {2}", firstName, lastName, reason);
  488. return new LLFailedLoginResponse("key", reason, "false");
  489. }
  490. // only now we can assume a login
  491. guinfo = m_GridUserService.LoggedIn(PrincipalIDstr);
  492. // Get Friends list
  493. FriendInfo[] friendsList = new FriendInfo[0];
  494. if (m_FriendsService != null)
  495. {
  496. friendsList = m_FriendsService.GetFriends(account.PrincipalID);
  497. // m_log.DebugFormat("[LLOGIN SERVICE]: Retrieved {0} friends", friendsList.Length);
  498. }
  499. //
  500. // Finally, fill out the response and return it
  501. //
  502. if (m_MessageUrl != String.Empty)
  503. {
  504. using(WebClient client = new WebClient())
  505. processedMessage = client.DownloadString(m_MessageUrl);
  506. }
  507. else
  508. {
  509. processedMessage = m_WelcomeMessage;
  510. }
  511. processedMessage = processedMessage.Replace("\\n", "\n").Replace("<USERNAME>", firstName + " " + lastName);
  512. LLLoginResponse response
  513. = new LLLoginResponse(
  514. account, aCircuit, guinfo, destination, inventorySkel, friendsList, m_LibraryService,
  515. where, startLocation, position, lookAt, gestures, processedMessage, home, clientIP,
  516. m_MapTileURL, m_ProfileURL, m_OpenIDURL, m_SearchURL, m_Currency, m_DSTZone,
  517. m_DestinationGuide, m_AvatarPicker, realID, m_ClassifiedFee,m_MaxAgentGroups);
  518. m_log.DebugFormat("[LLOGIN SERVICE]: All clear. Sending login response to {0} {1}", firstName, lastName);
  519. return response;
  520. }
  521. catch (Exception e)
  522. {
  523. m_log.WarnFormat("[LLOGIN SERVICE]: Exception processing login for {0} {1}: {2} {3}", firstName, lastName, e.ToString(), e.StackTrace);
  524. if (m_PresenceService != null)
  525. m_PresenceService.LogoutAgent(session);
  526. return LLFailedLoginResponse.InternalError;
  527. }
  528. }
  529. protected GridRegion FindDestination(
  530. UserAccount account, UUID scopeID, GridUserInfo pinfo, UUID sessionID, string startLocation,
  531. GridRegion home, out GridRegion gatekeeper,
  532. out string where, out Vector3 position, out Vector3 lookAt, out TeleportFlags flags)
  533. {
  534. flags = TeleportFlags.ViaLogin;
  535. m_log.DebugFormat(
  536. "[LLOGIN SERVICE]: Finding destination matching start location {0} for {1}",
  537. startLocation, account.Name);
  538. gatekeeper = null;
  539. where = "home";
  540. position = new Vector3(128, 128, 0);
  541. lookAt = new Vector3(0, 1, 0);
  542. if (m_GridService == null)
  543. return null;
  544. if (startLocation.Equals("home"))
  545. {
  546. // logging into home region
  547. if (pinfo == null)
  548. return null;
  549. GridRegion region = null;
  550. bool tryDefaults = false;
  551. if (home == null)
  552. {
  553. tryDefaults = true;
  554. }
  555. else
  556. {
  557. region = home;
  558. position = pinfo.HomePosition;
  559. lookAt = pinfo.HomeLookAt;
  560. flags |= TeleportFlags.ViaHome;
  561. }
  562. if (tryDefaults)
  563. {
  564. List<GridRegion> defaults = m_GridService.GetDefaultRegions(scopeID);
  565. if (defaults != null && defaults.Count > 0)
  566. {
  567. flags |= TeleportFlags.ViaRegionID;
  568. region = defaults[0];
  569. where = "safe";
  570. }
  571. else
  572. {
  573. m_log.WarnFormat("[LLOGIN SERVICE]: User {0} {1} does not have a valid home and this grid does not have default locations. Attempting to find random region",
  574. account.FirstName, account.LastName);
  575. region = FindAlternativeRegion(scopeID);
  576. if (region != null)
  577. {
  578. flags |= TeleportFlags.ViaRegionID;
  579. where = "safe";
  580. }
  581. }
  582. }
  583. return region;
  584. }
  585. else if (startLocation.Equals("last"))
  586. {
  587. // logging into last visited region
  588. where = "last";
  589. if (pinfo == null)
  590. return null;
  591. GridRegion region = null;
  592. if (pinfo.LastRegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(scopeID, pinfo.LastRegionID)) == null)
  593. {
  594. List<GridRegion> defaults = m_GridService.GetDefaultRegions(scopeID);
  595. if (defaults != null && defaults.Count > 0)
  596. {
  597. flags |= TeleportFlags.ViaRegionID;
  598. region = defaults[0];
  599. where = "safe";
  600. }
  601. else
  602. {
  603. m_log.Info("[LLOGIN SERVICE]: Last Region Not Found Attempting to find random region");
  604. region = FindAlternativeRegion(scopeID);
  605. if (region != null)
  606. {
  607. flags |= TeleportFlags.ViaRegionID;
  608. where = "safe";
  609. }
  610. }
  611. }
  612. else
  613. {
  614. position = pinfo.LastPosition;
  615. lookAt = pinfo.LastLookAt;
  616. }
  617. return region;
  618. }
  619. else
  620. {
  621. flags |= TeleportFlags.ViaRegionID;
  622. // free uri form
  623. // e.g. New Moon&135&46 New [email protected]:8002&153&34
  624. where = "url";
  625. GridRegion region = null;
  626. Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+[.]?\d*)&(?<y>\d+[.]?\d*)&(?<z>\d+[.]?\d*)$");
  627. Match uriMatch = reURI.Match(startLocation);
  628. if (uriMatch == null)
  629. {
  630. m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, but can't process it", startLocation);
  631. return null;
  632. }
  633. else
  634. {
  635. position = new Vector3(float.Parse(uriMatch.Groups["x"].Value, Culture.NumberFormatInfo),
  636. float.Parse(uriMatch.Groups["y"].Value, Culture.NumberFormatInfo),
  637. float.Parse(uriMatch.Groups["z"].Value, Culture.NumberFormatInfo));
  638. string regionName = uriMatch.Groups["region"].ToString();
  639. if (regionName != null)
  640. {
  641. if (!regionName.Contains("@"))
  642. {
  643. List<GridRegion> regions = m_GridService.GetRegionsByName(scopeID, regionName, 1);
  644. if ((regions == null) || (regions != null && regions.Count == 0))
  645. {
  646. m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}. Trying defaults.", startLocation, regionName);
  647. regions = m_GridService.GetDefaultRegions(scopeID);
  648. if (regions != null && regions.Count > 0)
  649. {
  650. where = "safe";
  651. return regions[0];
  652. }
  653. else
  654. {
  655. m_log.Info("[LLOGIN SERVICE]: Last Region Not Found Attempting to find random region");
  656. region = FindAlternativeRegion(scopeID);
  657. if (region != null)
  658. {
  659. where = "safe";
  660. return region;
  661. }
  662. else
  663. {
  664. m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, Grid does not provide default regions and no alternative found.", startLocation);
  665. return null;
  666. }
  667. }
  668. }
  669. //find a exact match
  670. foreach(GridRegion r in regions)
  671. {
  672. if(string.Equals(regionName, r.RegionName, StringComparison.CurrentCultureIgnoreCase))
  673. return r;
  674. }
  675. // else, whatever
  676. return regions[0];
  677. }
  678. else
  679. {
  680. if (m_UserAgentService == null)
  681. {
  682. m_log.WarnFormat("[LLLOGIN SERVICE]: This llogin service is not running a user agent service, as such it can't lauch agents at foreign grids");
  683. return null;
  684. }
  685. string[] parts = regionName.Split(new char[] { '@' });
  686. if (parts.Length < 2)
  687. {
  688. m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}", startLocation, regionName);
  689. return null;
  690. }
  691. // Valid specification of a remote grid
  692. regionName = parts[0];
  693. string domainLocator = parts[1];
  694. parts = domainLocator.Split(new char[] {':'});
  695. string domainName = parts[0];
  696. uint regionport = 0;
  697. if (parts.Length > 1)
  698. UInt32.TryParse(parts[1], out regionport);
  699. region = FindForeignRegion(domainName, regionport, regionName, account, out gatekeeper);
  700. return region;
  701. }
  702. }
  703. else
  704. {
  705. List<GridRegion> defaults = m_GridService.GetDefaultRegions(scopeID);
  706. if (defaults != null && defaults.Count > 0)
  707. {
  708. where = "safe";
  709. return defaults[0];
  710. }
  711. else
  712. return null;
  713. }
  714. }
  715. //response.LookAt = "[r0,r1,r0]";
  716. //// can be: last, home, safe, url
  717. //response.StartLocation = "url";
  718. }
  719. }
  720. private GridRegion FindAlternativeRegion(UUID scopeID)
  721. {
  722. List<GridRegion> hyperlinks = null;
  723. List<GridRegion> regions = m_GridService.GetFallbackRegions(scopeID, (int)Util.RegionToWorldLoc(1000), (int)Util.RegionToWorldLoc(1000));
  724. if (regions != null && regions.Count > 0)
  725. {
  726. hyperlinks = m_GridService.GetHyperlinks(scopeID);
  727. IEnumerable<GridRegion> availableRegions = regions.Except(hyperlinks);
  728. if (availableRegions.Count() > 0)
  729. return availableRegions.ElementAt(0);
  730. }
  731. // No fallbacks, try to find an arbitrary region that is not a hyperlink
  732. // maxNumber is fixed for now; maybe use some search pattern with increasing maxSize here?
  733. regions = m_GridService.GetRegionsByName(scopeID, "", 10);
  734. if (regions != null && regions.Count > 0)
  735. {
  736. if (hyperlinks == null)
  737. hyperlinks = m_GridService.GetHyperlinks(scopeID);
  738. IEnumerable<GridRegion> availableRegions = regions.Except(hyperlinks);
  739. if (availableRegions.Count() > 0)
  740. return availableRegions.ElementAt(0);
  741. }
  742. return null;
  743. }
  744. private GridRegion FindForeignRegion(string domainName, uint port, string regionName, UserAccount account, out GridRegion gatekeeper)
  745. {
  746. m_log.Debug("[LLLOGIN SERVICE]: attempting to findforeignregion " + domainName + ":" + port.ToString() + ":" + regionName);
  747. gatekeeper = new GridRegion();
  748. gatekeeper.ExternalHostName = domainName;
  749. gatekeeper.HttpPort = port;
  750. gatekeeper.RegionName = regionName;
  751. gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
  752. UUID regionID;
  753. ulong handle;
  754. string imageURL = string.Empty, reason = string.Empty;
  755. string message;
  756. int sizeX = (int)Constants.RegionSize;
  757. int sizeY = (int)Constants.RegionSize;
  758. if (m_GatekeeperConnector.LinkRegion(gatekeeper, out regionID, out handle, out domainName, out imageURL, out reason, out sizeX, out sizeY))
  759. {
  760. string homeURI = null;
  761. if (account.ServiceURLs != null && account.ServiceURLs.ContainsKey("HomeURI"))
  762. homeURI = (string)account.ServiceURLs["HomeURI"];
  763. GridRegion destination = m_GatekeeperConnector.GetHyperlinkRegion(gatekeeper, regionID, account.PrincipalID, homeURI, out message);
  764. return destination;
  765. }
  766. return null;
  767. }
  768. private string hostName = string.Empty;
  769. private int port = 0;
  770. private void SetHostAndPort(string url)
  771. {
  772. try
  773. {
  774. Uri uri = new Uri(url);
  775. hostName = uri.Host;
  776. port = uri.Port;
  777. }
  778. catch
  779. {
  780. m_log.WarnFormat("[LLLogin SERVICE]: Unable to parse GatekeeperURL {0}", url);
  781. }
  782. }
  783. protected AgentCircuitData LaunchAgentAtGrid(GridRegion gatekeeper, GridRegion destination, UserAccount account, AvatarAppearance avatar,
  784. UUID session, UUID secureSession, Vector3 position, string currentWhere, string viewer, string channel, string mac, string id0,
  785. IPEndPoint clientIP, TeleportFlags flags, out string where, out string reason, out GridRegion dest)
  786. {
  787. where = currentWhere;
  788. ISimulationService simConnector = null;
  789. reason = string.Empty;
  790. uint circuitCode = 0;
  791. AgentCircuitData aCircuit = null;
  792. dest = null;
  793. bool success = false;
  794. if (m_UserAgentService == null)
  795. {
  796. // HG standalones have both a localSimulatonDll and a remoteSimulationDll
  797. // non-HG standalones have just a localSimulationDll
  798. // independent login servers have just a remoteSimulationDll
  799. if (m_LocalSimulationService != null)
  800. simConnector = m_LocalSimulationService;
  801. else if (m_RemoteSimulationService != null)
  802. simConnector = m_RemoteSimulationService;
  803. if(simConnector == null)
  804. return null;
  805. circuitCode = (uint)Util.RandomClass.Next(); ;
  806. aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position,
  807. clientIP.Address.ToString(), viewer, channel, mac, id0);
  808. success = LaunchAgentDirectly(simConnector, destination, aCircuit, flags, out reason);
  809. if (!success && m_GridService != null)
  810. {
  811. // Try the fallback regions
  812. List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
  813. if (fallbacks != null)
  814. {
  815. foreach (GridRegion r in fallbacks)
  816. {
  817. success = LaunchAgentDirectly(simConnector, r, aCircuit, flags | TeleportFlags.ViaRegionID, out reason);
  818. if (success)
  819. {
  820. where = "safe";
  821. destination = r;
  822. break;
  823. }
  824. }
  825. }
  826. }
  827. }
  828. else
  829. {
  830. if (gatekeeper == null) // login to local grid
  831. {
  832. if (hostName == string.Empty)
  833. SetHostAndPort(m_GatekeeperURL);
  834. gatekeeper = new GridRegion(destination);
  835. gatekeeper.ExternalHostName = hostName;
  836. gatekeeper.HttpPort = (uint)port;
  837. gatekeeper.ServerURI = m_GatekeeperURL;
  838. }
  839. circuitCode = (uint)Util.RandomClass.Next(); ;
  840. aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position,
  841. clientIP.Address.ToString(), viewer, channel, mac, id0);
  842. aCircuit.teleportFlags |= (uint)flags;
  843. success = LaunchAgentIndirectly(gatekeeper, destination, aCircuit, clientIP, out reason);
  844. if (!success && m_GridService != null)
  845. {
  846. // Try the fallback regions
  847. List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
  848. if (fallbacks != null)
  849. {
  850. foreach (GridRegion r in fallbacks)
  851. {
  852. success = LaunchAgentIndirectly(gatekeeper, r, aCircuit, clientIP, out reason);
  853. if (success)
  854. {
  855. where = "safe";
  856. destination = r;
  857. break;
  858. }
  859. }
  860. }
  861. }
  862. }
  863. dest = destination;
  864. if (success)
  865. return aCircuit;
  866. else
  867. return null;
  868. }
  869. private AgentCircuitData MakeAgent(GridRegion region, UserAccount account,
  870. AvatarAppearance avatar, UUID session, UUID secureSession, uint circuit, Vector3 position,
  871. string ipaddress, string viewer, string channel, string mac, string id0)
  872. {
  873. AgentCircuitData aCircuit = new AgentCircuitData();
  874. aCircuit.AgentID = account.PrincipalID;
  875. if (avatar != null)
  876. aCircuit.Appearance = new AvatarAppearance(avatar);
  877. else
  878. aCircuit.Appearance = new AvatarAppearance();
  879. //aCircuit.BaseFolder = irrelevant
  880. aCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
  881. aCircuit.child = false; // the first login agent is root
  882. aCircuit.ChildrenCapSeeds = new Dictionary<ulong, string>();
  883. aCircuit.circuitcode = circuit;
  884. aCircuit.firstname = account.FirstName;
  885. //aCircuit.InventoryFolder = irrelevant
  886. aCircuit.lastname = account.LastName;
  887. aCircuit.SecureSessionID = secureSession;
  888. aCircuit.SessionID = session;
  889. aCircuit.startpos = position;
  890. aCircuit.IPAddress = ipaddress;
  891. aCircuit.Viewer = viewer;
  892. aCircuit.Channel = channel;
  893. aCircuit.Mac = mac;
  894. aCircuit.Id0 = id0;
  895. SetServiceURLs(aCircuit, account);
  896. return aCircuit;
  897. }
  898. private void SetServiceURLs(AgentCircuitData aCircuit, UserAccount account)
  899. {
  900. aCircuit.ServiceURLs = new Dictionary<string, object>();
  901. if (account.ServiceURLs == null)
  902. return;
  903. // Old style: get the service keys from the DB
  904. foreach (KeyValuePair<string, object> kvp in account.ServiceURLs)
  905. {
  906. if (kvp.Value != null)
  907. {
  908. aCircuit.ServiceURLs[kvp.Key] = kvp.Value;
  909. if (!aCircuit.ServiceURLs[kvp.Key].ToString().EndsWith("/"))
  910. aCircuit.ServiceURLs[kvp.Key] = aCircuit.ServiceURLs[kvp.Key] + "/";
  911. }
  912. }
  913. // New style: service keys start with SRV_; override the previous
  914. string[] keys = m_LoginServerConfig.GetKeys();
  915. if (keys.Length > 0)
  916. {
  917. bool newUrls = false;
  918. IEnumerable<string> serviceKeys = keys.Where(value => value.StartsWith("SRV_"));
  919. foreach (string serviceKey in serviceKeys)
  920. {
  921. string keyName = serviceKey.Replace("SRV_", "");
  922. string keyValue = m_LoginServerConfig.GetString(serviceKey, string.Empty);
  923. if (!keyValue.EndsWith("/"))
  924. keyValue = keyValue + "/";
  925. if (!account.ServiceURLs.ContainsKey(keyName) || (account.ServiceURLs.ContainsKey(keyName) && (string)account.ServiceURLs[keyName] != keyValue))
  926. {
  927. account.ServiceURLs[keyName] = keyValue;
  928. newUrls = true;
  929. }
  930. aCircuit.ServiceURLs[keyName] = keyValue;
  931. m_log.DebugFormat("[LLLOGIN SERVICE]: found new key {0} {1}", keyName, aCircuit.ServiceURLs[keyName]);
  932. }
  933. if (!account.ServiceURLs.ContainsKey("GatekeeperURI") && !string.IsNullOrEmpty(m_GatekeeperURL))
  934. {
  935. m_log.DebugFormat("[LLLOGIN SERVICE]: adding gatekeeper uri {0}", m_GatekeeperURL);
  936. account.ServiceURLs["GatekeeperURI"] = m_GatekeeperURL;
  937. newUrls = true;
  938. }
  939. // The grid operator decided to override the defaults in the
  940. // [LoginService] configuration. Let's store the correct ones.
  941. if (newUrls)
  942. m_UserAccountService.StoreUserAccount(account);
  943. }
  944. }
  945. private bool LaunchAgentDirectly(ISimulationService simConnector, GridRegion region, AgentCircuitData aCircuit, TeleportFlags flags, out string reason)
  946. {
  947. EntityTransferContext ctx = new EntityTransferContext();
  948. if (!simConnector.QueryAccess(
  949. region, aCircuit.AgentID, null, true, aCircuit.startpos, new List<UUID>(), ctx, out reason))
  950. return false;
  951. return simConnector.CreateAgent(null, region, aCircuit, (uint)flags, ctx, out reason);
  952. }
  953. private bool LaunchAgentIndirectly(GridRegion gatekeeper, GridRegion destination, AgentCircuitData aCircuit, IPEndPoint clientIP, out string reason)
  954. {
  955. m_log.Debug("[LLOGIN SERVICE]: Launching agent at " + destination.RegionName);
  956. if (m_UserAgentService.LoginAgentToGrid(null, aCircuit, gatekeeper, destination, true, out reason))
  957. return true;
  958. return false;
  959. }
  960. #region Console Commands
  961. private void RegisterCommands()
  962. {
  963. //MainConsole.Instance.Commands.AddCommand
  964. MainConsole.Instance.Commands.AddCommand("Users", false, "login level",
  965. "login level <level>",
  966. "Set the minimum user level to log in", HandleLoginCommand);
  967. MainConsole.Instance.Commands.AddCommand("Users", false, "login reset",
  968. "login reset",
  969. "Reset the login level to allow all users",
  970. HandleLoginCommand);
  971. MainConsole.Instance.Commands.AddCommand("Users", false, "login text",
  972. "login text <text>",
  973. "Set the text users will see on login", HandleLoginCommand);
  974. }
  975. private void HandleLoginCommand(string module, string[] cmd)
  976. {
  977. string subcommand = cmd[1];
  978. switch (subcommand)
  979. {
  980. case "level":
  981. // Set the minimum level to allow login
  982. // Useful to allow grid update without worrying about users.
  983. // or fixing critical issues
  984. //
  985. if (cmd.Length > 2)
  986. {
  987. if (Int32.TryParse(cmd[2], out m_MinLoginLevel))
  988. MainConsole.Instance.OutputFormat("Set minimum login level to {0}", m_MinLoginLevel);
  989. else
  990. MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid login level", cmd[2]);
  991. }
  992. break;
  993. case "reset":
  994. m_MinLoginLevel = m_LoginServerConfig.GetInt("MinLoginLevel", 0);
  995. MainConsole.Instance.OutputFormat("Reset min login level to {0}", m_MinLoginLevel);
  996. break;
  997. case "text":
  998. if (cmd.Length > 2)
  999. {
  1000. m_WelcomeMessage = cmd[2];
  1001. MainConsole.Instance.OutputFormat("Login welcome message set to '{0}'", m_WelcomeMessage);
  1002. }
  1003. break;
  1004. }
  1005. }
  1006. private bool SendAgentGodKillToRegion(UUID scopeID, UUID agentID , GridUserInfo guinfo)
  1007. {
  1008. UUID regionID = guinfo.LastRegionID;
  1009. GridRegion regInfo = m_GridService.GetRegionByUUID(scopeID, regionID);
  1010. if(regInfo == null)
  1011. return false;
  1012. string regURL = regInfo.ServerURI;
  1013. if(String.IsNullOrEmpty(regURL))
  1014. return false;
  1015. UUID guuid = new UUID("6571e388-6218-4574-87db-f9379718315e");
  1016. GridInstantMessage msg = new GridInstantMessage();
  1017. msg.imSessionID = UUID.Zero.Guid;
  1018. msg.fromAgentID = guuid.Guid;
  1019. msg.toAgentID = agentID.Guid;
  1020. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  1021. msg.fromAgentName = "GRID";
  1022. msg.message = string.Format("New login detected");
  1023. msg.dialog = 250; // God kick
  1024. msg.fromGroup = false;
  1025. msg.offline = (byte)0;
  1026. msg.ParentEstateID = 0;
  1027. msg.Position = Vector3.Zero;
  1028. msg.RegionID = scopeID.Guid;
  1029. msg.binaryBucket = new byte[1] {0};
  1030. InstantMessageServiceConnector.SendInstantMessage(regURL,msg);
  1031. m_GridUserService.LoggedOut(agentID.ToString(),
  1032. UUID.Zero, guinfo.LastRegionID, guinfo.LastPosition, guinfo.LastLookAt);
  1033. return true;
  1034. }
  1035. }
  1036. #endregion
  1037. }