PacketServer.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using OpenSim.world;
  5. using libsecondlife.Packets;
  6. namespace OpenSim
  7. {
  8. public class PacketServer
  9. {
  10. private OpenSimNetworkHandler _networkHandler;
  11. private World _localWorld;
  12. public Dictionary<uint, SimClient> ClientThreads = new Dictionary<uint, SimClient>();
  13. public PacketServer(OpenSimNetworkHandler networkHandler)
  14. {
  15. _networkHandler = networkHandler;
  16. _networkHandler.RegisterPacketServer(this);
  17. }
  18. public World LocalWorld
  19. {
  20. set
  21. {
  22. this._localWorld = value;
  23. }
  24. }
  25. public void ClientInPacket(uint circuitCode, Packet packet)
  26. {
  27. if (this.ClientThreads.ContainsKey(circuitCode))
  28. {
  29. ClientThreads[circuitCode].InPacket(packet);
  30. }
  31. }
  32. public bool AddNewCircuitCodeClient(uint circuitCode)
  33. {
  34. return false;
  35. }
  36. public void SendPacketToAllClients(Packet packet)
  37. {
  38. }
  39. public void SendPacketToAllExcept(Packet packet, SimClient simClient)
  40. {
  41. }
  42. public virtual void RegisterClientPacketHandlers()
  43. {
  44. if (this._localWorld != null)
  45. {
  46. SimClient.AddPacketHandler(PacketType.ModifyLand, _localWorld.ModifyTerrain);
  47. SimClient.AddPacketHandler(PacketType.ChatFromViewer, _localWorld.SimChat);
  48. SimClient.AddPacketHandler(PacketType.RezObject, _localWorld.RezObject);
  49. SimClient.AddPacketHandler(PacketType.DeRezObject, _localWorld.DeRezObject);
  50. SimClient.AddPacketHandler(PacketType.UUIDNameRequest, this.RequestUUIDName);
  51. }
  52. }
  53. #region Client Packet Handlers
  54. public bool RequestUUIDName(SimClient simClient, Packet packet)
  55. {
  56. System.Text.Encoding enc = System.Text.Encoding.ASCII;
  57. Console.WriteLine(packet.ToString());
  58. UUIDNameRequestPacket nameRequest = (UUIDNameRequestPacket)packet;
  59. UUIDNameReplyPacket nameReply = new UUIDNameReplyPacket();
  60. nameReply.UUIDNameBlock = new UUIDNameReplyPacket.UUIDNameBlockBlock[nameRequest.UUIDNameBlock.Length];
  61. for (int i = 0; i < nameRequest.UUIDNameBlock.Length; i++)
  62. {
  63. nameReply.UUIDNameBlock[i] = new UUIDNameReplyPacket.UUIDNameBlockBlock();
  64. nameReply.UUIDNameBlock[i].ID = nameRequest.UUIDNameBlock[i].ID;
  65. nameReply.UUIDNameBlock[i].FirstName = enc.GetBytes("Who\0"); //for now send any name
  66. nameReply.UUIDNameBlock[i].LastName = enc.GetBytes("Knows\0"); //in future need to look it up
  67. }
  68. simClient.OutPacket(nameReply);
  69. return true;
  70. }
  71. #endregion
  72. }
  73. }