aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/UDPServer.cs
diff options
context:
space:
mode:
authorSean Dague2007-07-16 15:40:11 +0000
committerSean Dague2007-07-16 15:40:11 +0000
commit2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6 (patch)
treee3f80ad51736cf17e856547b1bcf956010927434 /OpenSim/Region/ClientStack/UDPServer.cs
parent*Trunk compiles now (diff)
downloadopensim-SC-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.zip
opensim-SC-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.gz
opensim-SC-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.bz2
opensim-SC-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.xz
changed to native line ending encoding
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/UDPServer.cs390
1 files changed, 195 insertions, 195 deletions
diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs
index 6eea524..781f96a 100644
--- a/OpenSim/Region/ClientStack/UDPServer.cs
+++ b/OpenSim/Region/ClientStack/UDPServer.cs
@@ -1,196 +1,196 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Net; 30using System.Net;
31using System.Net.Sockets; 31using System.Net.Sockets;
32using libsecondlife.Packets; 32using libsecondlife.Packets;
33using OpenSim.Assets; 33using OpenSim.Assets;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
36using OpenSim.Framework.Interfaces; 36using OpenSim.Framework.Interfaces;
37using OpenSim.Region.Caches; 37using OpenSim.Region.Caches;
38 38
39namespace OpenSim.Region.ClientStack 39namespace OpenSim.Region.ClientStack
40{ 40{
41 41
42 public class UDPServer : ClientStackNetworkHandler 42 public class UDPServer : ClientStackNetworkHandler
43 { 43 {
44 protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>(); 44 protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>();
45 public Socket Server; 45 public Socket Server;
46 protected IPEndPoint ServerIncoming; 46 protected IPEndPoint ServerIncoming;
47 protected byte[] RecvBuffer = new byte[4096]; 47 protected byte[] RecvBuffer = new byte[4096];
48 protected byte[] ZeroBuffer = new byte[8192]; 48 protected byte[] ZeroBuffer = new byte[8192];
49 protected IPEndPoint ipeSender; 49 protected IPEndPoint ipeSender;
50 protected EndPoint epSender; 50 protected EndPoint epSender;
51 protected AsyncCallback ReceivedData; 51 protected AsyncCallback ReceivedData;
52 protected PacketServer _packetServer; 52 protected PacketServer _packetServer;
53 53
54 protected int listenPort; 54 protected int listenPort;
55 protected IWorld m_localWorld; 55 protected IWorld m_localWorld;
56 protected AssetCache m_assetCache; 56 protected AssetCache m_assetCache;
57 protected InventoryCache m_inventoryCache; 57 protected InventoryCache m_inventoryCache;
58 protected LogBase m_log; 58 protected LogBase m_log;
59 protected AuthenticateSessionsBase m_authenticateSessionsClass; 59 protected AuthenticateSessionsBase m_authenticateSessionsClass;
60 60
61 public PacketServer PacketServer 61 public PacketServer PacketServer
62 { 62 {
63 get 63 get
64 { 64 {
65 return _packetServer; 65 return _packetServer;
66 } 66 }
67 set 67 set
68 { 68 {
69 _packetServer = value; 69 _packetServer = value;
70 } 70 }
71 } 71 }
72 72
73 public IWorld LocalWorld 73 public IWorld LocalWorld
74 { 74 {
75 set 75 set
76 { 76 {
77 this.m_localWorld = value; 77 this.m_localWorld = value;
78 this._packetServer.LocalWorld = this.m_localWorld; 78 this._packetServer.LocalWorld = this.m_localWorld;
79 } 79 }
80 } 80 }
81 81
82 public UDPServer() 82 public UDPServer()
83 { 83 {
84 } 84 }
85 85
86 public UDPServer(int port, AssetCache assetCache, InventoryCache inventoryCache, LogBase console, AuthenticateSessionsBase authenticateClass) 86 public UDPServer(int port, AssetCache assetCache, InventoryCache inventoryCache, LogBase console, AuthenticateSessionsBase authenticateClass)
87 { 87 {
88 listenPort = port; 88 listenPort = port;
89 this.m_assetCache = assetCache; 89 this.m_assetCache = assetCache;
90 this.m_inventoryCache = inventoryCache; 90 this.m_inventoryCache = inventoryCache;
91 this.m_log = console; 91 this.m_log = console;
92 this.m_authenticateSessionsClass = authenticateClass; 92 this.m_authenticateSessionsClass = authenticateClass;
93 this.CreatePacketServer(); 93 this.CreatePacketServer();
94 94
95 } 95 }
96 96
97 protected virtual void CreatePacketServer() 97 protected virtual void CreatePacketServer()
98 { 98 {
99 PacketServer packetServer = new PacketServer(this); 99 PacketServer packetServer = new PacketServer(this);
100 } 100 }
101 101
102 protected virtual void OnReceivedData(IAsyncResult result) 102 protected virtual void OnReceivedData(IAsyncResult result)
103 { 103 {
104 ipeSender = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); 104 ipeSender = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
105 epSender = (EndPoint)ipeSender; 105 epSender = (EndPoint)ipeSender;
106 Packet packet = null; 106 Packet packet = null;
107 int numBytes = Server.EndReceiveFrom(result, ref epSender); 107 int numBytes = Server.EndReceiveFrom(result, ref epSender);
108 int packetEnd = numBytes - 1; 108 int packetEnd = numBytes - 1;
109 109
110 packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); 110 packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
111 111
112 // do we already have a circuit for this endpoint 112 // do we already have a circuit for this endpoint
113 if (this.clientCircuits.ContainsKey(epSender)) 113 if (this.clientCircuits.ContainsKey(epSender))
114 { 114 {
115 //if so then send packet to the packetserver 115 //if so then send packet to the packetserver
116 this._packetServer.ClientInPacket(this.clientCircuits[epSender], packet); 116 this._packetServer.ClientInPacket(this.clientCircuits[epSender], packet);
117 } 117 }
118 else if (packet.Type == PacketType.UseCircuitCode) 118 else if (packet.Type == PacketType.UseCircuitCode)
119 { 119 {
120 // new client 120 // new client
121 this.AddNewClient(packet); 121 this.AddNewClient(packet);
122 } 122 }
123 else 123 else
124 { // invalid client 124 { // invalid client
125 m_log.Warn("UDPServer.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString()); 125 m_log.Warn("UDPServer.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString());
126 } 126 }
127 127
128 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); 128 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
129 } 129 }
130 130
131 protected virtual void AddNewClient(Packet packet) 131 protected virtual void AddNewClient(Packet packet)
132 { 132 {
133 UseCircuitCodePacket useCircuit = (UseCircuitCodePacket)packet; 133 UseCircuitCodePacket useCircuit = (UseCircuitCodePacket)packet;
134 this.clientCircuits.Add(epSender, useCircuit.CircuitCode.Code); 134 this.clientCircuits.Add(epSender, useCircuit.CircuitCode.Code);
135 135
136 this.PacketServer.AddNewClient(epSender, useCircuit, m_assetCache, m_inventoryCache, m_authenticateSessionsClass); 136 this.PacketServer.AddNewClient(epSender, useCircuit, m_assetCache, m_inventoryCache, m_authenticateSessionsClass);
137 } 137 }
138 138
139 public void ServerListener() 139 public void ServerListener()
140 { 140 {
141 m_log.Status("UDPServer.cs:ServerListener() - Opening UDP socket on " + listenPort); 141 m_log.Status("UDPServer.cs:ServerListener() - Opening UDP socket on " + listenPort);
142 142
143 ServerIncoming = new IPEndPoint(IPAddress.Parse("0.0.0.0"), listenPort); 143 ServerIncoming = new IPEndPoint(IPAddress.Parse("0.0.0.0"), listenPort);
144 Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); 144 Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
145 Server.Bind(ServerIncoming); 145 Server.Bind(ServerIncoming);
146 146
147 m_log.Verbose("UDPServer.cs:ServerListener() - UDP socket bound, getting ready to listen"); 147 m_log.Verbose("UDPServer.cs:ServerListener() - UDP socket bound, getting ready to listen");
148 148
149 ipeSender = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); 149 ipeSender = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
150 epSender = (EndPoint)ipeSender; 150 epSender = (EndPoint)ipeSender;
151 ReceivedData = new AsyncCallback(this.OnReceivedData); 151 ReceivedData = new AsyncCallback(this.OnReceivedData);
152 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); 152 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
153 153
154 m_log.Verbose("UDPServer.cs:ServerListener() - Listening..."); 154 m_log.Verbose("UDPServer.cs:ServerListener() - Listening...");
155 155
156 } 156 }
157 157
158 public virtual void RegisterPacketServer(PacketServer server) 158 public virtual void RegisterPacketServer(PacketServer server)
159 { 159 {
160 this._packetServer = server; 160 this._packetServer = server;
161 } 161 }
162 162
163 public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)//EndPoint packetSender) 163 public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)//EndPoint packetSender)
164 { 164 {
165 // find the endpoint for this circuit 165 // find the endpoint for this circuit
166 EndPoint sendto = null; 166 EndPoint sendto = null;
167 foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits) 167 foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits)
168 { 168 {
169 if (p.Value == circuitcode) 169 if (p.Value == circuitcode)
170 { 170 {
171 sendto = p.Key; 171 sendto = p.Key;
172 break; 172 break;
173 } 173 }
174 } 174 }
175 if (sendto != null) 175 if (sendto != null)
176 { 176 {
177 //we found the endpoint so send the packet to it 177 //we found the endpoint so send the packet to it
178 this.Server.SendTo(buffer, size, flags, sendto); 178 this.Server.SendTo(buffer, size, flags, sendto);
179 } 179 }
180 } 180 }
181 181
182 public virtual void RemoveClientCircuit(uint circuitcode) 182 public virtual void RemoveClientCircuit(uint circuitcode)
183 { 183 {
184 foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits) 184 foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits)
185 { 185 {
186 if (p.Value == circuitcode) 186 if (p.Value == circuitcode)
187 { 187 {
188 this.clientCircuits.Remove(p.Key); 188 this.clientCircuits.Remove(p.Key);
189 break; 189 break;
190 } 190 }
191 } 191 }
192 } 192 }
193 193
194 194
195 } 195 }
196} \ No newline at end of file 196} \ No newline at end of file