Refactor: Join command
This commit is contained in:
parent
325fc2d758
commit
1689ba51a9
2
go.mod
2
go.mod
|
@ -24,6 +24,8 @@ require (
|
|||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
require git.tcp.direct/ircd/irc-go v0.0.0-20211219221708-8d8346959776
|
||||
|
||||
require (
|
||||
github.com/tidwall/btree v0.6.0 // indirect
|
||||
github.com/tidwall/gjson v1.8.0 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -1,5 +1,7 @@
|
|||
code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48 h1:/EMHruHCFXR9xClkGV/t0rmHrdhX4+trQUcBqjwc9xE=
|
||||
code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc=
|
||||
git.tcp.direct/ircd/irc-go v0.0.0-20211219221708-8d8346959776 h1:qLBcqf5BOln1+up1cPFlWhDtcl6llzSr4d/51Xsku20=
|
||||
git.tcp.direct/ircd/irc-go v0.0.0-20211219221708-8d8346959776/go.mod h1:F0aN7ZC3rnp38KQvFUTMmjC+cT0/ecQEH23j6FKViOk=
|
||||
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962 h1:KeNholpO2xKjgaaSyd+DyQRrsQjhbSeS7qe4nEw8aQw=
|
||||
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962/go.mod h1:kC29dT1vFpj7py2OvG1khBdQpo3kInWP+6QipLbdngo=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ergochat/irc-go/ircutils"
|
||||
"git.tcp.direct/ircd/irc-go/ircutils"
|
||||
|
||||
"git.tcp.direct/ircd/ircd-ergo/irc/caps"
|
||||
"git.tcp.direct/ircd/ircd-ergo/irc/history"
|
||||
|
@ -748,38 +748,46 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp
|
|||
return nil, ""
|
||||
}
|
||||
|
||||
// 0. SAJOIN always succeeds
|
||||
// 1. the founder can always join (even if they disabled auto +q on join)
|
||||
// 2. anyone who automatically receives halfop or higher can always join
|
||||
// 3. people invited with INVITE can join
|
||||
hasPrivs := isSajoin || (founder != "" && founder == details.account) ||
|
||||
(persistentMode != 0 && persistentMode != modes.Voice) ||
|
||||
client.CheckInvited(chcfname, createdAt)
|
||||
if !hasPrivs {
|
||||
if limit != 0 && chcount >= limit {
|
||||
return errLimitExceeded, forward
|
||||
}
|
||||
switch {
|
||||
case
|
||||
// 0. SAJOIN always succeeds
|
||||
isSajoin,
|
||||
// 1. the founder can always join (even if they disabled auto +q on join)
|
||||
founder == details.account && details.account != "",
|
||||
// 2. anyone who automatically receives halfop or higher can always join
|
||||
persistentMode != 0 && persistentMode != modes.Voice,
|
||||
// 3. people invited with INVITE can join
|
||||
client.CheckInvited(chcfname, createdAt):
|
||||
|
||||
if chkey != "" && !utils.SecretTokensMatch(chkey, key) {
|
||||
return errWrongChannelKey, forward
|
||||
}
|
||||
break
|
||||
|
||||
if channel.flags.HasMode(modes.InviteOnly) &&
|
||||
!channel.lists[modes.InviteMask].Match(details.nickMaskCasefolded) {
|
||||
return errInviteOnly, forward
|
||||
}
|
||||
// If the channel has limited capacity and they are over said capacity, don't join.
|
||||
case limit != 0 && chcount >= limit:
|
||||
return errLimitExceeded, forward
|
||||
|
||||
if channel.lists[modes.BanMask].Match(details.nickMaskCasefolded) &&
|
||||
!channel.lists[modes.ExceptMask].Match(details.nickMaskCasefolded) &&
|
||||
!channel.lists[modes.InviteMask].Match(details.nickMaskCasefolded) {
|
||||
// If they channel is +k (keyed), and the joinee does not have the correct key, don't join.
|
||||
case chkey != "" && !utils.SecretTokensMatch(chkey, key):
|
||||
return errWrongChannelKey, forward
|
||||
|
||||
// If the channel is invite only and they joinee does not have an invite exception, don't join.
|
||||
case channel.flags.HasMode(modes.InviteOnly):
|
||||
if channel.lists[modes.InviteMask].Match(details.nickMaskCasefolded) {
|
||||
break
|
||||
}
|
||||
return errInviteOnly, forward
|
||||
|
||||
// If the channel has banned the joinee and there is no ban exception, don't join.
|
||||
case channel.lists[modes.BanMask].Match(details.nickMaskCasefolded):
|
||||
if channel.lists[modes.ExceptMask].Match(details.nickMaskCasefolded) {
|
||||
// do not forward people who are banned:
|
||||
return errBanned, ""
|
||||
}
|
||||
|
||||
if details.account == "" &&
|
||||
(channel.flags.HasMode(modes.RegisteredOnly) || channel.server.Defcon() <= 2) {
|
||||
return errRegisteredOnly, forward
|
||||
}
|
||||
// If the channel is set to registered users only and there is no invite exception for the joinee, don't join.
|
||||
case details.account == "" &&
|
||||
(channel.flags.HasMode(modes.RegisteredOnly) || channel.server.Defcon() <= 2) &&
|
||||
!channel.lists[modes.InviteMask].Match(details.nickMaskCasefolded):
|
||||
return errRegisteredOnly, forward
|
||||
}
|
||||
|
||||
if joinErr := client.addChannel(channel, rb == nil); joinErr != nil {
|
||||
|
|
|
@ -527,9 +527,9 @@ func capHandler(server *Server, client *Client, msg ircmsg.Message, rb *Response
|
|||
// 1. WeeChat 1.4 won't accept the CAP reply unless it contains the server.name source
|
||||
// 2. old versions of Kiwi and The Lounge can't parse multiline CAP LS 302 (#661),
|
||||
// so try as hard as possible to get the response to fit on one line.
|
||||
// :server.name CAP * LS * :<tokens>\r\n
|
||||
// 1 [ 7 ] [4 ] [2 ]
|
||||
maxLen := (MaxLineLen - 2) - 1 - len(server.name) - 7 - len(subCommand) - 4
|
||||
// :server.name CAP nickname LS * :<tokens>\r\n
|
||||
// 1 [5 ] 1 [4 ] [2 ]
|
||||
maxLen := (MaxLineLen - 2) - 1 - len(server.name) - 5 - len(details.nick) - 1 - len(subCommand) - 4
|
||||
capLines := cset.Strings(version, values, maxLen)
|
||||
for i, capStr := range capLines {
|
||||
if version >= caps.Cap302 && i < len(capLines)-1 {
|
||||
|
|
Loading…
Reference in New Issue