adc: handle passworded logins, more error message types

--HG--
branch : adc
This commit is contained in:
mappu 2017-11-26 17:24:08 +13:00
parent 4c70900ef5
commit 916874e8bd
2 changed files with 88 additions and 33 deletions

View File

@ -112,8 +112,13 @@ func (this *AdcProtocol) ProcessCommand(msg string) {
}
this.sid = parts[1]
// State transition IDENTIFY --> VERIFY and send our own info
this.hc.SayRaw("BINF " + this.escape(this.sid) + " " + this.ourINFO(true) + "\n")
this.state = adcStateVerify
case "IINF":
// Hub telling information about itself
// ADCH++ sends this once we are successfully logged in
flags, err := this.parts2flags(parts[1:])
if err != nil {
@ -132,18 +137,8 @@ func (this *AdcProtocol) ProcessCommand(msg string) {
return
}
if this.state == adcStateIdentify {
// Transition to state VERIFY and send our own info
this.hc.SayRaw("BINF " + this.escape(this.sid) + " " + this.ourINFO(true) + "\n")
this.state = adcStateVerify
} else if this.state == adcStateNormal || this.state == adcStateVerify {
// OK
} else {
// Bad state to be in
this.malformed(parts)
return
if this.state != adcStateNormal {
this.enterNormalState() // successful login
}
case "BINF":
@ -211,8 +206,17 @@ func (this *AdcProtocol) ProcessCommand(msg string) {
handleNewUser()
}
case "IMSG":
// General message from the hub
if len(parts) < 2 {
this.malformed(parts)
return
}
this.hc.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_HUB, Message: this.unescape(parts[1])})
case "ISTA":
// Message from the hub
// Error message from the hub
if len(parts) < 3 {
this.malformed(parts)
return
@ -222,8 +226,75 @@ func (this *AdcProtocol) ProcessCommand(msg string) {
msg := this.unescape(parts[2])
this.hc.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_HUB, Message: this.ErrorMessage(code, msg)})
case "IQUI":
// Error message from the hub
// IQUI V3M6 DI1 MSNick\staken,\splease\spick\sanother\sone TL-1
flags, err := this.parts2flags(parts[1:])
if err != nil {
return
}
if msg, ok := flags["MS"]; ok {
this.hc.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_HUB, Message: "The hub is closing our connection because: " + this.unescape(msg)})
} else {
this.hc.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_HUB, Message: "The hub is closing our connection"})
}
case "BMSG":
// Message from a user
if len(parts) < 3 {
this.malformed(parts)
return
}
sid := this.unescape(parts[1])
msg := this.unescape(parts[2])
this.hc.usersMut.Lock()
defer this.hc.usersMut.Unlock()
nick, ok := this.hc.userSIDs[sid]
if !ok {
this.logError(fmt.Errorf("Recieved message from unknown SID '%s'", sid))
return
}
this.hc.processEvent(HubEvent{EventType: EVENT_PUBLIC, Nick: nick, Message: msg})
case "IGPA":
//
// Password is needed
// IGPA 7EIAAAECLMAAAPJQAAADQQYAAAWAYAAAKVFQAAF6EAAAAAYFAAAA
// HPAS LZDIJOTZDPWHINHGPT5RHT6WLU7DRME7DQO2O3Q
if len(parts) < 2 {
this.malformed(parts)
return
}
/*
For GPA/PAS, assuming that '12345' is the random data supplied in GPA, then;
PAS = Base32( Hash( password + '12345' ) )
GPA: The data parameter is at least 24 random bytes (base32 encoded).
*/
data_base32 := parts[1]
if len(data_base32)%5 != 0 {
data_base32 += strings.Repeat("=", 6-(len(data_base32)%5))
}
data_raw, err := base32.StdEncoding.DecodeString(data_base32)
if err != nil {
this.logError(err)
return
}
resp := Base32(Tiger(this.hc.Hco.NickPassword + string(data_raw)))
this.hc.SayRaw("HPAS " + resp + "\n")
case "EMSG":
// Private message from other user
// EMSG I5RO FMWH test\spm PMI5RO
case "DCTM": // Client-client ConnectToMe
// ignore
default:
this.malformed(parts)
@ -250,23 +321,7 @@ func (this *AdcProtocol) infoFlagsFor(u *UserInfo) map[string]string {
parts["VE"] = fmt.Sprintf("%s %s", u.ClientVersion, u.ClientTag)
}
ct := 0 // 1=bot, 2=registered user, 4=operator, 8=super user, 16=hub owner, 32=hub
if u.IsBot {
ct |= 1
}
if u.IsRegistered {
ct |= 2
}
if u.IsOperator {
ct |= 4
}
if u.IsSuperUser {
ct |= 8
}
if u.IsHubOwner {
ct |= 16
}
parts["CT"] = fmt.Sprintf("%d", ct)
// Do not send the hub a CT (it decides what type we are)
return parts
}

View File

@ -2,9 +2,9 @@ NMDC:
- Implement ZPipe ($ZOn)
ADC:
- Passworded logons
- SayPublic, SayPrivate
- Handle public messages
- Recieve PMs
- Test that user info updates work
- Usercommands
- ???