aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot/Bot.cs
diff options
context:
space:
mode:
authorMelanie Thielker2014-06-21 00:39:55 +0200
committerMelanie Thielker2014-06-21 00:39:55 +0200
commit159fcbf150b7da0e229b29aa7b94793484543d12 (patch)
treeb8c0ff3b4c758a3fba8315b556c923ef4c02a185 /OpenSim/Tools/pCampBot/Bot.cs
parentMerge commit '68c8633ba18f0a11cfc0ed04d1d0c7c59e6cec76' (diff)
parentMerge branch 'master' into careminster (diff)
downloadopensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.zip
opensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.tar.gz
opensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.tar.bz2
opensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.tar.xz
Merge branch 'master' of ssh://3dhosting.de/var/git/careminster
Conflicts: OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
Diffstat (limited to 'OpenSim/Tools/pCampBot/Bot.cs')
-rw-r--r--OpenSim/Tools/pCampBot/Bot.cs263
1 files changed, 202 insertions, 61 deletions
diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs
index 9821180..de464ab 100644
--- a/OpenSim/Tools/pCampBot/Bot.cs
+++ b/OpenSim/Tools/pCampBot/Bot.cs
@@ -59,22 +59,23 @@ namespace pCampBot
59 public delegate void AnEvent(Bot callbot, EventType someevent); // event delegate for bot events 59 public delegate void AnEvent(Bot callbot, EventType someevent); // event delegate for bot events
60 60
61 /// <summary> 61 /// <summary>
62 /// Bot manager. 62 /// Controls whether bots request textures for the object information they receive
63 /// </summary> 63 /// </summary>
64 public BotManager Manager { get; private set; } 64 public bool RequestObjectTextures { get; set; }
65 65
66 /// <summary> 66 /// <summary>
67 /// Bot config, passed from BotManager. 67 /// Bot manager.
68 /// </summary> 68 /// </summary>
69 private IConfig startupConfig; 69 public BotManager Manager { get; private set; }
70 70
71 /// <summary> 71 /// <summary>
72 /// Behaviours implemented by this bot. 72 /// Behaviours implemented by this bot.
73 /// </summary> 73 /// </summary>
74 /// <remarks> 74 /// <remarks>
75 /// Lock this list before manipulating it. 75 /// Indexed by abbreviated name. There can only be one instance of a particular behaviour.
76 /// Lock this structure before manipulating it.
76 /// </remarks> 77 /// </remarks>
77 public List<IBehaviour> Behaviours { get; private set; } 78 public Dictionary<string, IBehaviour> Behaviours { get; private set; }
78 79
79 /// <summary> 80 /// <summary>
80 /// Objects that the bot has discovered. 81 /// Objects that the bot has discovered.
@@ -97,11 +98,35 @@ namespace pCampBot
97 /// </summary> 98 /// </summary>
98 public ConnectionState ConnectionState { get; private set; } 99 public ConnectionState ConnectionState { get; private set; }
99 100
101 public List<Simulator> Simulators
102 {
103 get
104 {
105 lock (Client.Network.Simulators)
106 return new List<Simulator>(Client.Network.Simulators);
107 }
108 }
109
110 /// <summary>
111 /// The number of connections that this bot has to different simulators.
112 /// </summary>
113 /// <value>Includes both root and child connections.</value>
114 public int SimulatorsCount
115 {
116 get
117 {
118 lock (Client.Network.Simulators)
119 return Client.Network.Simulators.Count;
120 }
121 }
122
100 public string FirstName { get; private set; } 123 public string FirstName { get; private set; }
101 public string LastName { get; private set; } 124 public string LastName { get; private set; }
102 public string Name { get; private set; } 125 public string Name { get; private set; }
103 public string Password { get; private set; } 126 public string Password { get; private set; }
104 public string LoginUri { get; private set; } 127 public string LoginUri { get; private set; }
128 public string StartLocation { get; private set; }
129
105 public string saveDir; 130 public string saveDir;
106 public string wear; 131 public string wear;
107 132
@@ -137,94 +162,178 @@ namespace pCampBot
137 /// <param name="behaviours"></param> 162 /// <param name="behaviours"></param>
138 public Bot( 163 public Bot(
139 BotManager bm, List<IBehaviour> behaviours, 164 BotManager bm, List<IBehaviour> behaviours,
140 string firstName, string lastName, string password, string loginUri) 165 string firstName, string lastName, string password, string startLocation, string loginUri)
141 { 166 {
142 ConnectionState = ConnectionState.Disconnected; 167 ConnectionState = ConnectionState.Disconnected;
143 168
144 behaviours.ForEach(b => b.Initialize(this)); 169 Random = new Random(bm.Rng.Next());
145
146 Client = new GridClient();
147
148 Random = new Random(Environment.TickCount);// We do stuff randomly here
149 FirstName = firstName; 170 FirstName = firstName;
150 LastName = lastName; 171 LastName = lastName;
151 Name = string.Format("{0} {1}", FirstName, LastName); 172 Name = string.Format("{0} {1}", FirstName, LastName);
152 Password = password; 173 Password = password;
153 LoginUri = loginUri; 174 LoginUri = loginUri;
175 StartLocation = startLocation;
154 176
155 Manager = bm; 177 Manager = bm;
156 startupConfig = bm.Config;
157 readconfig();
158 178
159 Behaviours = behaviours; 179 Behaviours = new Dictionary<string, IBehaviour>();
180 foreach (IBehaviour behaviour in behaviours)
181 AddBehaviour(behaviour);
182
183 // Only calling for use as a template.
184 CreateLibOmvClient();
185 }
186
187 public bool TryGetBehaviour(string abbreviatedName, out IBehaviour behaviour)
188 {
189 lock (Behaviours)
190 return Behaviours.TryGetValue(abbreviatedName, out behaviour);
191 }
192
193 public bool AddBehaviour(IBehaviour behaviour)
194 {
195 lock (Behaviours)
196 {
197 if (!Behaviours.ContainsKey(behaviour.AbbreviatedName))
198 {
199 behaviour.Initialize(this);
200 Behaviours.Add(behaviour.AbbreviatedName, behaviour);
201
202 return true;
203 }
204 }
205
206 return false;
207 }
208
209 public bool RemoveBehaviour(string abbreviatedName)
210 {
211 lock (Behaviours)
212 {
213 IBehaviour behaviour;
214
215 if (!Behaviours.TryGetValue(abbreviatedName, out behaviour))
216 return false;
217
218 behaviour.Close();
219 Behaviours.Remove(abbreviatedName);
220
221 return true;
222 }
223 }
224
225 private void CreateLibOmvClient()
226 {
227 GridClient newClient = new GridClient();
228
229 if (Client != null)
230 {
231 newClient.Settings.LOGIN_SERVER = Client.Settings.LOGIN_SERVER;
232 newClient.Settings.ALWAYS_DECODE_OBJECTS = Client.Settings.ALWAYS_DECODE_OBJECTS;
233 newClient.Settings.AVATAR_TRACKING = Client.Settings.AVATAR_TRACKING;
234 newClient.Settings.OBJECT_TRACKING = Client.Settings.OBJECT_TRACKING;
235 newClient.Settings.SEND_AGENT_THROTTLE = Client.Settings.SEND_AGENT_THROTTLE;
236 newClient.Settings.SEND_AGENT_UPDATES = Client.Settings.SEND_AGENT_UPDATES;
237 newClient.Settings.SEND_PINGS = Client.Settings.SEND_PINGS;
238 newClient.Settings.STORE_LAND_PATCHES = Client.Settings.STORE_LAND_PATCHES;
239 newClient.Settings.USE_ASSET_CACHE = Client.Settings.USE_ASSET_CACHE;
240 newClient.Settings.MULTIPLE_SIMS = Client.Settings.MULTIPLE_SIMS;
241 newClient.Throttle.Asset = Client.Throttle.Asset;
242 newClient.Throttle.Land = Client.Throttle.Land;
243 newClient.Throttle.Task = Client.Throttle.Task;
244 newClient.Throttle.Texture = Client.Throttle.Texture;
245 newClient.Throttle.Wind = Client.Throttle.Wind;
246 newClient.Throttle.Total = Client.Throttle.Total;
247 }
248 else
249 {
250 newClient.Settings.LOGIN_SERVER = LoginUri;
251 newClient.Settings.ALWAYS_DECODE_OBJECTS = false;
252 newClient.Settings.AVATAR_TRACKING = false;
253 newClient.Settings.OBJECT_TRACKING = false;
254 newClient.Settings.SEND_AGENT_THROTTLE = true;
255 newClient.Settings.SEND_PINGS = true;
256 newClient.Settings.STORE_LAND_PATCHES = false;
257 newClient.Settings.USE_ASSET_CACHE = false;
258 newClient.Settings.MULTIPLE_SIMS = true;
259 newClient.Throttle.Asset = 100000;
260 newClient.Throttle.Land = 100000;
261 newClient.Throttle.Task = 100000;
262 newClient.Throttle.Texture = 100000;
263 newClient.Throttle.Wind = 100000;
264 newClient.Throttle.Total = 400000;
265 }
266
267 newClient.Network.LoginProgress += Network_LoginProgress;
268 newClient.Network.SimConnected += Network_SimConnected;
269 newClient.Network.SimDisconnected += Network_SimDisconnected;
270 newClient.Network.Disconnected += Network_OnDisconnected;
271 newClient.Objects.ObjectUpdate += Objects_NewPrim;
272
273 Client = newClient;
160 } 274 }
161 275
162 //We do our actions here. This is where one would 276 //We do our actions here. This is where one would
163 //add additional steps and/or things the bot should do 277 //add additional steps and/or things the bot should do
164 private void Action() 278 private void Action()
165 { 279 {
166 while (true) 280 while (ConnectionState == ConnectionState.Connected)
281 {
167 lock (Behaviours) 282 lock (Behaviours)
168 Behaviours.ForEach( 283 {
169 b => 284 foreach (IBehaviour behaviour in Behaviours.Values)
170 { 285 {
171 Thread.Sleep(Random.Next(3000, 10000)); 286// Thread.Sleep(Random.Next(3000, 10000));
172 287
173 // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); 288 // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType());
174 b.Action(); 289 behaviour.Action();
175 } 290 }
176 ); 291 }
177 }
178 292
179 /// <summary> 293 // XXX: This is a really shitty way of yielding so that behaviours can be added/removed
180 /// Read the Nini config and initialize 294 Thread.Sleep(100);
181 /// </summary> 295 }
182 public void readconfig() 296
183 { 297 lock (Behaviours)
184 wear = startupConfig.GetString("wear", "no"); 298 foreach (IBehaviour b in Behaviours.Values)
299 b.Close();
185 } 300 }
186 301
187 /// <summary> 302 /// <summary>
188 /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes. 303 /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes.
189 /// </summary> 304 /// </summary>
190 public void shutdown() 305 public void Disconnect()
191 { 306 {
192 ConnectionState = ConnectionState.Disconnecting; 307 ConnectionState = ConnectionState.Disconnecting;
193 308
194 if (m_actionThread != null) 309// if (m_actionThread != null)
195 m_actionThread.Abort(); 310// m_actionThread.Abort();
196 311
197 Client.Network.Logout(); 312 Client.Network.Logout();
198 } 313 }
199 314
315 public void Connect()
316 {
317 Thread connectThread = new Thread(ConnectInternal);
318 connectThread.Name = Name;
319 connectThread.IsBackground = true;
320
321 connectThread.Start();
322 }
323
200 /// <summary> 324 /// <summary>
201 /// This is the bot startup loop. 325 /// This is the bot startup loop.
202 /// </summary> 326 /// </summary>
203 public void startup() 327 private void ConnectInternal()
204 { 328 {
205 Client.Settings.LOGIN_SERVER = LoginUri;
206 Client.Settings.ALWAYS_DECODE_OBJECTS = false;
207 Client.Settings.AVATAR_TRACKING = false;
208 Client.Settings.OBJECT_TRACKING = false;
209 Client.Settings.SEND_AGENT_THROTTLE = true;
210 Client.Settings.SEND_PINGS = true;
211 Client.Settings.STORE_LAND_PATCHES = false;
212 Client.Settings.USE_ASSET_CACHE = false;
213 Client.Settings.MULTIPLE_SIMS = true;
214 Client.Throttle.Asset = 100000;
215 Client.Throttle.Land = 100000;
216 Client.Throttle.Task = 100000;
217 Client.Throttle.Texture = 100000;
218 Client.Throttle.Wind = 100000;
219 Client.Throttle.Total = 400000;
220 Client.Network.LoginProgress += this.Network_LoginProgress;
221 Client.Network.SimConnected += this.Network_SimConnected;
222 Client.Network.Disconnected += this.Network_OnDisconnected;
223 Client.Objects.ObjectUpdate += Objects_NewPrim;
224
225 ConnectionState = ConnectionState.Connecting; 329 ConnectionState = ConnectionState.Connecting;
226 330
227 if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) 331 // Current create a new client on each connect. libomv doesn't seem to process new sim
332 // information (e.g. EstablishAgentCommunication events) if connecting after a disceonnect with the same
333 // client
334 CreateLibOmvClient();
335
336 if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", StartLocation, "Your name"))
228 { 337 {
229 ConnectionState = ConnectionState.Connected; 338 ConnectionState = ConnectionState.Connected;
230 339
@@ -268,6 +377,30 @@ namespace pCampBot
268 } 377 }
269 } 378 }
270 379
380 /// <summary>
381 /// Sit this bot on the ground.
382 /// </summary>
383 public void SitOnGround()
384 {
385 if (ConnectionState == ConnectionState.Connected)
386 Client.Self.SitOnGround();
387 }
388
389 /// <summary>
390 /// Stand this bot
391 /// </summary>
392 public void Stand()
393 {
394 if (ConnectionState == ConnectionState.Connected)
395 {
396 // Unlike sit on ground, here libomv checks whether we have SEND_AGENT_UPDATES enabled.
397 bool prevUpdatesSetting = Client.Settings.SEND_AGENT_UPDATES;
398 Client.Settings.SEND_AGENT_UPDATES = true;
399 Client.Self.Stand();
400 Client.Settings.SEND_AGENT_UPDATES = prevUpdatesSetting;
401 }
402 }
403
271 public void SaveDefaultAppearance() 404 public void SaveDefaultAppearance()
272 { 405 {
273 saveDir = "MyAppearance/" + FirstName + "_" + LastName; 406 saveDir = "MyAppearance/" + FirstName + "_" + LastName;
@@ -451,7 +584,13 @@ namespace pCampBot
451 public void Network_SimConnected(object sender, SimConnectedEventArgs args) 584 public void Network_SimConnected(object sender, SimConnectedEventArgs args)
452 { 585 {
453 m_log.DebugFormat( 586 m_log.DebugFormat(
454 "[BOT]: Bot {0} connected to {1} at {2}", Name, args.Simulator.Name, args.Simulator.IPEndPoint); 587 "[BOT]: Bot {0} connected to region {1} at {2}", Name, args.Simulator.Name, args.Simulator.IPEndPoint);
588 }
589
590 public void Network_SimDisconnected(object sender, SimDisconnectedEventArgs args)
591 {
592 m_log.DebugFormat(
593 "[BOT]: Bot {0} disconnected from region {1} at {2}", Name, args.Simulator.Name, args.Simulator.IPEndPoint);
455 } 594 }
456 595
457 public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) 596 public void Network_OnDisconnected(object sender, DisconnectedEventArgs args)
@@ -459,7 +598,7 @@ namespace pCampBot
459 ConnectionState = ConnectionState.Disconnected; 598 ConnectionState = ConnectionState.Disconnected;
460 599
461 m_log.DebugFormat( 600 m_log.DebugFormat(
462 "[BOT]: Bot {0} disconnected reason {1}, message {2}", Name, args.Reason, args.Message); 601 "[BOT]: Bot {0} disconnected from grid, reason {1}, message {2}", Name, args.Reason, args.Message);
463 602
464// m_log.ErrorFormat("Fired Network_OnDisconnected"); 603// m_log.ErrorFormat("Fired Network_OnDisconnected");
465 604
@@ -468,6 +607,8 @@ namespace pCampBot
468// || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) 607// || args.Reason == NetworkManager.DisconnectType.NetworkTimeout)
469// && OnDisconnected != null) 608// && OnDisconnected != null)
470 609
610
611
471 if ( 612 if (
472 (args.Reason == NetworkManager.DisconnectType.ClientInitiated 613 (args.Reason == NetworkManager.DisconnectType.ClientInitiated
473 || args.Reason == NetworkManager.DisconnectType.ServerInitiated 614 || args.Reason == NetworkManager.DisconnectType.ServerInitiated
@@ -481,8 +622,8 @@ namespace pCampBot
481 622
482 public void Objects_NewPrim(object sender, PrimEventArgs args) 623 public void Objects_NewPrim(object sender, PrimEventArgs args)
483 { 624 {
484// if (Name.EndsWith("4")) 625 if (!RequestObjectTextures)
485// throw new Exception("Aaargh"); 626 return;
486 627
487 Primitive prim = args.Prim; 628 Primitive prim = args.Prim;
488 629