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
|
|
@ -123,9 +123,13 @@ namespace TShockAPI
|
|||
buffers[socket.whoAmI] = new PacketBuffer();
|
||||
}
|
||||
|
||||
void ServerHooks_SendBytes(ServerSock socket, byte[] buffer, int offset, int count, HandledEventArgs e)
|
||||
public void SendBytes(ServerSock socket, byte[] buffer)
|
||||
{
|
||||
SendBytes(socket, buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
public void SendBytes(ServerSock socket, byte[] buffer, int offset, int count)
|
||||
{
|
||||
e.Handled = true;
|
||||
lock (buffers[socket.whoAmI])
|
||||
{
|
||||
#if DEBUG_NET
|
||||
|
|
@ -142,6 +146,12 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerHooks_SendBytes(ServerSock socket, byte[] buffer, int offset, int count, HandledEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
SendBytes(socket, buffer, offset, count);
|
||||
}
|
||||
#if DEBUG_NET
|
||||
static int Compress(byte[] buffer, int offset, int count)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,5 +36,5 @@ using System.Runtime.InteropServices;
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
|
||||
[assembly: AssemblyVersion("3.2.6.0811")]
|
||||
[assembly: AssemblyFileVersion("3.2.6.0811")]
|
||||
[assembly: AssemblyVersion("3.2.6.0812")]
|
||||
[assembly: AssemblyFileVersion("3.2.6.0812")]
|
||||
|
|
|
|||
|
|
@ -339,20 +339,7 @@ namespace TShockAPI
|
|||
if (!RealPlayer || !ConnectionAlive)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
if (Netplay.serverSock[Index].tcpClient.Connected)
|
||||
{
|
||||
Netplay.serverSock[Index].networkStream.Write(data, 0, data.Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
}
|
||||
return false;
|
||||
return TShock.SendBytes(Netplay.serverSock[Index], data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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