diff options
author | Justin Clark-Casey (justincc) | 2011-10-31 23:10:10 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-10-31 23:10:10 +0000 |
commit | 210868a832439bb226dfcf153ca66563300dc2cf (patch) | |
tree | e74ba51bc117b8b35cf8fafb06f6e182c2b31cdc /OpenSim/TestSuite/PhysicsBot.cs | |
parent | Stop individual bots attempting to download the same asset more than once (diff) | |
download | opensim-SC_OLD-210868a832439bb226dfcf153ca66563300dc2cf.zip opensim-SC_OLD-210868a832439bb226dfcf153ca66563300dc2cf.tar.gz opensim-SC_OLD-210868a832439bb226dfcf153ca66563300dc2cf.tar.bz2 opensim-SC_OLD-210868a832439bb226dfcf153ca66563300dc2cf.tar.xz |
Remove OpenSim.TestSuite
Hasn't been touched since 2009 and wasn't more than another copy of pCampBot
Diffstat (limited to 'OpenSim/TestSuite/PhysicsBot.cs')
-rw-r--r-- | OpenSim/TestSuite/PhysicsBot.cs | 196 |
1 files changed, 0 insertions, 196 deletions
diff --git a/OpenSim/TestSuite/PhysicsBot.cs b/OpenSim/TestSuite/PhysicsBot.cs deleted file mode 100644 index fac4275..0000000 --- a/OpenSim/TestSuite/PhysicsBot.cs +++ /dev/null | |||
@@ -1,196 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.IO; | ||
30 | using System.Threading; | ||
31 | using System.Timers; | ||
32 | using OpenMetaverse; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Console; | ||
36 | using Timer=System.Timers.Timer; | ||
37 | |||
38 | namespace OpenSim.TestSuite | ||
39 | { | ||
40 | public class PhysicsBot | ||
41 | { | ||
42 | public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events | ||
43 | public IConfig startupConfig; // bot config, passed from BotManager | ||
44 | |||
45 | public string firstname; | ||
46 | public string lastname; | ||
47 | public string password; | ||
48 | public string loginURI; | ||
49 | |||
50 | public event AnEvent OnConnected; | ||
51 | public event AnEvent OnDisconnected; | ||
52 | |||
53 | protected Timer m_action; // Action Timer | ||
54 | |||
55 | protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here | ||
56 | |||
57 | //New instance of a SecondLife client | ||
58 | public GridClient client = new GridClient(); | ||
59 | |||
60 | protected string[] talkarray; | ||
61 | /// <summary> | ||
62 | /// | ||
63 | /// </summary> | ||
64 | /// <param name="bsconfig">nini config for the bot</param> | ||
65 | public PhysicsBot(IConfig bsconfig) | ||
66 | { | ||
67 | startupConfig = bsconfig; | ||
68 | readconfig(); | ||
69 | talkarray = readexcuses(); | ||
70 | } | ||
71 | |||
72 | //We do our actions here. This is where one would | ||
73 | //add additional steps and/or things the bot should do | ||
74 | |||
75 | void m_action_Elapsed(object sender, ElapsedEventArgs e) | ||
76 | { | ||
77 | //client.Throttle.Task = 500000f; | ||
78 | //client.Throttle.Set(); | ||
79 | int walkorrun = somthing.Next(4); // Randomize between walking and running. The greater this number, | ||
80 | // the greater the bot's chances to walk instead of run. | ||
81 | if (walkorrun == 0) | ||
82 | { | ||
83 | client.Self.Movement.AlwaysRun = true; | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | client.Self.Movement.AlwaysRun = false; | ||
88 | } | ||
89 | |||
90 | // TODO: unused: Vector3 pos = client.Self.SimPosition; | ||
91 | Vector3 newpos = new Vector3(somthing.Next(255), somthing.Next(255), somthing.Next(255)); | ||
92 | client.Self.Movement.TurnToward(newpos); | ||
93 | |||
94 | for (int i = 0; i < 2000; i++) | ||
95 | { | ||
96 | client.Self.Movement.AtPos = true; | ||
97 | Thread.Sleep(somthing.Next(25, 75)); // Makes sure the bots keep walking for this time. | ||
98 | } | ||
99 | client.Self.Jump(true); | ||
100 | |||
101 | string randomf = talkarray[somthing.Next(talkarray.Length)]; | ||
102 | if (talkarray.Length > 1 && randomf.Length > 1) | ||
103 | client.Self.Chat(randomf, 0, ChatType.Normal); | ||
104 | |||
105 | //Thread.Sleep(somthing.Next(1, 10)); // Apparently its better without it right now. | ||
106 | } | ||
107 | |||
108 | /// <summary> | ||
109 | /// Read the Nini config and initialize | ||
110 | /// </summary> | ||
111 | public void readconfig() | ||
112 | { | ||
113 | firstname = startupConfig.GetString("firstname", "random"); | ||
114 | lastname = startupConfig.GetString("lastname", "random"); | ||
115 | password = startupConfig.GetString("password", "12345"); | ||
116 | loginURI = startupConfig.GetString("loginuri"); | ||
117 | } | ||
118 | |||
119 | /// <summary> | ||
120 | /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes. | ||
121 | /// </summary> | ||
122 | public void shutdown() | ||
123 | { | ||
124 | client.Network.Logout(); | ||
125 | } | ||
126 | |||
127 | /// <summary> | ||
128 | /// This is the bot startup loop. | ||
129 | /// </summary> | ||
130 | public void startup() | ||
131 | { | ||
132 | client.Settings.LOGIN_SERVER = loginURI; | ||
133 | client.Network.LoginProgress += this.Network_LoginProgress; | ||
134 | client.Network.SimConnected += this.Network_SimConnected; | ||
135 | client.Network.Disconnected += this.Network_OnDisconnected; | ||
136 | if (client.Network.Login(firstname, lastname, password, "pCampBot", "Your name")) | ||
137 | { | ||
138 | |||
139 | if (OnConnected != null) | ||
140 | { | ||
141 | m_action = new Timer(somthing.Next(1000, 10000)); | ||
142 | m_action.Elapsed += new ElapsedEventHandler(m_action_Elapsed); | ||
143 | m_action.Start(); | ||
144 | OnConnected(this, EventType.CONNECTED); | ||
145 | client.Self.Jump(true); | ||
146 | } | ||
147 | } | ||
148 | else | ||
149 | { | ||
150 | MainConsole.Instance.Output(firstname + " " + lastname + "Can't login: " + client.Network.LoginMessage); | ||
151 | if (OnDisconnected != null) | ||
152 | { | ||
153 | OnDisconnected(this, EventType.DISCONNECTED); | ||
154 | } | ||
155 | } | ||
156 | } | ||
157 | |||
158 | public void Network_LoginProgress(object sender, LoginProgressEventArgs args) | ||
159 | { | ||
160 | if (args.Status == LoginStatus.Success) | ||
161 | { | ||
162 | if (OnConnected != null) | ||
163 | { | ||
164 | OnConnected(this, EventType.CONNECTED); | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | |||
169 | public void Network_SimConnected(object sender, SimConnectedEventArgs args) | ||
170 | { | ||
171 | } | ||
172 | |||
173 | public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) | ||
174 | { | ||
175 | if (OnDisconnected != null) | ||
176 | { | ||
177 | OnDisconnected(this, EventType.DISCONNECTED); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | public string[] readexcuses() | ||
182 | { | ||
183 | string allexcuses = ""; | ||
184 | |||
185 | string file = Path.Combine(Util.configDir(), "pCampBotSentences.txt"); | ||
186 | if (File.Exists(file)) | ||
187 | { | ||
188 | StreamReader csr = File.OpenText(file); | ||
189 | allexcuses = csr.ReadToEnd(); | ||
190 | csr.Close(); | ||
191 | } | ||
192 | |||
193 | return allexcuses.Split(Environment.NewLine.ToCharArray()); | ||
194 | } | ||
195 | } | ||
196 | } | ||