aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/TestSuite/PhysicsBot.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/TestSuite/PhysicsBot.cs203
1 files changed, 203 insertions, 0 deletions
diff --git a/OpenSim/TestSuite/PhysicsBot.cs b/OpenSim/TestSuite/PhysicsBot.cs
new file mode 100644
index 0000000..3e12bb1
--- /dev/null
+++ b/OpenSim/TestSuite/PhysicsBot.cs
@@ -0,0 +1,203 @@
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
41namespace pCampBot
42{
43 public class PhysicsBot
44 {
45 public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events
46 public IConfig startupConfig; // bot config, passed from BotManager
47
48 public string firstname;
49 public string lastname;
50 public string password;
51 public string loginURI;
52
53 public event AnEvent OnConnected;
54 public event AnEvent OnDisconnected;
55
56 protected Timer m_action; // Action Timer
57
58 protected Random somthing = new Random(System.Environment.TickCount);// We do stuff randomly here
59
60 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
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 int walkorrun = somthing.Next(4); // Randomize between walking and running. The greater this number,
85 // the greater the bot's chances to walk instead of run.
86 if (walkorrun == 0)
87 {
88 client.Self.Movement.AlwaysRun = true;
89 }
90 else
91 {
92 client.Self.Movement.AlwaysRun = false;
93 }
94
95 LLVector3 pos = client.Self.SimPosition;
96 LLVector3 newpos = new LLVector3(somthing.Next(255), somthing.Next(255), somthing.Next(255));
97 client.Self.Movement.TurnToward(newpos);
98
99 for (int i = 0; i < 2000; i++)
100 {
101 client.Self.Movement.AtPos = true;
102 Thread.Sleep(somthing.Next(25, 75)); // Makes sure the bots keep walking for this time.
103 }
104 client.Self.Jump();
105
106 string randomf = talkarray[somthing.Next(talkarray.Length)];
107 if (talkarray.Length > 1 && randomf.Length > 1)
108 client.Self.Chat(randomf, 0, ChatType.Normal);
109
110 //Thread.Sleep(somthing.Next(1, 10)); // Apparently its better without it right now.
111
112 }
113
114 /// <summary>
115 /// Read the Nini config and initialize
116 /// </summary>
117 public void readconfig()
118 {
119 firstname = startupConfig.GetString("firstname", "random");
120 lastname = startupConfig.GetString("lastname", "random");
121 password = startupConfig.GetString("password", "12345");
122 loginURI = startupConfig.GetString("loginuri");
123
124
125
126 }
127
128 /// <summary>
129 /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes.
130 /// </summary>
131 public void shutdown()
132 {
133 client.Network.Logout();
134 }
135
136 /// <summary>
137 /// This is the bot startup loop.
138 /// </summary>
139 public void startup()
140 {
141 client.Settings.LOGIN_SERVER = loginURI;
142 client.Network.OnConnected += new NetworkManager.ConnectedCallback(this.Network_OnConnected);
143 client.Network.OnSimConnected += new NetworkManager.SimConnectedCallback(this.Network_OnConnected);
144 client.Network.OnDisconnected += new NetworkManager.DisconnectedCallback(this.Network_OnDisconnected);
145 if (client.Network.Login(firstname, lastname, password, "pCampBot", "Your name"))
146 {
147
148 if (OnConnected != null)
149 {
150 m_action = new Timer(somthing.Next(1000, 10000));
151 m_action.Elapsed += new System.Timers.ElapsedEventHandler(m_action_Elapsed);
152 m_action.Start();
153 OnConnected(this, EventType.CONNECTED);
154 client.Self.Jump();
155
156 }
157 }
158 else
159 {
160 MainConsole.Instance.Error(firstname + " " + lastname, "Can't login: " + client.Network.LoginMessage);
161 if (OnDisconnected != null)
162 {
163 OnDisconnected(this, EventType.DISCONNECTED);
164 }
165 }
166 }
167
168 public void Network_OnConnected(object sender)
169 {
170 if (OnConnected != null)
171 {
172 OnConnected(this, EventType.CONNECTED);
173 }
174 }
175
176 public void Simulator_Connected(object sender)
177 {
178 }
179
180 public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
181 {
182 if (OnDisconnected != null)
183 {
184 OnDisconnected(this, EventType.DISCONNECTED);
185 }
186 }
187
188 public string[] readexcuses()
189 {
190 string allexcuses = "";
191
192 string file = Path.Combine(Util.configDir(), "pCampBotSentences.txt");
193 if (File.Exists(file))
194 {
195 StreamReader csr = File.OpenText(file);
196 allexcuses = csr.ReadToEnd();
197 csr.Close();
198 }
199
200 return allexcuses.Split(Environment.NewLine.ToCharArray());
201 }
202 }
203}