public void SentToPlayer(Package.Package p) { ThreadPool2.QueueWorkItem(() => { try { Writer.WriteLine(p.ToString()); Core.Logger.Debug($"Sent: {p.ToString()}", this); } catch (Exception) { } }); }
public void SendToAllOperator(Package.Package package) { lock (Collection.SyncRoot) { foreach (Networking network in ActivePlayer) { if (package.Network != null && package.Network != network) { network.SentToPlayer(package); } } } }
public void SendToAllPlayer(Package.Package package, bool exceptSelf = false) { lock (Collection.SyncRoot) { foreach (Networking network in ActivePlayer) { if (exceptSelf) { if (package.Network != null && package.Network != network) { network.SentToPlayer(package); } } else { network.SentToPlayer(package); } } } }
public Networking(Core core, TcpClient tcpClient) { Core = core; TcpClient = tcpClient; Reader = new StreamReader(tcpClient.GetStream()); Writer = new StreamWriter(tcpClient.GetStream()) { AutoFlush = true }; IsActive = true; Thread.Add(() => { int errorCount = 0; do { try { if (tcpClient.Available > -1) { string packageString = Reader.ReadLine(); if (!string.IsNullOrWhiteSpace(packageString)) { ThreadPool.QueueWorkItem(() => { Core.Logger.Debug($"Receive: {packageString}", this); Package.Package package = new Package.Package(Core, packageString, this); if (package.IsValid) { package.Handle(); } }); errorCount = 0; } else { errorCount++; if (errorCount > 10) { Dispose(); } } } else { Dispose(); } } catch (ThreadAbortException) { return; } catch (Exception) { if (IsActive) { Dispose(); } } } while (IsActive); }); }