aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/ClientViewBase.cs
diff options
context:
space:
mode:
authorlbsa712007-09-18 08:55:44 +0000
committerlbsa712007-09-18 08:55:44 +0000
commitffb4f97a664e8b80e209ccf0f89ad56a20a401fd (patch)
tree026179a8c09f85d63995078600d0117d67fc044b /OpenSim/Region/ClientStack/ClientViewBase.cs
parent* Made ClientViewBase abstract (diff)
downloadopensim-SC_OLD-ffb4f97a664e8b80e209ccf0f89ad56a20a401fd.zip
opensim-SC_OLD-ffb4f97a664e8b80e209ccf0f89ad56a20a401fd.tar.gz
opensim-SC_OLD-ffb4f97a664e8b80e209ccf0f89ad56a20a401fd.tar.bz2
opensim-SC_OLD-ffb4f97a664e8b80e209ccf0f89ad56a20a401fd.tar.xz
* Merged ClientViewBase into ClientView for great justice
Diffstat (limited to 'OpenSim/Region/ClientStack/ClientViewBase.cs')
-rw-r--r--OpenSim/Region/ClientStack/ClientViewBase.cs320
1 files changed, 0 insertions, 320 deletions
diff --git a/OpenSim/Region/ClientStack/ClientViewBase.cs b/OpenSim/Region/ClientStack/ClientViewBase.cs
deleted file mode 100644
index 965dc40..0000000
--- a/OpenSim/Region/ClientStack/ClientViewBase.cs
+++ /dev/null
@@ -1,320 +0,0 @@
1/*
2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Net;
31using System.Net.Sockets;
32using System.Timers;
33using libsecondlife;
34using libsecondlife.Packets;
35using OpenSim.Framework.Console;
36using OpenSim.Framework.Utilities;
37using OpenSim.Region.Environment;
38
39namespace OpenSim.Region.ClientStack
40{
41 public abstract class ClientViewBase
42 {
43 protected BlockingQueue<QueItem> PacketQueue;
44 protected Dictionary<uint, uint> PendingAcks = new Dictionary<uint, uint>();
45 protected Dictionary<uint, Packet> NeedAck = new Dictionary<uint, Packet>();
46
47 protected Timer AckTimer;
48 protected uint Sequence = 0;
49 protected object SequenceLock = new object();
50 protected const int MAX_APPENDED_ACKS = 10;
51 protected const int RESEND_TIMEOUT = 4000;
52 protected const int MAX_SEQUENCE = 0xFFFFFF;
53
54 public uint CircuitCode;
55 public EndPoint userEP;
56
57 protected PacketServer m_networkServer;
58
59 protected abstract void ProcessInPacket(Packet Pack);
60
61 protected virtual void ProcessOutPacket(Packet Pack)
62 {
63 // Keep track of when this packet was sent out
64 Pack.TickCount = System.Environment.TickCount;
65
66 if (!Pack.Header.Resent)
67 {
68 // Set the sequence number
69 lock (SequenceLock)
70 {
71 if (Sequence >= MAX_SEQUENCE)
72 {
73 Sequence = 1;
74 }
75 else
76 {
77 Sequence++;
78 }
79
80 Pack.Header.Sequence = Sequence;
81 }
82
83 if (Pack.Header.Reliable) //DIRTY HACK
84 {
85 lock (NeedAck)
86 {
87 if (!NeedAck.ContainsKey(Pack.Header.Sequence))
88 {
89 try
90 {
91 NeedAck.Add(Pack.Header.Sequence, Pack);
92 }
93 catch (Exception e) // HACKY
94 {
95 e.ToString();
96 // Ignore
97 // Seems to throw a exception here occasionally
98 // of 'duplicate key' despite being locked.
99 // !?!?!?
100 }
101 }
102 else
103 {
104 // Client.Log("Attempted to add a duplicate sequence number (" +
105 // packet.Header.Sequence + ") to the NeedAck dictionary for packet type " +
106 // packet.Type.ToString(), Helpers.LogLevel.Warning);
107 }
108 }
109
110 // Don't append ACKs to resent packets, in case that's what was causing the
111 // delivery to fail
112 if (!Pack.Header.Resent)
113 {
114 // Append any ACKs that need to be sent out to this packet
115 lock (PendingAcks)
116 {
117 if (PendingAcks.Count > 0 && PendingAcks.Count < MAX_APPENDED_ACKS &&
118 Pack.Type != PacketType.PacketAck &&
119 Pack.Type != PacketType.LogoutRequest)
120 {
121 Pack.Header.AckList = new uint[PendingAcks.Count];
122 int i = 0;
123
124 foreach (uint ack in PendingAcks.Values)
125 {
126 Pack.Header.AckList[i] = ack;
127 i++;
128 }
129
130 PendingAcks.Clear();
131 Pack.Header.AppendedAcks = true;
132 }
133 }
134 }
135 }
136 }
137
138 byte[] ZeroOutBuffer = new byte[4096];
139 byte[] sendbuffer;
140 sendbuffer = Pack.ToBytes();
141
142 try
143 {
144 if (Pack.Header.Zerocoded)
145 {
146 int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
147 m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, CircuitCode);//userEP);
148 }
149 else
150 {
151 m_networkServer.SendPacketTo(sendbuffer, sendbuffer.Length, SocketFlags.None, CircuitCode); //userEP);
152 }
153 }
154 catch (Exception)
155 {
156 MainLog.Instance.Warn("client", "OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " + userEP.ToString() + " - killing thread");
157 this.KillThread();
158 }
159
160 }
161
162 public virtual void InPacket(Packet NewPack)
163 {
164 // Handle appended ACKs
165 if (NewPack.Header.AppendedAcks)
166 {
167 lock (NeedAck)
168 {
169 foreach (uint ack in NewPack.Header.AckList)
170 {
171 NeedAck.Remove(ack);
172 }
173 }
174 }
175
176 // Handle PacketAck packets
177 if (NewPack.Type == PacketType.PacketAck)
178 {
179 PacketAckPacket ackPacket = (PacketAckPacket)NewPack;
180
181 lock (NeedAck)
182 {
183 foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets)
184 {
185 NeedAck.Remove(block.ID);
186 }
187 }
188 }
189 else if ((NewPack.Type == PacketType.StartPingCheck))
190 {
191 //reply to pingcheck
192 StartPingCheckPacket startPing = (StartPingCheckPacket)NewPack;
193 CompletePingCheckPacket endPing = new CompletePingCheckPacket();
194 endPing.PingID.PingID = startPing.PingID.PingID;
195 OutPacket(endPing);
196 }
197 else
198 {
199 QueItem item = new QueItem();
200 item.Packet = NewPack;
201 item.Incoming = true;
202 this.PacketQueue.Enqueue(item);
203 }
204
205 }
206
207 public virtual void OutPacket(Packet NewPack)
208 {
209 QueItem item = new QueItem();
210 item.Packet = NewPack;
211 item.Incoming = false;
212 this.PacketQueue.Enqueue(item);
213 }
214
215 # region Low Level Packet Methods
216
217 protected void ack_pack(Packet Pack)
218 {
219 if (Pack.Header.Reliable)
220 {
221 PacketAckPacket ack_it = new PacketAckPacket();
222 ack_it.Packets = new PacketAckPacket.PacketsBlock[1];
223 ack_it.Packets[0] = new PacketAckPacket.PacketsBlock();
224 ack_it.Packets[0].ID = Pack.Header.Sequence;
225 ack_it.Header.Reliable = false;
226
227 OutPacket(ack_it);
228
229 }
230 /*
231 if (Pack.Header.Reliable)
232 {
233 lock (PendingAcks)
234 {
235 uint sequence = (uint)Pack.Header.Sequence;
236 if (!PendingAcks.ContainsKey(sequence)) { PendingAcks[sequence] = sequence; }
237 }
238 }*/
239 }
240
241 protected void ResendUnacked()
242 {
243 int now = System.Environment.TickCount;
244
245 lock (NeedAck)
246 {
247 foreach (Packet packet in NeedAck.Values)
248 {
249 if ((now - packet.TickCount > RESEND_TIMEOUT) && (!packet.Header.Resent))
250 {
251 MainLog.Instance.Verbose( "Resending " + packet.Type.ToString() + " packet, " +
252 (now - packet.TickCount) + "ms have passed");
253
254 packet.Header.Resent = true;
255 OutPacket(packet);
256 }
257 }
258 }
259 }
260
261 protected void SendAcks()
262 {
263 lock (PendingAcks)
264 {
265 if (PendingAcks.Count > 0)
266 {
267 if (PendingAcks.Count > 250)
268 {
269 // FIXME: Handle the odd case where we have too many pending ACKs queued up
270 MainLog.Instance.Verbose( "Too many ACKs queued up!");
271 return;
272 }
273
274 //OpenSim.Framework.Console.MainLog.Instance.WriteLine("Sending PacketAck");
275
276
277 int i = 0;
278 PacketAckPacket acks = new PacketAckPacket();
279 acks.Packets = new PacketAckPacket.PacketsBlock[PendingAcks.Count];
280
281 foreach (uint ack in PendingAcks.Values)
282 {
283 acks.Packets[i] = new PacketAckPacket.PacketsBlock();
284 acks.Packets[i].ID = ack;
285 i++;
286 }
287
288 acks.Header.Reliable = false;
289 OutPacket(acks);
290
291 PendingAcks.Clear();
292 }
293 }
294 }
295
296 protected void AckTimer_Elapsed(object sender, ElapsedEventArgs ea)
297 {
298 SendAcks();
299 ResendUnacked();
300 }
301 #endregion
302
303 protected abstract void KillThread();
304
305 public abstract void ConnectionClosed();
306
307 #region Nested Classes
308
309 public class QueItem
310 {
311 public QueItem()
312 {
313 }
314
315 public Packet Packet;
316 public bool Incoming;
317 }
318 #endregion
319 }
320}