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

