/// <summary>
 /// Helper Function to easily throw a Critical Message and set the State of the ClientEmulator
 /// </summary>
 /// <param name="Message">Message to send to Log</param>
 private void throwCritical(string Message)
 {
     ClientEmulatorLogging.Log(this, MessageType.Critical, Message);
     this.state = CDKeyServerClientEmulatorState.Error;
 }
Esempio n. 2
0
 /// <summary>
 /// Helper Function to easily throw a Critical Message and set the State of the ClientEmulator
 /// </summary>
 /// <param name="Message">Message to send to Log</param>
 private void throwCritical(string Message)
 {
     ClientEmulatorLogging.Log(this, MessageType.Critical, Message);
     this.state = CDKeyServerClientEmulatorState.Error;
 }
        /// <summary>
        /// Create a new CDKey Server Client Emulator Instance
        /// </summary>
        /// <param name="CDKeyServerIPEndPoint">CDKey Server IP Endpoint to Connect to</param>
        /// <param name="RoundTips">Ammount of Retrys to Send to the CD Key Server before finishing</param>
        /// <param name="InterPacketGap">Milliseconds to wait between the Retrys</param>
        public CDKeyServerClientEmulator(IPEndPoint CDKeyServerIPEndPoint,int RoundTrips,int InterPacketGap)
        {
            this.cdKeyServer = CDKeyServerIPEndPoint;

            this.state = CDKeyServerClientEmulatorState.Initializing;
            //Add InstanceToInstanceNumber
            cdKeyServerInstanceCount++;
            this.instanceId = cdKeyServerInstanceCount;

            this.currentCDKeyServerRoundTripCounter = 0;
            this.currentCDKeyServerRoundTripSuccessCounter = 0;

            this.roundTripWatcher = new Stopwatch();

            //Start Initalizing the Client
            if (this.initalizeUDPClient())
            {
                ///Lets Hammer him
                for (currentCDKeyServerRoundTripCounter = 0; currentCDKeyServerRoundTripCounter < RoundTrips; currentCDKeyServerRoundTripCounter++)
                {
                    

                    this.state = CDKeyServerClientEmulatorState.Connecting;
                    client.Connect(cdKeyServer);

                    roundTripWatcher.Start();
                    if (client.Client.Connected)
                    {
                        //Client is Connected
                        this.state = CDKeyServerClientEmulatorState.Connected;

                        if(sendBuffer !=null) Array.Clear(sendBuffer, 0, sendBuffer.Length);
                        if(recieveBuffer != null) Array.Clear(recieveBuffer, 0, recieveBuffer.Length);

                        sendBuffer = Encoding.UTF8.GetBytes(
                            /* Decode it with Xor */
                             Xor(
                                 /* Generate Fake Request */
                                 GenerateRandomClientCDKeyValidationRequest()
                            ) 
                        );

                        //Send Data to the Client
                        client.Send(sendBuffer,sendBuffer.Length);

                        //Now lets Wait for the Request Recieve the Client Server Token
                        this.recieveBuffer = client.Receive(ref CDKeyServerIPEndPoint);

                        //Check if we got some Data
                        if(recieveBuffer.Length != 0)
                        {
                            //We recived Something
                            
                            //Decode it with Xor
                            String Response = Xor(Encoding.UTF8.GetString(this.recieveBuffer));

                            //Lets check if we got an Valid Response
                            if(recieveDataPattern.Match(Response).Success)
                            {
                                this.currentCDKeyServerRoundTripSuccessCounter++;
                            }
                        }
                        
                    }
                    else
                    {
                        this.throwCritical("Unable to connect to CDKey Server IP:" + cdKeyServer.Address.ToString() + ":" + cdKeyServer.Port.ToString());
                    }

                    roundTripWatcher.Stop();

                    if(averageRoundtripTime==0)
                    {
                        averageRoundtripTime = roundTripWatcher.Elapsed.Milliseconds;
                    }
                    else
                    {
                        averageRoundtripTime = roundTripWatcher.Elapsed.Milliseconds + averageRoundtripTime / 2;
                    }
                    //Add up the Retry Counter
                    this.currentCDKeyServerRoundTripCounter++;
                    Console.WriteLine(averageRoundtripTime + ":" + currentCDKeyServerRoundTripSuccessCounter + ":" +  currentCDKeyServerRoundTripCounter);
                }

            }
        }
