Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Codester241
GitHub Repository: Codester241/Kahoot-Flood
Path: blob/master/kahoot/answer.go
463 views
1
package kahoot
2
3
import "encoding/json"
4
5
func (c *Connection) WaitQuestion() error {
6
for {
7
p, err := c.ReadChannel("/service/player")
8
if err != nil {
9
return err
10
}
11
if data, ok := p.Content["data"]; ok {
12
m := data.(map[string]interface{})
13
if content, ok := m["content"]; ok {
14
m := map[string]interface{}{}
15
err := json.Unmarshal([]byte(content.(string)), &m)
16
if err == nil {
17
if _, ok := m["questionNumber"]; ok {
18
return nil
19
}
20
}
21
}
22
}
23
}
24
}
25
26
func (c *Connection) SendAnswer(choice int) error {
27
screen := map[string]interface{}{"width": 1920, "height": 1080}
28
device := map[string]interface{}{"userAgent": "hey", "screen": screen}
29
meta := map[string]interface{}{"lag": 13, "device": device}
30
content := map[string]interface{}{"choice": choice, "meta": meta}
31
if enc, err := json.Marshal(content); err != nil {
32
return err
33
} else {
34
data := map[string]interface{}{"type": "message", "gameid": c.gameId,
35
"host": "kahoot.it", "content": string(enc), "id": 6}
36
_, err = c.WriteData("/service/controller", data)
37
return err
38
}
39
}
40
41
func (c *Connection) SendCrashAnswer() error {
42
device := "haha ur code sucks"
43
meta := map[string]interface{}{"lag": 100000000, "device": device}
44
content := map[string]interface{}{"choice": 0, "meta": meta}
45
if enc, err := json.Marshal(content); err != nil {
46
return err
47
} else {
48
data := map[string]interface{}{"type": "message", "gameid": c.gameId,
49
"host": "kahoot.it", "content": string(enc), "id": 6}
50
_, err = c.WriteData("/service/controller", data)
51
return err
52
}
53
}
54
55