-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolol.go
159 lines (134 loc) · 3.96 KB
/
golol.go
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
Package golol is a library that provides a means of connecting and recieving data from Riot's League of Legend Servers
*/
package golol
import (
"encoding/hex"
"errors"
"fmt"
"golol/rtmpsclient"
"strconv"
"time"
)
//Might need to worry about ClientVersion being different on different Server
var (
ClientVersion = "3.15.13_12_13_16_07"
port = 2099
)
type LeagueConnection struct {
connection rtmpsclient.RTMPSClient
}
type LoginInfo struct {
ServerName string
Username string
Password string
}
type LeaguePool chan LeagueConnection
func NewPool(loginInfo ...LoginInfo) LeaguePool {
pool := make(LeaguePool, len(loginInfo))
finishChan := make(chan bool)
for _, v := range loginInfo {
go newPoolConnection(v, pool, finishChan)
}
for i := 0; i < len(loginInfo); i++ {
<-finishChan
}
fmt.Println("finished logging in")
return pool
}
func newPoolConnection(loginInfo LoginInfo, pool LeaguePool, finishChan chan<- bool) {
connection, err := New(loginInfo.ServerName, loginInfo.Username, loginInfo.Password)
if err != nil {
fmt.Printf("%s error logging in: %s", loginInfo.Username, err.Error())
} else {
pool <- connection
}
finishChan <- true
}
func New(serverName, username, password string) (LeagueConnection, error) {
serverinfo, ok := rtmpsclient.LeagueServerInfo[serverName]
if !ok {
return LeagueConnection{}, errors.New("Not A Valid Server Name")
}
serverString := fmt.Sprintf("%s:%d", serverinfo.Server.Host, port)
connection := rtmpsclient.New(serverString, "", "app:/mod_ser.dat", "")
err := connection.Connect()
if err != nil {
return LeagueConnection{}, err
}
err = connection.Login(username, password, ClientVersion)
if err != nil {
return LeagueConnection{}, err
}
return LeagueConnection{
connection: connection,
}, nil
}
func (pool LeaguePool) GetNextConnection() (client LeagueConnection, err error) {
select {
case client = <-pool:
pool <- client
case <-time.After(10 * time.Second):
err = errors.New("Could not find available connection in 10s")
}
return
}
func (pool LeaguePool) GetSummonerByName(summonerName string) (summoner Summoner, err error) {
client, err := pool.GetNextConnection()
if err != nil {
return summoner, err
}
return client.GetSummonerByName(summonerName)
}
func (client LeagueConnection) GetSummonerByName(summonerName string) (summoner Summoner, err error) {
response, err := client.connection.BlockingRequest("summonerService", "getSummonerByName", summonerName, 10)
if err != nil {
return summoner, err
}
return unmarshalSummoner(response)
}
func (pool LeaguePool) GetSummonerRunePages(summonerID int) (runePages []RunePage, err error) {
client, err := pool.GetNextConnection()
if err != nil {
return runePages, err
}
return client.GetSummonerRunePages(summonerID)
}
func (client LeagueConnection) GetSummonerRunePages(summonerID int) (runePages []RunePage, err error) {
response, err := client.connection.BlockingRequest("summonerService", "getAllPublicSummonerDataByAccount", summonerID, 10)
if err != nil {
return runePages, err
}
return unmarshalRunePages(response)
}
func (pool LeaguePool) GetSummonerRunePages2(summonerID int) {
client, err := pool.GetNextConnection()
if err != nil {
return
}
client.GetSummonerRunePages2(summonerID)
}
func (client LeagueConnection) GetSummonerRunePages2(summonerID int) {
response, err := client.connection.BlockingRequest("masteryBookService", "getMasteryBook", summonerID, 10)
if err != nil {
return
}
fmt.Println(response)
}
// id = client.invoke("summonerService", "getSummonerByName", new Object[] { "ManticoreX" });
func ChangeClientVersion(version string) {
ClientVersion = version
}
func ChangePort(newPort int) {
port = newPort
}
func GetLeagueID(summonerName string) (int, error) {
encode := hex.EncodeToString([]byte(summonerName))
value, _ := strconv.ParseUint(encode, 16, 64)
value = value % 10000
return int(value), nil
}
func GetRunePages(leagueID int) bool {
time.Sleep(time.Duration(2) * time.Minute)
return true
}