Fixed issue of the client being killed before receiving the disconnect message.
This commit is contained in:
parent
4dae27001c
commit
7b58100546
3 changed files with 55 additions and 29 deletions
|
|
@ -91,32 +91,49 @@ namespace TShockAPI
|
|||
}
|
||||
|
||||
void GameHooks_Update(GameTime obj)
|
||||
{
|
||||
FlushAll();
|
||||
}
|
||||
|
||||
public void FlushAll()
|
||||
{
|
||||
for (int i = 0; i < Netplay.serverSock.Length; i++)
|
||||
{
|
||||
if (Netplay.serverSock[i] == null || !Netplay.serverSock[i].active)
|
||||
continue;
|
||||
|
||||
if (!Netplay.serverSock[i].tcpClient.Client.Poll(0, SelectMode.SelectWrite))
|
||||
continue;
|
||||
|
||||
byte[] buff = buffers[i].GetBytes(BytesPerUpdate);
|
||||
if (buff == null)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
Netplay.serverSock[i].tcpClient.Client.Send(buff);
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
}
|
||||
Flush(Netplay.serverSock[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Flush(ServerSock socket)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (socket == null || !socket.active)
|
||||
return false;
|
||||
|
||||
if (!socket.tcpClient.Client.Poll(0, SelectMode.SelectWrite))
|
||||
return false;
|
||||
|
||||
byte[] buff = buffers[socket.whoAmI].GetBytes(BytesPerUpdate);
|
||||
if (buff == null)
|
||||
return false;
|
||||
|
||||
|
||||
socket.tcpClient.Client.Send(buff);
|
||||
return true;
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.ConsoleError(e.ToString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ServerHooks_SocketReset(ServerSock socket)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -156,6 +156,16 @@ namespace TShockAPI
|
|||
public virtual void Disconnect(string reason)
|
||||
{
|
||||
SendData(PacketTypes.Disconnect, reason);
|
||||
Flush();
|
||||
}
|
||||
|
||||
public virtual void Flush()
|
||||
{
|
||||
var sock = Netplay.serverSock[Index];
|
||||
if (sock == null)
|
||||
return;
|
||||
|
||||
TShock.PacketBuffer.Flush(sock);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace TShockAPI
|
|||
public static ConfigFile Config { get; set; }
|
||||
public static IDbConnection DB;
|
||||
public static bool OverridePort;
|
||||
static PacketBufferer bufferer;
|
||||
public static PacketBufferer PacketBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// Called after TShock is initialized. Useful for plugins that needs hooks before tshock but also depend on tshock being loaded.
|
||||
|
|
@ -178,7 +178,7 @@ namespace TShockAPI
|
|||
ServerHooks.Leave += OnLeave;
|
||||
ServerHooks.Chat += OnChat;
|
||||
ServerHooks.Command += ServerHooks_OnCommand;
|
||||
NetHooks.GetData += GetData;
|
||||
NetHooks.GetData += OnGetData;
|
||||
NetHooks.GreetPlayer += OnGreetPlayer;
|
||||
NpcHooks.StrikeNpc += NpcHooks_OnStrikeNpc;
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ namespace TShockAPI
|
|||
//RconHandler.StartThread();
|
||||
|
||||
if (Config.BufferPackets)
|
||||
bufferer = new PacketBufferer();
|
||||
PacketBuffer = new PacketBufferer();
|
||||
|
||||
Log.ConsoleInfo("AutoSave " + (Config.AutoSave ? "Enabled" : "Disabled"));
|
||||
Log.ConsoleInfo("Backups " + (Backups.Interval > 0 ? "Enabled" : "Disabled"));
|
||||
|
|
@ -211,7 +211,7 @@ namespace TShockAPI
|
|||
ServerHooks.Leave -= OnLeave;
|
||||
ServerHooks.Chat -= OnChat;
|
||||
ServerHooks.Command -= ServerHooks_OnCommand;
|
||||
NetHooks.GetData -= GetData;
|
||||
NetHooks.GetData -= OnGetData;
|
||||
NetHooks.GreetPlayer -= OnGreetPlayer;
|
||||
NpcHooks.StrikeNpc -= NpcHooks_OnStrikeNpc;
|
||||
if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
|
||||
|
|
@ -550,7 +550,7 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
private void GetData(GetDataEventArgs e)
|
||||
private void OnGetData(GetDataEventArgs e)
|
||||
{
|
||||
if (e.Handled)
|
||||
return;
|
||||
|
|
@ -569,8 +569,7 @@ namespace TShockAPI
|
|||
return;
|
||||
}
|
||||
|
||||
//if (type == PacketTypes.SyncPlayers)
|
||||
//Debug.WriteLine("Recv: {0:X} ({2}): {3} ({1:XX})", player.Index, (byte)type, player.TPlayer.dead ? "dead " : "alive", type.ToString());
|
||||
//Debug.WriteLine("Recv: {0:X} ({2}): {3} ({1:XX})", player.Index, (byte)type, player.TPlayer.dead ? "dead " : "alive", type);
|
||||
|
||||
// Stop accepting updates from player as this player is going to be kicked/banned during OnUpdate (different thread so can produce race conditions)
|
||||
if ((Config.BanKillTileAbusers || Config.KickKillTileAbusers) &&
|
||||
|
|
@ -655,9 +654,9 @@ namespace TShockAPI
|
|||
/// <returns>False on exception</returns>
|
||||
public static bool SendBytes(ServerSock client, byte[] bytes)
|
||||
{
|
||||
if (bufferer != null)
|
||||
if (PacketBuffer != null)
|
||||
{
|
||||
bufferer.SendBytes(client, bytes);
|
||||
PacketBuffer.SendBytes(client, bytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue