public void ResetCache() { ReceiveList.Clear(); SendList.Clear(); SendCount = 0; ReceiveCount = 0; }
private static void ConnectionLost() { Connected = false; SendList.Clear(); Disconnect(); MirScenes.SceneFunctions.ConnectionLost(); }
public static void Disconnect() { while (Connected && SendList.Count > 0) { BeginSend(SendList.Dequeue()); } Connected = false; if (Client != null) { Client.Client.Dispose(); } Client = null; SendList.Clear(); ReceiveList.Clear(); }
private void ReceiveData(IAsyncResult Result) { if (!Connected) { return; } int DataRead; try { DataRead = TClient.Client.EndReceive(Result); } catch { Connected = false; SendList.Clear(); Disconnect(); return; } if (DataRead == 0) { Disconnect(); return; } byte[] RawBytes = Result.AsyncState as byte[]; byte[] Temp = RawData; RawData = new byte[DataRead + Temp.Length]; System.Buffer.BlockCopy(Temp, 0, RawData, 0, Temp.Length); System.Buffer.BlockCopy(RawBytes, 0, RawData, Temp.Length, DataRead); Packet P; while ((P = Packet.ReceivePacket(RawData, out RawData)) != null) { ReceiveList.Enqueue(P); } BeginReceive(); }
private void BeginReceive() { if (!Connected) { return; } byte[] RawBytes = new byte[8 * 1024]; try { TClient.Client.BeginReceive(RawBytes, 0, RawBytes.Length, SocketFlags.None, ReceiveData, RawBytes); } catch { Connected = false; SendList.Clear(); Disconnect(); } }
private void BeginSend(Packet P) { if (!Connected || P == null) { return; } byte[] RawBytes = P.GetPacketBytes(); try { TClient.Client.BeginSend(RawBytes, 0, RawBytes.Length, SocketFlags.None, SendData, null); } catch { Connected = false; SendList.Clear(); Disconnect(); } }
public void Process() { while (ReceiveList.Count > 0) { ProcessPacket(ReceiveList.Dequeue()); TimeOutTime = Main.Time + Settings.TimeOut; } if (Main.Time > TimeOutTime) { Connected = false; SendList.Clear(); Disconnect(); return; } while (SendList.Count > 0) { BeginSend(SendList.Dequeue()); } }
public void Disconnect() { while (Connected && SendList.Count > 0) { BeginSend(SendList.Dequeue()); } Connected = false; if (Stage == GameStage.Disconnected) { return; } if (Stage == GameStage.Game) { Player.DeSpawn(); } Stage = GameStage.Disconnected; TimeDisconnected = Main.Time; if (TClient != null) { TClient.Client.Dispose(); } TClient = null; Account = null; SendList.Clear(); ReceiveList.Clear(); Network.ActiveConnections.Remove(this); if (!Network.ExpiredConnections.Contains(this)) { Network.ExpiredConnections.Add(this); } }