diff options
author | Sean Dague | 2008-03-11 18:06:25 +0000 |
---|---|---|
committer | Sean Dague | 2008-03-11 18:06:25 +0000 |
commit | fa79433d2eafbb11b5ca737fde8939c7b592e557 (patch) | |
tree | 4119540c78c674021b86338b4c6f261658889ca4 /OpenSim/TestSuite | |
parent | * Very minor error message change in GridAssetClient (diff) | |
download | opensim-SC-fa79433d2eafbb11b5ca737fde8939c7b592e557.zip opensim-SC-fa79433d2eafbb11b5ca737fde8939c7b592e557.tar.gz opensim-SC-fa79433d2eafbb11b5ca737fde8939c7b592e557.tar.bz2 opensim-SC-fa79433d2eafbb11b5ca737fde8939c7b592e557.tar.xz |
clone off pCampBot to OpenSim.TestSuite, as I'm going to be
making enough breaking changes that I'd rather not mess up
people currently using pCampBot effectively.
Diffstat (limited to 'OpenSim/TestSuite')
-rw-r--r-- | OpenSim/TestSuite/BotManager.cs | 239 | ||||
-rw-r--r-- | OpenSim/TestSuite/PhysicsBot.cs | 203 | ||||
-rw-r--r-- | OpenSim/TestSuite/pCampBot.cs | 114 |
3 files changed, 556 insertions, 0 deletions
diff --git a/OpenSim/TestSuite/BotManager.cs b/OpenSim/TestSuite/BotManager.cs new file mode 100644 index 0000000..efd1613 --- /dev/null +++ b/OpenSim/TestSuite/BotManager.cs | |||
@@ -0,0 +1,239 @@ | |||
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 OpenSim 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 | */ | ||
28 | |||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using System.IO; | ||
33 | using libsecondlife; | ||
34 | using libsecondlife.Packets; | ||
35 | using Nini.Config; | ||
36 | using System.Threading; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Console; | ||
39 | |||
40 | namespace pCampBot | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// Thread/Bot manager for the application | ||
44 | /// </summary> | ||
45 | public class BotManager : conscmd_callback | ||
46 | { | ||
47 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | protected ConsoleBase m_console; | ||
50 | protected List<PhysicsBot> m_lBot; | ||
51 | protected Thread[] m_td; | ||
52 | protected bool m_verbose = true; | ||
53 | protected Random somthing = new Random(System.Environment.TickCount); | ||
54 | protected int numbots = 0; | ||
55 | protected IConfig Previous_config; | ||
56 | |||
57 | /// <summary> | ||
58 | /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data | ||
59 | /// </summary> | ||
60 | public BotManager() | ||
61 | { | ||
62 | m_log.Info("In bot manager"); | ||
63 | // m_console = CreateConsole(); | ||
64 | // MainConsole.Instance = m_console; | ||
65 | m_lBot = new List<PhysicsBot>(); | ||
66 | } | ||
67 | |||
68 | /// <summary> | ||
69 | /// Startup number of bots specified in the starting arguments | ||
70 | /// </summary> | ||
71 | /// <param name="botcount">How many bots to start up</param> | ||
72 | /// <param name="cs">The configuration for the bots to use</param> | ||
73 | public void dobotStartup(int botcount, IConfig cs) | ||
74 | { | ||
75 | Previous_config = cs; | ||
76 | m_td = new Thread[botcount]; | ||
77 | for (int i = 0; i < botcount; i++) | ||
78 | { | ||
79 | startupBot(i, cs); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// Add additional bots (and threads) to our bot pool | ||
85 | /// </summary> | ||
86 | /// <param name="botcount">How Many of them to add</param> | ||
87 | public void addbots(int botcount) | ||
88 | { | ||
89 | int len = m_td.Length; | ||
90 | Thread[] m_td2 = new Thread[len + botcount]; | ||
91 | for (int i = 0; i < len; i++) | ||
92 | { | ||
93 | m_td2[i] = m_td[i]; | ||
94 | } | ||
95 | m_td = m_td2; | ||
96 | int newlen = len + botcount; | ||
97 | for (int i = len; i < newlen; i++) | ||
98 | { | ||
99 | startupBot(i, Previous_config); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | /// <summary> | ||
104 | /// This starts up the bot and stores the thread for the bot in the thread array | ||
105 | /// </summary> | ||
106 | /// <param name="pos">The position in the thread array to stick the bot's thread</param> | ||
107 | /// <param name="cs">Configuration of the bot</param> | ||
108 | public void startupBot(int pos, IConfig cs) | ||
109 | { | ||
110 | PhysicsBot pb = new PhysicsBot(cs); | ||
111 | |||
112 | pb.OnConnected += handlebotEvent; | ||
113 | pb.OnDisconnected += handlebotEvent; | ||
114 | if (cs.GetString("firstname", "random") == "random") pb.firstname = CreateRandomName(); | ||
115 | if (cs.GetString("lastname", "random") == "random") pb.lastname = CreateRandomName(); | ||
116 | |||
117 | m_td[pos] = new Thread(pb.startup); | ||
118 | m_td[pos].Name = "CampBot_" + pos; | ||
119 | m_td[pos].IsBackground = true; | ||
120 | m_td[pos].Start(); | ||
121 | m_lBot.Add(pb); | ||
122 | OpenSim.Framework.ThreadTracker.Add(m_td[pos]); | ||
123 | } | ||
124 | |||
125 | /// <summary> | ||
126 | /// Creates a random name for the bot | ||
127 | /// </summary> | ||
128 | /// <returns></returns> | ||
129 | private string CreateRandomName() | ||
130 | { | ||
131 | string returnstring = ""; | ||
132 | string chars = "abcdefghijklmnopqrstuvwxyz0123456789"; | ||
133 | |||
134 | for (int i = 0; i < 7; i++) | ||
135 | { | ||
136 | returnstring += chars.Substring(somthing.Next(chars.Length),1); | ||
137 | } | ||
138 | return returnstring; | ||
139 | } | ||
140 | |||
141 | /// <summary> | ||
142 | /// High level connnected/disconnected events so we can keep track of our threads by proxy | ||
143 | /// </summary> | ||
144 | /// <param name="callbot"></param> | ||
145 | /// <param name="eventt"></param> | ||
146 | public void handlebotEvent(PhysicsBot callbot, EventType eventt) | ||
147 | { | ||
148 | switch (eventt) | ||
149 | { | ||
150 | case EventType.CONNECTED: | ||
151 | m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Connected"); | ||
152 | numbots++; | ||
153 | break; | ||
154 | case EventType.DISCONNECTED: | ||
155 | m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Disconnected"); | ||
156 | m_td[m_lBot.IndexOf(callbot)].Abort(); | ||
157 | numbots--; | ||
158 | if (numbots >1) | ||
159 | Environment.Exit(0); | ||
160 | break; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | /// <summary> | ||
165 | /// Shutting down all bots | ||
166 | /// </summary> | ||
167 | public void doBotShutdown() | ||
168 | { | ||
169 | foreach (PhysicsBot pb in m_lBot) | ||
170 | { | ||
171 | pb.shutdown(); | ||
172 | } | ||
173 | } | ||
174 | |||
175 | /// <summary> | ||
176 | /// Standard CreateConsole routine | ||
177 | /// </summary> | ||
178 | /// <returns></returns> | ||
179 | protected ConsoleBase CreateConsole() | ||
180 | { | ||
181 | return new ConsoleBase("Region", this); | ||
182 | } | ||
183 | |||
184 | /// <summary> | ||
185 | /// I don't think the bots use this.. | ||
186 | /// </summary> | ||
187 | /// <param name="commandParams"></param> | ||
188 | /// <param name="pos"></param> | ||
189 | /// <returns></returns> | ||
190 | private string CombineParams(string[] commandParams, int pos) | ||
191 | { | ||
192 | string result = String.Empty; | ||
193 | for (int i = pos; i < commandParams.Length; i++) | ||
194 | { | ||
195 | result += commandParams[i] + " "; | ||
196 | } | ||
197 | result = result.TrimEnd(' '); | ||
198 | return result; | ||
199 | } | ||
200 | |||
201 | /// <summary> | ||
202 | /// Command runnint tool.. Currently use it to add bots, shutdown and (dangerous)Forcequit | ||
203 | /// </summary> | ||
204 | /// <param name="command"></param> | ||
205 | /// <param name="cmdparams"></param> | ||
206 | public void RunCmd(string command, string[] cmdparams) | ||
207 | { | ||
208 | switch (command) | ||
209 | { | ||
210 | case "shutdown": | ||
211 | m_console.Warn("BOTMANAGER", "Shutting down bots"); | ||
212 | doBotShutdown(); | ||
213 | break; | ||
214 | case "quit": | ||
215 | m_console.Warn("DANGER", "This should only be used to quit the program if you've already used the shutdown command and the program hasn't quit"); | ||
216 | Environment.Exit(0); | ||
217 | break; | ||
218 | case "addbots": | ||
219 | int newbots = 0; | ||
220 | Helpers.TryParse(cmdparams[0], out newbots); | ||
221 | |||
222 | if (newbots > 0) | ||
223 | addbots(newbots); | ||
224 | break; | ||
225 | case "help": | ||
226 | m_console.Notice("HELP", "\nshutdown - graceful shutdown\naddbots <n> - adds n bots to the test\nquit - forcequits, dangerous if you have not already run shutdown"); | ||
227 | break; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | /// <summary> | ||
232 | /// Required method to implement the conscmd_callback interface | ||
233 | /// </summary> | ||
234 | /// <param name="ShowWhat"></param> | ||
235 | public void Show(string ShowWhat) | ||
236 | { | ||
237 | } | ||
238 | } | ||
239 | } | ||
diff --git a/OpenSim/TestSuite/PhysicsBot.cs b/OpenSim/TestSuite/PhysicsBot.cs new file mode 100644 index 0000000..3e12bb1 --- /dev/null +++ b/OpenSim/TestSuite/PhysicsBot.cs | |||
@@ -0,0 +1,203 @@ | |||
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 OpenSim 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 | */ | ||
28 | |||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Text; | ||
33 | using libsecondlife; | ||
34 | using libsecondlife.Packets; | ||
35 | using Nini.Config; | ||
36 | using System.Threading; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Console; | ||
39 | using Timer = System.Timers.Timer; | ||
40 | |||
41 | namespace pCampBot | ||
42 | { | ||
43 | public class PhysicsBot | ||
44 | { | ||
45 | public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events | ||
46 | public IConfig startupConfig; // bot config, passed from BotManager | ||
47 | |||
48 | public string firstname; | ||
49 | public string lastname; | ||
50 | public string password; | ||
51 | public string loginURI; | ||
52 | |||
53 | public event AnEvent OnConnected; | ||
54 | public event AnEvent OnDisconnected; | ||
55 | |||
56 | protected Timer m_action; // Action Timer | ||
57 | |||
58 | protected Random somthing = new Random(System.Environment.TickCount);// We do stuff randomly here | ||
59 | |||
60 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
61 | |||
62 | //New instance of a SecondLife client | ||
63 | public SecondLife client = new SecondLife(); | ||
64 | |||
65 | protected string[] talkarray; | ||
66 | /// <summary> | ||
67 | /// | ||
68 | /// </summary> | ||
69 | /// <param name="bsconfig">nini config for the bot</param> | ||
70 | public PhysicsBot(IConfig bsconfig) | ||
71 | { | ||
72 | startupConfig = bsconfig; | ||
73 | readconfig(); | ||
74 | talkarray = readexcuses(); | ||
75 | } | ||
76 | |||
77 | //We do our actions here. This is where one would | ||
78 | //add additional steps and/or things the bot should do | ||
79 | |||
80 | void m_action_Elapsed(object sender, System.Timers.ElapsedEventArgs e) | ||
81 | { | ||
82 | //client.Throttle.Task = 500000f; | ||
83 | //client.Throttle.Set(); | ||
84 | int walkorrun = somthing.Next(4); // Randomize between walking and running. The greater this number, | ||
85 | // the greater the bot's chances to walk instead of run. | ||
86 | if (walkorrun == 0) | ||
87 | { | ||
88 | client.Self.Movement.AlwaysRun = true; | ||
89 | } | ||
90 | else | ||
91 | { | ||
92 | client.Self.Movement.AlwaysRun = false; | ||
93 | } | ||
94 | |||
95 | LLVector3 pos = client.Self.SimPosition; | ||
96 | LLVector3 newpos = new LLVector3(somthing.Next(255), somthing.Next(255), somthing.Next(255)); | ||
97 | client.Self.Movement.TurnToward(newpos); | ||
98 | |||
99 | for (int i = 0; i < 2000; i++) | ||
100 | { | ||
101 | client.Self.Movement.AtPos = true; | ||
102 | Thread.Sleep(somthing.Next(25, 75)); // Makes sure the bots keep walking for this time. | ||
103 | } | ||
104 | client.Self.Jump(); | ||
105 | |||
106 | string randomf = talkarray[somthing.Next(talkarray.Length)]; | ||
107 | if (talkarray.Length > 1 && randomf.Length > 1) | ||
108 | client.Self.Chat(randomf, 0, ChatType.Normal); | ||
109 | |||
110 | //Thread.Sleep(somthing.Next(1, 10)); // Apparently its better without it right now. | ||
111 | |||
112 | } | ||
113 | |||
114 | /// <summary> | ||
115 | /// Read the Nini config and initialize | ||
116 | /// </summary> | ||
117 | public void readconfig() | ||
118 | { | ||
119 | firstname = startupConfig.GetString("firstname", "random"); | ||
120 | lastname = startupConfig.GetString("lastname", "random"); | ||
121 | password = startupConfig.GetString("password", "12345"); | ||
122 | loginURI = startupConfig.GetString("loginuri"); | ||
123 | |||
124 | |||
125 | |||
126 | } | ||
127 | |||
128 | /// <summary> | ||
129 | /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes. | ||
130 | /// </summary> | ||
131 | public void shutdown() | ||
132 | { | ||
133 | client.Network.Logout(); | ||
134 | } | ||
135 | |||
136 | /// <summary> | ||
137 | /// This is the bot startup loop. | ||
138 | /// </summary> | ||
139 | public void startup() | ||
140 | { | ||
141 | client.Settings.LOGIN_SERVER = loginURI; | ||
142 | client.Network.OnConnected += new NetworkManager.ConnectedCallback(this.Network_OnConnected); | ||
143 | client.Network.OnSimConnected += new NetworkManager.SimConnectedCallback(this.Network_OnConnected); | ||
144 | client.Network.OnDisconnected += new NetworkManager.DisconnectedCallback(this.Network_OnDisconnected); | ||
145 | if (client.Network.Login(firstname, lastname, password, "pCampBot", "Your name")) | ||
146 | { | ||
147 | |||
148 | if (OnConnected != null) | ||
149 | { | ||
150 | m_action = new Timer(somthing.Next(1000, 10000)); | ||
151 | m_action.Elapsed += new System.Timers.ElapsedEventHandler(m_action_Elapsed); | ||
152 | m_action.Start(); | ||
153 | OnConnected(this, EventType.CONNECTED); | ||
154 | client.Self.Jump(); | ||
155 | |||
156 | } | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | MainConsole.Instance.Error(firstname + " " + lastname, "Can't login: " + client.Network.LoginMessage); | ||
161 | if (OnDisconnected != null) | ||
162 | { | ||
163 | OnDisconnected(this, EventType.DISCONNECTED); | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | |||
168 | public void Network_OnConnected(object sender) | ||
169 | { | ||
170 | if (OnConnected != null) | ||
171 | { | ||
172 | OnConnected(this, EventType.CONNECTED); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | public void Simulator_Connected(object sender) | ||
177 | { | ||
178 | } | ||
179 | |||
180 | public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message) | ||
181 | { | ||
182 | if (OnDisconnected != null) | ||
183 | { | ||
184 | OnDisconnected(this, EventType.DISCONNECTED); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | public string[] readexcuses() | ||
189 | { | ||
190 | string allexcuses = ""; | ||
191 | |||
192 | string file = Path.Combine(Util.configDir(), "pCampBotSentences.txt"); | ||
193 | if (File.Exists(file)) | ||
194 | { | ||
195 | StreamReader csr = File.OpenText(file); | ||
196 | allexcuses = csr.ReadToEnd(); | ||
197 | csr.Close(); | ||
198 | } | ||
199 | |||
200 | return allexcuses.Split(Environment.NewLine.ToCharArray()); | ||
201 | } | ||
202 | } | ||
203 | } | ||
diff --git a/OpenSim/TestSuite/pCampBot.cs b/OpenSim/TestSuite/pCampBot.cs new file mode 100644 index 0000000..d42d4bd --- /dev/null +++ b/OpenSim/TestSuite/pCampBot.cs | |||
@@ -0,0 +1,114 @@ | |||
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 OpenSim 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 | */ | ||
28 | |||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using libsecondlife; | ||
33 | using libsecondlife.Packets; | ||
34 | using Nini.Config; | ||
35 | using log4net; | ||
36 | using log4net.Config; | ||
37 | using System.Threading; | ||
38 | using OpenSim.Framework.Console; | ||
39 | |||
40 | namespace pCampBot | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// Event Types from the BOT. Add new events here | ||
44 | /// </summary> | ||
45 | public enum EventType:int | ||
46 | { | ||
47 | NONE = 0, | ||
48 | CONNECTED = 1, | ||
49 | DISCONNECTED = 2 | ||
50 | } | ||
51 | |||
52 | public class pCampBot | ||
53 | { | ||
54 | |||
55 | private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
56 | |||
57 | [STAThread] | ||
58 | public static void Main(string[] args) | ||
59 | { | ||
60 | // log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
61 | // log4net call | ||
62 | // BasicConfigurator.Configure(); | ||
63 | |||
64 | IConfig config = ParseConfig(args); | ||
65 | if (config.Get("help") != null || config.Get("loginuri") == null) { | ||
66 | Help(); | ||
67 | } else { | ||
68 | int botcount = config.GetInt("botcount", 1); | ||
69 | |||
70 | BotManager bm = new BotManager(); | ||
71 | |||
72 | System.Console.WriteLine("Error enabled: {0}", m_log.IsErrorEnabled); | ||
73 | //startup specified number of bots. 1 is the default | ||
74 | m_log.Error("pCampBot started with " + botcount + "bots"); | ||
75 | |||
76 | // bm.dobotStartup(botcount, config); | ||
77 | // while (true) | ||
78 | // { | ||
79 | // MainConsole.Instance.Prompt(); | ||
80 | // } | ||
81 | } | ||
82 | } | ||
83 | |||
84 | private static IConfig ParseConfig(String[] args) | ||
85 | { | ||
86 | //Set up our nifty config.. thanks to nini | ||
87 | ArgvConfigSource cs = new ArgvConfigSource(args); | ||
88 | |||
89 | cs.AddSwitch("Startup", "botcount","n"); | ||
90 | cs.AddSwitch("Startup", "loginuri","l"); | ||
91 | cs.AddSwitch("Startup", "firstname"); | ||
92 | cs.AddSwitch("Startup", "lastname"); | ||
93 | cs.AddSwitch("Startup", "password"); | ||
94 | cs.AddSwitch("Startup", "help","h"); | ||
95 | |||
96 | IConfig ol = cs.Configs["Startup"]; | ||
97 | return ol; | ||
98 | } | ||
99 | |||
100 | private static void Help() | ||
101 | { | ||
102 | System.Console.WriteLine( | ||
103 | "usage: pCampBot <-loginuri loginuri> [OPTIONS]\n" + | ||
104 | "Spawns a set of bots to test an OpenSim region\n\n" + | ||
105 | " -l, -loginuri loginuri for sim to log into (required)\n" + | ||
106 | " -n, -botcount number of bots to start (default: 1)\n" + | ||
107 | " -firstname first name for the bot(s) (default: random string)\n" + | ||
108 | " -lastname lastname for the bot(s) (default: random string)\n" + | ||
109 | " -password password for the bots(s) (default: random string)\n" + | ||
110 | " -h, -help show this message" | ||
111 | ); | ||
112 | } | ||
113 | } | ||
114 | } | ||