LLUDPServer.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using System.Net.Sockets;
  32. using System.Reflection;
  33. using log4net;
  34. using Nini.Config;
  35. using OpenMetaverse.Packets;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.Framework.Scenes;
  38. namespace OpenSim.Region.ClientStack.LindenUDP
  39. {
  40. /// <summary>
  41. /// This class handles the initial UDP circuit setup with a client and passes on subsequent packets to the LLPacketServer
  42. /// </summary>
  43. public class LLUDPServer : ILLClientStackNetworkHandler, IClientNetworkServer
  44. {
  45. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. /// <value>
  47. /// The client circuits established with this UDP server. If a client exists here we can also assume that
  48. /// it is populated in clientCircuits_reverse and proxyCircuits (if relevant)
  49. /// </value>
  50. protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>();
  51. public Hashtable clientCircuits_reverse = Hashtable.Synchronized(new Hashtable());
  52. protected Dictionary<uint, EndPoint> proxyCircuits = new Dictionary<uint, EndPoint>();
  53. private Socket m_socket;
  54. protected IPEndPoint ServerIncoming;
  55. protected byte[] RecvBuffer = new byte[4096];
  56. protected byte[] ZeroBuffer = new byte[8192];
  57. /// <value>
  58. /// This is an endpoint that is reused where we don't need to protect the information from potentially
  59. /// being stomped on by other threads.
  60. /// </value>
  61. protected EndPoint reusedEpSender = new IPEndPoint(IPAddress.Any, 0);
  62. protected int proxyPortOffset;
  63. protected AsyncCallback ReceivedData;
  64. protected LLPacketServer m_packetServer;
  65. protected Location m_location;
  66. protected uint listenPort;
  67. protected bool Allow_Alternate_Port;
  68. protected IPAddress listenIP = IPAddress.Parse("0.0.0.0");
  69. protected IScene m_localScene;
  70. protected IAssetCache m_assetCache;
  71. /// <value>
  72. /// Manages authentication for agent circuits
  73. /// </value>
  74. protected AgentCircuitManager m_circuitManager;
  75. public IScene LocalScene
  76. {
  77. set
  78. {
  79. m_localScene = value;
  80. m_packetServer.LocalScene = m_localScene;
  81. m_location = new Location(m_localScene.RegionInfo.RegionHandle);
  82. }
  83. }
  84. public ulong RegionHandle
  85. {
  86. get { return m_location.RegionHandle; }
  87. }
  88. Socket IClientNetworkServer.Server
  89. {
  90. get { return m_socket; }
  91. }
  92. public bool HandlesRegion(Location x)
  93. {
  94. //return x.RegionHandle == m_location.RegionHandle;
  95. return x == m_location;
  96. }
  97. public void AddScene(IScene x)
  98. {
  99. LocalScene = x;
  100. }
  101. public void Start()
  102. {
  103. ServerListener();
  104. }
  105. public void Stop()
  106. {
  107. m_socket.Close();
  108. }
  109. public LLUDPServer()
  110. {
  111. }
  112. public LLUDPServer(
  113. IPAddress _listenIP, ref uint port, int proxyPortOffset, bool allow_alternate_port, IConfigSource configSource,
  114. IAssetCache assetCache, AgentCircuitManager authenticateClass)
  115. {
  116. Initialise(_listenIP, ref port, proxyPortOffset, allow_alternate_port, configSource, assetCache, authenticateClass);
  117. }
  118. /// <summary>
  119. /// Initialize the server
  120. /// </summary>
  121. /// <param name="_listenIP"></param>
  122. /// <param name="port"></param>
  123. /// <param name="proxyPortOffsetParm"></param>
  124. /// <param name="allow_alternate_port"></param>
  125. /// <param name="configSource"></param>
  126. /// <param name="assetCache"></param>
  127. /// <param name="circuitManager"></param>
  128. public void Initialise(
  129. IPAddress _listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource,
  130. IAssetCache assetCache, AgentCircuitManager circuitManager)
  131. {
  132. ClientStackUserSettings userSettings = new ClientStackUserSettings();
  133. IConfig config = configSource.Configs["ClientStack.LindenUDP"];
  134. if (config != null)
  135. {
  136. if (config.Contains("client_throttle_multiplier"))
  137. userSettings.ClientThrottleMultipler = config.GetFloat("client_throttle_multiplier");
  138. }
  139. m_log.DebugFormat("[CLIENT]: client_throttle_multiplier = {0}", userSettings.ClientThrottleMultipler);
  140. proxyPortOffset = proxyPortOffsetParm;
  141. listenPort = (uint) (port + proxyPortOffsetParm);
  142. listenIP = _listenIP;
  143. Allow_Alternate_Port = allow_alternate_port;
  144. m_assetCache = assetCache;
  145. m_circuitManager = circuitManager;
  146. CreatePacketServer(userSettings);
  147. // Return new port
  148. // This because in Grid mode it is not really important what port the region listens to as long as it is correctly registered.
  149. // So the option allow_alternate_ports="true" was added to default.xml
  150. port = (uint)(listenPort - proxyPortOffsetParm);
  151. }
  152. protected virtual void CreatePacketServer(ClientStackUserSettings userSettings)
  153. {
  154. new LLPacketServer(this, userSettings);
  155. }
  156. /// <summary>
  157. /// This method is called every time that we receive new UDP data.
  158. /// </summary>
  159. /// <param name="result"></param>
  160. protected virtual void OnReceivedData(IAsyncResult result)
  161. {
  162. Packet packet = null;
  163. int numBytes = 1;
  164. EndPoint epSender = new IPEndPoint(IPAddress.Any, 0);
  165. if (EndReceive(out numBytes, result, ref epSender))
  166. {
  167. // Make sure we are getting zeroes when running off the
  168. // end of grab / degrab packets from old clients
  169. Array.Clear(RecvBuffer, numBytes, RecvBuffer.Length - numBytes);
  170. int packetEnd = numBytes - 1;
  171. if (proxyPortOffset != 0) packetEnd -= 6;
  172. try
  173. {
  174. packet = PacketPool.Instance.GetPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
  175. }
  176. catch (MalformedDataException e)
  177. {
  178. m_log.DebugFormat("[CLIENT]: Dropped Malformed Packet due to MalformedDataException: {0}", e.StackTrace);
  179. }
  180. catch (IndexOutOfRangeException e)
  181. {
  182. m_log.DebugFormat("[CLIENT]: Dropped Malformed Packet due to IndexOutOfRangeException: {0}", e.StackTrace);
  183. }
  184. catch (Exception e)
  185. {
  186. m_log.Debug("[CLIENT]: " + e);
  187. }
  188. }
  189. EndPoint epProxy = null;
  190. if (proxyPortOffset != 0)
  191. {
  192. // If we've received a use circuit packet, then we need to decode an endpoint proxy, if one exists,
  193. // before allowing the RecvBuffer to be overwritten by the next packet.
  194. if (packet != null && packet.Type == PacketType.UseCircuitCode)
  195. {
  196. epProxy = epSender;
  197. }
  198. // Now decode the message from the proxy server
  199. epSender = ProxyCodec.DecodeProxyMessage(RecvBuffer, ref numBytes);
  200. }
  201. BeginRobustReceive();
  202. if (packet != null)
  203. {
  204. if (packet.Type == PacketType.UseCircuitCode)
  205. AddNewClient((UseCircuitCodePacket)packet, epSender, epProxy);
  206. else
  207. ProcessInPacket(packet, epSender);
  208. }
  209. }
  210. /// <summary>
  211. /// Process a successfully received packet.
  212. /// </summary>
  213. /// <param name="packet"></param>
  214. /// <param name="epSender"></param>
  215. protected virtual void ProcessInPacket(Packet packet, EndPoint epSender)
  216. {
  217. try
  218. {
  219. // do we already have a circuit for this endpoint
  220. uint circuit;
  221. bool ret;
  222. lock (clientCircuits)
  223. {
  224. ret = clientCircuits.TryGetValue(epSender, out circuit);
  225. }
  226. if (ret)
  227. {
  228. //if so then send packet to the packetserver
  229. //m_log.DebugFormat(
  230. // "[UDPSERVER]: For circuit {0} {1} got packet {2}", circuit, epSender, packet.Type);
  231. m_packetServer.InPacket(circuit, packet);
  232. }
  233. }
  234. catch (Exception e)
  235. {
  236. m_log.Error("[CLIENT]: Exception in processing packet - ignoring: ", e);
  237. }
  238. }
  239. /// <summary>
  240. /// Begin an asynchronous receive of the next bit of raw data
  241. /// </summary>
  242. protected virtual void BeginReceive()
  243. {
  244. m_socket.BeginReceiveFrom(
  245. RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref reusedEpSender, ReceivedData, null);
  246. }
  247. /// <summary>
  248. /// Begin a robust asynchronous receive of the next bit of raw data. Robust means that SocketExceptions are
  249. /// automatically dealt with until the next set of valid UDP data is received.
  250. /// </summary>
  251. private void BeginRobustReceive()
  252. {
  253. try
  254. {
  255. BeginReceive();
  256. }
  257. catch (SocketException e)
  258. {
  259. // ENDLESS LOOP ON PURPOSE!
  260. // Reset connection and get next UDP packet off the buffer
  261. // If the UDP packet is part of the same stream, this will happen several hundreds of times before
  262. // the next set of UDP data is for a valid client.
  263. ResetServerEndPoint(e);
  264. }
  265. catch (ObjectDisposedException)
  266. {
  267. m_log.Info("[UDPSERVER]: UDP Object disposed. No need to worry about this if you're restarting the simulator.");
  268. }
  269. }
  270. /// <summary>
  271. /// Reset the server endpoint
  272. /// </summary>
  273. /// <param name="e">
  274. /// The exception that has triggered the reset. Can be null if there was no exception.
  275. /// </param>
  276. private void ResetServerEndPoint(Exception e)
  277. {
  278. try
  279. {
  280. CloseCircuit(e);
  281. }
  282. catch (Exception e2)
  283. {
  284. m_log.ErrorFormat(
  285. "[CLIENT]: Exception thrown when trying to close the circuit for {0} - {1}", reusedEpSender, e2);
  286. }
  287. // ENDLESS LOOP ON PURPOSE!
  288. // We need to purge the UDP stream of crap from the client that disconnected nastily or the UDP server will die
  289. // The only way to do that is to BeginRobustReceive again!
  290. BeginRobustReceive();
  291. }
  292. /// <summary>
  293. /// Close a client circuit. This is done in response to an exception on receive, and should not be called
  294. /// normally.
  295. /// </summary>
  296. /// <param name="e">The exception that caused the close. Can be null if there was no exception</param>
  297. private void CloseCircuit(Exception e)
  298. {
  299. uint circuit;
  300. lock (clientCircuits)
  301. {
  302. if (clientCircuits.TryGetValue(reusedEpSender, out circuit))
  303. {
  304. m_packetServer.CloseCircuit(circuit);
  305. if (e != null)
  306. m_log.ErrorFormat(
  307. "[CLIENT]: Closed circuit {0} {1} due to exception {2}", circuit, reusedEpSender, e);
  308. }
  309. }
  310. }
  311. /// <summary>
  312. /// Finish the process of asynchronously receiving the next bit of raw data
  313. /// </summary>
  314. /// <param name="numBytes">The number of bytes received. Will return 0 if no bytes were recieved
  315. /// <param name="result"></param>
  316. /// <param name="epSender">The sender of the data</param>
  317. /// <returns></returns>
  318. protected virtual bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender)
  319. {
  320. bool hasReceivedOkay = false;
  321. numBytes = 0;
  322. try
  323. {
  324. numBytes = m_socket.EndReceiveFrom(result, ref epSender);
  325. hasReceivedOkay = true;
  326. }
  327. catch (SocketException e)
  328. {
  329. // TODO : Actually only handle those states that we have control over, re-throw everything else,
  330. // TODO: implement cases as we encounter them.
  331. //m_log.Error("[CLIENT]: Connection Error! - " + e.ToString());
  332. switch (e.SocketErrorCode)
  333. {
  334. case SocketError.AlreadyInProgress:
  335. return hasReceivedOkay;
  336. case SocketError.NetworkReset:
  337. case SocketError.ConnectionReset:
  338. break;
  339. default:
  340. throw;
  341. }
  342. }
  343. catch (ObjectDisposedException e)
  344. {
  345. m_log.DebugFormat("[CLIENT]: ObjectDisposedException: Object {0} disposed.", e.ObjectName);
  346. // Uhh, what object, and why? this needs better handling.
  347. }
  348. return hasReceivedOkay;
  349. }
  350. /// <summary>
  351. /// Add a new client circuit.
  352. /// </summary>
  353. /// <param name="packet"></param>
  354. /// <param name="epSender"></param>
  355. /// <param name="epProxy"></param>
  356. protected virtual void AddNewClient(UseCircuitCodePacket useCircuit, EndPoint epSender, EndPoint epProxy)
  357. {
  358. //Slave regions don't accept new clients
  359. if (m_localScene.Region_Status != RegionStatus.SlaveScene)
  360. {
  361. AuthenticateResponse sessionInfo;
  362. bool isNewCircuit = false;
  363. if (!m_packetServer.IsClientAuthorized(useCircuit, m_circuitManager, out sessionInfo))
  364. {
  365. m_log.WarnFormat(
  366. "[CONNECTION FAILURE]: Connection request for client {0} connecting with unnotified circuit code {1} from {2}",
  367. useCircuit.CircuitCode.ID, useCircuit.CircuitCode.Code, epSender);
  368. return;
  369. }
  370. lock (clientCircuits)
  371. {
  372. if (!clientCircuits.ContainsKey(epSender))
  373. {
  374. clientCircuits.Add(epSender, useCircuit.CircuitCode.Code);
  375. isNewCircuit = true;
  376. }
  377. }
  378. if (isNewCircuit)
  379. {
  380. // This doesn't need locking as it's synchronized data
  381. clientCircuits_reverse[useCircuit.CircuitCode.Code] = epSender;
  382. lock (proxyCircuits)
  383. {
  384. proxyCircuits[useCircuit.CircuitCode.Code] = epProxy;
  385. }
  386. m_packetServer.AddNewClient(epSender, useCircuit, m_assetCache, sessionInfo, epProxy);
  387. //m_log.DebugFormat(
  388. // "[CONNECTION SUCCESS]: Incoming client {0} (circuit code {1}) received and authenticated for {2}",
  389. // useCircuit.CircuitCode.ID, useCircuit.CircuitCode.Code, m_localScene.RegionInfo.RegionName);
  390. }
  391. }
  392. // Ack the UseCircuitCode packet
  393. PacketAckPacket ack_it = (PacketAckPacket)PacketPool.Instance.GetPacket(PacketType.PacketAck);
  394. // TODO: don't create new blocks if recycling an old packet
  395. ack_it.Packets = new PacketAckPacket.PacketsBlock[1];
  396. ack_it.Packets[0] = new PacketAckPacket.PacketsBlock();
  397. ack_it.Packets[0].ID = useCircuit.Header.Sequence;
  398. // ((useCircuit.Header.Sequence < uint.MaxValue) ? useCircuit.Header.Sequence : 0) is just a failsafe to ensure that we don't overflow.
  399. ack_it.Header.Sequence = ((useCircuit.Header.Sequence < uint.MaxValue) ? useCircuit.Header.Sequence : 0) + 1;
  400. ack_it.Header.Reliable = false;
  401. byte[] ackmsg = ack_it.ToBytes();
  402. // Need some extra space in case we need to add proxy
  403. // information to the message later
  404. byte[] msg = new byte[4096];
  405. Buffer.BlockCopy(ackmsg, 0, msg, 0, ackmsg.Length);
  406. SendPacketTo(msg, ackmsg.Length, SocketFlags.None, useCircuit.CircuitCode.Code);
  407. PacketPool.Instance.ReturnPacket(useCircuit);
  408. }
  409. public void ServerListener()
  410. {
  411. uint newPort = listenPort;
  412. m_log.Info("[UDPSERVER]: Opening UDP socket on " + listenIP + " " + newPort + ".");
  413. ServerIncoming = new IPEndPoint(listenIP, (int)newPort);
  414. m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  415. m_socket.Bind(ServerIncoming);
  416. // Add flags to the UDP socket to prevent "Socket forcibly closed by host"
  417. // uint IOC_IN = 0x80000000;
  418. // uint IOC_VENDOR = 0x18000000;
  419. // uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
  420. // TODO: this apparently works in .NET but not in Mono, need to sort out the right flags here.
  421. // m_socket.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null);
  422. listenPort = newPort;
  423. m_log.Info("[UDPSERVER]: UDP socket bound, getting ready to listen");
  424. ReceivedData = OnReceivedData;
  425. BeginReceive();
  426. m_log.Info("[UDPSERVER]: Listening on port " + newPort);
  427. }
  428. public virtual void RegisterPacketServer(LLPacketServer server)
  429. {
  430. m_packetServer = server;
  431. }
  432. public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)
  433. //EndPoint packetSender)
  434. {
  435. // find the endpoint for this circuit
  436. EndPoint sendto;
  437. try
  438. {
  439. sendto = (EndPoint)clientCircuits_reverse[circuitcode];
  440. }
  441. catch
  442. {
  443. // Exceptions here mean there is no circuit
  444. m_log.Warn("[CLIENT]: Circuit not found, not sending packet");
  445. return;
  446. }
  447. if (sendto != null)
  448. {
  449. //we found the endpoint so send the packet to it
  450. if (proxyPortOffset != 0)
  451. {
  452. //MainLog.Instance.Verbose("UDPSERVER", "SendPacketTo proxy " + proxyCircuits[circuitcode].ToString() + ": client " + sendto.ToString());
  453. ProxyCodec.EncodeProxyMessage(buffer, ref size, sendto);
  454. m_socket.SendTo(buffer, size, flags, proxyCircuits[circuitcode]);
  455. }
  456. else
  457. {
  458. //MainLog.Instance.Verbose("UDPSERVER", "SendPacketTo : client " + sendto.ToString());
  459. try
  460. {
  461. m_socket.SendTo(buffer, size, flags, sendto);
  462. }
  463. catch (SocketException SockE)
  464. {
  465. m_log.ErrorFormat("[UDPSERVER]: Caught Socket Error in the send buffer!. {0}",SockE.ToString());
  466. }
  467. }
  468. }
  469. }
  470. public virtual void RemoveClientCircuit(uint circuitcode)
  471. {
  472. EndPoint sendto;
  473. if (clientCircuits_reverse.Contains(circuitcode))
  474. {
  475. sendto = (EndPoint)clientCircuits_reverse[circuitcode];
  476. clientCircuits_reverse.Remove(circuitcode);
  477. lock (clientCircuits)
  478. {
  479. if (sendto != null)
  480. {
  481. clientCircuits.Remove(sendto);
  482. }
  483. else
  484. {
  485. m_log.DebugFormat(
  486. "[CLIENT]: endpoint for circuit code {0} in RemoveClientCircuit() was unexpectedly null!", circuitcode);
  487. }
  488. }
  489. lock (proxyCircuits)
  490. {
  491. proxyCircuits.Remove(circuitcode);
  492. }
  493. }
  494. }
  495. public void RestoreClient(AgentCircuitData circuit, EndPoint userEP, EndPoint proxyEP)
  496. {
  497. //MainLog.Instance.Verbose("UDPSERVER", "RestoreClient");
  498. UseCircuitCodePacket useCircuit = new UseCircuitCodePacket();
  499. useCircuit.CircuitCode.Code = circuit.circuitcode;
  500. useCircuit.CircuitCode.ID = circuit.AgentID;
  501. useCircuit.CircuitCode.SessionID = circuit.SessionID;
  502. AuthenticateResponse sessionInfo;
  503. if (!m_packetServer.IsClientAuthorized(useCircuit, m_circuitManager, out sessionInfo))
  504. {
  505. m_log.WarnFormat(
  506. "[CLIENT]: Restore request denied to avatar {0} connecting with unauthorized circuit code {1}",
  507. useCircuit.CircuitCode.ID, useCircuit.CircuitCode.Code);
  508. return;
  509. }
  510. lock (clientCircuits)
  511. {
  512. if (!clientCircuits.ContainsKey(userEP))
  513. clientCircuits.Add(userEP, useCircuit.CircuitCode.Code);
  514. else
  515. m_log.Error("[CLIENT]: clientCircuits already contains entry for user " + useCircuit.CircuitCode.Code + ". NOT adding.");
  516. }
  517. // This data structure is synchronized, so we don't need the lock
  518. if (!clientCircuits_reverse.ContainsKey(useCircuit.CircuitCode.Code))
  519. clientCircuits_reverse.Add(useCircuit.CircuitCode.Code, userEP);
  520. else
  521. m_log.Error("[CLIENT]: clientCurcuits_reverse already contains entry for user " + useCircuit.CircuitCode.Code + ". NOT adding.");
  522. lock (proxyCircuits)
  523. {
  524. if (!proxyCircuits.ContainsKey(useCircuit.CircuitCode.Code))
  525. {
  526. proxyCircuits.Add(useCircuit.CircuitCode.Code, proxyEP);
  527. }
  528. else
  529. {
  530. // re-set proxy endpoint
  531. proxyCircuits.Remove(useCircuit.CircuitCode.Code);
  532. proxyCircuits.Add(useCircuit.CircuitCode.Code, proxyEP);
  533. }
  534. }
  535. m_packetServer.AddNewClient(userEP, useCircuit, m_assetCache, sessionInfo, proxyEP);
  536. }
  537. }
  538. }