Esempio n. 4
0
        /// <summary>
        /// Create a new CDKey Server Client Emulator Instance
        /// </summary>
        /// <param name="CDKeyServerIPEndPoint">CDKey Server IP Endpoint to Connect to</param>
        /// <param name="RoundTips">Ammount of Retrys to Send to the CD Key Server before finishing</param>
        /// <param name="InterPacketGap">Milliseconds to wait between the Retrys</param>
        public CDKeyServerClientEmulator(IPEndPoint CDKeyServerIPEndPoint, int RoundTrips, int InterPacketGap)
        {
            this.cdKeyServer = CDKeyServerIPEndPoint;

            this.state = CDKeyServerClientEmulatorState.Initializing;
            //Add InstanceToInstanceNumber
            cdKeyServerInstanceCount++;
            this.instanceId = cdKeyServerInstanceCount;

            this.currentCDKeyServerRoundTripCounter        = 0;
            this.currentCDKeyServerRoundTripSuccessCounter = 0;

            this.roundTripWatcher = new Stopwatch();

            //Start Initalizing the Client
            if (this.initalizeUDPClient())
            {
                ///Lets Hammer him
                for (currentCDKeyServerRoundTripCounter = 0; currentCDKeyServerRoundTripCounter < RoundTrips; currentCDKeyServerRoundTripCounter++)
                {
                    this.state = CDKeyServerClientEmulatorState.Connecting;
                    client.Connect(cdKeyServer);

                    roundTripWatcher.Start();
                    if (client.Client.Connected)
                    {
                        //Client is Connected
                        this.state = CDKeyServerClientEmulatorState.Connected;

                        if (sendBuffer != null)
                        {
                            Array.Clear(sendBuffer, 0, sendBuffer.Length);
                        }
                        if (recieveBuffer != null)
                        {
                            Array.Clear(recieveBuffer, 0, recieveBuffer.Length);
                        }

                        sendBuffer = Encoding.UTF8.GetBytes(
                            /* Decode it with Xor */
                            Xor(
                                /* Generate Fake Request */
                                GenerateRandomClientCDKeyValidationRequest()
                                )
                            );

                        //Send Data to the Client
                        client.Send(sendBuffer, sendBuffer.Length);

                        //Now lets Wait for the Request Recieve the Client Server Token
                        this.recieveBuffer = client.Receive(ref CDKeyServerIPEndPoint);

                        //Check if we got some Data
                        if (recieveBuffer.Length != 0)
                        {
                            //We recived Something

                            //Decode it with Xor
                            String Response = Xor(Encoding.UTF8.GetString(this.recieveBuffer));

                            //Lets check if we got an Valid Response
                            if (recieveDataPattern.Match(Response).Success)
                            {
                                this.currentCDKeyServerRoundTripSuccessCounter++;
                            }
                        }
                    }
                    else
                    {
                        this.throwCritical("Unable to connect to CDKey Server IP:" + cdKeyServer.Address.ToString() + ":" + cdKeyServer.Port.ToString());
                    }

                    roundTripWatcher.Stop();

                    if (averageRoundtripTime == 0)
                    {
                        averageRoundtripTime = roundTripWatcher.Elapsed.Milliseconds;
                    }
                    else
                    {
                        averageRoundtripTime = roundTripWatcher.Elapsed.Milliseconds + averageRoundtripTime / 2;
                    }
                    //Add up the Retry Counter
                    this.currentCDKeyServerRoundTripCounter++;
                    Console.WriteLine(averageRoundtripTime + ":" + currentCDKeyServerRoundTripSuccessCounter + ":" + currentCDKeyServerRoundTripCounter);
                }
            }
        }