UDPServer enabled, should no longer be any udp server code in OpenSimMain.

zircon^2
MW 2007-05-16 13:10:17 +00:00
parent 3d93d39048
commit fd67b36a5e
2 changed files with 37 additions and 133 deletions

View File

@ -54,13 +54,12 @@ using OpenSim.GenericConfig;
namespace OpenSim
{
public class OpenSimMain : OpenSimNetworkHandler, conscmd_callback
public class OpenSimMain : conscmd_callback
{
private IGenericConfig localConfig;
//private IGenericConfig remoteConfig;
private PhysicsManager physManager;
private Grid GridServers;
private PacketServer _packetServer;
private World LocalWorld;
private AssetCache AssetCache;
private InventoryCache InventoryCache;
@ -68,14 +67,6 @@ namespace OpenSim
private DateTime startuptime;
private RegionInfo regionData;
public Socket Server;
private IPEndPoint ServerIncoming;
private byte[] RecvBuffer = new byte[4096];
private byte[] ZeroBuffer = new byte[8192];
private IPEndPoint ipeSender;
private EndPoint epSender;
private AsyncCallback ReceivedData;
private System.Timers.Timer m_heartbeatTimer = new System.Timers.Timer();
public string m_physicsEngine;
public bool m_sandbox = false;
@ -85,6 +76,7 @@ namespace OpenSim
private bool configFileSetup = false;
public string m_config;
private UDPServer m_udpServer;
protected BaseHttpServer httpServer;
protected ConsoleBase m_console;
@ -147,7 +139,8 @@ namespace OpenSim
Environment.Exit(1);
}
PacketServer packetServer = new PacketServer(this);
//PacketServer packetServer = new PacketServer(this);
m_udpServer = new UDPServer(this.regionData.IPListenPort, this.GridServers, this.AssetCache, this.InventoryCache, this.regionData, this.m_sandbox, this.user_accounts, this.m_console);
//should be passing a IGenericConfig object to these so they can read the config data they want from it
GridServers.AssetServer.SetServerInfo(regionData.AssetURL, regionData.AssetSendKey);
@ -200,7 +193,8 @@ namespace OpenSim
m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Starting HTTP server");
httpServer.Start();
MainServerListener();
//MainServerListener();
this.m_udpServer.ServerListener();
m_heartbeatTimer.Enabled = true;
m_heartbeatTimer.Interval = 100;
@ -257,12 +251,12 @@ namespace OpenSim
m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Initialising world");
m_console.componentname = "Region " + regionData.RegionName;
LocalWorld = new World(this._packetServer.ClientThreads, regionData, regionData.RegionHandle, regionData.RegionName);
LocalWorld = new World(this.m_udpServer.PacketServer.ClientThreads, regionData, regionData.RegionHandle, regionData.RegionName);
LocalWorld.InventoryCache = InventoryCache;
LocalWorld.AssetCache = AssetCache;
this._packetServer.LocalWorld = LocalWorld;
this._packetServer.RegisterClientPacketHandlers();
this.m_udpServer.LocalWorld = LocalWorld;
this.m_udpServer.PacketServer.RegisterClientPacketHandlers();
this.physManager = new OpenSim.Physics.Manager.PhysicsManager();
this.physManager.LoadPlugins();
@ -489,114 +483,6 @@ namespace OpenSim
}
}
# region UDP
private void OnReceivedData(IAsyncResult result)
{
ipeSender = new IPEndPoint(IPAddress.Any, 0);
epSender = (EndPoint)ipeSender;
Packet packet = null;
int numBytes = Server.EndReceiveFrom(result, ref epSender);
int packetEnd = numBytes - 1;
packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
// This is either a new client or a packet to send to an old one
// if (OpenSimRoot.Instance.ClientThreads.ContainsKey(epSender))
// do we already have a circuit for this endpoint
if (this.clientCircuits.ContainsKey(epSender))
{
//ClientThreads[this.clientCircuits[epSender]].InPacket(packet);
this._packetServer.ClientInPacket(this.clientCircuits[epSender], packet);
}
else if (packet.Type == PacketType.UseCircuitCode)
{ // new client
UseCircuitCodePacket useCircuit = (UseCircuitCodePacket)packet;
this.clientCircuits.Add(epSender, useCircuit.CircuitCode.Code);
bool isChildAgent = false;
if (this.GridServers.GridServer.GetName() == "Remote")
{
isChildAgent = ((RemoteGridBase)this.GridServers.GridServer).agentcircuits[useCircuit.CircuitCode.Code].child;
}
SimClient newuser = new SimClient(epSender, useCircuit, LocalWorld, _packetServer.ClientThreads, AssetCache, GridServers.GridServer, this, InventoryCache, m_sandbox, isChildAgent, this.regionData);
if ((this.GridServers.UserServer != null) && (user_accounts))
{
newuser.UserServer = this.GridServers.UserServer;
}
//OpenSimRoot.Instance.ClientThreads.Add(epSender, newuser);
this._packetServer.ClientThreads.Add(useCircuit.CircuitCode.Code, newuser);
//if (!((RemoteGridBase)GridServers.GridServer).agentcircuits[useCircuit.CircuitCode.Code].child)
}
else
{ // invalid client
Console.Error.WriteLine("Main.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString());
}
Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
}
private void MainServerListener()
{
m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:MainServerListener() - New thread started");
m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:MainServerListener() - Opening UDP socket on " + regionData.IPListenAddr + ":" + regionData.IPListenPort);
ServerIncoming = new IPEndPoint(IPAddress.Any, regionData.IPListenPort);
Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
Server.Bind(ServerIncoming);
m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:MainServerListener() - UDP socket bound, getting ready to listen");
ipeSender = new IPEndPoint(IPAddress.Any, 0);
epSender = (EndPoint)ipeSender;
ReceivedData = new AsyncCallback(this.OnReceivedData);
Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:MainServerListener() - Listening...");
}
public void RegisterPacketServer(PacketServer server)
{
this._packetServer = server;
}
public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)//EndPoint packetSender)
{
// find the endpoint for this circuit
EndPoint sendto = null;
foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits)
{
if (p.Value == circuitcode)
{
sendto = p.Key;
break;
}
}
if (sendto != null)
{
//we found the endpoint so send the packet to it
this.Server.SendTo(buffer, size, flags, sendto);
}
}
public virtual void RemoveClientCircuit(uint circuitcode)
{
foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits)
{
if (p.Value == circuitcode)
{
this.clientCircuits.Remove(p.Key);
break;
}
}
}
#endregion
/// <summary>
/// Performs any last-minute sanity checking and shuts down the region server
/// </summary>

