Annotation of /trunk/IdealistViewer/Application/Protocol.cs
Parent Directory
|
Revision Log
Revision 111 - (view) (download)
| 1 : | teravus | 2 | using System; |
| 2 : | using System.Collections.Generic; | ||
| 3 : | teravus | 31 | using System.Reflection; |
| 4 : | teravus | 2 | using System.Text; |
| 5 : | using OpenMetaverse; | ||
| 6 : | using OpenMetaverse.Rendering; | ||
| 7 : | teravus | 31 | using log4net; |
| 8 : | teravus | 2 | |
| 9 : | teravus | 31 | |
| 10 : | teravus | 2 | namespace IdealistViewer |
| 11 : | { | ||
| 12 : | public class SLProtocol | ||
| 13 : | { | ||
| 14 : | teravus | 31 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
| 15 : | |||
| 16 : | teravus | 2 | public delegate void GridConnected(); |
| 17 : | public delegate void Chat(string message, ChatAudibleLevel audible, ChatType type, ChatSourceType sourcetype, | ||
| 18 : | string fromName, UUID id, UUID ownerid, Vector3 position); | ||
| 19 : | public delegate void LandPatch(Simulator sim, int x, int y, int width, float[] data); | ||
| 20 : | public delegate void NewAvatar(Simulator sim, Avatar avatar, ulong regionHandle, | ||
| 21 : | ushort timeDilation); | ||
| 22 : | public delegate void NewPrim(Simulator sim, Primitive prim, ulong regionHandle, | ||
| 23 : | ushort timeDilation); | ||
| 24 : | public delegate void Login(LoginStatus status, string message); | ||
| 25 : | public delegate void ObjectKilled(Simulator sim, uint objectID); | ||
| 26 : | public delegate void ObjectUpdated(Simulator simulator, ObjectUpdate update, ulong regionHandle, ushort timeDilation); | ||
| 27 : | public delegate void SimConnected(Simulator sim); | ||
| 28 : | teravus | 13 | public delegate void ImageReceived(AssetTexture tex); |
| 29 : | teravus | 2 | |
| 30 : | public event NewAvatar OnNewAvatar; | ||
| 31 : | public event Chat OnChat; | ||
| 32 : | public event GridConnected OnGridConnected; | ||
| 33 : | public event SimConnected OnSimConnected; | ||
| 34 : | public event LandPatch OnLandPatch; | ||
| 35 : | public event Login OnLogin; | ||
| 36 : | public event NewPrim OnNewPrim; | ||
| 37 : | public event ObjectKilled OnObjectKilled; | ||
| 38 : | public event ObjectUpdated OnObjectUpdated; | ||
| 39 : | teravus | 16 | public event ImageReceived OnImageReceived; |
| 40 : | teravus | 2 | |
| 41 : | GridClient m_user; | ||
| 42 : | public SLProtocol() | ||
| 43 : | { | ||
| 44 : | m_user = new GridClient(); | ||
| 45 : | //m_user.Settings.STORE_LAND_PATCHES = true; | ||
| 46 : | dahlia | 111 | m_user.Settings.MULTIPLE_SIMS = true; |
| 47 : | //m_user.Settings.MULTIPLE_SIMS = false; | ||
| 48 : | teravus | 24 | //m_user.Settings.OBJECT_TRACKING = true; |
| 49 : | teravus | 17 | //m_user.Settings.AVATAR_TRACKING = true; |
| 50 : | teravus | 16 | m_user.Settings.USE_TEXTURE_CACHE = false; |
| 51 : | teravus | 13 | //m_user.Settings. |
| 52 : | teravus | 104 | m_user.Settings.ALWAYS_DECODE_OBJECTS = false; |
| 53 : | teravus | 24 | |
| 54 : | teravus | 104 | m_user.Settings.SEND_AGENT_THROTTLE = true; |
| 55 : | teravus | 2 | //m_user.Settings.SEND_PINGS = true; |
| 56 : | |||
| 57 : | m_user.Network.OnConnected += gridConnectedCallback; | ||
| 58 : | m_user.Network.OnSimConnected += simConnectedCallback; | ||
| 59 : | m_user.Terrain.OnLandPatch += landPatchCallback; | ||
| 60 : | m_user.Self.OnChat += chatCallback; | ||
| 61 : | m_user.Objects.OnNewAvatar += newAvatarCallback; | ||
| 62 : | m_user.Objects.OnNewPrim += newPrim; | ||
| 63 : | m_user.Objects.OnObjectKilled += objectKilledCallback; | ||
| 64 : | m_user.Network.OnLogin += loginCallback; | ||
| 65 : | m_user.Objects.OnObjectUpdated += objectUpdatedCallback; | ||
| 66 : | teravus | 16 | m_user.Assets.OnImageReceived += imageReceivedCallback; |
| 67 : | teravus | 13 | //m_user.Assets.RequestImage( |
| 68 : | //m_user.Assets.Cache..RequestImage(UUID.Zero, ImageType.Normal); | ||
| 69 : | teravus | 2 | |
| 70 : | } | ||
| 71 : | teravus | 16 | private void imageReceivedCallback(ImageDownload image, AssetTexture asset) |
| 72 : | { | ||
| 73 : | if (OnImageReceived != null) | ||
| 74 : | { | ||
| 75 : | OnImageReceived(asset); | ||
| 76 : | } | ||
| 77 : | } | ||
| 78 : | teravus | 2 | private void objectKilledCallback(Simulator simulator, uint objectID) |
| 79 : | { | ||
| 80 : | if (OnObjectKilled != null) | ||
| 81 : | { | ||
| 82 : | OnObjectKilled(simulator, objectID); | ||
| 83 : | } | ||
| 84 : | } | ||
| 85 : | |||
| 86 : | teravus | 31 | public void BeginLogin(string loginURI, string username, string password, string startlocation) |
| 87 : | teravus | 2 | { |
| 88 : | teravus | 31 | LoginParams loginParams = getLoginParams(loginURI, username, password, startlocation); |
| 89 : | teravus | 2 | |
| 90 : | m_user.Network.BeginLogin(loginParams); | ||
| 91 : | } | ||
| 92 : | private void gridConnectedCallback(object sender) | ||
| 93 : | { | ||
| 94 : | |||
| 95 : | m_user.Appearance.SetPreviousAppearance(false); | ||
| 96 : | |||
| 97 : | |||
| 98 : | |||
| 99 : | if (OnGridConnected != null) | ||
| 100 : | { | ||
| 101 : | OnGridConnected(); | ||
| 102 : | } | ||
| 103 : | } | ||
| 104 : | private void simConnectedCallback(Simulator sender) | ||
| 105 : | { | ||
| 106 : | teravus | 101 | m_user.Throttle.Total = 600000; |
| 107 : | teravus | 2 | m_user.Throttle.Land = 80000; |
| 108 : | m_user.Throttle.Task = 200000; | ||
| 109 : | teravus | 16 | m_user.Throttle.Texture = 150000; |
| 110 : | teravus | 2 | m_user.Throttle.Wind = 10000; |
| 111 : | m_user.Throttle.Resend = 100000; | ||
| 112 : | m_user.Throttle.Asset = 100000; | ||
| 113 : | m_user.Throttle.Cloud = 10000; | ||
| 114 : | teravus | 35 | m_user.Self.Movement.Camera.Far = 64f; |
| 115 : | teravus | 24 | m_user.Self.Movement.Camera.Position = m_user.Self.RelativePosition; |
| 116 : | teravus | 101 | SetHeightWidth(768, 1024); |
| 117 : | teravus | 2 | if (OnSimConnected != null) |
| 118 : | { | ||
| 119 : | OnSimConnected(sender); | ||
| 120 : | } | ||
| 121 : | } | ||
| 122 : | private void loginCallback(LoginStatus status, string message) | ||
| 123 : | { | ||
| 124 : | if (OnLogin != null) | ||
| 125 : | { | ||
| 126 : | OnLogin((LoginStatus)status, message); | ||
| 127 : | } | ||
| 128 : | } | ||
| 129 : | public void Logout() | ||
| 130 : | { | ||
| 131 : | if (m_user.Network.Connected) | ||
| 132 : | { | ||
| 133 : | m_user.Network.Logout(); | ||
| 134 : | } | ||
| 135 : | } | ||
| 136 : | public bool Connected | ||
| 137 : | { | ||
| 138 : | get { return m_user.Network.Connected; } | ||
| 139 : | } | ||
| 140 : | public void Whisper(string message) | ||
| 141 : | { | ||
| 142 : | m_user.Self.Chat(message, 0, ChatType.Whisper); | ||
| 143 : | } | ||
| 144 : | |||
| 145 : | public void Say(string message) | ||
| 146 : | { | ||
| 147 : | m_user.Self.Chat(message, 0, ChatType.Normal); | ||
| 148 : | } | ||
| 149 : | |||
| 150 : | public void Shout(string message) | ||
| 151 : | { | ||
| 152 : | m_user.Self.Chat(message, 0, ChatType.Shout); | ||
| 153 : | } | ||
| 154 : | |||
| 155 : | dahlia | 111 | public void Teleport(string region, float x, float y, float z) |
| 156 : | { | ||
| 157 : | m_user.Self.Teleport(region, new Vector3(x, y, z)); | ||
| 158 : | } | ||
| 159 : | |||
| 160 : | teravus | 31 | private LoginParams getLoginParams(string loginURI, string username, string password, string startlocation) |
| 161 : | teravus | 2 | { |
| 162 : | string firstname; | ||
| 163 : | string lastname; | ||
| 164 : | |||
| 165 : | Util.separateUsername(username, out firstname, out lastname); | ||
| 166 : | |||
| 167 : | LoginParams loginParams = m_user.Network.DefaultLoginParams( | ||
| 168 : | firstname, lastname, password, "IdealistViewer", "0.0.0.1");//Constants.Version); | ||
| 169 : | |||
| 170 : | |||
| 171 : | teravus | 31 | loginURI = Util.getSaneLoginURI(loginURI); |
| 172 : | |||
| 173 : | if (startlocation.Length == 0) | ||
| 174 : | { | ||
| 175 : | |||
| 176 : | if (!loginURI.EndsWith("/")) | ||
| 177 : | loginURI += "/"; | ||
| 178 : | |||
| 179 : | string[] locationparse = loginURI.Split('/'); | ||
| 180 : | try | ||
| 181 : | { | ||
| 182 : | startlocation = locationparse[locationparse.Length - 2]; | ||
| 183 : | if (startlocation == locationparse[2]) | ||
| 184 : | { | ||
| 185 : | startlocation = "last"; | ||
| 186 : | } | ||
| 187 : | else | ||
| 188 : | { | ||
| 189 : | loginURI = ""; | ||
| 190 : | for (int i = 0; i < locationparse.Length - 2; i++) | ||
| 191 : | { | ||
| 192 : | loginURI += locationparse[i] + "/"; | ||
| 193 : | } | ||
| 194 : | } | ||
| 195 : | |||
| 196 : | } | ||
| 197 : | catch (Exception) | ||
| 198 : | { | ||
| 199 : | startlocation = "last"; | ||
| 200 : | } | ||
| 201 : | |||
| 202 : | } | ||
| 203 : | else | ||
| 204 : | { | ||
| 205 : | |||
| 206 : | |||
| 207 : | teravus | 32 | //if (!loginURI.EndsWith("/")) |
| 208 : | // loginURI += "/"; | ||
| 209 : | teravus | 31 | |
| 210 : | teravus | 32 | // string[] locationparse = loginURI.Split('/'); |
| 211 : | // try | ||
| 212 : | // { | ||
| 213 : | // string end = locationparse[locationparse.Length - 2]; | ||
| 214 : | // if (end != locationparse[2]) | ||
| 215 : | // { | ||
| 216 : | // loginURI = ""; | ||
| 217 : | // for (int i = 0; i < 3; i++) | ||
| 218 : | // { | ||
| 219 : | // if (locationparse[i].Length != 0 || i==1) | ||
| 220 : | // loginURI += locationparse[i] + "/"; | ||
| 221 : | // } | ||
| 222 : | // } | ||
| 223 : | teravus | 31 | |
| 224 : | teravus | 32 | //} |
| 225 : | // catch (Exception) | ||
| 226 : | //{ | ||
| 227 : | teravus | 31 | //startlocation = "last"; |
| 228 : | teravus | 32 | // m_log.Warn("[URLPARSING]: Unable to parse URL provided!"); |
| 229 : | //} | ||
| 230 : | teravus | 31 | |
| 231 : | |||
| 232 : | } | ||
| 233 : | |||
| 234 : | loginParams.URI = loginURI; | ||
| 235 : | teravus | 32 | |
| 236 : | |||
| 237 : | if (startlocation != "last" && startlocation != "home") | ||
| 238 : | teravus | 33 | startlocation = "uri:" + startlocation + "&128&128&20"; |
| 239 : | teravus | 32 | |
| 240 : | teravus | 31 | loginParams.Start = startlocation; |
| 241 : | |||
| 242 : | teravus | 2 | return loginParams; |
| 243 : | } | ||
| 244 : | |||
| 245 : | private void chatCallback(string message, ChatAudibleLevel audible, ChatType type, ChatSourceType sourcetype, | ||
| 246 : | string fromName, UUID id, UUID ownerid, Vector3 position) | ||
| 247 : | { | ||
| 248 : | // This is weird -- we get start/stop typing chats from | ||
| 249 : | // other avatars, and we get messages back that we sent. | ||
| 250 : | // (Tested on OpenSim r3187) | ||
| 251 : | // So we explicitly check for those cases here. | ||
| 252 : | dahlia | 111 | if ((int)type < 4 && id != m_user.Self.AgentID) |
| 253 : | teravus | 2 | { |
| 254 : | dahlia | 111 | m_log.Debug("Chat: " + fromName + ": " + message); |
| 255 : | if (OnChat != null) | ||
| 256 : | { | ||
| 257 : | OnChat(message, audible, type, sourcetype, | ||
| 258 : | fromName, id, ownerid, position); | ||
| 259 : | } | ||
| 260 : | teravus | 2 | } |
| 261 : | } | ||
| 262 : | |||
| 263 : | |||
| 264 : | |||
| 265 : | private void newPrim(Simulator simulator, Primitive prim, ulong regionHandle, | ||
| 266 : | ushort timeDilation) | ||
| 267 : | { | ||
| 268 : | |||
| 269 : | if (OnNewPrim != null) | ||
| 270 : | { | ||
| 271 : | OnNewPrim(simulator,prim, regionHandle,timeDilation); | ||
| 272 : | } | ||
| 273 : | } | ||
| 274 : | |||
| 275 : | |||
| 276 : | private void landPatchCallback(Simulator simulator, int x, int y, int width, float[] data) | ||
| 277 : | { | ||
| 278 : | if (OnLandPatch != null) | ||
| 279 : | { | ||
| 280 : | OnLandPatch(simulator,x, y, width, data); | ||
| 281 : | } | ||
| 282 : | } | ||
| 283 : | private void newAvatarCallback(Simulator simulator, Avatar avatar, ulong regionHandle, | ||
| 284 : | ushort timeDilation) | ||
| 285 : | { | ||
| 286 : | if (OnNewAvatar != null) | ||
| 287 : | { | ||
| 288 : | //avatar.Velocity | ||
| 289 : | OnNewAvatar(simulator,avatar,regionHandle,timeDilation); | ||
| 290 : | } | ||
| 291 : | } | ||
| 292 : | private void objectUpdatedCallback(Simulator simulator, ObjectUpdate update, ulong regionHandle, | ||
| 293 : | ushort timeDilation) | ||
| 294 : | { | ||
| 295 : | if (OnObjectUpdated != null) | ||
| 296 : | { | ||
| 297 : | OnObjectUpdated(simulator, update, regionHandle, timeDilation); | ||
| 298 : | } | ||
| 299 : | } | ||
| 300 : | |||
| 301 : | teravus | 16 | public void RequestTexture(UUID assetID) |
| 302 : | { | ||
| 303 : | m_user.Assets.RequestImage(assetID, ImageType.Normal); | ||
| 304 : | } | ||
| 305 : | teravus | 97 | |
| 306 : | teravus | 101 | public void SetCameraPosition(Vector3[] camdata) |
| 307 : | teravus | 24 | { |
| 308 : | teravus | 101 | |
| 309 : | for (int i=0;i<camdata.Length; i++) | ||
| 310 : | if (Single.IsNaN(camdata[i].X) || Single.IsNaN(camdata[i].Y) || Single.IsNaN(camdata[i].Z)) | ||
| 311 : | teravus | 99 | return; |
| 312 : | |||
| 313 : | teravus | 101 | //m_user.Self.Movement.Camera.Position = pPosition; |
| 314 : | //m_user.Self.Movement.Camera.LookAt(pPosition, pTarget); | ||
| 315 : | m_user.Self.Movement.Camera.AtAxis = camdata[1]; | ||
| 316 : | m_user.Self.Movement.Camera.LeftAxis = camdata[0]; | ||
| 317 : | m_user.Self.Movement.Camera.LeftAxis = camdata[2]; | ||
| 318 : | teravus | 99 | |
| 319 : | teravus | 24 | } |
| 320 : | teravus | 101 | |
| 321 : | public void SetHeightWidth(uint height, uint width) | ||
| 322 : | { | ||
| 323 : | m_user.Self.SetHeightWidth((ushort)height, (ushort)width); | ||
| 324 : | } | ||
| 325 : | teravus | 97 | |
| 326 : | public UUID GetSelfUUID | ||
| 327 : | { | ||
| 328 : | get { return m_user.Self.AgentID; } | ||
| 329 : | } | ||
| 330 : | |||
| 331 : | public bool StraffLeft | ||
| 332 : | { | ||
| 333 : | set {m_user.Self.Movement.LeftPos = value;} | ||
| 334 : | get { return m_user.Self.Movement.LeftPos; } | ||
| 335 : | } | ||
| 336 : | public bool StraffRight | ||
| 337 : | { | ||
| 338 : | set { m_user.Self.Movement.LeftNeg = value; } | ||
| 339 : | get { return m_user.Self.Movement.LeftNeg; } | ||
| 340 : | } | ||
| 341 : | |||
| 342 : | public void UpdateFromHeading(double heading) | ||
| 343 : | { | ||
| 344 : | m_user.Self.Movement.UpdateFromHeading(heading ,false); | ||
| 345 : | } | ||
| 346 : | |||
| 347 : | public void TurnToward(Vector3 target) | ||
| 348 : | { | ||
| 349 : | m_user.Self.Movement.TurnToward(target); | ||
| 350 : | } | ||
| 351 : | |||
| 352 : | public bool Forward | ||
| 353 : | { | ||
| 354 : | set {m_user.Self.Movement.AtPos = value;} | ||
| 355 : | get { return m_user.Self.Movement.AtPos; } | ||
| 356 : | } | ||
| 357 : | |||
| 358 : | public bool Backward | ||
| 359 : | { | ||
| 360 : | set { m_user.Self.Movement.AtNeg = value; } | ||
| 361 : | get { return m_user.Self.Movement.AtNeg; } | ||
| 362 : | } | ||
| 363 : | |||
| 364 : | public bool Jump | ||
| 365 : | { | ||
| 366 : | set { m_user.Self.Jump(value); } | ||
| 367 : | } | ||
| 368 : | |||
| 369 : | public bool Flying | ||
| 370 : | { | ||
| 371 : | get { return m_user.Self.Movement.Fly; } | ||
| 372 : | set { m_user.Self.Movement.Fly = value; } | ||
| 373 : | } | ||
| 374 : | |||
| 375 : | public bool Up | ||
| 376 : | { | ||
| 377 : | get { return m_user.Self.Movement.UpPos; } | ||
| 378 : | set { m_user.Self.Movement.UpPos = value; } | ||
| 379 : | } | ||
| 380 : | |||
| 381 : | public bool Down | ||
| 382 : | { | ||
| 383 : | get { return m_user.Self.Movement.UpNeg; } | ||
| 384 : | set { m_user.Self.Movement.UpNeg = value; } | ||
| 385 : | } | ||
| 386 : | |||
| 387 : | |||
| 388 : | |||
| 389 : | |||
| 390 : | teravus | 2 | } |
| 391 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

