Added TShock.SendBytes which uses packetbuffer if available, otherwise sends like normal.
This commit is contained in:
parent
2ed91e26a0
commit
258b7d48fb
4 changed files with 44 additions and 19 deletions
|
|
@ -30,6 +30,7 @@ using System.Data;
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Linq;
|
||||
|
|
@ -64,7 +65,7 @@ namespace TShockAPI
|
|||
public static ConfigFile Config { get; set; }
|
||||
public static IDbConnection DB;
|
||||
public static bool OverridePort;
|
||||
PacketBufferer bufferer;
|
||||
static PacketBufferer bufferer;
|
||||
|
||||
|
||||
public override Version Version
|
||||
|
|
@ -655,6 +656,33 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send bytes to client using packetbuffering if available
|
||||
/// </summary>
|
||||
/// <param name="client">socket to send to</param>
|
||||
/// <param name="bytes">bytes to send</param>
|
||||
/// <returns>False on exception</returns>
|
||||
public static bool SendBytes(ServerSock client, byte[] bytes)
|
||||
{
|
||||
if (bufferer != null)
|
||||
{
|
||||
bufferer.SendBytes(client, bytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (client.tcpClient.Connected)
|
||||
client.networkStream.Write(bytes, 0, bytes.Length);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnSaveWorld(bool resettime, HandledEventArgs e)
|
||||
{
|
||||
Tools.Broadcast("Saving world. Momentary lag might result from this.", Color.Red);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue