aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorDan Lake2011-10-31 16:42:50 -0700
committerDan Lake2011-10-31 16:42:50 -0700
commit9d214d4903755e0c681c4458166b44c78b1ca677 (patch)
treeeaa54bd49923d432fc4e039c6c02d602b16d829d /OpenSim
parentRemoved unused show commands from Scene.cs and SceneBase.cs. The show modules... (diff)
parentMake bots share a cache so that asset downloads attempts are only made once i... (diff)
downloadopensim-SC_OLD-9d214d4903755e0c681c4458166b44c78b1ca677.zip
opensim-SC_OLD-9d214d4903755e0c681c4458166b44c78b1ca677.tar.gz
opensim-SC_OLD-9d214d4903755e0c681c4458166b44c78b1ca677.tar.bz2
opensim-SC_OLD-9d214d4903755e0c681c4458166b44c78b1ca677.tar.xz
Merge branch 'master' of git://opensimulator.org/git/opensim
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/TestSuite/BotManager.cs170
-rw-r--r--OpenSim/TestSuite/Main.cs98
-rw-r--r--OpenSim/TestSuite/PhysicsBot.cs196
-rw-r--r--OpenSim/TestSuite/README.txt25
-rw-r--r--OpenSim/TestSuite/Util.cs81
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs19
-rw-r--r--OpenSim/Tools/pCampBot/PhysicsBot.cs64
7 files changed, 58 insertions, 595 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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Threading;
32using OpenMetaverse;
33using log4net;
34using Nini.Config;
35using OpenSim.Framework;
36using OpenSim.Framework.Console;
37
38namespace 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}
diff --git a/OpenSim/TestSuite/Main.cs b/OpenSim/TestSuite/Main.cs
deleted file mode 100644
index ee75bf5..0000000
--- a/OpenSim/TestSuite/Main.cs
+++ /dev/null
@@ -1,98 +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
28using System;
29using Nini.Config;
30
31namespace OpenSim.TestSuite
32{
33 /// <summary>
34 /// Event Types from the BOT. Add new events here
35 /// </summary>
36 public enum EventType : int
37 {
38 NONE = 0,
39 CONNECTED = 1,
40 DISCONNECTED = 2
41 }
42
43 public class TestSuite
44 {
45 public static void Main(string[] args)
46 {
47 // TODO: config parser
48
49 // TODO: load tests from addings
50
51 // TODO: create base bot cloud for use in tests
52
53 IConfig config = ParseConfig(args);
54 if (config.Get("help") != null || config.Get("loginuri") == null)
55 {
56 Help();
57 }
58 else
59 {
60 // TODO: unused: int botcount = config.GetInt("botcount", 1);
61
62 // BotManager bm = new BotManager();
63
64 Utils.TestPass("Completed Startup");
65 }
66 }
67
68 private static IConfig ParseConfig(String[] args)
69 {
70 //Set up our nifty config.. thanks to nini
71 ArgvConfigSource cs = new ArgvConfigSource(args);
72
73 // TODO: unused: cs.AddSwitch("Startup", "botcount","n");
74 cs.AddSwitch("Startup", "loginuri","l");
75 cs.AddSwitch("Startup", "firstname");
76 cs.AddSwitch("Startup", "lastname");
77 cs.AddSwitch("Startup", "password");
78 cs.AddSwitch("Startup", "help","h");
79
80 IConfig ol = cs.Configs["Startup"];
81 return ol;
82 }
83
84 private static void Help()
85 {
86 Console.WriteLine(
87 "usage: pCampBot <-loginuri loginuri> [OPTIONS]\n" +
88 "Spawns a set of bots to test an OpenSim region\n\n" +
89 " -l, -loginuri loginuri for sim to log into (required)\n" +
90 // TODO: unused: " -n, -botcount number of bots to start (default: 1)\n" +
91 " -firstname first name for the bot(s) (default: random string)\n" +
92 " -lastname lastname for the bot(s) (default: random string)\n" +
93 " -password password for the bots(s) (default: random string)\n" +
94 " -h, -help show this message"
95 );
96 }
97 }
98}
diff --git a/OpenSim/TestSuite/PhysicsBot.cs b/OpenSim/TestSuite/PhysicsBot.cs
deleted file mode 100644
index fac4275..0000000
--- a/OpenSim/TestSuite/PhysicsBot.cs
+++ /dev/null
@@ -1,196 +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
28using System;
29using System.IO;
30using System.Threading;
31using System.Timers;
32using OpenMetaverse;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Console;
36using Timer=System.Timers.Timer;
37
38namespace OpenSim.TestSuite
39{
40 public class PhysicsBot
41 {
42 public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events
43 public IConfig startupConfig; // bot config, passed from BotManager
44
45 public string firstname;
46 public string lastname;
47 public string password;
48 public string loginURI;
49
50 public event AnEvent OnConnected;
51 public event AnEvent OnDisconnected;
52
53 protected Timer m_action; // Action Timer
54
55 protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here
56
57 //New instance of a SecondLife client
58 public GridClient client = new GridClient();
59
60 protected string[] talkarray;
61 /// <summary>
62 ///
63 /// </summary>
64 /// <param name="bsconfig">nini config for the bot</param>
65 public PhysicsBot(IConfig bsconfig)
66 {
67 startupConfig = bsconfig;
68 readconfig();
69 talkarray = readexcuses();
70 }
71
72 //We do our actions here. This is where one would
73 //add additional steps and/or things the bot should do
74
75 void m_action_Elapsed(object sender, ElapsedEventArgs e)
76 {
77 //client.Throttle.Task = 500000f;
78 //client.Throttle.Set();
79 int walkorrun = somthing.Next(4); // Randomize between walking and running. The greater this number,
80 // the greater the bot's chances to walk instead of run.
81 if (walkorrun == 0)
82 {
83 client.Self.Movement.AlwaysRun = true;
84 }
85 else
86 {
87 client.Self.Movement.AlwaysRun = false;
88 }
89
90 // TODO: unused: Vector3 pos = client.Self.SimPosition;
91 Vector3 newpos = new Vector3(somthing.Next(255), somthing.Next(255), somthing.Next(255));
92 client.Self.Movement.TurnToward(newpos);
93
94 for (int i = 0; i < 2000; i++)
95 {
96 client.Self.Movement.AtPos = true;
97 Thread.Sleep(somthing.Next(25, 75)); // Makes sure the bots keep walking for this time.
98 }
99 client.Self.Jump(true);
100
101 string randomf = talkarray[somthing.Next(talkarray.Length)];
102 if (talkarray.Length > 1 && randomf.Length > 1)
103 client.Self.Chat(randomf, 0, ChatType.Normal);
104
105 //Thread.Sleep(somthing.Next(1, 10)); // Apparently its better without it right now.
106 }
107
108 /// <summary>
109 /// Read the Nini config and initialize
110 /// </summary>
111 public void readconfig()
112 {
113 firstname = startupConfig.GetString("firstname", "random");
114 lastname = startupConfig.GetString("lastname", "random");
115 password = startupConfig.GetString("password", "12345");
116 loginURI = startupConfig.GetString("loginuri");
117 }
118
119 /// <summary>
120 /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes.
121 /// </summary>
122 public void shutdown()
123 {
124 client.Network.Logout();
125 }
126
127 /// <summary>
128 /// This is the bot startup loop.
129 /// </summary>
130 public void startup()
131 {
132 client.Settings.LOGIN_SERVER = loginURI;
133 client.Network.LoginProgress += this.Network_LoginProgress;
134 client.Network.SimConnected += this.Network_SimConnected;
135 client.Network.Disconnected += this.Network_OnDisconnected;
136 if (client.Network.Login(firstname, lastname, password, "pCampBot", "Your name"))
137 {
138
139 if (OnConnected != null)
140 {
141 m_action = new Timer(somthing.Next(1000, 10000));
142 m_action.Elapsed += new ElapsedEventHandler(m_action_Elapsed);
143 m_action.Start();
144 OnConnected(this, EventType.CONNECTED);
145 client.Self.Jump(true);
146 }
147 }
148 else
149 {
150 MainConsole.Instance.Output(firstname + " " + lastname + "Can't login: " + client.Network.LoginMessage);
151 if (OnDisconnected != null)
152 {
153 OnDisconnected(this, EventType.DISCONNECTED);
154 }
155 }
156 }
157
158 public void Network_LoginProgress(object sender, LoginProgressEventArgs args)
159 {
160 if (args.Status == LoginStatus.Success)
161 {
162 if (OnConnected != null)
163 {
164 OnConnected(this, EventType.CONNECTED);
165 }
166 }
167 }
168
169 public void Network_SimConnected(object sender, SimConnectedEventArgs args)
170 {
171 }
172
173 public void Network_OnDisconnected(object sender, DisconnectedEventArgs args)
174 {
175 if (OnDisconnected != null)
176 {
177 OnDisconnected(this, EventType.DISCONNECTED);
178 }
179 }
180
181 public string[] readexcuses()
182 {
183 string allexcuses = "";
184
185 string file = Path.Combine(Util.configDir(), "pCampBotSentences.txt");
186 if (File.Exists(file))
187 {
188 StreamReader csr = File.OpenText(file);
189 allexcuses = csr.ReadToEnd();
190 csr.Close();
191 }
192
193 return allexcuses.Split(Environment.NewLine.ToCharArray());
194 }
195 }
196}
diff --git a/OpenSim/TestSuite/README.txt b/OpenSim/TestSuite/README.txt
deleted file mode 100644
index cdfa4a7..0000000
--- a/OpenSim/TestSuite/README.txt
+++ /dev/null
@@ -1,25 +0,0 @@
1OpenSim Test Suite
2------------------------------------------------------------
3
4The eventual goal of the OpenSim Test Suite is to provide a framework
5and a set of tests to do system level regression testing of OpenSim.
6In short:
7
8OpenSim Test Suite will have Test Modules (Mono Addins?) that will
9verify certain paths in the code. Some early modules may be (subject
10to change):
11
12 * Login Tests
13 - Attempt to Log in 1, 5, 20 bots.
14 * Basic Walk Tests
15 - Attempt to Log in and move about in well known tracks
16 - Repeat with 5, 20 bots
17 * Basic Construct Tests
18 - Construct Simple Objects in World
19 - Ensure bots can see other objects constructed
20 * Basic Asset Tests
21 - Construct Simple Objects in World with Textures
22 - Pull Objects and Textures
23
24
25 \ No newline at end of file
diff --git a/OpenSim/TestSuite/Util.cs b/OpenSim/TestSuite/Util.cs
deleted file mode 100644
index e050c07..0000000
--- a/OpenSim/TestSuite/Util.cs
+++ /dev/null
@@ -1,81 +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
28using System;
29
30namespace OpenSim.TestSuite
31{
32 public class Utils
33 {
34 enum Result
35 {
36 Fail = 0,
37 Pass = 1,
38 Skip = 3
39 }
40
41 private static String ResultToString(Result r)
42 {
43 if (r == Result.Pass)
44 {
45 return "PASS";
46 }
47 else if (r == Result.Fail)
48 {
49 return "FAIL";
50 }
51 else if (r == Result.Skip)
52 {
53 return "SKIP";
54 }
55 else
56 {
57 return "UNKNOWN";
58 }
59 }
60
61 private static void TestResult(Result r, String msg)
62 {
63 Console.WriteLine("[{0}]: {1}", ResultToString(r), msg);
64 }
65
66 public static void TestFail(String msg)
67 {
68 TestResult(Result.Fail, msg);
69 }
70
71 public static void TestPass(String msg)
72 {
73 TestResult(Result.Pass, msg);
74 }
75
76 public static void TestSkip(String msg)
77 {
78 TestResult(Result.Skip, msg);
79 }
80 }
81}
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 0aaa226..03bb820 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -53,13 +53,20 @@ namespace pCampBot
53 protected bool m_verbose = true; 53 protected bool m_verbose = true;
54 protected Random somthing = new Random(Environment.TickCount); 54 protected Random somthing = new Random(Environment.TickCount);
55 protected int numbots = 0; 55 protected int numbots = 0;
56 private IConfig Config; 56 public IConfig Config { get; private set; }
57
58 /// <summary>
59 /// Track the assets we have and have not received so we don't endlessly repeat requests.
60 /// </summary>
61 public Dictionary<UUID, bool> AssetsReceived { get; private set; }
57 62
58 /// <summary> 63 /// <summary>
59 /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data 64 /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
60 /// </summary> 65 /// </summary>
61 public BotManager() 66 public BotManager()
62 { 67 {
68 AssetsReceived = new Dictionary<UUID, bool>();
69
63 m_console = CreateConsole(); 70 m_console = CreateConsole();
64 MainConsole.Instance = m_console; 71 MainConsole.Instance = m_console;
65 72
@@ -113,7 +120,7 @@ namespace pCampBot
113 for (int i = 0; i < botcount; i++) 120 for (int i = 0; i < botcount; i++)
114 { 121 {
115 string lastName = string.Format("{0}_{1}", lastNameStem, i); 122 string lastName = string.Format("{0}_{1}", lastNameStem, i);
116 startupBot(i, cs, firstName, lastName, password, loginUri); 123 startupBot(i, this, firstName, lastName, password, loginUri);
117 } 124 }
118 } 125 }
119 126
@@ -146,9 +153,9 @@ namespace pCampBot
146 /// <param name="lastName">Last name</param> 153 /// <param name="lastName">Last name</param>
147 /// <param name="password">Password</param> 154 /// <param name="password">Password</param>
148 /// <param name="loginUri">Login URI</param> 155 /// <param name="loginUri">Login URI</param>
149 public void startupBot(int pos, IConfig cs, string firstName, string lastName, string password, string loginUri) 156 public void startupBot(int pos, BotManager bm, string firstName, string lastName, string password, string loginUri)
150 { 157 {
151 PhysicsBot pb = new PhysicsBot(cs, firstName, lastName, password, loginUri); 158 PhysicsBot pb = new PhysicsBot(bm, firstName, lastName, password, loginUri);
152 159
153 pb.OnConnected += handlebotEvent; 160 pb.OnConnected += handlebotEvent;
154 pb.OnDisconnected += handlebotEvent; 161 pb.OnDisconnected += handlebotEvent;
@@ -165,18 +172,20 @@ namespace pCampBot
165 /// </summary> 172 /// </summary>
166 /// <param name="callbot"></param> 173 /// <param name="callbot"></param>
167 /// <param name="eventt"></param> 174 /// <param name="eventt"></param>
168 public void handlebotEvent(PhysicsBot callbot, EventType eventt) 175 private void handlebotEvent(PhysicsBot callbot, EventType eventt)
169 { 176 {
170 switch (eventt) 177 switch (eventt)
171 { 178 {
172 case EventType.CONNECTED: 179 case EventType.CONNECTED:
173 m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Connected"); 180 m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Connected");
174 numbots++; 181 numbots++;
182// m_log.InfoFormat("NUMBOTS {0}", numbots);
175 break; 183 break;
176 case EventType.DISCONNECTED: 184 case EventType.DISCONNECTED:
177 m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Disconnected"); 185 m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Disconnected");
178 m_td[m_lBot.IndexOf(callbot)].Abort(); 186 m_td[m_lBot.IndexOf(callbot)].Abort();
179 numbots--; 187 numbots--;
188// m_log.InfoFormat("NUMBOTS {0}", numbots);
180 if (numbots <= 0) 189 if (numbots <= 0)
181 Environment.Exit(0); 190 Environment.Exit(0);
182 break; 191 break;
diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs
index 1531b27..2070bfd 100644
--- a/OpenSim/Tools/pCampBot/PhysicsBot.cs
+++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs
@@ -29,21 +29,27 @@ using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Text; 30using System.Text;
31using System.IO; 31using System.IO;
32using System.Reflection;
32using System.Threading; 33using System.Threading;
33using System.Timers; 34using System.Timers;
35using log4net;
34using OpenMetaverse; 36using OpenMetaverse;
35using OpenMetaverse.Assets; 37using OpenMetaverse.Assets;
36using Nini.Config; 38using Nini.Config;
37using OpenSim.Framework; 39using OpenSim.Framework;
38using OpenSim.Framework.Console; 40using OpenSim.Framework.Console;
39using Timer=System.Timers.Timer; 41using Timer = System.Timers.Timer;
40 42
41namespace pCampBot 43namespace pCampBot
42{ 44{
43 public class PhysicsBot 45 public class PhysicsBot
44 { 46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
45 public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events 49 public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events
46 public IConfig startupConfig; // bot config, passed from BotManager 50
51 public BotManager BotManager { get; private set; }
52 private IConfig startupConfig; // bot config, passed from BotManager
47 53
48 public string FirstName { get; private set; } 54 public string FirstName { get; private set; }
49 public string LastName { get; private set; } 55 public string LastName { get; private set; }
@@ -71,19 +77,21 @@ namespace pCampBot
71 /// <summary> 77 /// <summary>
72 /// Constructor 78 /// Constructor
73 /// </summary> 79 /// </summary>
74 /// <param name="bsconfig"></param> 80 /// <param name="bm"></param>
75 /// <param name="firstName"></param> 81 /// <param name="firstName"></param>
76 /// <param name="lastName"></param> 82 /// <param name="lastName"></param>
77 /// <param name="password"></param> 83 /// <param name="password"></param>
78 /// <param name="loginUri"></param> 84 /// <param name="loginUri"></param>
79 public PhysicsBot(IConfig bsconfig, string firstName, string lastName, string password, string loginUri) 85 public PhysicsBot(BotManager bm, string firstName, string lastName, string password, string loginUri)
80 { 86 {
81 FirstName = firstName; 87 FirstName = firstName;
82 LastName = lastName; 88 LastName = lastName;
83 Name = string.Format("{0} {1}", FirstName, LastName); 89 Name = string.Format("{0} {1}", FirstName, LastName);
84 Password = password; 90 Password = password;
85 LoginUri = loginUri; 91 LoginUri = loginUri;
86 startupConfig = bsconfig; 92
93 BotManager = bm;
94 startupConfig = bm.Config;
87 readconfig(); 95 readconfig();
88 talkarray = readexcuses(); 96 talkarray = readexcuses();
89 } 97 }
@@ -162,9 +170,9 @@ namespace pCampBot
162 client.Throttle.Total = 400000; 170 client.Throttle.Total = 400000;
163 client.Network.LoginProgress += this.Network_LoginProgress; 171 client.Network.LoginProgress += this.Network_LoginProgress;
164 client.Network.SimConnected += this.Network_SimConnected; 172 client.Network.SimConnected += this.Network_SimConnected;
165// client.Network.Disconnected += this.Network_OnDisconnected; 173 client.Network.Disconnected += this.Network_OnDisconnected;
166 client.Objects.ObjectUpdate += Objects_NewPrim; 174 client.Objects.ObjectUpdate += Objects_NewPrim;
167 //client.Assets.OnAssetReceived += Asset_ReceivedCallback; 175
168 if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) 176 if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name"))
169 { 177 {
170 if (OnConnected != null) 178 if (OnConnected != null)
@@ -227,7 +235,7 @@ namespace pCampBot
227 { 235 {
228 if (asset.Decode()) 236 if (asset.Decode())
229 { 237 {
230 File.WriteAllBytes(Path.Combine(saveDir, String.Format("{1}.{0}", 238 File.WriteAllBytes(Path.Combine(saveDir, String.Format("{1}.{0}",
231 asset.AssetType.ToString().ToLower(), 239 asset.AssetType.ToString().ToLower(),
232 asset.WearableType)), asset.AssetData); 240 asset.WearableType)), asset.AssetData);
233 } 241 }
@@ -377,6 +385,7 @@ namespace pCampBot
377 385
378 public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) 386 public void Network_OnDisconnected(object sender, DisconnectedEventArgs args)
379 { 387 {
388// m_log.ErrorFormat("Fired Network_OnDisconnected");
380 if (OnDisconnected != null) 389 if (OnDisconnected != null)
381 { 390 {
382 OnDisconnected(this, EventType.DISCONNECTED); 391 OnDisconnected(this, EventType.DISCONNECTED);
@@ -393,40 +402,55 @@ namespace pCampBot
393 { 402 {
394 if (prim.Textures.DefaultTexture.TextureID != UUID.Zero) 403 if (prim.Textures.DefaultTexture.TextureID != UUID.Zero)
395 { 404 {
396 client.Assets.RequestImage(prim.Textures.DefaultTexture.TextureID, ImageType.Normal, Asset_TextureCallback_Texture); 405 GetTexture(prim.Textures.DefaultTexture.TextureID);
397 } 406 }
398 407
399 for (int i = 0; i < prim.Textures.FaceTextures.Length; i++) 408 for (int i = 0; i < prim.Textures.FaceTextures.Length; i++)
400 { 409 {
401 if (prim.Textures.FaceTextures[i] != null) 410 UUID textureID = prim.Textures.FaceTextures[i].TextureID;
411
412 if (textureID != null && textureID != UUID.Zero)
402 { 413 {
403 if (prim.Textures.FaceTextures[i].TextureID != UUID.Zero) 414 GetTexture(textureID);
404 {
405 client.Assets.RequestImage(prim.Textures.FaceTextures[i].TextureID, ImageType.Normal, Asset_TextureCallback_Texture);
406 }
407 } 415 }
408 } 416 }
409 } 417 }
410 418
411 if (prim.Sculpt.SculptTexture != UUID.Zero) 419 if (prim.Sculpt.SculptTexture != UUID.Zero)
412 { 420 {
413 client.Assets.RequestImage(prim.Sculpt.SculptTexture, ImageType.Normal, Asset_TextureCallback_Texture); 421 GetTexture(prim.Sculpt.SculptTexture);
414 } 422 }
415 } 423 }
416 } 424 }
417 425
426 private void GetTexture(UUID textureID)
427 {
428 lock (BotManager.AssetsReceived)
429 {
430 // Don't request assets more than once.
431 if (BotManager.AssetsReceived.ContainsKey(textureID))
432 return;
433
434 BotManager.AssetsReceived[textureID] = false;
435 client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture);
436 }
437 }
438
418 439
419 public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) 440 public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture)
420 { 441 {
421 //TODO: Implement texture saving and applying 442 //TODO: Implement texture saving and applying
422 } 443 }
423 444
424 public void Asset_ReceivedCallback(AssetDownload transfer,Asset asset) 445 public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset)
425 { 446 {
426 if (wear == "save") 447 lock (BotManager.AssetsReceived)
427 { 448 BotManager.AssetsReceived[asset.AssetID] = true;
428 SaveAsset((AssetWearable) asset); 449
429 } 450// if (wear == "save")
451// {
452// SaveAsset((AssetWearable) asset);
453// }
430 } 454 }
431 455
432 public string[] readexcuses() 456 public string[] readexcuses()