Revert "So much cuteness"

This reverts commit 28b42ce2d2.
This commit is contained in:
cinder
2022-11-20 00:08:33 -06:00
parent 2af59f2d10
commit d7de598d7e
11 changed files with 165 additions and 124 deletions

View File

@@ -36,7 +36,7 @@ using OpenMetaverse.Interfaces;
using OpenMetaverse.Messages.Linden;
namespace OpenMetaverse
{
{
/// <summary>
/// NetworkManager is responsible for managing the network layer of
/// OpenMetaverse. It tracks all the server connections, serializes
@@ -463,14 +463,14 @@ namespace OpenMetaverse
{
Logger.DebugLog("simulator object was null, using first found connected simulator", Client);
simulator = Client.Network.Simulators[0];
}
}
if (simulator != null)
{
simulator.SendPacket(packet);
}
else
{
NetworkInvaildWarning("simulator", "SendPacket");
else
{
NetworkInvaildWarning("simulator", "SendPacket");
}
}
@@ -479,34 +479,34 @@ namespace OpenMetaverse
/// </summary>
/// <param name="packet">Incoming packet to process</param>
public void EnqueueIncoming(IncomingPacket packet)
{
if (_packetInbox != null)
{
if (_packetInbox.Writer.TryWrite(packet))
Interlocked.Increment(ref _packetInboxCount);
{
if (_packetInbox != null)
{
if (_packetInbox.Writer.TryWrite(packet))
Interlocked.Increment(ref _packetInboxCount);
}
else
{
NetworkInvaildWarning("_packetInbox", "EnqueueIncoming");
}
else
{
NetworkInvaildWarning("_packetInbox", "EnqueueIncoming");
}
}
}
/// <summary>
/// adds a debug message when you try to access a network item
/// while they are still null
/// </summary>
/// <param name="source">what</param>
/// <param name="function">where</param>
protected void NetworkInvaildWarning(string source,string function)
{
long now = DateTimeOffset.Now.ToUnixTimeSeconds();
long dif = lastpacketwarning - now;
if (dif > 10)
{
lastpacketwarning = now;
Logger.Log(source+" is null (Are we disconnected?) - from: "+ function,
Helpers.LogLevel.Debug);
}
protected void NetworkInvaildWarning(string source,string function)
{
long now = DateTimeOffset.Now.ToUnixTimeSeconds();
long dif = lastpacketwarning - now;
if (dif > 10)
{
lastpacketwarning = now;
Logger.Log(source+" is null (Are we disconnected?) - from: "+ function,
Helpers.LogLevel.Debug);
}
}
/// <summary>
@@ -515,14 +515,14 @@ namespace OpenMetaverse
/// <param name="packet">Incoming packet to process</param>
public void EnqueueOutgoing(OutgoingPacket packet)
{
if (_packetOutbox != null)
{
if (_packetOutbox.Writer.TryWrite(packet))
if (_packetOutbox != null)
{
if (_packetOutbox.Writer.TryWrite(packet))
Interlocked.Increment(ref _packetOutboxCount);
}
else
{
NetworkInvaildWarning("_packetOutbox", "EnqueueOutgoing");
}
else
{
NetworkInvaildWarning("_packetOutbox", "EnqueueOutgoing");
}
}
@@ -607,8 +607,12 @@ namespace OpenMetaverse
// Attempt to establish a connection to the simulator
if (simulator.Connect(setDefault))
{
DisconnectTimer ??= new Timer(DisconnectTimer_Elapsed, null,
Client.Settings.SIMULATOR_TIMEOUT, Client.Settings.SIMULATOR_TIMEOUT);
if (DisconnectTimer == null)
{
// Start a timer that checks if we've been disconnected
DisconnectTimer = new Timer(DisconnectTimer_Elapsed, null,
Client.Settings.SIMULATOR_TIMEOUT, Client.Settings.SIMULATOR_TIMEOUT);
}
if (setDefault)
{
@@ -785,9 +789,9 @@ namespace OpenMetaverse
if (simulatorsCount == 0) Shutdown(DisconnectType.SimShutdown);
}
else
{
NetworkInvaildWarning("simulator", "DisconnectSim");
else
{
NetworkInvaildWarning("simulator", "DisconnectSim");
}
}
@@ -909,73 +913,73 @@ namespace OpenMetaverse
private async Task OutgoingPacketHandler()
{
if (_packetOutbox != null)
{
var reader = _packetOutbox.Reader;
// FIXME: This is kind of ridiculous. Port the HTB code from Simian over ASAP!
var stopwatch = new System.Diagnostics.Stopwatch();
while (await reader.WaitToReadAsync() && Connected)
{
while (reader.TryRead(out var outgoingPacket))
{
Interlocked.Decrement(ref _packetOutboxCount);
var simulator = outgoingPacket.Simulator;
stopwatch.Stop();
if (stopwatch.ElapsedMilliseconds < 10)
{
//Logger.DebugLog(String.Format("Rate limiting, last packet was {0}ms ago", ms));
Thread.Sleep(10 - (int)stopwatch.ElapsedMilliseconds);
}
simulator.SendPacketFinal(outgoingPacket);
stopwatch.Start();
}
if (_packetOutbox != null)
{
var reader = _packetOutbox.Reader;
// FIXME: This is kind of ridiculous. Port the HTB code from Simian over ASAP!
var stopwatch = new System.Diagnostics.Stopwatch();
while (await reader.WaitToReadAsync() && Connected)
{
while (reader.TryRead(out var outgoingPacket))
{
Interlocked.Decrement(ref _packetOutboxCount);
var simulator = outgoingPacket.Simulator;
stopwatch.Stop();
if (stopwatch.ElapsedMilliseconds < 10)
{
//Logger.DebugLog(String.Format("Rate limiting, last packet was {0}ms ago", ms));
Thread.Sleep(10 - (int)stopwatch.ElapsedMilliseconds);
}
simulator.SendPacketFinal(outgoingPacket);
stopwatch.Start();
}
}
}
else
{
NetworkInvaildWarning("_packetOutbox", "OutgoingPacketHandler");
}
else
{
NetworkInvaildWarning("_packetOutbox", "OutgoingPacketHandler");
}
}
private async Task IncomingPacketHandler()
{
if (_packetInbox != null)
{
var reader = _packetInbox.Reader;
while (await reader.WaitToReadAsync() && Connected)
{
while (reader.TryRead(out var incomingPacket))
{
Interlocked.Decrement(ref _packetInboxCount);
var packet = incomingPacket.Packet;
var simulator = incomingPacket.Simulator;
if (packet == null) continue;
// Skip blacklisted packets
if (UDPBlacklist.Contains(packet.Type.ToString()))
{
Logger.Log($"Discarding Blacklisted packet {packet.Type} from {simulator.IPEndPoint}",
Helpers.LogLevel.Warning);
return;
}
// Fire the callback(s), if any
PacketEvents.RaiseEvent(packet.Type, packet, simulator);
}
if (_packetInbox != null)
{
var reader = _packetInbox.Reader;
while (await reader.WaitToReadAsync() && Connected)
{
while (reader.TryRead(out var incomingPacket))
{
Interlocked.Decrement(ref _packetInboxCount);
var packet = incomingPacket.Packet;
var simulator = incomingPacket.Simulator;
if (packet == null) continue;
// Skip blacklisted packets
if (UDPBlacklist.Contains(packet.Type.ToString()))
{
Logger.Log($"Discarding Blacklisted packet {packet.Type} from {simulator.IPEndPoint}",
Helpers.LogLevel.Warning);
return;
}
// Fire the callback(s), if any
PacketEvents.RaiseEvent(packet.Type, packet, simulator);
}
}
}
else
{
NetworkInvaildWarning("_packetInbox", "IncomingPacketHandler");
}
else
{
NetworkInvaildWarning("_packetInbox", "IncomingPacketHandler");
}
}