-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
92 lines (80 loc) · 1.78 KB
/
main.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
package main
import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"strconv"
"strings"
"sync"
"syscall"
"github.com/unixpickle/kahoot-hack/kahoot"
)
const ConcurrencyCount = 4
func main() {
if len(os.Args) != 3 && len(os.Args) != 4 {
fmt.Fprintln(os.Stderr, "Usage: flood <game pin> <nickname prefix> <count>")
fmt.Fprintln(os.Stderr, " flood <game pin> <name_list.txt>")
os.Exit(1)
}
gamePin, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Fprintln(os.Stderr, "invalid game pin:", os.Args[1])
os.Exit(1)
}
var dieLock sync.Mutex
connChan := make(chan *kahoot.Conn)
for i := 0; i < ConcurrencyCount; i++ {
go func() {
for {
conn, err := kahoot.NewConn(gamePin)
if err != nil {
dieLock.Lock()
fmt.Fprintln(os.Stderr, "failed to connect:", err)
os.Exit(1)
dieLock.Unlock()
}
connChan <- conn
}
}()
}
for _, nickname := range nicknames() {
conn := <-connChan
defer conn.GracefulClose()
conn.Login(nickname)
}
fmt.Println("Kill this process to deauthenticate.")
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
<-sigChan
}
func nicknames() []string {
if len(os.Args) == 4 {
count, err := strconv.Atoi(os.Args[3])
if err != nil {
fmt.Fprintln(os.Stderr, "invalid count:", os.Args[3])
os.Exit(1)
}
base := os.Args[2]
res := make([]string, count)
for x := 0; x < count; x++ {
res[x] = base + strconv.Itoa(x+1)
}
return res
}
contents, err := ioutil.ReadFile(os.Args[2])
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
res := strings.Split(string(contents), "\n")
for i := 0; i < len(res); i++ {
res[i] = strings.TrimSpace(res[i])
if len(res[i]) == 0 {
res[i] = res[len(res)-1]
res = res[:len(res)-1]
i--
}
}
return res
}