pCampBot.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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();
  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 botConfig = configSource.Configs["Bot"];
  76. if (botConfig != null)
  77. {
  78. bm.InitBotSendAgentUpdates
  79. = botConfig.GetBoolean("SendAgentUpdates", bm.InitBotSendAgentUpdates);
  80. bm.InitBotRequestObjectTextures
  81. = botConfig.GetBoolean("RequestObjectTextures", bm.InitBotRequestObjectTextures);
  82. }
  83. }
  84. int botcount = commandLineConfig.GetInt("botcount", 1);
  85. bool startConnected = commandLineConfig.Get("connect") != null;
  86. bm.CreateBots(botcount, commandLineConfig);
  87. if (startConnected)
  88. bm.ConnectBots(botcount);
  89. while (true)
  90. {
  91. try
  92. {
  93. MainConsole.Instance.Prompt();
  94. }
  95. catch (Exception e)
  96. {
  97. m_log.ErrorFormat("Command error: {0}", e);
  98. }
  99. }
  100. }
  101. }
  102. private static IConfig ParseConfig(String[] args)
  103. {
  104. //Set up our nifty config.. thanks to nini
  105. ArgvConfigSource cs = new ArgvConfigSource(args);
  106. cs.AddSwitch("Startup", "connect", "c");
  107. cs.AddSwitch("Startup", "botcount", "n");
  108. cs.AddSwitch("Startup", "from", "f");
  109. cs.AddSwitch("Startup", "loginuri", "l");
  110. cs.AddSwitch("Startup", "start", "s");
  111. cs.AddSwitch("Startup", "firstname");
  112. cs.AddSwitch("Startup", "lastname");
  113. cs.AddSwitch("Startup", "password");
  114. cs.AddSwitch("Startup", "behaviours", "b");
  115. cs.AddSwitch("Startup", "help", "h");
  116. cs.AddSwitch("Startup", "wear");
  117. IConfig ol = cs.Configs["Startup"];
  118. return ol;
  119. }
  120. private static void Help()
  121. {
  122. // Added the wear command. This allows the bot to wear real clothes instead of default locked ones.
  123. // You can either say no, to not load anything, yes, to load one of the default wearables, a folder
  124. // name, to load an specific folder, or save, to save an avatar with some already existing wearables
  125. // worn to the folder MyAppearance/FirstName_LastName, and the load it.
  126. Console.WriteLine(
  127. "usage: pCampBot <-loginuri loginuri> [OPTIONS]\n"
  128. + "Spawns a set of bots to test an OpenSim region\n\n"
  129. + " -l, -loginuri loginuri for grid/standalone (required)\n"
  130. + " -s, -start start location for bots (optional). Can be \"last\", \"home\" or a specific location with or without co-ords (e.g. \"region1\" or \"region2/50/30/90\"\n"
  131. + " -firstname first name for the bots (required)\n"
  132. + " -lastname lastname for the bots (required). Each lastname will have _<bot-number> appended, e.g. Ima Bot_0\n"
  133. + " -password password for the bots (required)\n"
  134. + " -n, -botcount number of bots to start (default: 1) (optional)\n"
  135. + " -f, -from starting number for login bot names, e.g. 25 will login Ima Bot_25, Ima Bot_26, etc. (default: 0) (optional)\n"
  136. + " -c, -connect connect all bots at startup (optional)\n"
  137. + " -b, behaviours behaviours for bots. Comma separated, e.g. p,g. Default is p (required)\n"
  138. + " current options are:\n"
  139. + " p (physics - bots constantly move and jump around)\n"
  140. + " g (grab - bots randomly click prims whether set clickable or not)\n"
  141. + " n (none - bots do nothing)\n"
  142. + " t (teleport - bots regularly teleport between regions on the grid)\n"
  143. // " c (cross)\n" +
  144. + " -wear folder from which to load appearance data, \"no\" if there is no such folder (default: no) (optional)\n"
  145. + " -h, -help show this message.\n");
  146. }
  147. }
  148. }