mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-06 21:25:42 +12:00
fix disconnecting
This commit is contained in:
parent
db248c5962
commit
a7ebf7ad0c
2 changed files with 12 additions and 21 deletions
|
@ -59,7 +59,6 @@ namespace HISP.Server
|
|||
|
||||
private List<byte> currentPacket = new List<byte>();
|
||||
private byte[] workBuffer = new byte[1028];
|
||||
private bool dcLock = false;
|
||||
|
||||
public GameClient(Socket clientSocket)
|
||||
{
|
||||
|
@ -81,6 +80,7 @@ namespace HISP.Server
|
|||
e.Completed += receivePackets;
|
||||
e.SetBuffer(workBuffer, 0, workBuffer.Length);
|
||||
ClientSocket.ReceiveAsync(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
|
||||
|
||||
if (!ClientSocket.Connected)
|
||||
isDisconnecting = true;
|
||||
|
||||
if (e.SocketError == SocketError.Success && !isDisconnecting)
|
||||
{
|
||||
|
||||
|
@ -119,13 +122,8 @@ namespace HISP.Server
|
|||
ClientSocket.ReceiveAsync(e);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
while (dcLock) { }; // Refuse to shut down until dcLock is cleared. (prevents TOCTOU issues.)
|
||||
|
||||
|
||||
Disconnect();
|
||||
|
||||
// Stop Timers
|
||||
if (inactivityTimer != null)
|
||||
|
@ -144,12 +142,11 @@ namespace HISP.Server
|
|||
ClientSocket.Close();
|
||||
ClientSocket.Dispose();
|
||||
|
||||
return; // Stop the task.
|
||||
return;
|
||||
}
|
||||
|
||||
private void minuteTimerTick(object state)
|
||||
{
|
||||
dcLock = true;
|
||||
totalMinutesElapsed++;
|
||||
if (LoggedIn)
|
||||
{
|
||||
|
@ -166,7 +163,6 @@ namespace HISP.Server
|
|||
LoggedinUser.FreeMinutes = 0;
|
||||
if (!LoggedinUser.Subscribed && !LoggedinUser.Moderator && !LoggedinUser.Administrator)
|
||||
{
|
||||
dcLock = false;
|
||||
Kick(Messages.KickReasonNoTime);
|
||||
return;
|
||||
}
|
||||
|
@ -311,7 +307,6 @@ namespace HISP.Server
|
|||
|
||||
if (!isDisconnecting)
|
||||
minuteTimer.Change(oneMinute, oneMinute);
|
||||
dcLock = false;
|
||||
}
|
||||
private void keepAliveTimerTick(object state)
|
||||
{
|
||||
|
|
|
@ -4,7 +4,6 @@ using System.Globalization;
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
using HISP.Game;
|
||||
using HISP.Game.Horse;
|
||||
using HISP.Game.SwfModules;
|
||||
|
||||
namespace HISP.Server
|
||||
|
@ -229,15 +228,12 @@ namespace HISP.Server
|
|||
|
||||
public static byte[] Create2PlayerClose()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
ms.WriteByte(PACKET_SWFMODULE);
|
||||
ms.WriteByte(SWFMODULE_2PLAYER_CLOSED);
|
||||
ms.WriteByte(PACKET_TERMINATOR);
|
||||
byte[] packet = new byte[3];
|
||||
packet[0] = PACKET_SWFMODULE;
|
||||
packet[1] = SWFMODULE_2PLAYER_CLOSED;
|
||||
packet[2] = PACKET_TERMINATOR;
|
||||
|
||||
ms.Seek(0x00, SeekOrigin.Begin);
|
||||
byte[] response = ms.ToArray();
|
||||
ms.Dispose();
|
||||
return response;
|
||||
return packet;
|
||||
}
|
||||
public static byte[] CreateDressupRoomPeiceMove(int peiceId, double x, double y, bool active)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue