Esempio n. 1
0
 public void ResetCache()
 {
     ReceiveList.Clear();
     SendList.Clear();
     SendCount    = 0;
     ReceiveCount = 0;
 }
Esempio n. 2
0
        private static void ConnectionLost()
        {
            Connected = false;
            SendList.Clear();
            Disconnect();

            MirScenes.SceneFunctions.ConnectionLost();
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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();
            }
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
0
        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());
            }
        }
Esempio n. 8
0
        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);
            }
        }