Browse Source

Add EventWho

master
Trevor Slocum 3 weeks ago
parent
commit
882585bf24
  1. 24
      client.go
  2. 4
      event.go

24
client.go

@ -146,7 +146,7 @@ func (c *Client) handleWrite() {
var buffer bytes.Buffer
var p []byte
var crlfBuffer [2]byte = [2]byte{'\r', '\n'}
crlfBuffer := [2]byte{'\r', '\n'}
crlf := crlfBuffer[:]
help := []byte("help")
@ -156,6 +156,7 @@ func (c *Client) handleWrite() {
watch := []byte("watch")
tv := []byte("tv")
reset := []byte("reset")
textBoard := []byte("textboard")
about := []byte("about")
show := []byte("show")
average := []byte("average")
@ -185,6 +186,15 @@ func (c *Client) handleWrite() {
lf("%s", c.who[username])
}
continue
} else if bytes.Equal(bytes.ToLower(b), textBoard) {
go func() {
c.Out <- []byte("set boardstyle 2")
time.Sleep(time.Second)
c.Out <- []byte("board")
time.Sleep(time.Second)
c.Out <- []byte("set boardstyle 3")
}()
continue
} else if bytes.HasPrefix(bytes.ToLower(b), help) || bytes.HasPrefix(bytes.ToLower(b), about) || bytes.HasPrefix(bytes.ToLower(b), average) ||
bytes.HasPrefix(bytes.ToLower(b), dicetest) || bytes.HasPrefix(bytes.ToLower(b), show) || bytes.HasPrefix(bytes.ToLower(b), stat) {
c.rawMode = true
@ -586,9 +596,19 @@ func (c *Client) eventLoop() {
} else if bytes.HasPrefix(b, TypeWhoInfo) {
c.updateWhoInfo(b[2:])
// TODO who window
// TODO is endwhoinfo always sent?
continue
} else if bytes.HasPrefix(b, TypeEndWhoInfo) {
// TODO draw who info event
who := make([]*WhoInfo, len(c.who))
i := 0
for _, whoInfo := range c.who {
who[i] = whoInfo
i++
}
c.Event <- &EventWho{
Who: who,
}
continue
} else if bytes.HasPrefix(b, TypeLogin) || bytes.HasPrefix(b, TypeLogout) {
b = b[2:]

4
event.go

@ -16,3 +16,7 @@ type EventMessage struct {
}
type EventDraw struct{}
type EventWho struct {
Who []*WhoInfo
}

Loading…
Cancel
Save