corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) 2006-2014, openmetaverse.org
3 * All rights reserved.
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 *
8 * - Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * - Neither the name of the openmetaverse.org nor the names
11 * of its contributors may be used to endorse or promote products derived from
12 * this software without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26  
27 using System;
28 using System.Collections;
29 using System.Collections.Generic;
30 using System.Threading;
31 using OpenMetaverse;
32 using OpenMetaverse.Packets;
33  
34 namespace OpenMetaverse.Utilities
35 {
36 /// <summary>
37 ///
38 /// </summary>
39 public enum WaterType
40 {
41 /// <summary></summary>
42 Unknown,
43 /// <summary></summary>
44 Dry,
45 /// <summary></summary>
46 Waterfront,
47 /// <summary></summary>
48 Underwater
49 }
50  
51 public static class Realism
52 {
53 /// <summary>
54 /// Aims at the specified position, enters mouselook, presses and
55 /// releases the left mouse button, and leaves mouselook
56 /// </summary>
57 /// <param name="client"></param>
58 /// <param name="target">Target to shoot at</param>
59 /// <returns></returns>
60 public static bool Shoot(GridClient client, Vector3 target)
61 {
62 if (client.Self.Movement.TurnToward(target))
63 return Shoot(client);
64 else
65 return false;
66 }
67  
68 /// <summary>
69 /// Enters mouselook, presses and releases the left mouse button, and leaves mouselook
70 /// </summary>
71 /// <returns></returns>
72 public static bool Shoot(GridClient client)
73 {
74 if (client.Settings.SEND_AGENT_UPDATES)
75 {
76 client.Self.Movement.Mouselook = true;
77 client.Self.Movement.MLButtonDown = true;
78 client.Self.Movement.SendUpdate();
79  
80 client.Self.Movement.MLButtonUp = true;
81 client.Self.Movement.MLButtonDown = false;
82 client.Self.Movement.FinishAnim = true;
83 client.Self.Movement.SendUpdate();
84  
85 client.Self.Movement.Mouselook = false;
86 client.Self.Movement.MLButtonUp = false;
87 client.Self.Movement.FinishAnim = false;
88 client.Self.Movement.SendUpdate();
89  
90 return true;
91 }
92 else
93 {
94 Logger.Log("Attempted Shoot but agent updates are disabled", Helpers.LogLevel.Warning, client);
95 return false;
96 }
97 }
98  
99 /// <summary>
100 /// A psuedo-realistic chat function that uses the typing sound and
101 /// animation, types at three characters per second, and randomly
102 /// pauses. This function will block until the message has been sent
103 /// </summary>
104 /// <param name="client">A reference to the client that will chat</param>
105 /// <param name="message">The chat message to send</param>
106 public static void Chat(GridClient client, string message)
107 {
108 Chat(client, message, ChatType.Normal, 3);
109 }
110  
111 /// <summary>
112 /// A psuedo-realistic chat function that uses the typing sound and
113 /// animation, types at a given rate, and randomly pauses. This
114 /// function will block until the message has been sent
115 /// </summary>
116 /// <param name="client">A reference to the client that will chat</param>
117 /// <param name="message">The chat message to send</param>
118 /// <param name="type">The chat type (usually Normal, Whisper or Shout)</param>
119 /// <param name="cps">Characters per second rate for chatting</param>
120 public static void Chat(GridClient client, string message, ChatType type, int cps)
121 {
122 Random rand = new Random();
123 int characters = 0;
124 bool typing = true;
125  
126 // Start typing
127 client.Self.Chat(String.Empty, 0, ChatType.StartTyping);
128 client.Self.AnimationStart(Animations.TYPE, false);
129  
130 while (characters < message.Length)
131 {
132 if (!typing)
133 {
134 // Start typing again
135 client.Self.Chat(String.Empty, 0, ChatType.StartTyping);
136 client.Self.AnimationStart(Animations.TYPE, false);
137 typing = true;
138 }
139 else
140 {
141 // Randomly pause typing
142 if (rand.Next(10) >= 9)
143 {
144 client.Self.Chat(String.Empty, 0, ChatType.StopTyping);
145 client.Self.AnimationStop(Animations.TYPE, false);
146 typing = false;
147 }
148 }
149  
150 // Sleep for a second and increase the amount of characters we've typed
151 System.Threading.Thread.Sleep(1000);
152 characters += cps;
153 }
154  
155 // Send the message
156 client.Self.Chat(message, 0, type);
157  
158 // Stop typing
159 client.Self.Chat(String.Empty, 0, ChatType.StopTyping);
160 client.Self.AnimationStop(Animations.TYPE, false);
161 }
162 }
163  
164 public class ConnectionManager
165 {
166 private GridClient Client;
167 private ulong SimHandle;
168 private Vector3 Position = Vector3.Zero;
169 private System.Timers.Timer CheckTimer;
170  
171 public ConnectionManager(GridClient client, int timerFrequency)
172 {
173 Client = client;
174  
175 CheckTimer = new System.Timers.Timer(timerFrequency);
176 CheckTimer.Elapsed += new System.Timers.ElapsedEventHandler(CheckTimer_Elapsed);
177 }
178  
179 public static bool PersistentLogin(GridClient client, string firstName, string lastName, string password,
180 string userAgent, string start, string author)
181 {
182 int unknownLogins = 0;
183  
184 Start:
185  
186 if (client.Network.Login(firstName, lastName, password, userAgent, start, author))
187 {
188 Logger.Log("Logged in to " + client.Network.CurrentSim, Helpers.LogLevel.Info, client);
189 return true;
190 }
191 else
192 {
193 if (client.Network.LoginErrorKey == "god")
194 {
195 Logger.Log("Grid is down, waiting 10 minutes", Helpers.LogLevel.Warning, client);
196 LoginWait(10);
197 goto Start;
198 }
199 else if (client.Network.LoginErrorKey == "key")
200 {
201 Logger.Log("Bad username or password, giving up on login", Helpers.LogLevel.Error, client);
202 return false;
203 }
204 else if (client.Network.LoginErrorKey == "presence")
205 {
206 Logger.Log("Server is still logging us out, waiting 1 minute", Helpers.LogLevel.Warning, client);
207 LoginWait(1);
208 goto Start;
209 }
210 else if (client.Network.LoginErrorKey == "disabled")
211 {
212 Logger.Log("This account has been banned! Giving up on login", Helpers.LogLevel.Error, client);
213 return false;
214 }
215 else if (client.Network.LoginErrorKey == "timed out" ||client.Network.LoginErrorKey == "no connection" )
216 {
217 Logger.Log("Login request timed out, waiting 1 minute", Helpers.LogLevel.Warning, client);
218 LoginWait(1);
219 goto Start;
220 } else if (client.Network.LoginErrorKey == "bad response") {
221 Logger.Log("Login server returned unparsable result", Helpers.LogLevel.Warning, client);
222 LoginWait(1);
223 goto Start;
224 } else
225 {
226 ++unknownLogins;
227  
228 if (unknownLogins < 5)
229 {
230 Logger.Log("Unknown login error, waiting 2 minutes: " + client.Network.LoginErrorKey,
231 Helpers.LogLevel.Warning, client);
232 LoginWait(2);
233 goto Start;
234 }
235 else
236 {
237 Logger.Log("Too many unknown login error codes, giving up", Helpers.LogLevel.Error, client);
238 return false;
239 }
240 }
241 }
242 }
243  
244 public void StayInSim(ulong handle, Vector3 desiredPosition)
245 {
246 SimHandle = handle;
247 Position = desiredPosition;
248 CheckTimer.Start();
249 }
250  
251 private static void LoginWait(int minutes)
252 {
253 Thread.Sleep(1000 * 60 * minutes);
254 }
255  
256 private void CheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
257 {
258 if (SimHandle != 0)
259 {
260 if (Client.Network.CurrentSim.Handle != 0 &&
261 Client.Network.CurrentSim.Handle != SimHandle)
262 {
263 // Attempt to move to our target sim
264 Client.Self.Teleport(SimHandle, Position);
265 }
266 }
267 }
268 }
269 }