Example #1
0
        /// <summary>
        /// When a new connection is established, we the parent class are responsible
        /// for handling the processing
        /// </summary>
        /// <param name="Stream">A GamespyTcpStream object that wraps the I/O AsyncEventArgs and socket</param>
        protected override void ProcessAccept(GamespyTcpStream Stream)
        {
            // Get our connection id
            long       ConID = Interlocked.Increment(ref ConnectionCounter);
            GpcmClient client;

            try
            {
                // Create a new GpcmClient, passing the IO object for the TcpClientStream
                client = new GpcmClient(Stream, ConID);
                Processing.TryAdd(ConID, client);

                // Begin the asynchronous login process
                client.SendServerChallenge();
            }
            catch (Exception e)
            {
                // Log the error
                Program.ErrorLog.Write("WARNING: An Error occured at [GpcmServer.ProcessAccept] : Generating Exception Log");
                ExceptionHandler.GenerateExceptionLog(e);

                // Remove pending connection
                Processing.TryRemove(ConID, out client);

                // Release this stream so it can be used again
                base.Release(Stream);
            }
        }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="client"></param>
        public GpspClient(GamespyTcpStream client, long connectionId)
        {
            // Generate a unique name for this connection
            ConnectionID = connectionId;

            // Init a new client stream class
            Stream = client;
            Stream.OnDisconnect += () => Dispose();
            Stream.DataReceived += (message) =>
            {
                // Read client message, and parse it into key value pairs
                string[] recieved = message.TrimStart('\\').Split('\\');
                Dictionary <string, string> Data = ConvertToKeyValue(recieved);
                switch (recieved[0])
                {
                case "nicks":
                    SendNicks(Data);
                    break;

                case "check":
                    SendCheck(Data);
                    break;
                }
            };
        }
