Added TShock.SendBytes which uses packetbuffer if available, otherwise sends like normal.

This commit is contained in:
high 2011-08-12 23:17:23 -04:00
parent 2ed91e26a0
commit 258b7d48fb
4 changed files with 44 additions and 19 deletions

View file

@ -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);