fb806748eeedc7c568f7d7eb097ed15d9369d55d — Katie Wolfe 11 months ago 7582be2
Allow peers to send an optional payload with udprelay!channel commands
2 files changed, 31 insertions(+), 7 deletions(-)

M relay.go
M udprelay.7.scd
M relay.go => relay.go +24 -5
@@ 59,9 59,12 @@ func (relay *Relay) HandlePacket(conn *net.UDPConn, addr *net.UDPAddr, packet []

	sender := peer
	for _, peer := range relay.channels[peer.Channel].Peers {
		if peer.Addr == sender.Addr {
	relay.sendPacket(conn, peer, peer.Channel, packet)

func (relay *Relay) sendPacket(conn *net.UDPConn, sender *Peer, channel string, packet []byte) {
	for _, peer := range relay.channels[channel].Peers {
		if sender != nil && peer.Addr == sender.Addr {

@@ 107,9 110,25 @@ func (relay *Relay) handleCommand(conn *net.UDPConn, packet []byte, peer *Peer, 
			relay.Log.Printf("error: replying to ping: %s\n", err)
	case "channel":
		relay.switchChannel(peer, string(args))
		channelID := args
		var payload []byte
		hasPayload := false
		for i, ch := range args {
			if asciiSpace[ch] == 1 {
				channelID = args[:i]
				payload = args[i+1:]
				hasPayload = true

		_, err := conn.WriteToUDP(packet, peer.Addr)
		relay.switchChannel(peer, string(channelID))

		if hasPayload {
			relay.sendPacket(conn, peer, string(channelID), payload)

		_, err := conn.WriteToUDP([]byte("udprelay!channel "+string(channelID)), peer.Addr)
		if err != nil {
			relay.Log.Printf("error: replying to channel switch message: %s\n", err)

M udprelay.7.scd => udprelay.7.scd +7 -2
@@ 32,8 32,13 @@ The *channel* command switches the peer to a different channel identified by the
first string of non-spacing-characters in the command's _body_. If the _body_ is
empty, the peer is switched to the default unnamed channel. Peers will only
receive and send messages sent by and to peers who have connected to the same
channel. After switching the peer's channel, the server will send the command's
packet back to its originator unchanged.
channel. After switching the peer's channel, the server will respond with the
string _udprelay!channel_ followed by a space (0x20) and the same channel
identifier that was sent to the server.

If a spacing character follows the channel identifier, the data following the
spacing character will be sent to that channel as if it had been sent in its own
packet. If no data follows the spacing character, an empty packet will be sent.

## echo