From 4c32cb965e392a3f36aa7bb0cc72ffdad78a2b37 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 26 Nov 2017 19:19:06 +1300 Subject: [PATCH] adc: usercommand support --HG-- branch : adc --- AdcProtocol.go | 45 ++++++++++++++++++++++++++++++++++++++++++++- UserCommand.go | 9 +++++---- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/AdcProtocol.go b/AdcProtocol.go index 8488c4a..fe4bdfa 100644 --- a/AdcProtocol.go +++ b/AdcProtocol.go @@ -53,7 +53,7 @@ func NewAdcProtocol(hc *HubConnection) Protocol { proto.pid = pid_base32 // Start logging in - hc.SayRaw("HSUP ADBASE ADTIGR\n") + hc.SayRaw("HSUP ADBASE ADTIGR ADUCMD\n") return &proto } @@ -375,6 +375,49 @@ func (this *AdcProtocol) ProcessCommand(msg string) { msg := this.unescape(parts[3]) this.hc.processEvent(HubEvent{EventType: EVENT_PRIVATE, Nick: senderNick, Message: msg}) + case "ICMD": + // Usercommand + // ICMD ADCH++/About\sthis\shub TTHMSG\s+about\n CT3 + + if len(parts) < 2 { + this.malformed(parts) + return + } + + uc := UserCommand{ + Message: this.unescape(parts[1]), + Type: USERCOMMAND_TYPE_RAW, // default + } + + flags, err := this.parts2flags(parts[2:]) + if err != nil { + this.malformed(parts) + return + } + + if ct, ok := flags["CT"]; ok { + ct64, _ := strconv.ParseUint(ct, 10, 64) + uc.Context = UserCommandContext(ct64) + } + + if tt, ok := flags["TT"]; ok { + uc.Command = tt + } + + if sp, ok := flags["SP"]; ok && sp == "1" { + uc.Type = USERCOMMAND_TYPE_SEPARATOR + } + + if co, ok := flags["CO"]; ok && co == "1" { + uc.Type = USERCOMMAND_TYPE_NICKLIMITED // "Constrained" in ADC parlance + } + + if rm, ok := flags["RM"]; ok && rm == "1" { + uc.RemoveThis = true + } + + this.hc.processEvent(HubEvent{EventType: EVENT_USERCOMMAND, UserCommand: &uc}) + // Ignored messages // ```````````````` diff --git a/UserCommand.go b/UserCommand.go index 9032223..6b7c0a5 100644 --- a/UserCommand.go +++ b/UserCommand.go @@ -19,8 +19,9 @@ const ( ) type UserCommand struct { - Type UserCommandType - Context UserCommandContext - Message string - Command string + Type UserCommandType + Context UserCommandContext + Message string + Command string + RemoveThis bool // Currently only set by ADC hubs }