This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gosnipe.go
275 lines (261 loc) · 7.85 KB
/
gosnipe.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package main
import (
"bufio"
"encoding/json"
"fmt"
"os"
"strconv"
"time"
gosnipe "github.com/MCGoSnipe/Runtime"
flag "github.com/spf13/pflag"
)
var (
autooffset int
speedlimit int
msa bool
offset float64
name string
path string
bearer string
snipereqs int
queue bool
)
type msaRes struct {
AccessToken *string `json:"access_token"`
MSAError *string `json:"error"`
}
// https://stackoverflow.com/a/54747682
func isFlagPassed(name string) bool {
found := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})
return found
}
func initFlags() {
flag.Float64VarP(&offset, "offset", "o", 0, "offset in milliseconds before snipe.")
flag.IntVarP(&speedlimit, "auto-offset", "a", 3, "automatically set offset with X requests.")
flag.IntVarP(&speedlimit, "speed-limit", "l", 0, "offset between requests.")
flag.IntVarP(&snipereqs, "requests", "r", 2, "number of requests.")
flag.BoolVarP(&msa, "microsoft", "m", false, "load a microsoft account.")
flag.BoolVarP(&queue, "queue", "q", false, "enables STDIN name queueing")
flag.StringVarP(&bearer, "bearer", "b", "", "load a microsoft account with this response. requires -m")
flag.StringVarP(&name, "name", "n", "", "name to snipe.")
flag.StringVarP(&path, "path", "p", "", "path to accounts text file.")
}
func timeSnipeQueue(ch chan gosnipe.SnipeRes, timestamp time.Time, lines []string, name string) {
time.Sleep(time.Until(timestamp.Add(time.Second * -20)))
bearers, labels, _ := gosnipe.SliceStrToBearers(lines)
i := 0
if isFlagPassed("microsoft") {
i++
}
for _, bearer2 := range bearers {
for j := 0; j < snipereqs; j++ {
config := gosnipe.Configuration{
Bearer: bearer2,
Name: name,
Offset: offset - float64(speedlimit*i*snipereqs+speedlimit*j),
Timestamp: timestamp,
Label: &labels[i],
}
go gosnipe.Snipe(config, ch)
}
i++
}
}
func timeSnipe(ch chan gosnipe.SnipeRes, timestamp time.Time, lines []string) {
time.Sleep(time.Until(timestamp.Add(time.Second * -20)))
bearers, labels, _ := gosnipe.SliceStrToBearers(lines)
i := 0
if isFlagPassed("microsoft") {
i++
}
for _, bearer2 := range bearers {
for j := 0; j < snipereqs; j++ {
config := gosnipe.Configuration{
Bearer: bearer2,
Name: name,
Offset: offset - float64(speedlimit*i*snipereqs+speedlimit*j),
Timestamp: timestamp,
Label: &labels[i],
}
go gosnipe.Snipe(config, ch)
}
i++
}
}
func getResp(ch chan gosnipe.SnipeRes) {
for true {
snipeRes := <-ch
if snipeRes.Status != nil {
fmt.Println(*snipeRes.Label + " Status: " + strconv.Itoa(*snipeRes.Status) + " Sent:" + snipeRes.Sent.Format("2006/01/02 15:04:05.0000000") + " Recv: " + snipeRes.Recv.Format("2006/01/02 15:04:05.0000000"))
} else {
fmt.Println("Status was nil.")
}
}
}
func main() {
fmt.Println( //frick you linter, ruining how this should look
" ██████╗ ██████╗ ███████╗███╗ ██╗██╗██████╗ ███████╗\n" +
"██╔════╝ ██╔═══██╗██╔════╝████╗ ██║██║██╔══██╗██╔════╝\n" +
"██║ ███╗██║ ██║███████╗██╔██╗ ██║██║██████╔╝█████╗ \n" +
"██║ ██║██║ ██║╚════██║██║╚██╗██║██║██╔═══╝ ██╔══╝ \n" +
"╚██████╔╝╚██████╔╝███████║██║ ╚████║██║██║ ███████╗\n" +
" ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝╚═╝╚═╝ ╚══════╝")
initFlags()
flag.Parse()
if !isFlagPassed("name") || name == "" {
if !isFlagPassed("queue") {
fmt.Println("No name specified. Exiting.")
os.Exit(1)
}
}
if !isFlagPassed("path") && !isFlagPassed("microsoft") {
fmt.Println("No accounts file was loaded and no MS accounts were loaded. Exiting.")
os.Exit(1)
}
read := bufio.NewReader(os.Stdin)
if !isFlagPassed("offset") {
if isFlagPassed("auto-offset") {
offsetTemp := gosnipe.AutoOffset(autooffset)
if offsetTemp == nil {
offset = 0
} else {
offset = *offsetTemp
fmt.Println("Auto-offset used: " + strconv.FormatFloat(offset, 'f', 4, 64))
}
}
}
var lines []string
if isFlagPassed("path") {
lines, _ = gosnipe.TextToSliceStr(path)
}
ch := make(chan gosnipe.SnipeRes)
var timestamp time.Time
if !isFlagPassed("queue") {
timestampTemp := gosnipe.GetDropTime(name)
if timestampTemp == nil {
fmt.Println("Failed to fetch droptime.")
os.Exit(1)
}
timestamp = *timestampTemp
}
var resp msaRes
if isFlagPassed("microsoft") {
if msa {
label := "Microsoft Account"
if !isFlagPassed("bearer") {
fmt.Println("Head to the link below, authorize the app, and paste the page shown afterwards here.")
fmt.Println(gosnipe.MicrosoftLoginAPI)
res, err := read.ReadString('\n')
if err != nil {
fmt.Println("Failed to read from STDIN.")
os.Exit(1)
}
json.Unmarshal([]byte(res), &resp)
if resp.AccessToken == nil {
fmt.Println("Failed to authenticate, exiting...")
os.Exit(1)
}
if !isFlagPassed("queue") {
for j := 0; j < snipereqs; j++ {
config := gosnipe.Configuration{
Bearer: *resp.AccessToken,
Name: name,
Offset: offset + float64(speedlimit*j),
Timestamp: timestamp,
Label: &label,
}
go gosnipe.Snipe(config, ch)
}
}
} else {
json.Unmarshal([]byte(bearer), &resp)
if resp.AccessToken == nil {
fmt.Println("Failed to authenticate, exiting...")
os.Exit(1)
}
if !isFlagPassed("queue") {
for j := 0; j < snipereqs; j++ {
config := gosnipe.Configuration{
Bearer: *resp.AccessToken,
Name: name,
Offset: offset + float64(speedlimit*j),
Timestamp: timestamp,
Label: &label,
}
go gosnipe.Snipe(config, ch)
}
}
}
} else {
if !isFlagPassed("path") {
fmt.Println("No accounts file was loaded and no MS accounts were loaded. Exiting.")
os.Exit(1)
}
}
}
if !isFlagPassed("queue") {
fmt.Println("Snipe running. Press enter to close.")
go getResp(ch)
go timeSnipe(ch, timestamp, lines)
read.ReadString('\n')
os.Exit(0)
} else {
go getResp(ch)
queueFunc(read, resp, lines, ch)
}
}
func queueFunc(reader *bufio.Reader, msaResp msaRes, lines []string, ch chan gosnipe.SnipeRes) {
name := " "
for name != "" {
fmt.Print("Enter name to queue or leave blank to finalize: ")
name, err := reader.ReadString('\n')
if err != nil {
fmt.Println("Error occurred reading name, finalizing...")
break
}
namebytes := []byte(name)
if namebytes[len(namebytes)-1] == '\n' {
namebytes = namebytes[:len(namebytes)-1]
}
name = string(namebytes)
if name == "" {
break
}
if namebytes[len(namebytes)-1] == '\r' {
namebytes = namebytes[:len(namebytes)-1]
}
name = string(namebytes)
if name == "" {
break
}
timestampTemp := gosnipe.GetDropTime(name)
if timestampTemp == nil {
fmt.Println("Failed to fetch droptime for " + name + ".")
continue
}
timestamp := *timestampTemp
go timeSnipeQueue(ch, timestamp, lines, name)
if msaResp.AccessToken != nil {
label := "Microsoft Account"
for j := 0; j < snipereqs; j++ {
config := gosnipe.Configuration{
Bearer: *msaResp.AccessToken,
Name: name,
Offset: offset + float64(speedlimit*j),
Timestamp: timestamp,
Label: &label,
}
go gosnipe.Snipe(config, ch)
}
}
fmt.Println("Snipe started for " + name + ".")
}
fmt.Println("Finalized. Press enter to quit.")
reader.ReadString('\n')
os.Exit(0)
}