Exemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var client   = new EbClient();
                var response = client.Do((byte)Headers.Reserved2, new object[]
                {
                    new StatisticsRequest()
                    {
                        Username = UsernameTextBox.Text,
                        Password = PasswordTextBox.Password,
                        Data     = new object[] { 0, 55, 10, 90 }
                    }
                });

                if (response.Success)
                {
                    Telemetry = (TelemetryService.TelemetryData)Serialization.Deserialize(response.Data);
                }

                MessageBox.Show(response.Success ? "Got data!" : "Server denied the request", "", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 private static void SendTelemetry(int gameid)
 {
     Task.Run(() =>
     {
         try
         {
             var client = new EbClient();
             var result = client.Do((byte)Headers.Reserved1,
                                    new object[]
             {
                 new TelemetryRequest
                 {
                     Token      = Authenticator.Token,
                     GameId     = gameid,
                     Assemblies = Settings.Instance.InstalledAddons.Where(addon => addon.Enabled).Select(a => new AddonData
                     {
                         AddonState   = (int)a.State,
                         AddonType    = (int)a.Type,
                         Author       = a.Author,
                         IsBuddyAddon = a.IsBuddyAddon,
                         IsLocal      = a.IsLocal,
                         Name         = a.GetUniqueName(),
                         Repository   = a.Url
                     }).ToArray(),
                     Data = new object[] { }
                 }
             });
             client.Close();
             client.InnerChannel.Dispose();
         }
         catch (Exception e)
         {
             Log.Instance.DoLog(string.Format("Exception while trying to send telemetry data. Exception: {0}", e.Message), Log.LogType.Error);
         }
     });
 }
        internal static bool Login(string username, string password, bool autoLogin = false)
        {
            if (!autoLogin)
            {
                using (var rsaProvider = new RSACryptoServiceProvider(new CspParameters {
                    ProviderType = 1
                }))
                {
                    rsaProvider.ImportCspBlob(Convert.FromBase64String(PublicKey1));
                    password = Convert.ToBase64String(rsaProvider.Encrypt(Encoding.Default.GetBytes(password), false));
                }
            }

            try
            {
                var client        = new EbClient();
                var netAuthPacket = client.Do((byte)Headers.Authentication,
                                              new object[]
                {
                    new AuthRequest
                    {
                        Username      = username,
                        Password      = password,
                        Version       = EnvironmentHelper.GetAssemblyVersion().ToString(),
                        Hash          = Md5Hash.Compute(File.ReadAllBytes(EnvironmentHelper.FileName)),
                        Hwid          = Hwid,
                        LeagueVersion = LoaderUpdate.LeagueVersion,
                        Params        = new object[] { (int?)Settings.Instance.SelectedLanguage, Settings.Instance.Directories.AppDataDirectory, Settings.Instance.DeveloperMode }
                    }
                });
                client.Close();
                client.InnerChannel.Dispose();

                if (netAuthPacket.Success)
                {
                    AuthResponse response;
                    using (var stream = new MemoryStream(netAuthPacket.Data))
                    {
                        var dataContractSerializer = new DataContractSerializer(typeof(AuthResponse));
                        response = (AuthResponse)dataContractSerializer.ReadObject(stream);
                    }

                    DisplayName = response.DisplayName;
                    Avatar      = response.Avatar != null?Image.FromStream(new MemoryStream(response.Avatar)) : null;

                    GroupName = response.GroupName;
                    GroupId   = response.GroupId;
                    Token     = response.Token;

                    Credentials = new Credentials(username, password);
                    NLog.Info("Successful login: {0}", username);
                }
                else
                {
                    LastError = netAuthPacket.Body;
                    NLog.Error("Failed login: \"{0}\" with error: \"{1}\"", username, netAuthPacket.Body);
                }

                return(netAuthPacket.Success);
            }
            catch (Exception e)
            {
                Log.Instance.DoLog(string.Format("Exception while trying to authenticate. Exception: {0}", e.Message), Log.LogType.Error);
                Log.Instance.DoLog("Authenticating as guest.");

                // Fail safe
                DisplayName = "Guest";
                Credentials = new Credentials(username, "");
                LastError   = "Unable to reach the server!";

                return(true);
            }
        }