adc: usercommand support

--HG--
branch : adc
This commit is contained in:
mappu 2017-11-26 19:19:06 +13:00
parent 882f60f157
commit 4c32cb965e
2 changed files with 49 additions and 5 deletions

View File

@ -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
// ````````````````

View File

@ -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
}