aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/UDPServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/UDPServer.cs')
-rw-r--r--OpenSim/Region/ClientStack/UDPServer.cs100
1 files changed, 1 insertions, 99 deletions
diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs
index 10435bf..bcbd81a 100644
--- a/OpenSim/Region/ClientStack/UDPServer.cs
+++ b/OpenSim/Region/ClientStack/UDPServer.cs
@@ -30,7 +30,6 @@ using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Net; 31using System.Net;
32using System.Net.Sockets; 32using System.Net.Sockets;
33using libsecondlife;
34using libsecondlife.Packets; 33using libsecondlife.Packets;
35using OpenSim.Framework; 34using OpenSim.Framework;
36using OpenSim.Framework.Communications.Cache; 35using OpenSim.Framework.Communications.Cache;
@@ -38,103 +37,6 @@ using OpenSim.Framework.Console;
38 37
39namespace OpenSim.Region.ClientStack 38namespace OpenSim.Region.ClientStack
40{ 39{
41 public sealed class PacketPool
42 {
43 // Set up a thread-safe singleton pattern
44 static PacketPool()
45 {
46 }
47
48 private static readonly PacketPool instance = new PacketPool();
49
50 public static PacketPool Instance
51 {
52 get { return instance; }
53 }
54
55 private Hashtable pool = new Hashtable();
56
57 public Packet GetPacket(PacketType type)
58 {
59 Packet packet = null;
60
61 lock (pool)
62 {
63 if (pool[type] == null || ((Stack) pool[type]).Count == 0)
64 {
65 // Creating a new packet if we cannot reuse an old package
66 packet = Packet.BuildPacket(type);
67 }
68 else
69 {
70 // Recycle old packages
71 packet = (Packet) ((Stack) pool[type]).Pop();
72 }
73 }
74
75 return packet;
76 }
77
78 public Packet GetPacket(byte[] bytes, ref int packetEnd, byte[] zeroBuffer)
79 {
80 Packet packet = GetPacket(GetType(bytes, packetEnd, zeroBuffer));
81
82 int i = 0;
83 packet.FromBytes(bytes, ref i, ref packetEnd, zeroBuffer);
84 return packet;
85 }
86
87 public PacketType GetType(byte[] bytes, int packetEnd, byte[] zeroBuffer)
88 {
89 //Function removed from LibSL revision 1540
90 // We're using it.. so Built it into UDP server for now..
91 ushort id;
92 PacketFrequency freq;
93 int i = 0, end = packetEnd;
94 Header header = Header.BuildHeader(bytes, ref i, ref end);
95 if (header.Zerocoded)
96 {
97 end = Helpers.ZeroDecode(bytes, end + 1, zeroBuffer) - 1;
98 bytes = zeroBuffer;
99 }
100
101 if (bytes[6] == 0xFF)
102 {
103 if (bytes[7] == 0xFF)
104 {
105 id = (ushort) ((bytes[8] << 8) + bytes[9]);
106 freq = PacketFrequency.Low;
107 }
108 else
109 {
110 id = (ushort) bytes[7];
111 freq = PacketFrequency.Medium;
112 }
113 }
114 else
115 {
116 id = (ushort) bytes[6];
117 freq = PacketFrequency.High;
118 }
119 return Packet.GetType(id, freq);
120 }
121
122 public void ReturnPacket(Packet packet)
123 {
124 lock (pool)
125 {
126 PacketType type = packet.Type;
127
128 if (pool[type] == null)
129 {
130 pool[type] = new Stack();
131 }
132
133 ((Stack) pool[type]).Push(packet);
134 }
135 }
136 }
137
138 public class UDPServer : ClientStackNetworkHandler 40 public class UDPServer : ClientStackNetworkHandler
139 { 41 {
140 protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>(); 42 protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>();
@@ -386,4 +288,4 @@ namespace OpenSim.Region.ClientStack
386 } 288 }
387 } 289 }
388 } 290 }
389} \ No newline at end of file 291}