View File

@ -46,11 +46,31 @@ namespace OpenSim
private bool user_accounts = false;
private ConsoleBase m_console;
public UDPServer(int port, Grid gridServers, World localWorld, AssetCache assetCache, InventoryCache inventoryCache, RegionInfo _regionData, bool sandbox, bool accounts, ConsoleBase console)
public PacketServer PacketServer
{
get
{
return _packetServer;
}
set
{
_packetServer = value;
}
}
public World LocalWorld
{
set
{
this.m_localWorld = value;
this._packetServer.LocalWorld = this.m_localWorld;
}
}
public UDPServer(int port, Grid gridServers, AssetCache assetCache, InventoryCache inventoryCache, RegionInfo _regionData, bool sandbox, bool accounts, ConsoleBase console)
{
listenPort = port;
this.m_gridServers = gridServers;
this.m_localWorld = localWorld;
this.m_assetCache = assetCache;
this.m_inventoryCache = inventoryCache;
this.m_regionData = _regionData;
@ -58,8 +78,6 @@ namespace OpenSim
this.user_accounts = accounts;
this.m_console = console;
PacketServer packetServer = new PacketServer(this);
this._packetServer.LocalWorld = m_localWorld;
this._packetServer.RegisterClientPacketHandlers();
}
protected virtual void OnReceivedData(IAsyncResult result)
@ -85,7 +103,7 @@ namespace OpenSim
}
else
{ // invalid client
Console.Error.WriteLine("Main.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString());
Console.Error.WriteLine("UDPServer.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString());
}
Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
@ -106,22 +124,22 @@ namespace OpenSim
this._packetServer.ClientThreads.Add(useCircuit.CircuitCode.Code, newuser);
}
private void ServerListener()
public void ServerListener()
{
m_console.WriteLine("Main.cs:MainServerListener() - Opening UDP socket on " + listenPort);
m_console.WriteLine("UDPServer.cs:ServerListener() - Opening UDP socket on " + listenPort);
ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort);
Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
Server.Bind(ServerIncoming);
m_console.WriteLine("Main.cs:MainServerListener() - UDP socket bound, getting ready to listen");
m_console.WriteLine("UDPServer.cs:ServerListener() - UDP socket bound, getting ready to listen");
ipeSender = new IPEndPoint(IPAddress.Any, 0);
epSender = (EndPoint)ipeSender;
ReceivedData = new AsyncCallback(this.OnReceivedData);
Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
m_console.WriteLine("Main.cs:MainServerListener() - Listening...");
m_console.WriteLine("UDPServer.cs:ServerListener() - Listening...");
}