42wim/matterircd

Matterircd ignores server on login when DefaultServer is set in configuration

Opened this issue · 1 comments

Hi,

When using a matterircd instance for connecting to multiple Mattermost servers, if there is a DefaultServer in the configuration, it is impossible to connect to any other server even though they're listed in Restrict.

Is DefaultServer actually a forced server option? Or is it a way to define the default server when the user does not specify a specific server to log into in the mattermost /msg?

Steps to reproduce

  • Set up matterircd config with:
[mattermost]
DefaultServer = "whatever.com"
DefaultTeam = "myteam"
Restrict = ["whatever.com", "chat.charmhub.io"]
  • Connect to matterircd with an IRC client
  • Send /msg mattermost login chat.charmhub.io charmhub username token=....

This yields:

[2023-10-24T01:20:35Z] DEBUG matterircd: flushing buffer: &irc.Message{Prefix:(*irc.Prefix)(nil), Command:"PRIVMSG", Params:[]string{"mattermost"}, Trailing:"login chat.charmhub.io charmhub kotodama token=REDACTED
", EmptyTrailing:false
}
[2023-10-24T01:20:35Z] DEBUG matterircd: Executed &irc.Message{Prefix:(*irc.Prefix)(nil), Command:"PRIVMSG", Params:[]string{"mattermost"}, Trailing:"<redacted>", EmptyTrailing:false} <nil>
[2023-10-24T01:20:35Z] DEBUG matterircd: args_len: 4
[2023-10-24T01:20:35Z] DEBUG matterircd: team: myteam
[2023-10-24T01:20:35Z] DEBUG matterircd: server: .com
[2023-10-24T01:20:35Z] DEBUG matterircd: restrict: [whatever.com chat.charmhub.io]
loggerlevel: debug
[2023-10-24T01:20:36Z]  INFO bridge/mattermost: login as kotodama (team: myteam) on whatever.com
[2023-10-24T01:20:36Z]  INFO matterclient: Found version 7.8.0.7.8.0.1d38ab1b122bcd3de4a230cfc66281cd.true
[2023-10-24T01:20:36Z] DEBUG matterclient: trying login myteam kotodama whatever.com
[2023-10-24T01:20:36Z] DEBUG matterclient: trying login with personal token
[2023-10-24T01:20:36Z] ERROR bridge/mattermost: login failed: Invalid or expired session, please login again., 

Thank you!

Yeah, I think it's these bits of code:

https://github.com/42wim/matterircd/blame/master/mm-go-irckit/service.go#L122

https://github.com/42wim/matterircd/blame/master/mm-go-irckit/service.go#L147

So if either of DefaultServer or DefaultTeam, IIUC, they will be used instead of what team and server args are provided. I'll work on a fix when I get some spare cycles.