Add EventWho

This commit is contained in:
Trevor Slocum 2021-09-30 18:02:23 -07:00
parent 391fe97215
commit 882585bf24
2 changed files with 26 additions and 2 deletions

View File

@ -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:]

View File

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