aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/pCampBot/PhysicsBot.cs
diff options
context:
space:
mode:
authorTeravus Ovares2008-02-03 04:13:46 +0000
committerTeravus Ovares2008-02-03 04:13:46 +0000
commitb0c6baaeb05c5f15c951d3128419fac82b399911 (patch)
tree2ca4b26583e5371e2b3fa177574f0ffe76364cbd /pCampBot/PhysicsBot.cs
parentImplements LSL function llDialog(). (diff)
downloadopensim-SC-b0c6baaeb05c5f15c951d3128419fac82b399911.zip
opensim-SC-b0c6baaeb05c5f15c951d3128419fac82b399911.tar.gz
opensim-SC-b0c6baaeb05c5f15c951d3128419fac82b399911.tar.bz2
opensim-SC-b0c6baaeb05c5f15c951d3128419fac82b399911.tar.xz
* Adding the PhysicsCamperBot load testing app to the SVN in it's own folder. You'll have to build it separately to take advantage of it. *read the Readme file*. The bots created by this application roam around amusingly to simulate load.
* Be smart, Don't use this on a public grid, lest you get banned permanently.
Diffstat (limited to '')
-rw-r--r--pCampBot/PhysicsBot.cs208
1 files changed, 208 insertions, 0 deletions
diff --git a/pCampBot/PhysicsBot.cs b/pCampBot/PhysicsBot.cs
new file mode 100644
index 0000000..53a774a
--- /dev/null
+++ b/pCampBot/PhysicsBot.cs
@@ -0,0 +1,208 @@
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 OpenSim 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
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Text;
33using libsecondlife;
34using libsecondlife.Packets;
35using Nini.Config;
36using System.Threading;
37using OpenSim.Framework;
38using OpenSim.Framework.Console;
39using Timer=System.Timers.Timer;
40
41
42
43namespace pCampBot
44{
45 public class PhysicsBot
46 {
47 public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events
48 public IConfig startupConfig; // bot config, passed from BotManager
49
50 public string firstname;
51 public string lastname;
52 public string password;
53 public string loginURI;
54
55 public event AnEvent OnConnected;
56 public event AnEvent OnDisconnected;
57
58 protected Timer m_action; // Action Timer
59
60 protected Random somthing = new Random(System.Environment.TickCount);// We do stuff randomly here
61
62 //New instance of a SecondLife client
63 public SecondLife client = new SecondLife();
64
65 protected string[] talkarray;
66 /// <summary>
67 ///
68 /// </summary>
69 /// <param name="bsconfig">nini config for the bot</param>
70 public PhysicsBot(IConfig bsconfig)
71 {
72 startupConfig = bsconfig;
73 readconfig();
74 talkarray = readexcuses();
75 }
76
77 //We do our actions here. This is where one would
78 //add additional steps and/or things the bot should do
79
80 void m_action_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
81 {
82 //client.Throttle.Task = 500000f;
83 //client.Throttle.Set();
84
85 client.Self.Movement.AlwaysRun = true;
86 LLVector3 pos = client.Self.SimPosition;
87 LLVector3 newpos = new LLVector3(somthing.Next(255),somthing.Next(255),somthing.Next(255));
88
89
90 client.Self.Movement.TurnToward(newpos);
91 for (int i = 0; i < 2000; i++)
92 {
93 client.Self.Movement.AtPos = true;
94 }
95 client.Self.Jump();
96 string randomf = talkarray[somthing.Next(talkarray.Length)];
97 if (talkarray.Length > 1 && randomf.Length > 1)
98 client.Self.Chat("Can't do it, " + randomf, 0, ChatType.Normal);
99
100 Thread.Sleep(somthing.Next(1,20));
101
102 }
103
104 /// <summary>
105 /// Read the Nini config and initialize
106 /// </summary>
107 public void readconfig()
108 {
109 firstname = startupConfig.GetString("firstname", "random");
110 lastname = startupConfig.GetString("lastname", "random");
111 password = startupConfig.GetString("password", "12345");
112 loginURI = startupConfig.GetString("loginuri", "http://10.1.1.5:9000");
113
114
115
116 }
117
118 /// <summary>
119 /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes.
120 /// </summary>
121 public void shutdown()
122 {
123 client.Network.Logout();
124 }
125 /// <summary>
126 /// This is the bot startup loop.
127 /// </summary>
128 public void startup()
129 {
130
131 client.Settings.LOGIN_SERVER = loginURI;
132 client.Network.OnConnected += new NetworkManager.ConnectedCallback(this.Network_OnConnected);
133 client.Network.OnSimConnected += new NetworkManager.SimConnectedCallback(this.Network_OnConnected);
134 client.Network.OnDisconnected += new NetworkManager.DisconnectedCallback(this.Network_OnDisconnected);
135 if (client.Network.Login(firstname, lastname, password, "pCampBot", "Your name"))
136 {
137
138 if (OnConnected != null)
139 {
140 m_action = new Timer(somthing.Next(1000, 10000));
141 m_action.Elapsed += new System.Timers.ElapsedEventHandler(m_action_Elapsed);
142 m_action.Start();
143 OnConnected(this, EventType.CONNECTED);
144 client.Self.Jump();
145
146 }
147 }
148 else
149 {
150
151 MainLog.Instance.Error(firstname + " " + lastname,"Can't Log in: " + client.Network.LoginMessage);
152 if (OnDisconnected != null)
153 {
154 OnDisconnected(this, EventType.DISCONNECTED);
155 }
156 }
157
158 }
159
160 public void Network_OnConnected(object sender)
161 {
162 if (OnConnected != null)
163 {
164 OnConnected(this, EventType.CONNECTED);
165 }
166
167 }
168 public void Simulator_Connected(object sender)
169 {
170
171
172 }
173
174 public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
175 {
176 if (OnDisconnected != null)
177 {
178 OnDisconnected(this,EventType.DISCONNECTED);
179 }
180
181
182 }
183 public string[] readexcuses()
184 {
185
186
187
188 string allexcuses = "";
189
190
191 string file = Path.Combine(Util.configDir(), "excuses");
192 if (File.Exists(file))
193 {
194 StreamReader csr = File.OpenText(file);
195 allexcuses = csr.ReadToEnd();
196 csr.Close();
197 }
198
199
200 return allexcuses.Split(Environment.NewLine.ToCharArray());
201
202 }
203
204
205 }
206
207
208}