fix disconnecting

This commit is contained in:
Bluzume 2021-11-02 02:15:46 -04:00
parent db248c5962
commit a7ebf7ad0c
2 changed files with 12 additions and 21 deletions

View file

@ -59,7 +59,6 @@ namespace HISP.Server
private List<byte> currentPacket = new List<byte>(); private List<byte> currentPacket = new List<byte>();
private byte[] workBuffer = new byte[1028]; private byte[] workBuffer = new byte[1028];
private bool dcLock = false;
public GameClient(Socket clientSocket) public GameClient(Socket clientSocket)
{ {
@ -81,6 +80,7 @@ namespace HISP.Server
e.Completed += receivePackets; e.Completed += receivePackets;
e.SetBuffer(workBuffer, 0, workBuffer.Length); e.SetBuffer(workBuffer, 0, workBuffer.Length);
ClientSocket.ReceiveAsync(e); ClientSocket.ReceiveAsync(e);
} }
public static void CreateClient(object sender, SocketAsyncEventArgs e) public static void CreateClient(object sender, SocketAsyncEventArgs e)
@ -97,6 +97,9 @@ namespace HISP.Server
// HI1 Packets are terminates by 0x00 so we have to read until we receive that terminator // HI1 Packets are terminates by 0x00 so we have to read until we receive that terminator
if (!ClientSocket.Connected)
isDisconnecting = true;
if (e.SocketError == SocketError.Success && !isDisconnecting) if (e.SocketError == SocketError.Success && !isDisconnecting)
{ {
@ -119,13 +122,8 @@ namespace HISP.Server
ClientSocket.ReceiveAsync(e); ClientSocket.ReceiveAsync(e);
return; return;
} }
else
{ Disconnect();
Disconnect();
}
while (dcLock) { }; // Refuse to shut down until dcLock is cleared. (prevents TOCTOU issues.)
// Stop Timers // Stop Timers
if (inactivityTimer != null) if (inactivityTimer != null)
@ -144,12 +142,11 @@ namespace HISP.Server
ClientSocket.Close(); ClientSocket.Close();
ClientSocket.Dispose(); ClientSocket.Dispose();
return; // Stop the task. return;
} }
private void minuteTimerTick(object state) private void minuteTimerTick(object state)
{ {
dcLock = true;
totalMinutesElapsed++; totalMinutesElapsed++;
if (LoggedIn) if (LoggedIn)
{ {
@ -166,7 +163,6 @@ namespace HISP.Server
LoggedinUser.FreeMinutes = 0; LoggedinUser.FreeMinutes = 0;
if (!LoggedinUser.Subscribed && !LoggedinUser.Moderator && !LoggedinUser.Administrator) if (!LoggedinUser.Subscribed && !LoggedinUser.Moderator && !LoggedinUser.Administrator)
{ {
dcLock = false;
Kick(Messages.KickReasonNoTime); Kick(Messages.KickReasonNoTime);
return; return;
} }
@ -311,7 +307,6 @@ namespace HISP.Server
if (!isDisconnecting) if (!isDisconnecting)
minuteTimer.Change(oneMinute, oneMinute); minuteTimer.Change(oneMinute, oneMinute);
dcLock = false;
} }
private void keepAliveTimerTick(object state) private void keepAliveTimerTick(object state)
{ {

View file

@ -4,7 +4,6 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Text; using System.Text;
using HISP.Game; using HISP.Game;
using HISP.Game.Horse;
using HISP.Game.SwfModules; using HISP.Game.SwfModules;
namespace HISP.Server namespace HISP.Server
@ -229,15 +228,12 @@ namespace HISP.Server
public static byte[] Create2PlayerClose() public static byte[] Create2PlayerClose()
{ {
MemoryStream ms = new MemoryStream(); byte[] packet = new byte[3];
ms.WriteByte(PACKET_SWFMODULE); packet[0] = PACKET_SWFMODULE;
ms.WriteByte(SWFMODULE_2PLAYER_CLOSED); packet[1] = SWFMODULE_2PLAYER_CLOSED;
ms.WriteByte(PACKET_TERMINATOR); packet[2] = PACKET_TERMINATOR;
ms.Seek(0x00, SeekOrigin.Begin); return packet;
byte[] response = ms.ToArray();
ms.Dispose();
return response;
} }
public static byte[] CreateDressupRoomPeiceMove(int peiceId, double x, double y, bool active) public static byte[] CreateDressupRoomPeiceMove(int peiceId, double x, double y, bool active)
{ {