pCampBot.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.IO;
  29. using System.Reflection;
  30. using System.Threading;
  31. using log4net;
  32. using log4net.Config;
  33. using Nini.Config;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.Console;
  36. namespace pCampBot
  37. {
  38. /// <summary>
  39. /// Event Types from the BOT. Add new events here
  40. /// </summary>
  41. public enum EventType:int
  42. {
  43. NONE = 0,
  44. CONNECTED = 1,
  45. DISCONNECTED = 2
  46. }
  47. public class pCampBot
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. public const string ConfigFileName = "pCampBot.ini";
  51. [STAThread]
  52. public static void Main(string[] args)
  53. {
  54. XmlConfigurator.Configure(new System.IO.FileInfo("pCampBot.exe.config"));
  55. IConfig commandLineConfig = ParseConfig(args);
  56. if (commandLineConfig.Get("help") != null || commandLineConfig.Get("loginuri") == null)
  57. {
  58. Help();
  59. }
  60. else if (
  61. commandLineConfig.Get("firstname") == null
  62. || commandLineConfig.Get("lastname") == null
  63. || commandLineConfig.Get("password") == null)
  64. {
  65. Console.WriteLine("ERROR: You must supply a firstname, lastname and password for the bots.");
  66. }
  67. else
  68. {
  69. BotManager bm = new BotManager();
  70. string iniFilePath = Path.GetFullPath(Path.Combine(Util.configDir(), ConfigFileName));
  71. if (File.Exists(iniFilePath))
  72. {
  73. m_log.InfoFormat("[PCAMPBOT]: Reading configuration settings from {0}", iniFilePath);
  74. IConfigSource configSource = new IniConfigSource(iniFilePath);
  75. IConfig botManagerConfig = configSource.Configs["BotManager"];
  76. if (botManagerConfig != null)
  77. {
  78. bm.LoginDelay = botManagerConfig.GetInt("LoginDelay", bm.LoginDelay);
  79. }
  80. IConfig botConfig = configSource.Configs["Bot"];
  81. if (botConfig != null)
  82. {
  83. bm.InitBotSendAgentUpdates
  84. = botConfig.GetBoolean("SendAgentUpdates", bm.InitBotSendAgentUpdates);
  85. bm.InitBotRequestObjectTextures
  86. = botConfig.GetBoolean("RequestObjectTextures", bm.InitBotRequestObjectTextures);
  87. }
  88. }
  89. int botcount = commandLineConfig.GetInt("botcount", 1);
  90. bool startConnected = commandLineConfig.Get("connect") != null;
  91. bm.CreateBots(botcount, commandLineConfig);
  92. if (startConnected)
  93. bm.ConnectBots(botcount);
  94. while (true)
  95. {
  96. try
  97. {
  98. MainConsole.Instance.Prompt();
  99. }
  100. catch (Exception e)
  101. {
  102. m_log.ErrorFormat("Command error: {0}", e);
  103. }
  104. }
  105. }
  106. }
  107. private static IConfig ParseConfig(String[] args)
  108. {
  109. //Set up our nifty config.. thanks to nini
  110. ArgvConfigSource cs = new ArgvConfigSource(args);
  111. cs.AddSwitch("Startup", "connect", "c");
  112. cs.AddSwitch("Startup", "botcount", "n");
  113. cs.AddSwitch("Startup", "from", "f");
  114. cs.AddSwitch("Startup", "loginuri", "l");
  115. cs.AddSwitch("Startup", "start", "s");
  116. cs.AddSwitch("Startup", "firstname");
  117. cs.AddSwitch("Startup", "lastname");
  118. cs.AddSwitch("Startup", "password");
  119. cs.AddSwitch("Startup", "behaviours", "b");
  120. cs.AddSwitch("Startup", "help", "h");
  121. cs.AddSwitch("Startup", "wear");
  122. IConfig ol = cs.Configs["Startup"];
  123. return ol;
  124. }
  125. private static void Help()
  126. {
  127. // Added the wear command. This allows the bot to wear real clothes instead of default locked ones.
  128. // You can either say no, to not load anything, yes, to load one of the default wearables, a folder
  129. // name, to load an specific folder, or save, to save an avatar with some already existing wearables
  130. // worn to the folder MyAppearance/FirstName_LastName, and the load it.
  131. Console.WriteLine(
  132. "Usage: pCampBot -loginuri <loginuri> -firstname <first-name> -lastname <last-name> -password <password> [OPTIONS]\n"
  133. + "Spawns a set of bots to test an OpenSim region\n\n"
  134. + " -l, -loginuri loginuri for grid/standalone (required)\n"
  135. + " -s, -start start location for bots (default: last) (optional). Can be \"last\", \"home\" or a specific location with or without co-ords (e.g. \"region1\" or \"region2/50/30/90\"\n"
  136. + " -firstname first name for the bots (required)\n"
  137. + " -lastname lastname for the bots (required). Each lastname will have _<bot-number> appended, e.g. Ima Bot_0\n"
  138. + " -password password for the bots (required)\n"
  139. + " -n, -botcount number of bots to start (default: 1) (optional)\n"
  140. + " -f, -from starting number for login bot names, e.g. 25 will login Ima Bot_25, Ima Bot_26, etc. (default: 0) (optional)\n"
  141. + " -c, -connect connect all bots at startup (optional)\n"
  142. + " -b, behaviours behaviours for bots. Comma separated, e.g. p,g (default: p) (optional)\n"
  143. + " current options are:\n"
  144. + " p (physics - bots constantly move and jump around)\n"
  145. + " g (grab - bots randomly click prims whether set clickable or not)\n"
  146. + " n (none - bots do nothing)\n"
  147. + " t (teleport - bots regularly teleport between regions on the grid)\n"
  148. // " c (cross)\n" +
  149. + " -wear folder from which to load appearance data, \"no\" if there is no such folder (default: no) (optional)\n"
  150. + " -h, -help show this message.\n");
  151. }
  152. }
  153. }