Пример #1
0
        internal static void SetupListener(int Port)
        {
            SessionManagement.Init();
            mListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint Endpoint = new IPEndPoint(IPAddress.Any, Port);

            mListener.Bind(Endpoint);

            mListener.Listen(1000);
            mConnectionReqCallback = new AsyncCallback(ConnectionRequest);
        }
Пример #2
0
        internal void Close()
        {
            Authorizated = false;
            if (mClosed)
            {
                return;
            }
            else
            {
                mClosed = true;
            }

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

            //mSock = null;
            //mDataBuffer = null;
            SessionManagement.RemoveSession(this);
            Logging.WriteLine("Reached end of session");
            //GC.Collect();
        }
Пример #3
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] == "bitch")
                            {
                                Logging.WriteLine(mIP + " -> Reached session");
                                SendData("authok");
                                SessionManagement.RegisterSession(this);
                                Authorizated = true;

                                DatabaseStats.totalQueries   = 0;
                                DatabaseStats.totalQueryTime = 0;
                            }
                            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;

                                int    totalQueries   = DatabaseStats.totalQueries;
                                double totalQueryTime = DatabaseStats.totalQueryTime;

                                DatabaseStats.totalQueries   = 0;
                                DatabaseStats.totalQueryTime = 0;

                                int rate = 0;

                                if (totalQueryTime != 0 && totalQueries != 0)
                                {
                                    rate = (int)(totalQueryTime / totalQueries);
                                }

                                if (count == 0)
                                {
                                    queryspersecond = totalQueries;
                                    count++;
                                }
                                else
                                {
                                    count = 0;
                                }

                                //
                                SendData("data:onlinecount=" + (PiciEnvironment.GetGame().GetClientManager().ClientCount) + ",roomloadcount=" + PiciEnvironment.GetGame().GetRoomManager().LoadedRoomsCount + ",disconnectionrate=" + Rate + ",qurate=" + rate + ",qps=" + queryspersecond);
                            }
                            break;
                        }
                        }
                    }
                    ContinueListening();
                }
                catch
                {
                    Close();
                }
            }
            catch
            {
                Close();
            }
        }