diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim.RegionServer/OpenSimMain.cs | 134 |
1 files changed, 10 insertions, 124 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> |