BF2Statistics.Gamespy.GpcmClient.SendServerChallenge C# (CSharp) Method

SendServerChallenge() public method

This method starts off by sending a random string 10 characters in length, known as the Server challenge key. This is used by the client to return a client challenge key, which is used to validate login information later.
public SendServerChallenge ( ) : void
return void
        public void SendServerChallenge()
        {
            // Only send the login challenge once
            if (Status != LoginStatus.None)
                throw new Exception("The server challenge has already been sent. Cannot send another login challenge.");

            // First we need to create a random string the length of 10 characters
            StringBuilder Temp = new StringBuilder(10);
            for (int i = 0; i < 10; i++)
                Temp.Append(AlphaChars[RandInstance.Next(AlphaChars.Length)]);

            // Next we send the client the challenge key
            ServerChallengeKey = Temp.ToString();
            Status = LoginStatus.Processing;
            Stream.SendAsync(@"\lc\1\challenge\{0}\id\1\final\", ServerChallengeKey);
        }

Usage Example

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
            int        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
                L.LogError("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);
            }
        }
All Usage Examples Of BF2Statistics.Gamespy.GpcmClient::SendServerChallenge