-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
161 lines (138 loc) · 3.54 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
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
// Simple mumble stress testing tool
package main
import (
"crypto/tls"
"flag"
"fmt"
"github.com/layeh/gumble/gumble"
"github.com/layeh/gumble/gumbleffmpeg"
"github.com/layeh/gumble/gumbleutil"
_ "github.com/layeh/gumble/opus"
"log"
"net"
)
var (
clients []*gumble.Client
numClient = flag.Int("clients", 10, "Number of clients to spawn")
addr = flag.String("address", "localhost:64738", "Address of the mumble server")
password = flag.String("pw", "", "Password to connect with")
curChannel = uint32(0)
)
func main() {
flag.Parse()
for i := 0; i < *numClient; i++ {
err := spawnClient(fmt.Sprintf("Mumchmark_%d", i), *password, *addr)
if err != nil {
fmt.Printf("Failed to connect to server %q: %s\n", *addr, err.Error())
return
}
}
loop()
for _, v := range clients {
v.Disconnect()
}
}
func loop() {
for {
fmt.Println("=======================")
fmt.Println("What do you want to do?")
fmt.Println("[q] Quit?")
fmt.Println("[a] Play some audio (plays audio.mp3)")
fmt.Println("[t] Send a text message")
option := ""
fmt.Scanln(&option)
switch option {
case "t":
sendText()
case "a":
playAudio()
case "q":
fmt.Println("Quitting")
return
default:
continue
}
}
}
func inputAmount() (int, bool) {
fmt.Printf("Input a number: ")
num := 0
fmt.Scanln(&num)
if num <= 0 {
return len(clients), true
} else if num > len(clients) {
fmt.Println("num is >clients")
return 0, false
}
return num, true
}
func sendText() {
fmt.Println("What should the message be? (leave empty for \"testing\"")
str := "testing"
fmt.Scanln(&str)
fmt.Printf("Message set to %q, How may clients should send this? leave empty for %d\n", str, len(clients))
num, ok := inputAmount()
if !ok {
return
}
for i := 0; i < num; i++ {
client := clients[i]
channel := client.Channels[curChannel]
channel.Send(str, false)
}
}
func playAudio() {
fmt.Printf("How many clients should play audio.mp3? leave empty for %d\n", len(clients))
num, ok := inputAmount()
if !ok {
return
}
for i := 0; i < num; i++ {
client := clients[i]
ff := gumbleffmpeg.New(client, gumbleffmpeg.SourceFile("audio.mp3"))
err := ff.Play()
if err != nil {
log.Println("Error playing audio: ", err)
}
}
}
func spawnClient(user, pw, server string) error {
tlsConfig := &tls.Config{
InsecureSkipVerify: true,
}
config := &gumble.Config{
Username: user,
Password: pw,
AudioInterval: gumble.AudioDefaultInterval,
AudioDataBytes: gumble.AudioDefaultDataBytes,
}
config.Attach(gumbleutil.Listener{
TextMessage: textMessageHandler,
Connect: connectHandler,
Disconnect: dcHandler,
ChannelChange: channelChangeHandler,
})
client, err := gumble.DialWithDialer(new(net.Dialer), server, config, tlsConfig)
if err != nil {
return err
}
clients = append(clients, client)
log.Printf("mumchmark user %q Connected to server %q!\n", user, server)
return nil
}
func textMessageHandler(msg *gumble.TextMessageEvent) {
//fmt.Printf("Received text message: %s\n", msg.Message)
}
func connectHandler(c *gumble.ConnectEvent) {
msg := "(none)"
if c.WelcomeMessage != nil {
msg = *c.WelcomeMessage
}
fmt.Printf("Connected to server, welcome message: %q\n", msg)
}
func dcHandler(c *gumble.DisconnectEvent) {
fmt.Println("Disconnected..", c.String)
}
func channelChangeHandler(c *gumble.ChannelChangeEvent) {
curChannel = c.Channel.ID
}