diff options
Diffstat (limited to 'OpenSim/Tools/pCampBot/Bot.cs')
-rw-r--r-- | OpenSim/Tools/pCampBot/Bot.cs | 142 |
1 files changed, 117 insertions, 25 deletions
diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs index 32bf32b..d418288 100644 --- a/OpenSim/Tools/pCampBot/Bot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs | |||
@@ -97,6 +97,28 @@ namespace pCampBot | |||
97 | /// </summary> | 97 | /// </summary> |
98 | public ConnectionState ConnectionState { get; private set; } | 98 | public ConnectionState ConnectionState { get; private set; } |
99 | 99 | ||
100 | public List<Simulator> Simulators | ||
101 | { | ||
102 | get | ||
103 | { | ||
104 | lock (Client.Network.Simulators) | ||
105 | return new List<Simulator>(Client.Network.Simulators); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | /// <summary> | ||
110 | /// The number of connections that this bot has to different simulators. | ||
111 | /// </summary> | ||
112 | /// <value>Includes both root and child connections.</value> | ||
113 | public int SimulatorsCount | ||
114 | { | ||
115 | get | ||
116 | { | ||
117 | lock (Client.Network.Simulators) | ||
118 | return Client.Network.Simulators.Count; | ||
119 | } | ||
120 | } | ||
121 | |||
100 | public string FirstName { get; private set; } | 122 | public string FirstName { get; private set; } |
101 | public string LastName { get; private set; } | 123 | public string LastName { get; private set; } |
102 | public string Name { get; private set; } | 124 | public string Name { get; private set; } |
@@ -144,8 +166,6 @@ namespace pCampBot | |||
144 | ConnectionState = ConnectionState.Disconnected; | 166 | ConnectionState = ConnectionState.Disconnected; |
145 | 167 | ||
146 | behaviours.ForEach(b => b.Initialize(this)); | 168 | behaviours.ForEach(b => b.Initialize(this)); |
147 | |||
148 | Client = new GridClient(); | ||
149 | 169 | ||
150 | Random = new Random(Environment.TickCount);// We do stuff randomly here | 170 | Random = new Random(Environment.TickCount);// We do stuff randomly here |
151 | FirstName = firstName; | 171 | FirstName = firstName; |
@@ -157,6 +177,59 @@ namespace pCampBot | |||
157 | 177 | ||
158 | Manager = bm; | 178 | Manager = bm; |
159 | Behaviours = behaviours; | 179 | Behaviours = behaviours; |
180 | |||
181 | // Only calling for use as a template. | ||
182 | CreateLibOmvClient(); | ||
183 | } | ||
184 | |||
185 | private void CreateLibOmvClient() | ||
186 | { | ||
187 | GridClient newClient = new GridClient(); | ||
188 | |||
189 | if (Client != null) | ||
190 | { | ||
191 | newClient.Settings.LOGIN_SERVER = Client.Settings.LOGIN_SERVER; | ||
192 | newClient.Settings.ALWAYS_DECODE_OBJECTS = Client.Settings.ALWAYS_DECODE_OBJECTS; | ||
193 | newClient.Settings.AVATAR_TRACKING = Client.Settings.AVATAR_TRACKING; | ||
194 | newClient.Settings.OBJECT_TRACKING = Client.Settings.OBJECT_TRACKING; | ||
195 | newClient.Settings.SEND_AGENT_THROTTLE = Client.Settings.SEND_AGENT_THROTTLE; | ||
196 | newClient.Settings.SEND_AGENT_UPDATES = Client.Settings.SEND_AGENT_UPDATES; | ||
197 | newClient.Settings.SEND_PINGS = Client.Settings.SEND_PINGS; | ||
198 | newClient.Settings.STORE_LAND_PATCHES = Client.Settings.STORE_LAND_PATCHES; | ||
199 | newClient.Settings.USE_ASSET_CACHE = Client.Settings.USE_ASSET_CACHE; | ||
200 | newClient.Settings.MULTIPLE_SIMS = Client.Settings.MULTIPLE_SIMS; | ||
201 | newClient.Throttle.Asset = Client.Throttle.Asset; | ||
202 | newClient.Throttle.Land = Client.Throttle.Land; | ||
203 | newClient.Throttle.Task = Client.Throttle.Task; | ||
204 | newClient.Throttle.Texture = Client.Throttle.Texture; | ||
205 | newClient.Throttle.Wind = Client.Throttle.Wind; | ||
206 | newClient.Throttle.Total = Client.Throttle.Total; | ||
207 | } | ||
208 | else | ||
209 | { | ||
210 | newClient.Settings.LOGIN_SERVER = LoginUri; | ||
211 | newClient.Settings.ALWAYS_DECODE_OBJECTS = false; | ||
212 | newClient.Settings.AVATAR_TRACKING = false; | ||
213 | newClient.Settings.OBJECT_TRACKING = false; | ||
214 | newClient.Settings.SEND_AGENT_THROTTLE = true; | ||
215 | newClient.Settings.SEND_PINGS = true; | ||
216 | newClient.Settings.STORE_LAND_PATCHES = false; | ||
217 | newClient.Settings.USE_ASSET_CACHE = false; | ||
218 | newClient.Settings.MULTIPLE_SIMS = true; | ||
219 | newClient.Throttle.Asset = 100000; | ||
220 | newClient.Throttle.Land = 100000; | ||
221 | newClient.Throttle.Task = 100000; | ||
222 | newClient.Throttle.Texture = 100000; | ||
223 | newClient.Throttle.Wind = 100000; | ||
224 | newClient.Throttle.Total = 400000; | ||
225 | } | ||
226 | |||
227 | newClient.Network.LoginProgress += this.Network_LoginProgress; | ||
228 | newClient.Network.SimConnected += this.Network_SimConnected; | ||
229 | newClient.Network.Disconnected += this.Network_OnDisconnected; | ||
230 | newClient.Objects.ObjectUpdate += Objects_NewPrim; | ||
231 | |||
232 | Client = newClient; | ||
160 | } | 233 | } |
161 | 234 | ||
162 | //We do our actions here. This is where one would | 235 | //We do our actions here. This is where one would |
@@ -179,7 +252,7 @@ namespace pCampBot | |||
179 | /// <summary> | 252 | /// <summary> |
180 | /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes. | 253 | /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes. |
181 | /// </summary> | 254 | /// </summary> |
182 | public void shutdown() | 255 | public void Disconnect() |
183 | { | 256 | { |
184 | ConnectionState = ConnectionState.Disconnecting; | 257 | ConnectionState = ConnectionState.Disconnecting; |
185 | 258 | ||
@@ -189,34 +262,27 @@ namespace pCampBot | |||
189 | Client.Network.Logout(); | 262 | Client.Network.Logout(); |
190 | } | 263 | } |
191 | 264 | ||
265 | public void Connect() | ||
266 | { | ||
267 | Thread connectThread = new Thread(ConnectInternal); | ||
268 | connectThread.Name = Name; | ||
269 | connectThread.IsBackground = true; | ||
270 | |||
271 | connectThread.Start(); | ||
272 | } | ||
273 | |||
192 | /// <summary> | 274 | /// <summary> |
193 | /// This is the bot startup loop. | 275 | /// This is the bot startup loop. |
194 | /// </summary> | 276 | /// </summary> |
195 | public void startup() | 277 | private void ConnectInternal() |
196 | { | 278 | { |
197 | Client.Settings.LOGIN_SERVER = LoginUri; | ||
198 | Client.Settings.ALWAYS_DECODE_OBJECTS = false; | ||
199 | Client.Settings.AVATAR_TRACKING = false; | ||
200 | Client.Settings.OBJECT_TRACKING = false; | ||
201 | Client.Settings.SEND_AGENT_THROTTLE = true; | ||
202 | Client.Settings.SEND_AGENT_UPDATES = false; | ||
203 | Client.Settings.SEND_PINGS = true; | ||
204 | Client.Settings.STORE_LAND_PATCHES = false; | ||
205 | Client.Settings.USE_ASSET_CACHE = false; | ||
206 | Client.Settings.MULTIPLE_SIMS = true; | ||
207 | Client.Throttle.Asset = 100000; | ||
208 | Client.Throttle.Land = 100000; | ||
209 | Client.Throttle.Task = 100000; | ||
210 | Client.Throttle.Texture = 100000; | ||
211 | Client.Throttle.Wind = 100000; | ||
212 | Client.Throttle.Total = 400000; | ||
213 | Client.Network.LoginProgress += this.Network_LoginProgress; | ||
214 | Client.Network.SimConnected += this.Network_SimConnected; | ||
215 | Client.Network.Disconnected += this.Network_OnDisconnected; | ||
216 | Client.Objects.ObjectUpdate += Objects_NewPrim; | ||
217 | |||
218 | ConnectionState = ConnectionState.Connecting; | 279 | ConnectionState = ConnectionState.Connecting; |
219 | 280 | ||
281 | // Current create a new client on each connect. libomv doesn't seem to process new sim | ||
282 | // information (e.g. EstablishAgentCommunication events) if connecting after a disceonnect with the same | ||
283 | // client | ||
284 | CreateLibOmvClient(); | ||
285 | |||
220 | if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", StartLocation, "Your name")) | 286 | if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", StartLocation, "Your name")) |
221 | { | 287 | { |
222 | ConnectionState = ConnectionState.Connected; | 288 | ConnectionState = ConnectionState.Connected; |
@@ -261,6 +327,30 @@ namespace pCampBot | |||
261 | } | 327 | } |
262 | } | 328 | } |
263 | 329 | ||
330 | /// <summary> | ||
331 | /// Sit this bot on the ground. | ||
332 | /// </summary> | ||
333 | public void SitOnGround() | ||
334 | { | ||
335 | if (ConnectionState == ConnectionState.Connected) | ||
336 | Client.Self.SitOnGround(); | ||
337 | } | ||
338 | |||
339 | /// <summary> | ||
340 | /// Stand this bot | ||
341 | /// </summary> | ||
342 | public void Stand() | ||
343 | { | ||
344 | if (ConnectionState == ConnectionState.Connected) | ||
345 | { | ||
346 | // Unlike sit on ground, here libomv checks whether we have SEND_AGENT_UPDATES enabled. | ||
347 | bool prevUpdatesSetting = Client.Settings.SEND_AGENT_UPDATES; | ||
348 | Client.Settings.SEND_AGENT_UPDATES = true; | ||
349 | Client.Self.Stand(); | ||
350 | Client.Settings.SEND_AGENT_UPDATES = prevUpdatesSetting; | ||
351 | } | ||
352 | } | ||
353 | |||
264 | public void SaveDefaultAppearance() | 354 | public void SaveDefaultAppearance() |
265 | { | 355 | { |
266 | saveDir = "MyAppearance/" + FirstName + "_" + LastName; | 356 | saveDir = "MyAppearance/" + FirstName + "_" + LastName; |
@@ -461,6 +551,8 @@ namespace pCampBot | |||
461 | // || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) | 551 | // || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) |
462 | // && OnDisconnected != null) | 552 | // && OnDisconnected != null) |
463 | 553 | ||
554 | |||
555 | |||
464 | if ( | 556 | if ( |
465 | (args.Reason == NetworkManager.DisconnectType.ClientInitiated | 557 | (args.Reason == NetworkManager.DisconnectType.ClientInitiated |
466 | || args.Reason == NetworkManager.DisconnectType.ServerInitiated | 558 | || args.Reason == NetworkManager.DisconnectType.ServerInitiated |