Пример #1
0
func sendln(t *telnet.Conn, s string) {
	checkErr(t.SetWriteDeadline(time.Now().Add(timeout)))
	buf := make([]byte, len(s)+1)
	copy(buf, s)
	buf[len(s)] = '\n'
	_, err := t.Write(buf)
	checkErr(err)
}
Пример #2
0
func expect(t *telnet.Conn, d ...string) (err error) {
	t.SetReadDeadline(time.Now().Add(timeout))

	err = t.SkipUntil(d...)
	if err != nil {
		return err
	}

	return nil
}
Пример #3
0
func send(conn *telnet.Conn, s string, timeout time.Duration) error {
	conn.SetWriteDeadline(time.Now().Add(timeout))
	buf := make([]byte, len(s)+1)
	copy(buf, s)
	buf[len(s)] = '\n'
	_, err := conn.Write(buf)
	if err != nil {
		return err
	}
	return nil
}
Пример #4
0
func serveGIF(conn *telnet.Conn, anim *Anim) {
	writeImage(conn, anim.ImageAtTime(500))

	// Close the connection when done serving
	err := conn.Close()
	if err != nil {
		log.Print("Error closing connection:", err)
		return
	}
	log.Print(conn.RemoteAddr(), " ] Client disconnected.")
}
Пример #5
0
func (t *TelnetConfig) writeCmd(tn *telnet.Conn, s string) (err error) {
	buf := make([]byte, len(s)+1)
	copy(buf, s)
	buf[len(s)] = '\n'

	_, err = tn.Write(buf)
	if err != nil {
		return err
	}

	return nil
}
Пример #6
0
func (t *TelnetConfig) readUnitl(tn *telnet.Conn, d ...string) (err error) {
	var data []byte
	data, err = tn.ReadUntil(d...)
	if err != nil {
		return err
	}

	if t.Debug {
		os.Stdout.WriteString("\n")
		os.Stdout.Write(data)
		os.Stdout.WriteString("\n")
	}

	return nil
}
Пример #7
0
func sendln(t *telnet.Conn, s string) (err error) {
	err = t.SetWriteDeadline(time.Now().Add(timeout))
	if err != nil {
		return err
	}

	buf := make([]byte, len(s)+1)
	copy(buf, s)
	buf[len(s)] = '\n'

	_, err = t.Write(buf)
	if err != nil {
		return err
	}

	return nil
}
Пример #8
0
func checkForMessages(t *telnet.Conn, disco *discord.Discord) (err error) {
	data := []byte{}
	message := ""
	for {
		if data, err = t.ReadUntil("\n"); err != nil {
			err = fmt.Errorf("Error reading", err.Error())
			return
		}
		message = string(data)
		//log.Printf("[DEBUG OOC] %s", message)
		if len(message) < 3 { //ignore small messages
			continue
		}
		if !strings.Contains(message, "says ooc,") { //ignore non-ooc
			continue
		}
		if strings.Index(message, ">") > 0 && strings.Index(message, ">") < strings.Index(message, " ") { //ignore prompts
			message = message[strings.Index(message, ">")+1:]
		}
		if message[0:1] == "*" { //ignore echo backs
			continue
		}

		sender := message[0:strings.Index(message, " says ooc,")]
		message = message[strings.Index(message, "says ooc, '")+11 : len(message)-3]
		sender = strings.Replace(sender, "_", " ", -1)

		message = convertLinks(config.Discord.ItemUrl, message)

		if _, err = disco.SendMessage(channelID, fmt.Sprintf("**%s OOC**: %s", sender, message)); err != nil {
			log.Printf("[OOC] Error sending message (%s: %s) %s", sender, message, err.Error())
			continue
		}
		log.Printf("[OOC] %s: %s\n", sender, message)
	}
}
Пример #9
0
func expect(t *telnet.Conn, d ...string) {
	checkErr(t.SetReadDeadline(time.Now().Add(timeout)))
	checkErr(t.SkipUntil(d...))
}