diff options
Diffstat (limited to 'OpenSim/Tools/pCampBot')
-rw-r--r-- | OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs | 56 | ||||
-rw-r--r-- | OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs | 95 | ||||
-rw-r--r-- | OpenSim/Tools/pCampBot/Bot.cs (renamed from OpenSim/Tools/pCampBot/PhysicsBot.cs) | 189 | ||||
-rw-r--r-- | OpenSim/Tools/pCampBot/BotManager.cs | 36 | ||||
-rw-r--r-- | OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs | 36 | ||||
-rw-r--r-- | OpenSim/Tools/pCampBot/pCampBot.cs | 22 |
6 files changed, 327 insertions, 107 deletions
diff --git a/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs new file mode 100644 index 0000000..7084ab4 --- /dev/null +++ b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs | |||
@@ -0,0 +1,56 @@ | |||
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 OpenMetaverse; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Linq; | ||
32 | using pCampBot.Interfaces; | ||
33 | |||
34 | namespace pCampBot | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// Click (grab) on random objects in the scene. | ||
38 | /// </summary> | ||
39 | /// <remarks> | ||
40 | /// The viewer itself does not give the option of grabbing objects that haven't been signalled as grabbable. | ||
41 | /// </remarks> | ||
42 | public class GrabbingBehaviour : IBehaviour | ||
43 | { | ||
44 | public void Action(Bot bot) | ||
45 | { | ||
46 | Dictionary<UUID, Primitive> objects = bot.Objects; | ||
47 | |||
48 | Primitive prim = objects.ElementAt(bot.Random.Next(0, objects.Count)).Value; | ||
49 | |||
50 | // This appears to be a typical message sent when a viewer user clicks a clickable object | ||
51 | bot.Client.Self.Grab(prim.LocalID); | ||
52 | bot.Client.Self.GrabUpdate(prim.ID, Vector3.Zero); | ||
53 | bot.Client.Self.DeGrab(prim.LocalID); | ||
54 | } | ||
55 | } | ||
56 | } \ No newline at end of file | ||
diff --git a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs new file mode 100644 index 0000000..3ce08bf --- /dev/null +++ b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs | |||
@@ -0,0 +1,95 @@ | |||
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.IO; | ||
30 | using System.Threading; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using pCampBot.Interfaces; | ||
34 | |||
35 | namespace pCampBot | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Stress physics by moving and bouncing around bots a whole lot. | ||
39 | /// </summary> | ||
40 | /// <remarks> | ||
41 | /// TODO: talkarray should be in a separate behaviour. | ||
42 | /// </remarks> | ||
43 | public class PhysicsBehaviour : IBehaviour | ||
44 | { | ||
45 | private string[] talkarray; | ||
46 | |||
47 | public PhysicsBehaviour() | ||
48 | { | ||
49 | talkarray = readexcuses(); | ||
50 | } | ||
51 | |||
52 | public void Action(Bot bot) | ||
53 | { | ||
54 | int walkorrun = bot.Random.Next(4); // Randomize between walking and running. The greater this number, | ||
55 | // the greater the bot's chances to walk instead of run. | ||
56 | bot.Client.Self.Jump(false); | ||
57 | if (walkorrun == 0) | ||
58 | { | ||
59 | bot.Client.Self.Movement.AlwaysRun = true; | ||
60 | } | ||
61 | else | ||
62 | { | ||
63 | bot.Client.Self.Movement.AlwaysRun = false; | ||
64 | } | ||
65 | |||
66 | // TODO: unused: Vector3 pos = client.Self.SimPosition; | ||
67 | Vector3 newpos = new Vector3(bot.Random.Next(1, 254), bot.Random.Next(1, 254), bot.Random.Next(1, 254)); | ||
68 | bot.Client.Self.Movement.TurnToward(newpos); | ||
69 | |||
70 | bot.Client.Self.Movement.AtPos = true; | ||
71 | Thread.Sleep(bot.Random.Next(3000, 13000)); | ||
72 | bot.Client.Self.Movement.AtPos = false; | ||
73 | bot.Client.Self.Jump(true); | ||
74 | |||
75 | string randomf = talkarray[bot.Random.Next(talkarray.Length)]; | ||
76 | if (talkarray.Length > 1 && randomf.Length > 1) | ||
77 | bot.Client.Self.Chat(randomf, 0, ChatType.Normal); | ||
78 | } | ||
79 | |||
80 | private string[] readexcuses() | ||
81 | { | ||
82 | string allexcuses = ""; | ||
83 | |||
84 | string file = Path.Combine(Util.configDir(), "pCampBotSentences.txt"); | ||
85 | if (File.Exists(file)) | ||
86 | { | ||
87 | StreamReader csr = File.OpenText(file); | ||
88 | allexcuses = csr.ReadToEnd(); | ||
89 | csr.Close(); | ||
90 | } | ||
91 | |||
92 | return allexcuses.Split(Environment.NewLine.ToCharArray()); | ||
93 | } | ||
94 | } | ||
95 | } \ No newline at end of file | ||
diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/Bot.cs index a8b2426..1b30766 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs | |||
@@ -38,20 +38,45 @@ using OpenMetaverse.Assets; | |||
38 | using Nini.Config; | 38 | using Nini.Config; |
39 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
40 | using OpenSim.Framework.Console; | 40 | using OpenSim.Framework.Console; |
41 | using pCampBot.Interfaces; | ||
41 | using Timer = System.Timers.Timer; | 42 | using Timer = System.Timers.Timer; |
42 | 43 | ||
43 | namespace pCampBot | 44 | namespace pCampBot |
44 | { | 45 | { |
45 | public class PhysicsBot | 46 | public class Bot |
46 | { | 47 | { |
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 49 | ||
49 | public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events | 50 | public delegate void AnEvent(Bot callbot, EventType someevent); // event delegate for bot events |
50 | 51 | ||
51 | public BotManager BotManager { get; private set; } | 52 | public BotManager BotManager { get; private set; } |
52 | private IConfig startupConfig; // bot config, passed from BotManager | 53 | private IConfig startupConfig; // bot config, passed from BotManager |
53 | 54 | ||
54 | /// <summary> | 55 | /// <summary> |
56 | /// Behaviours implemented by this bot. | ||
57 | /// </summary> | ||
58 | /// <remarks> | ||
59 | /// Lock this list before manipulating it. | ||
60 | /// </remarks> | ||
61 | public List<IBehaviour> Behaviours { get; private set; } | ||
62 | |||
63 | /// <summary> | ||
64 | /// Objects that the bot has discovered. | ||
65 | /// </summary> | ||
66 | /// <remarks> | ||
67 | /// Returns a list copy. Inserting new objects manually will have no effect. | ||
68 | /// </remarks> | ||
69 | public Dictionary<UUID, Primitive> Objects | ||
70 | { | ||
71 | get | ||
72 | { | ||
73 | lock (m_objects) | ||
74 | return new Dictionary<UUID, Primitive>(m_objects); | ||
75 | } | ||
76 | } | ||
77 | private Dictionary<UUID, Primitive> m_objects = new Dictionary<UUID, Primitive>(); | ||
78 | |||
79 | /// <summary> | ||
55 | /// Is this bot connected to the grid? | 80 | /// Is this bot connected to the grid? |
56 | /// </summary> | 81 | /// </summary> |
57 | public bool IsConnected { get; private set; } | 82 | public bool IsConnected { get; private set; } |
@@ -74,25 +99,33 @@ namespace pCampBot | |||
74 | 99 | ||
75 | protected List<uint> objectIDs = new List<uint>(); | 100 | protected List<uint> objectIDs = new List<uint>(); |
76 | 101 | ||
77 | protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here | 102 | /// <summary> |
103 | /// Random number generator. | ||
104 | /// </summary> | ||
105 | public Random Random { get; private set; } | ||
78 | 106 | ||
79 | /// <summary> | 107 | /// <summary> |
80 | /// New instance of a SecondLife client | 108 | /// New instance of a SecondLife client |
81 | /// </summary> | 109 | /// </summary> |
82 | public GridClient client = new GridClient(); | 110 | public GridClient Client { get; private set; } |
83 | |||
84 | protected string[] talkarray; | ||
85 | 111 | ||
86 | /// <summary> | 112 | /// <summary> |
87 | /// Constructor | 113 | /// Constructor |
88 | /// </summary> | 114 | /// </summary> |
89 | /// <param name="bm"></param> | 115 | /// <param name="bm"></param> |
116 | /// <param name="behaviours">Behaviours for this bot to perform</param> | ||
90 | /// <param name="firstName"></param> | 117 | /// <param name="firstName"></param> |
91 | /// <param name="lastName"></param> | 118 | /// <param name="lastName"></param> |
92 | /// <param name="password"></param> | 119 | /// <param name="password"></param> |
93 | /// <param name="loginUri"></param> | 120 | /// <param name="loginUri"></param> |
94 | public PhysicsBot(BotManager bm, string firstName, string lastName, string password, string loginUri) | 121 | /// <param name="behaviours"></param> |
122 | public Bot( | ||
123 | BotManager bm, List<IBehaviour> behaviours, | ||
124 | string firstName, string lastName, string password, string loginUri) | ||
95 | { | 125 | { |
126 | Client = new GridClient(); | ||
127 | |||
128 | Random = new Random(Environment.TickCount);// We do stuff randomly here | ||
96 | FirstName = firstName; | 129 | FirstName = firstName; |
97 | LastName = lastName; | 130 | LastName = lastName; |
98 | Name = string.Format("{0} {1}", FirstName, LastName); | 131 | Name = string.Format("{0} {1}", FirstName, LastName); |
@@ -102,7 +135,8 @@ namespace pCampBot | |||
102 | BotManager = bm; | 135 | BotManager = bm; |
103 | startupConfig = bm.Config; | 136 | startupConfig = bm.Config; |
104 | readconfig(); | 137 | readconfig(); |
105 | talkarray = readexcuses(); | 138 | |
139 | Behaviours = behaviours; | ||
106 | } | 140 | } |
107 | 141 | ||
108 | //We do our actions here. This is where one would | 142 | //We do our actions here. This is where one would |
@@ -110,34 +144,16 @@ namespace pCampBot | |||
110 | private void Action() | 144 | private void Action() |
111 | { | 145 | { |
112 | while (true) | 146 | while (true) |
113 | { | 147 | lock (Behaviours) |
114 | int walkorrun = somthing.Next(4); // Randomize between walking and running. The greater this number, | 148 | Behaviours.ForEach( |
115 | // the greater the bot's chances to walk instead of run. | 149 | b => |
116 | client.Self.Jump(false); | 150 | { |
117 | if (walkorrun == 0) | 151 | // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); |
118 | { | 152 | b.Action(this); |
119 | client.Self.Movement.AlwaysRun = true; | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | client.Self.Movement.AlwaysRun = false; | ||
124 | } | ||
125 | |||
126 | // TODO: unused: Vector3 pos = client.Self.SimPosition; | ||
127 | Vector3 newpos = new Vector3(somthing.Next(1, 254), somthing.Next(1, 254), somthing.Next(1, 254)); | ||
128 | client.Self.Movement.TurnToward(newpos); | ||
129 | |||
130 | client.Self.Movement.AtPos = true; | ||
131 | Thread.Sleep(somthing.Next(3000, 13000)); | ||
132 | client.Self.Movement.AtPos = false; | ||
133 | client.Self.Jump(true); | ||
134 | |||
135 | string randomf = talkarray[somthing.Next(talkarray.Length)]; | ||
136 | if (talkarray.Length > 1 && randomf.Length > 1) | ||
137 | client.Self.Chat(randomf, 0, ChatType.Normal); | ||
138 | 153 | ||
139 | Thread.Sleep(somthing.Next(1000, 10000)); | 154 | Thread.Sleep(Random.Next(1000, 10000)); |
140 | } | 155 | } |
156 | ); | ||
141 | } | 157 | } |
142 | 158 | ||
143 | /// <summary> | 159 | /// <summary> |
@@ -145,7 +161,7 @@ namespace pCampBot | |||
145 | /// </summary> | 161 | /// </summary> |
146 | public void readconfig() | 162 | public void readconfig() |
147 | { | 163 | { |
148 | wear = startupConfig.GetString("wear","no"); | 164 | wear = startupConfig.GetString("wear", "no"); |
149 | } | 165 | } |
150 | 166 | ||
151 | /// <summary> | 167 | /// <summary> |
@@ -156,7 +172,7 @@ namespace pCampBot | |||
156 | if (m_actionThread != null) | 172 | if (m_actionThread != null) |
157 | m_actionThread.Abort(); | 173 | m_actionThread.Abort(); |
158 | 174 | ||
159 | client.Network.Logout(); | 175 | Client.Network.Logout(); |
160 | } | 176 | } |
161 | 177 | ||
162 | /// <summary> | 178 | /// <summary> |
@@ -164,50 +180,50 @@ namespace pCampBot | |||
164 | /// </summary> | 180 | /// </summary> |
165 | public void startup() | 181 | public void startup() |
166 | { | 182 | { |
167 | client.Settings.LOGIN_SERVER = LoginUri; | 183 | Client.Settings.LOGIN_SERVER = LoginUri; |
168 | client.Settings.ALWAYS_DECODE_OBJECTS = false; | 184 | Client.Settings.ALWAYS_DECODE_OBJECTS = false; |
169 | client.Settings.AVATAR_TRACKING = false; | 185 | Client.Settings.AVATAR_TRACKING = false; |
170 | client.Settings.OBJECT_TRACKING = false; | 186 | Client.Settings.OBJECT_TRACKING = false; |
171 | client.Settings.SEND_AGENT_THROTTLE = true; | 187 | Client.Settings.SEND_AGENT_THROTTLE = true; |
172 | client.Settings.SEND_PINGS = true; | 188 | Client.Settings.SEND_PINGS = true; |
173 | client.Settings.STORE_LAND_PATCHES = false; | 189 | Client.Settings.STORE_LAND_PATCHES = false; |
174 | client.Settings.USE_ASSET_CACHE = false; | 190 | Client.Settings.USE_ASSET_CACHE = false; |
175 | client.Settings.MULTIPLE_SIMS = true; | 191 | Client.Settings.MULTIPLE_SIMS = true; |
176 | client.Throttle.Asset = 100000; | 192 | Client.Throttle.Asset = 100000; |
177 | client.Throttle.Land = 100000; | 193 | Client.Throttle.Land = 100000; |
178 | client.Throttle.Task = 100000; | 194 | Client.Throttle.Task = 100000; |
179 | client.Throttle.Texture = 100000; | 195 | Client.Throttle.Texture = 100000; |
180 | client.Throttle.Wind = 100000; | 196 | Client.Throttle.Wind = 100000; |
181 | client.Throttle.Total = 400000; | 197 | Client.Throttle.Total = 400000; |
182 | client.Network.LoginProgress += this.Network_LoginProgress; | 198 | Client.Network.LoginProgress += this.Network_LoginProgress; |
183 | client.Network.SimConnected += this.Network_SimConnected; | 199 | Client.Network.SimConnected += this.Network_SimConnected; |
184 | client.Network.Disconnected += this.Network_OnDisconnected; | 200 | Client.Network.Disconnected += this.Network_OnDisconnected; |
185 | client.Objects.ObjectUpdate += Objects_NewPrim; | 201 | Client.Objects.ObjectUpdate += Objects_NewPrim; |
186 | 202 | ||
187 | if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) | 203 | if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) |
188 | { | 204 | { |
189 | IsConnected = true; | 205 | IsConnected = true; |
190 | 206 | ||
191 | Thread.Sleep(somthing.Next(1000, 10000)); | 207 | Thread.Sleep(Random.Next(1000, 10000)); |
192 | m_actionThread = new Thread(Action); | 208 | m_actionThread = new Thread(Action); |
193 | m_actionThread.Start(); | 209 | m_actionThread.Start(); |
194 | 210 | ||
195 | // OnConnected(this, EventType.CONNECTED); | 211 | // OnConnected(this, EventType.CONNECTED); |
196 | if (wear == "save") | 212 | if (wear == "save") |
197 | { | 213 | { |
198 | client.Appearance.SetPreviousAppearance(); | 214 | Client.Appearance.SetPreviousAppearance(); |
199 | SaveDefaultAppearance(); | 215 | SaveDefaultAppearance(); |
200 | } | 216 | } |
201 | else if (wear != "no") | 217 | else if (wear != "no") |
202 | { | 218 | { |
203 | MakeDefaultAppearance(wear); | 219 | MakeDefaultAppearance(wear); |
204 | } | 220 | } |
205 | client.Self.Jump(true); | 221 | Client.Self.Jump(true); |
206 | } | 222 | } |
207 | else | 223 | else |
208 | { | 224 | { |
209 | MainConsole.Instance.OutputFormat( | 225 | MainConsole.Instance.OutputFormat( |
210 | "{0} {1} cannot login: {2}", FirstName, LastName, client.Network.LoginMessage); | 226 | "{0} {1} cannot login: {2}", FirstName, LastName, Client.Network.LoginMessage); |
211 | 227 | ||
212 | if (OnDisconnected != null) | 228 | if (OnDisconnected != null) |
213 | { | 229 | { |
@@ -227,11 +243,11 @@ namespace pCampBot | |||
227 | Array wtypes = Enum.GetValues(typeof(WearableType)); | 243 | Array wtypes = Enum.GetValues(typeof(WearableType)); |
228 | foreach (WearableType wtype in wtypes) | 244 | foreach (WearableType wtype in wtypes) |
229 | { | 245 | { |
230 | UUID wearable = client.Appearance.GetWearableAsset(wtype); | 246 | UUID wearable = Client.Appearance.GetWearableAsset(wtype); |
231 | if (wearable != UUID.Zero) | 247 | if (wearable != UUID.Zero) |
232 | { | 248 | { |
233 | client.Assets.RequestAsset(wearable, AssetType.Clothing, false, Asset_ReceivedCallback); | 249 | Client.Assets.RequestAsset(wearable, AssetType.Clothing, false, Asset_ReceivedCallback); |
234 | client.Assets.RequestAsset(wearable, AssetType.Bodypart, false, Asset_ReceivedCallback); | 250 | Client.Assets.RequestAsset(wearable, AssetType.Bodypart, false, Asset_ReceivedCallback); |
235 | } | 251 | } |
236 | } | 252 | } |
237 | } | 253 | } |
@@ -306,11 +322,11 @@ namespace pCampBot | |||
306 | UUID assetID = UUID.Random(); | 322 | UUID assetID = UUID.Random(); |
307 | AssetClothing asset = new AssetClothing(assetID, File.ReadAllBytes(clothing[i])); | 323 | AssetClothing asset = new AssetClothing(assetID, File.ReadAllBytes(clothing[i])); |
308 | asset.Decode(); | 324 | asset.Decode(); |
309 | asset.Owner = client.Self.AgentID; | 325 | asset.Owner = Client.Self.AgentID; |
310 | asset.WearableType = GetWearableType(clothing[i]); | 326 | asset.WearableType = GetWearableType(clothing[i]); |
311 | asset.Encode(); | 327 | asset.Encode(); |
312 | transid = client.Assets.RequestUpload(asset,true); | 328 | transid = Client.Assets.RequestUpload(asset,true); |
313 | client.Inventory.RequestCreateItem(clothfolder.UUID, "MyClothing" + i.ToString(), "MyClothing", AssetType.Clothing, | 329 | Client.Inventory.RequestCreateItem(clothfolder.UUID, "MyClothing" + i.ToString(), "MyClothing", AssetType.Clothing, |
314 | transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) | 330 | transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) |
315 | { | 331 | { |
316 | if (success) | 332 | if (success) |
@@ -328,11 +344,11 @@ namespace pCampBot | |||
328 | UUID assetID = UUID.Random(); | 344 | UUID assetID = UUID.Random(); |
329 | AssetBodypart asset = new AssetBodypart(assetID, File.ReadAllBytes(bodyparts[i])); | 345 | AssetBodypart asset = new AssetBodypart(assetID, File.ReadAllBytes(bodyparts[i])); |
330 | asset.Decode(); | 346 | asset.Decode(); |
331 | asset.Owner = client.Self.AgentID; | 347 | asset.Owner = Client.Self.AgentID; |
332 | asset.WearableType = GetWearableType(bodyparts[i]); | 348 | asset.WearableType = GetWearableType(bodyparts[i]); |
333 | asset.Encode(); | 349 | asset.Encode(); |
334 | transid = client.Assets.RequestUpload(asset,true); | 350 | transid = Client.Assets.RequestUpload(asset,true); |
335 | client.Inventory.RequestCreateItem(clothfolder.UUID, "MyBodyPart" + i.ToString(), "MyBodyPart", AssetType.Bodypart, | 351 | Client.Inventory.RequestCreateItem(clothfolder.UUID, "MyBodyPart" + i.ToString(), "MyBodyPart", AssetType.Bodypart, |
336 | transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) | 352 | transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) |
337 | { | 353 | { |
338 | if (success) | 354 | if (success) |
@@ -352,7 +368,7 @@ namespace pCampBot | |||
352 | else | 368 | else |
353 | { | 369 | { |
354 | MainConsole.Instance.Output(String.Format("Sending {0} wearables...",listwearables.Count)); | 370 | MainConsole.Instance.Output(String.Format("Sending {0} wearables...",listwearables.Count)); |
355 | client.Appearance.WearOutfit(listwearables, false); | 371 | Client.Appearance.WearOutfit(listwearables, false); |
356 | } | 372 | } |
357 | } | 373 | } |
358 | catch (Exception ex) | 374 | catch (Exception ex) |
@@ -363,8 +379,8 @@ namespace pCampBot | |||
363 | 379 | ||
364 | public InventoryFolder FindClothingFolder() | 380 | public InventoryFolder FindClothingFolder() |
365 | { | 381 | { |
366 | UUID rootfolder = client.Inventory.Store.RootFolder.UUID; | 382 | UUID rootfolder = Client.Inventory.Store.RootFolder.UUID; |
367 | List<InventoryBase> listfolders = client.Inventory.Store.GetContents(rootfolder); | 383 | List<InventoryBase> listfolders = Client.Inventory.Store.GetContents(rootfolder); |
368 | InventoryFolder clothfolder = new InventoryFolder(UUID.Random()); | 384 | InventoryFolder clothfolder = new InventoryFolder(UUID.Random()); |
369 | foreach (InventoryBase folder in listfolders) | 385 | foreach (InventoryBase folder in listfolders) |
370 | { | 386 | { |
@@ -419,6 +435,9 @@ namespace pCampBot | |||
419 | 435 | ||
420 | if (prim != null) | 436 | if (prim != null) |
421 | { | 437 | { |
438 | lock (m_objects) | ||
439 | m_objects[prim.ID] = prim; | ||
440 | |||
422 | if (prim.Textures != null) | 441 | if (prim.Textures != null) |
423 | { | 442 | { |
424 | if (prim.Textures.DefaultTexture.TextureID != UUID.Zero) | 443 | if (prim.Textures.DefaultTexture.TextureID != UUID.Zero) |
@@ -430,10 +449,8 @@ namespace pCampBot | |||
430 | { | 449 | { |
431 | UUID textureID = prim.Textures.FaceTextures[i].TextureID; | 450 | UUID textureID = prim.Textures.FaceTextures[i].TextureID; |
432 | 451 | ||
433 | if (textureID != null && textureID != UUID.Zero) | 452 | if (textureID != UUID.Zero) |
434 | { | ||
435 | GetTexture(textureID); | 453 | GetTexture(textureID); |
436 | } | ||
437 | } | 454 | } |
438 | } | 455 | } |
439 | 456 | ||
@@ -453,10 +470,9 @@ namespace pCampBot | |||
453 | return; | 470 | return; |
454 | 471 | ||
455 | BotManager.AssetsReceived[textureID] = false; | 472 | BotManager.AssetsReceived[textureID] = false; |
456 | client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture); | 473 | Client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture); |
457 | } | 474 | } |
458 | } | 475 | } |
459 | |||
460 | 476 | ||
461 | public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) | 477 | public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) |
462 | { | 478 | { |
@@ -473,20 +489,5 @@ namespace pCampBot | |||
473 | // SaveAsset((AssetWearable) asset); | 489 | // SaveAsset((AssetWearable) asset); |
474 | // } | 490 | // } |
475 | } | 491 | } |
476 | |||
477 | public string[] readexcuses() | ||
478 | { | ||
479 | string allexcuses = ""; | ||
480 | |||
481 | string file = Path.Combine(Util.configDir(), "pCampBotSentences.txt"); | ||
482 | if (File.Exists(file)) | ||
483 | { | ||
484 | StreamReader csr = File.OpenText(file); | ||
485 | allexcuses = csr.ReadToEnd(); | ||
486 | csr.Close(); | ||
487 | } | ||
488 | |||
489 | return allexcuses.Split(Environment.NewLine.ToCharArray()); | ||
490 | } | ||
491 | } | 492 | } |
492 | } | 493 | } |
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index b05bd6d..704770a 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs | |||
@@ -37,6 +37,7 @@ using log4net.Repository; | |||
37 | using Nini.Config; | 37 | using Nini.Config; |
38 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
39 | using OpenSim.Framework.Console; | 39 | using OpenSim.Framework.Console; |
40 | using pCampBot.Interfaces; | ||
40 | 41 | ||
41 | namespace pCampBot | 42 | namespace pCampBot |
42 | { | 43 | { |
@@ -48,7 +49,7 @@ namespace pCampBot | |||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
49 | 50 | ||
50 | protected CommandConsole m_console; | 51 | protected CommandConsole m_console; |
51 | protected List<PhysicsBot> m_lBot; | 52 | protected List<Bot> m_lBot; |
52 | protected Random somthing = new Random(Environment.TickCount); | 53 | protected Random somthing = new Random(Environment.TickCount); |
53 | protected int numbots = 0; | 54 | protected int numbots = 0; |
54 | public IConfig Config { get; private set; } | 55 | public IConfig Config { get; private set; } |
@@ -102,7 +103,7 @@ namespace pCampBot | |||
102 | // "add bots <number>", | 103 | // "add bots <number>", |
103 | // "Add more bots", HandleAddBots); | 104 | // "Add more bots", HandleAddBots); |
104 | 105 | ||
105 | m_lBot = new List<PhysicsBot>(); | 106 | m_lBot = new List<Bot>(); |
106 | } | 107 | } |
107 | 108 | ||
108 | /// <summary> | 109 | /// <summary> |
@@ -119,10 +120,24 @@ namespace pCampBot | |||
119 | string password = cs.GetString("password"); | 120 | string password = cs.GetString("password"); |
120 | string loginUri = cs.GetString("loginuri"); | 121 | string loginUri = cs.GetString("loginuri"); |
121 | 122 | ||
123 | HashSet<string> behaviourSwitches = new HashSet<string>(); | ||
124 | Array.ForEach<string>( | ||
125 | cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b)); | ||
126 | |||
122 | for (int i = 0; i < botcount; i++) | 127 | for (int i = 0; i < botcount; i++) |
123 | { | 128 | { |
124 | string lastName = string.Format("{0}_{1}", lastNameStem, i); | 129 | string lastName = string.Format("{0}_{1}", lastNameStem, i); |
125 | startupBot(i, this, firstName, lastName, password, loginUri); | 130 | |
131 | List<IBehaviour> behaviours = new List<IBehaviour>(); | ||
132 | |||
133 | // Hard-coded for now | ||
134 | if (behaviourSwitches.Contains("p")) | ||
135 | behaviours.Add(new PhysicsBehaviour()); | ||
136 | |||
137 | if (behaviourSwitches.Contains("g")) | ||
138 | behaviours.Add(new GrabbingBehaviour()); | ||
139 | |||
140 | startupBot(i, this, behaviours, firstName, lastName, password, loginUri); | ||
126 | } | 141 | } |
127 | } | 142 | } |
128 | 143 | ||
@@ -150,14 +165,17 @@ namespace pCampBot | |||
150 | /// This starts up the bot and stores the thread for the bot in the thread array | 165 | /// This starts up the bot and stores the thread for the bot in the thread array |
151 | /// </summary> | 166 | /// </summary> |
152 | /// <param name="pos">The position in the thread array to stick the bot's thread</param> | 167 | /// <param name="pos">The position in the thread array to stick the bot's thread</param> |
153 | /// <param name="cs">Configuration of the bot</param> | 168 | /// <param name="bm"></param> |
169 | /// <param name="behaviours">Behaviours for this bot to perform.</param> | ||
154 | /// <param name="firstName">First name</param> | 170 | /// <param name="firstName">First name</param> |
155 | /// <param name="lastName">Last name</param> | 171 | /// <param name="lastName">Last name</param> |
156 | /// <param name="password">Password</param> | 172 | /// <param name="password">Password</param> |
157 | /// <param name="loginUri">Login URI</param> | 173 | /// <param name="loginUri">Login URI</param> |
158 | public void startupBot(int pos, BotManager bm, string firstName, string lastName, string password, string loginUri) | 174 | public void startupBot( |
175 | int pos, BotManager bm, List<IBehaviour> behaviours, | ||
176 | string firstName, string lastName, string password, string loginUri) | ||
159 | { | 177 | { |
160 | PhysicsBot pb = new PhysicsBot(bm, firstName, lastName, password, loginUri); | 178 | Bot pb = new Bot(bm, behaviours, firstName, lastName, password, loginUri); |
161 | 179 | ||
162 | pb.OnConnected += handlebotEvent; | 180 | pb.OnConnected += handlebotEvent; |
163 | pb.OnDisconnected += handlebotEvent; | 181 | pb.OnDisconnected += handlebotEvent; |
@@ -176,7 +194,7 @@ namespace pCampBot | |||
176 | /// </summary> | 194 | /// </summary> |
177 | /// <param name="callbot"></param> | 195 | /// <param name="callbot"></param> |
178 | /// <param name="eventt"></param> | 196 | /// <param name="eventt"></param> |
179 | private void handlebotEvent(PhysicsBot callbot, EventType eventt) | 197 | private void handlebotEvent(Bot callbot, EventType eventt) |
180 | { | 198 | { |
181 | switch (eventt) | 199 | switch (eventt) |
182 | { | 200 | { |
@@ -201,7 +219,7 @@ namespace pCampBot | |||
201 | public void doBotShutdown() | 219 | public void doBotShutdown() |
202 | { | 220 | { |
203 | lock (m_lBot) | 221 | lock (m_lBot) |
204 | foreach (PhysicsBot pb in m_lBot) | 222 | foreach (Bot pb in m_lBot) |
205 | pb.shutdown(); | 223 | pb.shutdown(); |
206 | } | 224 | } |
207 | 225 | ||
@@ -227,7 +245,7 @@ namespace pCampBot | |||
227 | 245 | ||
228 | lock (m_lBot) | 246 | lock (m_lBot) |
229 | { | 247 | { |
230 | foreach (PhysicsBot pb in m_lBot) | 248 | foreach (Bot pb in m_lBot) |
231 | { | 249 | { |
232 | MainConsole.Instance.OutputFormat( | 250 | MainConsole.Instance.OutputFormat( |
233 | outputFormat, pb.Name, (pb.IsConnected ? "Connected" : "Disconnected")); | 251 | outputFormat, pb.Name, (pb.IsConnected ? "Connected" : "Disconnected")); |
diff --git a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs new file mode 100644 index 0000000..d4ae0f0 --- /dev/null +++ b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs | |||
@@ -0,0 +1,36 @@ | |||
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 | |||
30 | namespace pCampBot.Interfaces | ||
31 | { | ||
32 | public interface IBehaviour | ||
33 | { | ||
34 | void Action(Bot bot); | ||
35 | } | ||
36 | } \ No newline at end of file | ||
diff --git a/OpenSim/Tools/pCampBot/pCampBot.cs b/OpenSim/Tools/pCampBot/pCampBot.cs index a69fbf0..4d3b06d 100644 --- a/OpenSim/Tools/pCampBot/pCampBot.cs +++ b/OpenSim/Tools/pCampBot/pCampBot.cs | |||
@@ -26,6 +26,8 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Reflection; | ||
30 | using log4net; | ||
29 | using Nini.Config; | 31 | using Nini.Config; |
30 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
31 | using OpenSim.Framework.Console; | 33 | using OpenSim.Framework.Console; |
@@ -44,6 +46,8 @@ namespace pCampBot | |||
44 | 46 | ||
45 | public class pCampBot | 47 | public class pCampBot |
46 | { | 48 | { |
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
47 | [STAThread] | 51 | [STAThread] |
48 | public static void Main(string[] args) | 52 | public static void Main(string[] args) |
49 | { | 53 | { |
@@ -60,9 +64,17 @@ namespace pCampBot | |||
60 | 64 | ||
61 | //startup specified number of bots. 1 is the default | 65 | //startup specified number of bots. 1 is the default |
62 | bm.dobotStartup(botcount, config); | 66 | bm.dobotStartup(botcount, config); |
67 | |||
63 | while (true) | 68 | while (true) |
64 | { | 69 | { |
65 | MainConsole.Instance.Prompt(); | 70 | try |
71 | { | ||
72 | MainConsole.Instance.Prompt(); | ||
73 | } | ||
74 | catch (Exception e) | ||
75 | { | ||
76 | m_log.ErrorFormat("Command error: {0}", e); | ||
77 | } | ||
66 | } | 78 | } |
67 | } | 79 | } |
68 | } | 80 | } |
@@ -72,12 +84,13 @@ namespace pCampBot | |||
72 | //Set up our nifty config.. thanks to nini | 84 | //Set up our nifty config.. thanks to nini |
73 | ArgvConfigSource cs = new ArgvConfigSource(args); | 85 | ArgvConfigSource cs = new ArgvConfigSource(args); |
74 | 86 | ||
75 | cs.AddSwitch("Startup", "botcount","n"); | 87 | cs.AddSwitch("Startup", "botcount", "n"); |
76 | cs.AddSwitch("Startup", "loginuri","l"); | 88 | cs.AddSwitch("Startup", "loginuri", "l"); |
77 | cs.AddSwitch("Startup", "firstname"); | 89 | cs.AddSwitch("Startup", "firstname"); |
78 | cs.AddSwitch("Startup", "lastname"); | 90 | cs.AddSwitch("Startup", "lastname"); |
79 | cs.AddSwitch("Startup", "password"); | 91 | cs.AddSwitch("Startup", "password"); |
80 | cs.AddSwitch("Startup", "help","h"); | 92 | cs.AddSwitch("Startup", "behaviours", "b"); |
93 | cs.AddSwitch("Startup", "help", "h"); | ||
81 | cs.AddSwitch("Startup", "wear"); | 94 | cs.AddSwitch("Startup", "wear"); |
82 | 95 | ||
83 | IConfig ol = cs.Configs["Startup"]; | 96 | IConfig ol = cs.Configs["Startup"]; |
@@ -98,6 +111,7 @@ namespace pCampBot | |||
98 | " -firstname first name for the bots\n" + | 111 | " -firstname first name for the bots\n" + |
99 | " -lastname lastname for the bots. Each lastname will have _<bot-number> appended, e.g. Ima Bot_0\n" + | 112 | " -lastname lastname for the bots. Each lastname will have _<bot-number> appended, e.g. Ima Bot_0\n" + |
100 | " -password password for the bots\n" + | 113 | " -password password for the bots\n" + |
114 | " -b, behaviours behaviours for bots. Current options p (physics), g (grab). Comma separated, e.g. p,g. Default is p", | ||
101 | " -wear set appearance folder to load from (default: no)\n" + | 115 | " -wear set appearance folder to load from (default: no)\n" + |
102 | " -h, -help show this message" | 116 | " -h, -help show this message" |
103 | ); | 117 | ); |