diff options
Diffstat (limited to 'OpenSim/TestSuite/BotManager.cs')
-rw-r--r-- | OpenSim/TestSuite/BotManager.cs | 170 |
1 files changed, 0 insertions, 170 deletions
diff --git a/OpenSim/TestSuite/BotManager.cs b/OpenSim/TestSuite/BotManager.cs deleted file mode 100644 index 55ba687..0000000 --- a/OpenSim/TestSuite/BotManager.cs +++ /dev/null | |||
@@ -1,170 +0,0 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using OpenMetaverse; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Console; | ||
37 | |||
38 | namespace OpenSim.TestSuite | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Thread/Bot manager for the application | ||
42 | /// </summary> | ||
43 | public class BotManager | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | protected CommandConsole m_console; | ||
48 | protected List<PhysicsBot> m_lBot; | ||
49 | protected Thread[] m_td; | ||
50 | protected bool m_verbose = true; | ||
51 | protected Random somthing = new Random(Environment.TickCount); | ||
52 | protected int numbots = 0; | ||
53 | protected IConfig Previous_config; | ||
54 | |||
55 | /// <summary> | ||
56 | /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data | ||
57 | /// </summary> | ||
58 | public BotManager() | ||
59 | { | ||
60 | m_log.Info("In bot manager"); | ||
61 | m_lBot = new List<PhysicsBot>(); | ||
62 | } | ||
63 | |||
64 | /// <summary> | ||
65 | /// Startup number of bots specified in the starting arguments | ||
66 | /// </summary> | ||
67 | /// <param name="botcount">How many bots to start up</param> | ||
68 | /// <param name="cs">The configuration for the bots to use</param> | ||
69 | public void dobotStartup(int botcount, IConfig cs) | ||
70 | { | ||
71 | Previous_config = cs; | ||
72 | m_td = new Thread[botcount]; | ||
73 | for (int i = 0; i < botcount; i++) | ||
74 | { | ||
75 | startupBot(i, cs); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | /// <summary> | ||
80 | /// Add additional bots (and threads) to our bot pool | ||
81 | /// </summary> | ||
82 | /// <param name="botcount">How Many of them to add</param> | ||
83 | public void addbots(int botcount) | ||
84 | { | ||
85 | int len = m_td.Length; | ||
86 | Thread[] m_td2 = new Thread[len + botcount]; | ||
87 | for (int i = 0; i < len; i++) | ||
88 | { | ||
89 | m_td2[i] = m_td[i]; | ||
90 | } | ||
91 | m_td = m_td2; | ||
92 | int newlen = len + botcount; | ||
93 | for (int i = len; i < newlen; i++) | ||
94 | { | ||
95 | startupBot(i, Previous_config); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | /// <summary> | ||
100 | /// This starts up the bot and stores the thread for the bot in the thread array | ||
101 | /// </summary> | ||
102 | /// <param name="pos">The position in the thread array to stick the bot's thread</param> | ||
103 | /// <param name="cs">Configuration of the bot</param> | ||
104 | public void startupBot(int pos, IConfig cs) | ||
105 | { | ||
106 | PhysicsBot pb = new PhysicsBot(cs); | ||
107 | |||
108 | pb.OnConnected += handlebotEvent; | ||
109 | pb.OnDisconnected += handlebotEvent; | ||
110 | if (cs.GetString("firstname", "random") == "random") pb.firstname = CreateRandomName(); | ||
111 | if (cs.GetString("lastname", "random") == "random") pb.lastname = CreateRandomName(); | ||
112 | |||
113 | m_td[pos] = new Thread(pb.startup); | ||
114 | m_td[pos].Name = "CampBot_" + pos; | ||
115 | m_td[pos].IsBackground = true; | ||
116 | m_td[pos].Start(); | ||
117 | m_lBot.Add(pb); | ||
118 | } | ||
119 | |||
120 | /// <summary> | ||
121 | /// Creates a random name for the bot | ||
122 | /// </summary> | ||
123 | /// <returns></returns> | ||
124 | private string CreateRandomName() | ||
125 | { | ||
126 | string returnstring = ""; | ||
127 | string chars = "abcdefghijklmnopqrstuvwxyz0123456789"; | ||
128 | |||
129 | for (int i = 0; i < 7; i++) | ||
130 | { | ||
131 | returnstring += chars.Substring(somthing.Next(chars.Length),1); | ||
132 | } | ||
133 | return returnstring; | ||
134 | } | ||
135 | |||
136 | /// <summary> | ||
137 | /// High level connnected/disconnected events so we can keep track of our threads by proxy | ||
138 | /// </summary> | ||
139 | /// <param name="callbot"></param> | ||
140 | /// <param name="eventt"></param> | ||
141 | public void handlebotEvent(PhysicsBot callbot, EventType eventt) | ||
142 | { | ||
143 | switch (eventt) | ||
144 | { | ||
145 | case EventType.CONNECTED: | ||
146 | m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Connected"); | ||
147 | numbots++; | ||
148 | break; | ||
149 | case EventType.DISCONNECTED: | ||
150 | m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Disconnected"); | ||
151 | m_td[m_lBot.IndexOf(callbot)].Abort(); | ||
152 | numbots--; | ||
153 | if (numbots > 1) | ||
154 | Environment.Exit(0); | ||
155 | break; | ||
156 | } | ||
157 | } | ||
158 | |||
159 | /// <summary> | ||
160 | /// Shutting down all bots | ||
161 | /// </summary> | ||
162 | public void doBotShutdown() | ||
163 | { | ||
164 | foreach (PhysicsBot pb in m_lBot) | ||
165 | { | ||
166 | pb.shutdown(); | ||
167 | } | ||
168 | } | ||
169 | } | ||
170 | } | ||