-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathClient.cs
More file actions
104 lines (83 loc) · 3.09 KB
/
Client.cs
File metadata and controls
104 lines (83 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#region
using System;
using System.Collections.Generic;
using System.Linq;
using PVPNetConnect;
using PVPNetConnect.RiotObjects.Platform.Catalog.Champion;
#endregion
namespace LoL_Account_Checker
{
public delegate void Report(object sender, Client.Result result);
public class Client
{
public enum Result
{
Success,
Error
}
private bool _completed;
public bool Completed { get { return _completed; } }
public PVPNetConnection Connection;
public AccountData Data;
public string ErrorMessage;
public Client(Region region, string username, string password)
{
Data = new AccountData { Username = username, Password = password };
_completed = false;
Connection = new PVPNetConnection();
Connection.OnLogin += OnLogin;
Connection.OnError += OnError;
Connection.Connect(username, password, region, "5.2.15");
Console.WriteLine("[{0:HH:mm}] <{1}> Connecting to PvP.net", DateTime.Now, Data.Username);
}
public event Report OnReport;
public void Disconnect()
{
Connection.Disconnect();
Console.WriteLine("[{0:HH:mm}] <{1}> Disconnecting", DateTime.Now, Data.Username);
}
private void OnLogin(object sender, string username, string ipAddress)
{
Console.WriteLine("[{0:HH:mm}] <{1}> Logged in!", DateTime.Now, Data.Username);
GetData();
}
private void OnError(object sender, Error error)
{
Console.WriteLine("[{0:HH:mm}] <{1}> Error: {2}", DateTime.Now, Data.Username, error.Message);
ErrorMessage = error.Message;
_completed = true;
Report(Result.Error);
}
private async void GetData()
{
var loginPacket = await Connection.GetLoginDataPacketForUser();
if (loginPacket.AllSummonerData == null)
{
return;
}
var champions = await Connection.GetAvailableChampions();
var skins = new List<ChampionSkinDTO>();
foreach (var champion in champions)
{
skins.AddRange(champion.ChampionSkins.Where(s => s.Owned));
}
Data.Level = (int) loginPacket.AllSummonerData.SummonerLevel.Level;
Data.RpBalance = (int) loginPacket.RpBalance;
Data.Ipbalance = (int) loginPacket.IpBalance;
Data.Champions = champions.Count(c => c.Owned);
Data.Skins = skins.Count;
Data.RunePages = loginPacket.AllSummonerData.SpellBook.BookPages.Count;
Data.SummonerName = loginPacket.AllSummonerData.Summoner.Name;
Console.WriteLine("[{0:HH:mm}] <{1}> Data received!", DateTime.Now, Data.Username);
_completed = true;
Report(Result.Success);
}
protected virtual void Report(Result result)
{
if (OnReport != null)
{
OnReport(this, result);
}
}
}
}