Skip to content

Commit

Permalink
Set threads to background so server respond to kill.
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasOlofsson committed Jul 13, 2016
1 parent c923121 commit df515a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/MiNET/MiNET.Client/MiNetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ public void AddToProcessing(Package message)
if(_processingThread == null)
{
_processingThread = new Thread(ProcessQueueThread);
_processingThread.IsBackground = true;
_processingThread.Start();
}

Expand Down
11 changes: 5 additions & 6 deletions src/MiNET/MiNET.ServiceKiller/Emulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static void Main(string[] args)
playerName, (int) (DateTime.UtcNow.Ticks - start), endPoint,
RanSleepMin, RanSleepMax, RequestChunkRadius);

new Thread(o => { client.EmulateClient(); }).Start();
new Thread(o => { client.EmulateClient(); }) {IsBackground = true}.Start();
//ThreadPool.QueueUserWorkItem(delegate { client.EmulateClient(); });

Thread.Sleep(TimeBetweenSpawns);
Expand All @@ -80,7 +80,6 @@ private static void Main(string[] args)
Console.WriteLine("Press <enter> to stop all clients.");
Console.ReadLine();
emulator.Running = false;

}
catch (Exception e)
{
Expand Down Expand Up @@ -184,14 +183,14 @@ public void EmulateClient()

double angle = 0.0;
const double angleStepsize = 0.05;
float heightStepsize = (float)(Random.NextDouble() / 5);
float heightStepsize = (float) (Random.NextDouble()/5);

while (angle < 2 * Math.PI && Emulator.Running)
while (angle < 2*Math.PI && Emulator.Running)
{
if (client.UdpClient == null) break;

float x = (float)(length * Math.Cos(angle));
float z = (float)(length * Math.Sin(angle));
float x = (float) (length*Math.Cos(angle));
float z = (float) (length*Math.Sin(angle));
y += heightStepsize;

x += client.Level.SpawnX;
Expand Down
8 changes: 3 additions & 5 deletions src/MiNET/MiNET/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private void HandleMcpeClientMagic(McpeClientMagic message)
var serverInfo = Server.ServerInfo;
Interlocked.Increment(ref serverInfo.ConnectionsInConnectPhase);

new Thread(Start).Start();
new Thread(Start) {IsBackground = true}.Start();
}

protected virtual void HandleMcpePlayerInput(McpePlayerInput message)
Expand Down Expand Up @@ -981,7 +981,7 @@ protected virtual void DecodeCert(McpeLogin message)
var serverInfo = Server.ServerInfo;
Interlocked.Increment(ref serverInfo.ConnectionsInConnectPhase);

new Thread(Start).Start();
new Thread(Start) {IsBackground = true}.Start();
}
}
catch (Exception e)
Expand Down Expand Up @@ -1312,11 +1312,9 @@ public virtual void SpawnLevel(Level toLevel, PlayerLocation spawnPoint, bool us

ForcedSendChunks(() =>
{

Log.InfoFormat("Respawn player {0} on level {1}", Username, Level.LevelId);

SendSetTime();

});
});
}
Expand Down Expand Up @@ -1620,7 +1618,7 @@ protected virtual void HandlePlayerDropItem(McpeDropItem message)
Item droppedItem = message.item;
if (Log.IsDebugEnabled) Log.Debug($"Player {Username} drops item {droppedItem} with inv slot {message.itemtype}");

if(droppedItem.Count == 0) return; // 0.15 bug
if (droppedItem.Count == 0) return; // 0.15 bug

if (!VerifyItemStack(droppedItem)) return;

Expand Down
12 changes: 5 additions & 7 deletions src/MiNET/MiNET/PlayerNetworkSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ public void AddToProcessing(Package message)

bool forceOrder = Config.GetProperty("ForceOrderingForAll", false);

if(!forceOrder)
if (!forceOrder)
{
Log.Warn($"Expected forced order {Player.Username}, Force={forceOrder}");

if (CryptoContext == null || CryptoContext.UseEncryption == false)
{
_lastSequenceNumber = message.OrderingIndex;
Expand All @@ -155,11 +153,11 @@ public void AddToProcessing(Package message)
return;
}

if (_processingThread== null)
if (_processingThread == null)
{
_processingThread = new Thread(ProcessQueueThread);
_processingThread = new Thread(ProcessQueueThread) {IsBackground = true};
_processingThread.Start();
Log.Warn($"Started processing thread for {Player.Username}");
if (Log.IsDebugEnabled) Log.Warn($"Started processing thread for {Player.Username}");
}

_queue.Enqueue(message.OrderingIndex, message);
Expand Down Expand Up @@ -267,7 +265,7 @@ internal void HandlePackage(Package message, PlayerNetworkSession playerSession)
if (typeof (UnknownPackage) == message.GetType())
{
UnknownPackage packet = (UnknownPackage) message;
if(Log.IsDebugEnabled) Log.Warn($"Received unknown package 0x{message.Id:X2}\n{Package.HexDump(packet.Message)}");
if (Log.IsDebugEnabled) Log.Warn($"Received unknown package 0x{message.Id:X2}\n{Package.HexDump(packet.Message)}");

message.PutPool();
return;
Expand Down

0 comments on commit df515a6

Please sign in to comment.