diff options
author | MW | 2007-05-16 13:10:17 +0000 |
---|---|---|
committer | MW | 2007-05-16 13:10:17 +0000 |
commit | fd67b36a5eb3623b9f98b1fc11ea3e5b607c5901 (patch) | |
tree | bcd8f437ea29acc0438a4700b04293605dbba5e9 /OpenSim.RegionServer | |
parent | started to refactor startup code and to move udp server code out to its own c... (diff) | |
download | opensim-SC-fd67b36a5eb3623b9f98b1fc11ea3e5b607c5901.zip opensim-SC-fd67b36a5eb3623b9f98b1fc11ea3e5b607c5901.tar.gz opensim-SC-fd67b36a5eb3623b9f98b1fc11ea3e5b607c5901.tar.bz2 opensim-SC-fd67b36a5eb3623b9f98b1fc11ea3e5b607c5901.tar.xz |
UDPServer enabled, should no longer be any udp server code in OpenSimMain.
Diffstat (limited to 'OpenSim.RegionServer')
-rw-r--r-- | OpenSim.RegionServer/OpenSimMain.cs | 134 | ||||
-rw-r--r-- | OpenSim.RegionServer/UDPServer.cs | 36 |
2 files changed, 37 insertions, 133 deletions
diff --git a/OpenSim.RegionServer/OpenSimMain.cs b/OpenSim.RegionServer/OpenSimMain.cs index 9995d96..46b682b 100644 --- a/OpenSim.RegionServer/OpenSimMain.cs +++ b/OpenSim.RegionServer/OpenSimMain.cs | |||
@@ -54,13 +54,12 @@ using OpenSim.GenericConfig; | |||
54 | namespace OpenSim | 54 | namespace OpenSim |
55 | { | 55 | { |
56 | 56 | ||
57 | public class OpenSimMain : OpenSimNetworkHandler, conscmd_callback | 57 | public class OpenSimMain : conscmd_callback |
58 | { | 58 | { |
59 | private IGenericConfig localConfig; | 59 | private IGenericConfig localConfig; |
60 | //private IGenericConfig remoteConfig; | 60 | //private IGenericConfig remoteConfig; |
61 | private PhysicsManager physManager; | 61 | private PhysicsManager physManager; |
62 | private Grid GridServers; | 62 | private Grid GridServers; |
63 | private PacketServer _packetServer; | ||
64 | private World LocalWorld; | 63 | private World LocalWorld; |
65 | private AssetCache AssetCache; | 64 | private AssetCache AssetCache; |
66 | private InventoryCache InventoryCache; | 65 | private InventoryCache InventoryCache; |
@@ -68,14 +67,6 @@ namespace OpenSim | |||
68 | private DateTime startuptime; | 67 | private DateTime startuptime; |
69 | private RegionInfo regionData; | 68 | private RegionInfo regionData; |
70 | 69 | ||
71 | public Socket Server; | ||
72 | private IPEndPoint ServerIncoming; | ||
73 | private byte[] RecvBuffer = new byte[4096]; | ||
74 | private byte[] ZeroBuffer = new byte[8192]; | ||
75 | private IPEndPoint ipeSender; | ||
76 | private EndPoint epSender; | ||
77 | private AsyncCallback ReceivedData; | ||
78 | |||
79 | private System.Timers.Timer m_heartbeatTimer = new System.Timers.Timer(); | 70 | private System.Timers.Timer m_heartbeatTimer = new System.Timers.Timer(); |
80 | public string m_physicsEngine; | 71 | public string m_physicsEngine; |
81 | public bool m_sandbox = false; | 72 | public bool m_sandbox = false; |
@@ -85,6 +76,7 @@ namespace OpenSim | |||
85 | private bool configFileSetup = false; | 76 | private bool configFileSetup = false; |
86 | public string m_config; | 77 | public string m_config; |
87 | 78 | ||
79 | private UDPServer m_udpServer; | ||
88 | protected BaseHttpServer httpServer; | 80 | protected BaseHttpServer httpServer; |
89 | 81 | ||
90 | protected ConsoleBase m_console; | 82 | protected ConsoleBase m_console; |
@@ -147,8 +139,9 @@ namespace OpenSim | |||
147 | Environment.Exit(1); | 139 | Environment.Exit(1); |
148 | } | 140 | } |
149 | 141 | ||
150 | PacketServer packetServer = new PacketServer(this); | 142 | //PacketServer packetServer = new PacketServer(this); |
151 | 143 | m_udpServer = new UDPServer(this.regionData.IPListenPort, this.GridServers, this.AssetCache, this.InventoryCache, this.regionData, this.m_sandbox, this.user_accounts, this.m_console); | |
144 | |||
152 | //should be passing a IGenericConfig object to these so they can read the config data they want from it | 145 | //should be passing a IGenericConfig object to these so they can read the config data they want from it |
153 | GridServers.AssetServer.SetServerInfo(regionData.AssetURL, regionData.AssetSendKey); | 146 | GridServers.AssetServer.SetServerInfo(regionData.AssetURL, regionData.AssetSendKey); |
154 | IGridServer gridServer = GridServers.GridServer; | 147 | IGridServer gridServer = GridServers.GridServer; |
@@ -200,7 +193,8 @@ namespace OpenSim | |||
200 | m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Starting HTTP server"); | 193 | m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Starting HTTP server"); |
201 | httpServer.Start(); | 194 | httpServer.Start(); |
202 | 195 | ||
203 | MainServerListener(); | 196 | //MainServerListener(); |
197 | this.m_udpServer.ServerListener(); | ||
204 | 198 | ||
205 | m_heartbeatTimer.Enabled = true; | 199 | m_heartbeatTimer.Enabled = true; |
206 | m_heartbeatTimer.Interval = 100; | 200 | m_heartbeatTimer.Interval = 100; |
@@ -257,12 +251,12 @@ namespace OpenSim | |||
257 | m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Initialising world"); | 251 | m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Initialising world"); |
258 | m_console.componentname = "Region " + regionData.RegionName; | 252 | m_console.componentname = "Region " + regionData.RegionName; |
259 | 253 | ||
260 | LocalWorld = new World(this._packetServer.ClientThreads, regionData, regionData.RegionHandle, regionData.RegionName); | 254 | LocalWorld = new World(this.m_udpServer.PacketServer.ClientThreads, regionData, regionData.RegionHandle, regionData.RegionName); |
261 | LocalWorld.InventoryCache = InventoryCache; | 255 | LocalWorld.InventoryCache = InventoryCache; |
262 | LocalWorld.AssetCache = AssetCache; | 256 | LocalWorld.AssetCache = AssetCache; |
263 | 257 | ||
264 | this._packetServer.LocalWorld = LocalWorld; | 258 | this.m_udpServer.LocalWorld = LocalWorld; |
265 | this._packetServer.RegisterClientPacketHandlers(); | 259 | this.m_udpServer.PacketServer.RegisterClientPacketHandlers(); |
266 | 260 | ||
267 | this.physManager = new OpenSim.Physics.Manager.PhysicsManager(); | 261 | this.physManager = new OpenSim.Physics.Manager.PhysicsManager(); |
268 | this.physManager.LoadPlugins(); | 262 | this.physManager.LoadPlugins(); |
@@ -489,114 +483,6 @@ namespace OpenSim | |||
489 | } | 483 | } |
490 | } | 484 | } |
491 | 485 | ||
492 | # region UDP | ||
493 | private void OnReceivedData(IAsyncResult result) | ||
494 | { | ||
495 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
496 | epSender = (EndPoint)ipeSender; | ||
497 | Packet packet = null; | ||
498 | int numBytes = Server.EndReceiveFrom(result, ref epSender); | ||
499 | int packetEnd = numBytes - 1; | ||
500 | |||
501 | packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); | ||
502 | |||
503 | // This is either a new client or a packet to send to an old one | ||
504 | // if (OpenSimRoot.Instance.ClientThreads.ContainsKey(epSender)) | ||
505 | |||
506 | // do we already have a circuit for this endpoint | ||
507 | if (this.clientCircuits.ContainsKey(epSender)) | ||
508 | { | ||
509 | //ClientThreads[this.clientCircuits[epSender]].InPacket(packet); | ||
510 | this._packetServer.ClientInPacket(this.clientCircuits[epSender], packet); | ||
511 | } | ||
512 | else if (packet.Type == PacketType.UseCircuitCode) | ||
513 | { // new client | ||
514 | |||
515 | UseCircuitCodePacket useCircuit = (UseCircuitCodePacket)packet; | ||
516 | this.clientCircuits.Add(epSender, useCircuit.CircuitCode.Code); | ||
517 | bool isChildAgent = false; | ||
518 | if (this.GridServers.GridServer.GetName() == "Remote") | ||
519 | { | ||
520 | isChildAgent = ((RemoteGridBase)this.GridServers.GridServer).agentcircuits[useCircuit.CircuitCode.Code].child; | ||
521 | } | ||
522 | SimClient newuser = new SimClient(epSender, useCircuit, LocalWorld, _packetServer.ClientThreads, AssetCache, GridServers.GridServer, this, InventoryCache, m_sandbox, isChildAgent, this.regionData); | ||
523 | if ((this.GridServers.UserServer != null) && (user_accounts)) | ||
524 | { | ||
525 | newuser.UserServer = this.GridServers.UserServer; | ||
526 | } | ||
527 | //OpenSimRoot.Instance.ClientThreads.Add(epSender, newuser); | ||
528 | this._packetServer.ClientThreads.Add(useCircuit.CircuitCode.Code, newuser); | ||
529 | |||
530 | //if (!((RemoteGridBase)GridServers.GridServer).agentcircuits[useCircuit.CircuitCode.Code].child) | ||
531 | |||
532 | |||
533 | } | ||
534 | else | ||
535 | { // invalid client | ||
536 | Console.Error.WriteLine("Main.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString()); | ||
537 | } | ||
538 | |||
539 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
540 | } | ||
541 | |||
542 | private void MainServerListener() | ||
543 | { | ||
544 | m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:MainServerListener() - New thread started"); | ||
545 | m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:MainServerListener() - Opening UDP socket on " + regionData.IPListenAddr + ":" + regionData.IPListenPort); | ||
546 | |||
547 | ServerIncoming = new IPEndPoint(IPAddress.Any, regionData.IPListenPort); | ||
548 | Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); | ||
549 | Server.Bind(ServerIncoming); | ||
550 | |||
551 | m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:MainServerListener() - UDP socket bound, getting ready to listen"); | ||
552 | |||
553 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
554 | epSender = (EndPoint)ipeSender; | ||
555 | ReceivedData = new AsyncCallback(this.OnReceivedData); | ||
556 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
557 | |||
558 | m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:MainServerListener() - Listening..."); | ||
559 | |||
560 | } | ||
561 | |||
562 | public void RegisterPacketServer(PacketServer server) | ||
563 | { | ||
564 | this._packetServer = server; | ||
565 | } | ||
566 | |||
567 | public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)//EndPoint packetSender) | ||
568 | { | ||
569 | // find the endpoint for this circuit | ||
570 | EndPoint sendto = null; | ||
571 | foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits) | ||
572 | { | ||
573 | if (p.Value == circuitcode) | ||
574 | { | ||
575 | sendto = p.Key; | ||
576 | break; | ||
577 | } | ||
578 | } | ||
579 | if (sendto != null) | ||
580 | { | ||
581 | //we found the endpoint so send the packet to it | ||
582 | this.Server.SendTo(buffer, size, flags, sendto); | ||
583 | } | ||
584 | } | ||
585 | |||
586 | public virtual void RemoveClientCircuit(uint circuitcode) | ||
587 | { | ||
588 | foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits) | ||
589 | { | ||
590 | if (p.Value == circuitcode) | ||
591 | { | ||
592 | this.clientCircuits.Remove(p.Key); | ||
593 | break; | ||
594 | } | ||
595 | } | ||
596 | } | ||
597 | |||
598 | #endregion | ||
599 | |||
600 | /// <summary> | 486 | /// <summary> |
601 | /// Performs any last-minute sanity checking and shuts down the region server | 487 | /// Performs any last-minute sanity checking and shuts down the region server |
602 | /// </summary> | 488 | /// </summary> |
diff --git a/OpenSim.RegionServer/UDPServer.cs b/OpenSim.RegionServer/UDPServer.cs index e70ae78..89c4f67 100644 --- a/OpenSim.RegionServer/UDPServer.cs +++ b/OpenSim.RegionServer/UDPServer.cs | |||
@@ -46,11 +46,31 @@ namespace OpenSim | |||
46 | private bool user_accounts = false; | 46 | private bool user_accounts = false; |
47 | private ConsoleBase m_console; | 47 | private ConsoleBase m_console; |
48 | 48 | ||
49 | public UDPServer(int port, Grid gridServers, World localWorld, AssetCache assetCache, InventoryCache inventoryCache, RegionInfo _regionData, bool sandbox, bool accounts, ConsoleBase console) | 49 | public PacketServer PacketServer |
50 | { | ||
51 | get | ||
52 | { | ||
53 | return _packetServer; | ||
54 | } | ||
55 | set | ||
56 | { | ||
57 | _packetServer = value; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | public World LocalWorld | ||
62 | { | ||
63 | set | ||
64 | { | ||
65 | this.m_localWorld = value; | ||
66 | this._packetServer.LocalWorld = this.m_localWorld; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | public UDPServer(int port, Grid gridServers, AssetCache assetCache, InventoryCache inventoryCache, RegionInfo _regionData, bool sandbox, bool accounts, ConsoleBase console) | ||
50 | { | 71 | { |
51 | listenPort = port; | 72 | listenPort = port; |
52 | this.m_gridServers = gridServers; | 73 | this.m_gridServers = gridServers; |
53 | this.m_localWorld = localWorld; | ||
54 | this.m_assetCache = assetCache; | 74 | this.m_assetCache = assetCache; |
55 | this.m_inventoryCache = inventoryCache; | 75 | this.m_inventoryCache = inventoryCache; |
56 | this.m_regionData = _regionData; | 76 | this.m_regionData = _regionData; |
@@ -58,8 +78,6 @@ namespace OpenSim | |||
58 | this.user_accounts = accounts; | 78 | this.user_accounts = accounts; |
59 | this.m_console = console; | 79 | this.m_console = console; |
60 | PacketServer packetServer = new PacketServer(this); | 80 | PacketServer packetServer = new PacketServer(this); |
61 | this._packetServer.LocalWorld = m_localWorld; | ||
62 | this._packetServer.RegisterClientPacketHandlers(); | ||
63 | } | 81 | } |
64 | 82 | ||
65 | protected virtual void OnReceivedData(IAsyncResult result) | 83 | protected virtual void OnReceivedData(IAsyncResult result) |
@@ -85,7 +103,7 @@ namespace OpenSim | |||
85 | } | 103 | } |
86 | else | 104 | else |
87 | { // invalid client | 105 | { // invalid client |
88 | Console.Error.WriteLine("Main.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString()); | 106 | Console.Error.WriteLine("UDPServer.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString()); |
89 | } | 107 | } |
90 | 108 | ||
91 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | 109 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); |
@@ -106,22 +124,22 @@ namespace OpenSim | |||
106 | this._packetServer.ClientThreads.Add(useCircuit.CircuitCode.Code, newuser); | 124 | this._packetServer.ClientThreads.Add(useCircuit.CircuitCode.Code, newuser); |
107 | } | 125 | } |
108 | 126 | ||
109 | private void ServerListener() | 127 | public void ServerListener() |
110 | { | 128 | { |
111 | m_console.WriteLine("Main.cs:MainServerListener() - Opening UDP socket on " + listenPort); | 129 | m_console.WriteLine("UDPServer.cs:ServerListener() - Opening UDP socket on " + listenPort); |
112 | 130 | ||
113 | ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort); | 131 | ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort); |
114 | Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); | 132 | Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); |
115 | Server.Bind(ServerIncoming); | 133 | Server.Bind(ServerIncoming); |
116 | 134 | ||
117 | m_console.WriteLine("Main.cs:MainServerListener() - UDP socket bound, getting ready to listen"); | 135 | m_console.WriteLine("UDPServer.cs:ServerListener() - UDP socket bound, getting ready to listen"); |
118 | 136 | ||
119 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | 137 | ipeSender = new IPEndPoint(IPAddress.Any, 0); |
120 | epSender = (EndPoint)ipeSender; | 138 | epSender = (EndPoint)ipeSender; |
121 | ReceivedData = new AsyncCallback(this.OnReceivedData); | 139 | ReceivedData = new AsyncCallback(this.OnReceivedData); |
122 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | 140 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); |
123 | 141 | ||
124 | m_console.WriteLine("Main.cs:MainServerListener() - Listening..."); | 142 | m_console.WriteLine("UDPServer.cs:ServerListener() - Listening..."); |
125 | 143 | ||
126 | } | 144 | } |
127 | 145 | ||