Beispiel #1
0
func tsBot(conn *ts3.Conn, user string, passwd string) []string {
	connectionCommand := "login " + user + " " + passwd
	var cmds = []string{"version", connectionCommand, "use 1"}

	for _, s := range cmds {
		r, _ := conn.Cmd(s)
		fmt.Println("response:  ", r)
		time.Sleep(500 * time.Millisecond)
	}
	r, _ := conn.Cmd("clientlist")
	log.Println("Response: ", r)
	playerLine := strings.Split(r, "|")
	var toReturn []string
	for pl := range playerLine {
		if strings.Contains(playerLine[pl], "client_type=1") {
			log.Println("Skipping " + playerLine[pl])
			continue
		}
		parts := strings.Split(playerLine[pl], " ")
		for i := range parts {
			if strings.Contains(parts[i], "client_nickname") {
				user := strings.Split(parts[i], "=")[1]
				log.Println("Found a user ", user)
				toReturn = append(toReturn, user)
			}
		}
	}
	return toReturn
}
Beispiel #2
0
// bot is a simple bot that checks version, signs in and sends a text message to
// channel#1 then exits.
func bot(conn *ts3.Conn) {
	defer conn.Cmd("quit")

	var cmds = []string{
		// Show version
		"version",
		// Login
		"login serveradmin 123456",
		// Choose virtual server
		"use 1",
		// Update nickname
		`clientupdate client_nickname=My\sBot`,
		// "clientlist",
		// Send message to channel with id=1
		`sendtextmessage targetmode=2 target=1 msg=Bot\smessage!`,
	}

	for _, s := range cmds {
		// Send command and wait for its response
		r := conn.Cmd(s)
		// Display as:
		//     > request
		//     response
		fmt.Printf("> %s\n%s", s, r)
		// Wait a bit after each command so we don't get banned. By default you
		// can issue 10 commands within 3 seconds.  More info on the
		// WHITELISTING AND BLACKLISTING section of TS3 ServerQuery Manual
		// (http://goo.gl/OpJXz).
		time.Sleep(350 * time.Millisecond)
	}
}
Beispiel #3
0
func getClients(conn *ts3.Conn) (res []Client, err error) {

	// Get client information from the virtual server.

	r, errMsg := conn.Cmd("clientlist")
	if err := handleError(&errMsg); err != nil {
		return nil, err
	}
	clients := strings.Split(r, "|")
	for i := range clients {
		cliParams := mappingParams(clients[i])
		if cliParams["client_type"] == "0" {
			clid, err := strconv.Atoi(cliParams["clid"])
			if err != nil {
				return nil, err
			}
			cid, err := strconv.Atoi(cliParams["cid"])
			if err != nil {
				return nil, err
			}
			res = append(res, *NewClient(clid, cid, ts3.Unquote(cliParams["client_nickname"])))
		}
	}
	return
}
Beispiel #4
0
func connectToServer(conn *ts3.Conn, serverID string) error {

	// Connect to the virtual server.

	_, err := conn.Cmd(fmt.Sprintf("use %s", serverID))
	return handleError(&err)
}
Beispiel #5
0
func initConn(conn *ts3.Conn, username, password string) error {

	// Login to team speak server query.

	_, err := conn.Cmd(fmt.Sprintf("login %s %s", username, password))
	return handleError(&err)
}
Beispiel #6
0
func getChannelInfo(conn *ts3.Conn, cid int) (map[string]string, error) {

	// Getting information of the channel.

	r, errMsg := conn.Cmd(fmt.Sprintf("channelinfo cid=%d", cid))
	if err := handleError(&errMsg); err != nil {
		return nil, err
	}
	return mappingParams(r), nil
}
Beispiel #7
0
// bot is a simple bot that registers itself for channel#1 text messages (using
// notifications).
func bot(conn *ts3.Conn) {
	defer conn.Cmd("quit")

	var cmdList = []string{
		// Login
		"login serveradmin 123456",
		// Choose virtual server
		"use 1",
		// Update nickname
		`clientupdate client_nickname=My\sBot`,
		// Register to channel id=1 text messages
		"servernotifyregister event=textchannel id=1",
	}

	// Chans returns a struct with three `chan string`.  We want `ch.Not` the
	// one that contains notifications.
	ch := conn.Chans()

	for _, cmdReq := range cmdList {
		// Send request to server (feed in a command)
		ch.In <- cmdReq + "\n"
		// Wait for its response
		cmdResp := <-ch.Out
		// Display as:
		//     > request
		//     response
		fmt.Printf("> %s\n%s", cmdReq, r)
		// Wait a bit after each command so we don't get banned. By default you
		// can issue 10 commands within 3 seconds.  More info on the
		// WHITELISTING AND BLACKLISTING section of TS3 ServerQuery Manual
		// (http://goo.gl/OpJXz).
		time.Sleep(350 * time.Millisecond)
	}

	// Keep
	for m := range nch {
		fmt.Printf("Notification: %s", m)
	}
}