PacketServer.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using libsecondlife.Packets;
  5. using OpenSim.Framework.Interfaces;
  6. using OpenSim.Framework;
  7. using System.Net;
  8. using System.Net.Sockets;
  9. using OpenSim.Assets;
  10. namespace OpenSim
  11. {
  12. public class PacketServer
  13. {
  14. private OpenSimNetworkHandler _networkHandler;
  15. private IWorld _localWorld;
  16. public Dictionary<uint, ClientView> ClientThreads = new Dictionary<uint, ClientView>();
  17. public Dictionary<uint, IClientAPI> ClientAPIs = new Dictionary<uint, IClientAPI>();
  18. protected uint serverPort;
  19. public PacketServer(OpenSimNetworkHandler networkHandler, uint port)
  20. {
  21. _networkHandler = networkHandler;
  22. this.serverPort = port;
  23. _networkHandler.RegisterPacketServer(this);
  24. }
  25. public IWorld LocalWorld
  26. {
  27. set
  28. {
  29. this._localWorld = value;
  30. }
  31. }
  32. public virtual void ClientInPacket(uint circuitCode, Packet packet)
  33. {
  34. if (this.ClientThreads.ContainsKey(circuitCode))
  35. {
  36. ClientThreads[circuitCode].InPacket(packet);
  37. }
  38. }
  39. public virtual bool AddNewCircuitCodeClient(uint circuitCode)
  40. {
  41. return false;
  42. }
  43. public virtual void SendPacketToAllClients(Packet packet)
  44. {
  45. }
  46. public virtual void SendPacketToAllExcept(Packet packet, ClientView simClient)
  47. {
  48. }
  49. public virtual void AddClientPacketHandler(PacketType packetType, PacketMethod handler)
  50. {
  51. }
  52. public virtual void RegisterClientPacketHandlers()
  53. {
  54. }
  55. public virtual bool AddNewClient(EndPoint epSender, UseCircuitCodePacket useCircuit, AssetCache assetCache, InventoryCache inventoryCache, AuthenticateSessionsBase authenticateSessionsClass)
  56. {
  57. ClientView newuser = new ClientView(epSender, useCircuit, this.ClientThreads, this._localWorld, assetCache, this, inventoryCache, authenticateSessionsClass, serverPort);
  58. this.ClientThreads.Add(useCircuit.CircuitCode.Code, newuser);
  59. this.ClientAPIs.Add(useCircuit.CircuitCode.Code, (IClientAPI)newuser);
  60. return true;
  61. }
  62. public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)
  63. {
  64. this._networkHandler.SendPacketTo(buffer, size, flags, circuitcode);
  65. }
  66. public virtual void RemoveClientCircuit(uint circuitcode)
  67. {
  68. this._networkHandler.RemoveClientCircuit(circuitcode);
  69. }
  70. }
  71. }