Beispiel #1
0
        internal void Close()
        {
            Authorizated = false;
            if (mClosed)
            {
                return;
            }
            else
            {
                mClosed = true;
            }

            try
            {
                mSock.Close();
            }
            catch { }

            //mSock = null;
            //mDataBuffer = null;
            SessionManagement.RemoveSession(this);
            GC.Collect();
        }
Beispiel #2
0
        private void BytesReceived(IAsyncResult pIar)
        {
            try
            {
                int BytesReceived = mSock.EndReceive(pIar);
                try
                {
                    byte[] ReceivedData = new byte[BytesReceived];
                    Array.Copy(mDataBuffer, ReceivedData, BytesReceived);
                    string[] Packets = System.Text.Encoding.Default.GetString(mDataBuffer, 0, BytesReceived).Split('|');
                    foreach (string Packet in Packets)
                    {
                        if (string.IsNullOrEmpty(Packet))
                        {
                            continue;
                        }
                        string[] Data = Packet.Split(':');
                        if (Data[0].Length == 0)
                        {
                            Close();
                            return;
                        }

                        switch (Data[0])
                        {
                        /*
                         *
                         *
                         */
                        case "auth":
                        {
                            if (Data[1] == "123")
                            {
                                SendData("authok");
                                SessionManagement.RegisterSession(this);
                                Authorizated = true;
                            }
                            else
                            {
                                Close();
                            }
                            break;
                        }

                        case "upda":
                        {
                            if (!Authorizated)
                            {
                                Close();
                            }
                            else
                            {
                                int Rate;
                                if (mDisconnections == 0)
                                {
                                    Rate = 0;
                                }
                                else if (mDisconnections == 0 && mDisconnectionErrors > 0)
                                {
                                    Rate = mDisconnectionErrors;
                                }
                                else
                                {
                                    Rate = mDisconnectionErrors / mDisconnections;
                                }
                                mDisconnections      = 0;
                                mDisconnectionErrors = 0;
                                //
                                SendData("data:onlinecount=" + (ButterflyEnvironment.GetGame().GetClientManager().ClientCount) + ",roomloadcount=" + ButterflyEnvironment.GetGame().GetRoomManager().LoadedRoomsCount + ",disconnectionrate=" + Rate);
                                i++;
                            }
                            break;
                        }
                        }
                    }
                    ContinueListening();
                }
                catch
                {
                    Close();
                }
            }
            catch
            {
                Close();
            }
        }