Example #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="client"></param>
        public MasterClient(GamespyTcpStream client)
        {
            // Internal Variables
            this.Disposed = false;

            // Generate a unique name for this connection
            this.ConnectionId = Interlocked.Increment(ref SessionsCreated);

            // Init a new client stream class
            Stream = client;
            Stream.OnDisconnect += () => Dispose();
            Stream.DataReceived += (receivedData) =>
            {
                // lets split up the message based on the delimiter
                string[] messages = receivedData.Split(new string[] { "\x00\x00\x00\x00" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string message in messages)
                {
                    // Ignore Non-BF2 related queries
                    if (message.StartsWith("battlefield2"))
                    {
                        ParseRequest(message);
                    }
                }
            };
        }
Example #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        public GpspClient(GamespyTcpStream client)
        {
            // Set disposed to false!
            this.Disposed = false;

            // Generate a unique name for this connection
            this.ConnectionId = Interlocked.Increment(ref SessionsCreated);

            // Init a new client stream class
            Stream = client;
            Stream.OnDisconnect += () => Dispose();
            Stream.DataReceived += (message) =>
            {
                // Read client message, and parse it into key value pairs
                string[] recieved = message.TrimStart('\\').Split('\\');
                switch (recieved[0])
                {
                case "nicks":
                    SendNicks(ConvertToKeyValue(recieved));
                    break;

                case "check":
                    SendCheck(ConvertToKeyValue(recieved));
                    break;
                }
            };
        }
Example #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ReadArgs">The Tcp Client connection</param>
        public GpcmClient(GamespyTcpStream ConnectionStream, long ConnectionId)
        {
            // Set default variable values
            PlayerNick     = "Connecting...";
            PlayerId       = 0;
            RemoteEndPoint = (IPEndPoint)ConnectionStream.RemoteEndPoint;
            Disposed       = false;
            Status         = LoginStatus.Connected;

            // Set the connection ID
            this.ConnectionId = ConnectionId;

            // Create our Client Stream
            Stream = ConnectionStream;
            Stream.OnDisconnect += Stream_OnDisconnect;
            Stream.DataReceived += Stream_DataReceived;
            Stream.BeginReceive();
        }
Example #6
0
        /// <summary>
        /// When a new connection is established, we the parent class are responsible
        /// for handling the processing
        /// </summary>
        /// <param name="Stream">A GamespyTcpStream object that wraps the I/O AsyncEventArgs and socket</param>
        protected override void ProcessAccept(GamespyTcpStream Stream)
        {
            try
            {
                // Convert the TcpClient to a MasterClient
                GpspClient client = new GpspClient(Stream);
                Clients.TryAdd(client.ConnectionId, client);

                // Begin accepting data now that we are fully connected
                Stream.BeginReceive();
            }
            catch (Exception e)
            {
                L.LogError("WARNING: An Error occured at [Gpsp.ProcessAccept] : Generating Exception Log");
                ExceptionHandler.GenerateExceptionLog(e);
                base.Release(Stream);
            }
        }
Example #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="client"></param>
        public MasterClient(GamespyTcpStream client, long connectionId)
        {
            // Generate a unique name for this connection
            ConnectionID = connectionId;

            // Init a new client stream class
            Stream = client;
            Stream.OnDisconnect += () => Dispose();
            Stream.DataReceived += (receivedData) =>
            {
                // lets split up the message based on the delimiter
                string[] messages = receivedData.Split(new string[] { "\x00\x00\x00\x00" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string message in messages)
                {
                    // Ignore Non-BF2 related queries
                    if (message.StartsWith("battlefield2"))
                        ParseRequest(message);
                }
            };
        }
        /// <summary>
        /// Accepts a TcpClient, and begin the serverlist fetching process for the client.
        /// This method is executed when the user updates his server browser ingame
        /// </summary>
        protected override void ProcessAccept(GamespyTcpStream Stream)
        {
            // End the operation and display the received data on
            // the console.
            try
            {
                // Convert the TcpClient to a MasterClient
                MasterClient client = new MasterClient(Stream);
                Clients.TryAdd(client.ConnectionId, client);

                // Begin accepting data now that we are fully connected
                Stream.BeginReceive();
            }
            catch (Exception e)
            {
                Program.ErrorLog.Write("WARNING: An Error occured at [MstrServer.AcceptClient] : Generating Exception Log");
                ExceptionHandler.GenerateExceptionLog(e);
                base.Release(Stream);
            }
        }
        /// <summary>
        /// When a new connection is established, we the parent class are responsible
        /// for handling the processing
        /// </summary>
        /// <param name="Stream">A GamespyTcpStream object that wraps the I/O AsyncEventArgs and socket</param>
        protected override void ProcessAccept(GamespyTcpStream Stream)
        {
            // Get our connection id
            long       ConID = Interlocked.Increment(ref ConnectionCounter);
            GpspClient client;

            try
            {
                // Convert the TcpClient to a MasterClient
                client = new GpspClient(Stream, ConID);
                Clients.TryAdd(ConID, client);

                // Start receiving data
                Stream.BeginReceive();
            }
            catch
            {
                // Remove pending connection
                Clients.TryRemove(ConID, out client);
            }
        }
        /// <summary>
        /// Accepts a TcpClient, and begin the serverlist fetching process for the client.
        /// This method is executed when the user updates his server browser ingame
        /// </summary>
        protected override void ProcessAccept(GamespyTcpStream Stream)
        {
            // Get our connection id
            long         ConID = Interlocked.Increment(ref ConnectionCounter);
            MasterClient client;

            // End the operation and display the received data on
            // the console.
            try
            {
                // Convert the TcpClient to a MasterClient
                client = new MasterClient(Stream, ConID);
                Clients.TryAdd(client.ConnectionID, client);

                // Start receiving data
                Stream.BeginReceive();
            }
            catch (ObjectDisposedException) // Ignore
            {
                // Remove client
                Clients.TryRemove(ConID, out client);
            }
            catch (IOException) // Connection closed before a TcpClientStream could be made
            {
                // Remove client
                Clients.TryRemove(ConID, out client);
            }
            catch (Exception e)
            {
                // Remove client
                Clients.TryRemove(ConID, out client);

                // Report error
                Program.ErrorLog.Write("NOTICE: An Error occured at [MstrServer.AcceptClient] : Generating Exception Log");
                ExceptionHandler.GenerateExceptionLog(e);
            }
        }