aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot/PhysicsBot.cs
diff options
context:
space:
mode:
authorJeff Ames2008-02-15 02:53:05 +0000
committerJeff Ames2008-02-15 02:53:05 +0000
commit21b623b70e33b80dc8caae3b1730bcd8069e3caa (patch)
tree72e4640a56de3b8cfc03589d24b380da80984f7a /OpenSim/Tools/pCampBot/PhysicsBot.cs
parentOops. Forgot about Windows users. (diff)
downloadopensim-SC_OLD-21b623b70e33b80dc8caae3b1730bcd8069e3caa.zip
opensim-SC_OLD-21b623b70e33b80dc8caae3b1730bcd8069e3caa.tar.gz
opensim-SC_OLD-21b623b70e33b80dc8caae3b1730bcd8069e3caa.tar.bz2
opensim-SC_OLD-21b623b70e33b80dc8caae3b1730bcd8069e3caa.tar.xz
Moved pCampBot to OpenSim/Tools
Diffstat (limited to 'OpenSim/Tools/pCampBot/PhysicsBot.cs')
-rw-r--r--OpenSim/Tools/pCampBot/PhysicsBot.cs191
1 files changed, 191 insertions, 0 deletions
diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs
new file mode 100644
index 0000000..500683a
--- /dev/null
+++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs
@@ -0,0 +1,191 @@
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 //New instance of a SecondLife client
61 public SecondLife client = new SecondLife();
62
63 protected string[] talkarray;
64 /// <summary>
65 ///
66 /// </summary>
67 /// <param name="bsconfig">nini config for the bot</param>
68 public PhysicsBot(IConfig bsconfig)
69 {
70 startupConfig = bsconfig;
71 readconfig();
72 talkarray = readexcuses();
73 }
74
75 //We do our actions here. This is where one would
76 //add additional steps and/or things the bot should do
77
78 void m_action_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
79 {
80 //client.Throttle.Task = 500000f;
81 //client.Throttle.Set();
82
83 client.Self.Movement.AlwaysRun = true;
84 LLVector3 pos = client.Self.SimPosition;
85 LLVector3 newpos = new LLVector3(somthing.Next(255),somthing.Next(255),somthing.Next(255));
86
87
88 client.Self.Movement.TurnToward(newpos);
89 for (int i = 0; i < 2000; i++)
90 {
91 client.Self.Movement.AtPos = true;
92 }
93 client.Self.Jump();
94 string randomf = talkarray[somthing.Next(talkarray.Length)];
95 if (talkarray.Length > 1 && randomf.Length > 1)
96 client.Self.Chat("Can't do it, " + randomf, 0, ChatType.Normal);
97
98 Thread.Sleep(somthing.Next(1,20));
99
100 }
101
102 /// <summary>
103 /// Read the Nini config and initialize
104 /// </summary>
105 public void readconfig()
106 {
107 firstname = startupConfig.GetString("firstname", "random");
108 lastname = startupConfig.GetString("lastname", "random");
109 password = startupConfig.GetString("password", "12345");
110 loginURI = startupConfig.GetString("loginuri", "http://10.1.1.5:9000");
111
112
113
114 }
115
116 /// <summary>
117 /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes.
118 /// </summary>
119 public void shutdown()
120 {
121 client.Network.Logout();
122 }
123
124 /// <summary>
125 /// This is the bot startup loop.
126 /// </summary>
127 public void startup()
128 {
129 client.Settings.LOGIN_SERVER = loginURI;
130 client.Network.OnConnected += new NetworkManager.ConnectedCallback(this.Network_OnConnected);
131 client.Network.OnSimConnected += new NetworkManager.SimConnectedCallback(this.Network_OnConnected);
132 client.Network.OnDisconnected += new NetworkManager.DisconnectedCallback(this.Network_OnDisconnected);
133 if (client.Network.Login(firstname, lastname, password, "pCampBot", "Your name"))
134 {
135
136 if (OnConnected != null)
137 {
138 m_action = new Timer(somthing.Next(1000, 10000));
139 m_action.Elapsed += new System.Timers.ElapsedEventHandler(m_action_Elapsed);
140 m_action.Start();
141 OnConnected(this, EventType.CONNECTED);
142 client.Self.Jump();
143
144 }
145 }
146 else
147 {
148 MainConsole.Instance.Error(firstname + " " + lastname, "Can't login: " + client.Network.LoginMessage);
149 if (OnDisconnected != null)
150 {
151 OnDisconnected(this, EventType.DISCONNECTED);
152 }
153 }
154 }
155
156 public void Network_OnConnected(object sender)
157 {
158 if (OnConnected != null)
159 {
160 OnConnected(this, EventType.CONNECTED);
161 }
162 }
163
164 public void Simulator_Connected(object sender)
165 {
166 }
167
168 public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
169 {
170 if (OnDisconnected != null)
171 {
172 OnDisconnected(this,EventType.DISCONNECTED);
173 }
174 }
175
176 public string[] readexcuses()
177 {
178 string allexcuses = "";
179
180 string file = Path.Combine(Util.configDir(), "excuses");
181 if (File.Exists(file))
182 {
183 StreamReader csr = File.OpenText(file);
184 allexcuses = csr.ReadToEnd();
185 csr.Close();
186 }
187
188 return allexcuses.Split(Environment.NewLine.ToCharArray());
189 }
190 }
191}