From 139dcfd15327e41c20e622aeca42c7f5eefb4ce0 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 04:20:31 +0000 Subject: [PATCH] IRC: Solanum's channel modes for registered rooms, INVITE and KNOCK A registered room's ops set its modes with MODE (/mode in the BBS's chat): n t s p m i z g T, the key (k) and limit (l), and the lists: bans (b), quiets (q), exceptions (e) and invite exceptions (I), with masks nick!how@nodeN and the extbans $a, $a:mask and $o (~ negates). c and C are always on, as the rooms always were. MODE b/q/e/I with no mask lists them (367, 728, 348, 346). Modes and lists are kept in room_reg and the new room_lists table, and are the room's: a caller on the text BBS, AOL or Yahoo is kept out or quiet as an IRC user is. INVITE (an op, or anyone in a +g room) gets one past i, k and l for the hour; KNOCK asks the ops of a room one is kept out of, once a minute, but not in a +p room. ChanServ gains INVITE and GETKEY (the i flag, which also gets past i, k and l), and INFO shows the modes. JOIN takes keys; /join ROOM KEY, /invite and /knock come to the BBS's chat. ISUPPORT gives CHANMODES=Ibeq,k,l,CcTgimnpstz, EXCEPTS, INVEX, EXTBAN, MAXLIST, KEYLEN and KNOCK. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRTXE7MNm3r3hHAmTG2 --- docs/wiki/Chat-and-Paging.md | 4 + docs/wiki/IRC.md | 48 ++- internal/bbs/chanserv.go | 35 +- internal/bbs/chat.go | 96 ++++- internal/bbs/chatcmd.go | 52 ++- internal/bbs/roommodes.go | 689 +++++++++++++++++++++++++++++++++++ internal/bbs/roomreg.go | 5 +- internal/ircd/chanserv.go | 40 -- internal/ircd/commands.go | 68 +++- internal/ircd/modes.go | 157 ++++++++ internal/ircd/modes_test.go | 172 +++++++++ internal/ircd/numerics.go | 2 + internal/ircd/server.go | 8 +- internal/store/copy.go | 2 +- internal/store/roomreg.go | 100 ++++- internal/store/schema.go | 16 +- 16 files changed, 1411 insertions(+), 83 deletions(-) create mode 100644 internal/bbs/roommodes.go create mode 100644 internal/ircd/modes.go create mode 100644 internal/ircd/modes_test.go diff --git a/docs/wiki/Chat-and-Paging.md b/docs/wiki/Chat-and-Paging.md index 5fbf79c..67562ea 100644 --- a/docs/wiki/Chat-and-Paging.md +++ b/docs/wiki/Chat-and-Paging.md @@ -25,6 +25,10 @@ last caller leaves, unless the sysop has made it | `/topic [TEXT]` | the room's topic; a [registered room](IRC#chanserv)'s ops set it, the sysop a [permanent room](IRC#permanent-rooms)'s | | `/cs COMMAND` | ChanServ: [register a room](IRC#chanserv), its access list (`/cs HELP`) | | `/kick WHO [WHY]` | put one out of the room (a registered room's ops; `Carol_Ann` for Carol Ann) | +| `/mode [CHANGES]` | a registered room's [channel modes](IRC#channel-modes): `/mode +m`, `/mode +b alice`, `/mode +b` lists the bans | +| `/invite WHO` | ask one into the room (past `+i`, `+k`, `+l`) | +| `/join ROOM KEY` | come into a room with a key | +| `/knock ROOM [WHY]` | ask the ops of a room you are kept out of to let you in | | `/quit` | leave the chat | | `/help` | these | diff --git a/docs/wiki/IRC.md b/docs/wiki/IRC.md index dccdd9c..19fe9c3 100644 --- a/docs/wiki/IRC.md +++ b/docs/wiki/IRC.md @@ -68,8 +68,48 @@ ChanServ: then its access list says who is opped or voiced on coming in, and its ops can `MODE +o`/`-o`/`+v`/`-v`, `KICK` and set the topic. [Permanent](#permanent-rooms) and registered rooms have topics; others don't. Colours and other formatting are stripped from lines going into -the rooms. Channel modes besides `o` and `v` are not the BBS's yet: a -room is always `+nt`. +the rooms. A registered room's ops set its [channel modes](#channel-modes). + +## Channel modes + +A registered room has Solanum's channel modes, set by its ops with `MODE` +(`/mode` in the BBS's chat). A room nobody has registered is `+Ccnt`, and +its modes can't change. Like ops and bans, the modes are the room's, so a +caller on the text BBS, AOL or Yahoo is kept out or kept quiet just as an +IRC user is, and they are kept across restarts. + +| Mode | What it does | +|---|---| +| `o`, `v` | an operator; a voice | +| `n` | no lines from outside the room (on when registered) | +| `t` | only ops set the topic (on when registered) | +| `s` | secret: not in `LIST` or the BBS's room lists, its members not shown, to those outside | +| `p` | private: no `KNOCK` | +| `m` | moderated: only ops and voices talk | +| `i` | invite only: in by `INVITE`, an `I` mask, or the `i` flag | +| `k KEY` | a key to come in: `JOIN #room KEY`, or `/join room KEY` | +| `l N` | at most N users (someone on two nodes counts once) | +| `z` | lines that `m`, `b` or `q` stop go to the ops instead | +| `g` | anyone in the room may `INVITE` | +| `T` | no `NOTICE`s to the room | +| `b MASK` | banned: kept out, and quiet if in | +| `q MASK` | quieted: may not talk | +| `e MASK` | an exception to `b` and `q` | +| `I MASK` | an exception to `i` | +| `c`, `C` | colours stripped, CTCPs dropped: always on | + +A mask is `nick!user@host`, where a BBS user is `Nick!how@nodeN` (how they +came: `irc`, `telnet`, `ssh`...): `+b alice` bans `alice!*@*`, which, nicks +being BBS names, is alice's account, and `+q *!telnet@*` quiets everyone +on telnet. Extbans: `$a` matches every account (so `$~a` no one of ours), +`$a:MASK` an account by name, `$o` sysops. Each list holds 100. + +An invite lasts an hour, gets past `i`, `k` and `l`, and is used up by +coming in. `KNOCK #room [why]` asks the ops of a room that is invite only, +keyed or full to let you in, once a minute. Sysops and a room's founder +come in always, and sysops, ops and voices always talk; someone with the +`e` flag isn't kept out by bans, and one with `i` gets past `i`, `k` and +`l`. Modes beside these (`f`, `j`, `S`, `P`, `L`...) are refused. A sysop is told of a page by a `NOTICE`. Joining `#sysop-N` answers the page from node N, just as `/answer` does in the BBS's chat. @@ -126,6 +166,8 @@ or `/CS COMMAND`; on the text BBS, `/cs COMMAND` in chat. | `OP`, `DEOP #room [nick ...]` | `o` | ops you, or them | | `VOICE`, `DEVOICE #room [nick ...]` | `v` | voices you, or them | | `TOPIC #room [text]` | `t` | sets the topic | +| `INVITE #room` | `i` | invites you in (past `+i`, `+k` and `+l`, for the hour) | +| `GETKEY #room` | `i` | tells you the key | | `KICK #room nick [reason]` | `r` | puts one out | | `BAN`, `UNBAN #room nick` | `r` | keeps one out (`b` on their entry), or lets them in again | | `CLEAR #room USERS [reason]` | `R` | puts everyone out but you | @@ -141,7 +183,7 @@ The flags are Atheme's: |---|---|---|---| | `v` | voice through ChanServ | `V` | voiced on coming in | | `o` | ops through ChanServ | `O` | opped on coming in | -| `t` | sets the topic | `i` | invites (for the modes to come) | +| `t` | sets the topic | `i` | `INVITE`, `GETKEY`; gets past `+i`, `+k`, `+l` | | `r` | `KICK`, `BAN`, `UNBAN` | `R` | `CLEAR` | | `f` | changes the access list | `s` | `SET` | | `A` | sees the access list | `e` | not kept out by a ban | diff --git a/internal/bbs/chanserv.go b/internal/bbs/chanserv.go index 7751fe2..4265933 100644 --- a/internal/bbs/chanserv.go +++ b/internal/bbs/chanserv.go @@ -46,7 +46,7 @@ theirs; with changes, it changes them (needs f): +AO-v, a template give or take flags you have yourself, unless you have F. v voice through ChanServ V voiced on coming in o ops through ChanServ O opped on coming in - t sets the topic i invites (to come) + t sets the topic i INVITE, GETKEY; past +i, +k, +l r KICK, BAN, UNBAN R CLEAR f changes the access list s SET A sees the access list e not kept out by a ban @@ -69,6 +69,10 @@ Templates: VOP +AV, AOP +AOiortv, SOP +AORefiorstv, FOUNDER +AFORefiorstv.`, csF and puts them out if they are in. UNBAN takes it off.`, csBan}, "unban": {"UNBAN <#room> ", "lets one banned in again (needs r)", "UNBAN takes b off someone's entry, so they may come in again.", csUnban}, + "invite": {"INVITE <#room>", "invites you into a room (needs i)", + "INVITE invites you into the room: past +i, its key and its limit, for the hour.", csInvite}, + "getkey": {"GETKEY <#room>", "tells you a room's key (needs i)", + "GETKEY tells you the room's key (+k).", csGetKey}, "clear": {"CLEAR <#room> USERS [reason]", "puts everyone out of a room (needs R)", "CLEAR USERS puts everyone out of the room but you.", csClear}, "set": {"SET <#room> [value]", "changes a room's settings (needs s)", @@ -272,7 +276,8 @@ func csInfo(n *Node, u *store.User, args []string) ([]string, error) { if len(set) > 0 { out = append(out, "Settings : "+strings.Join(set, " ")) } - return out, nil + modes, _ := n.b.RoomModes(reg.Name, has(flags, FlagView)) + return append(out, "Modes : "+modes), nil } // sortedFlags are flags, each once, in AllRoomFlags' order. @@ -599,6 +604,32 @@ func csUnban(n *Node, u *store.User, args []string) ([]string, error) { return []string{Nick(t.Name) + " may come into #" + reg.Name + " again."}, nil } +func csInvite(n *Node, u *store.User, args []string) ([]string, error) { + if len(args) != 1 { + return nil, errSyntax + } + reg, _, err := n.regFor(args[0], u, string(FlagInvite)) + if err != nil { + return nil, err + } + n.b.invite(reg.Name, u.ID) + return []string{"You are invited into #" + reg.Name + " for the hour: /join #" + reg.Name}, nil +} + +func csGetKey(n *Node, u *store.User, args []string) ([]string, error) { + if len(args) != 1 { + return nil, errSyntax + } + reg, _, err := n.regFor(args[0], u, string(FlagInvite)) + if err != nil { + return nil, err + } + if reg.Key == "" { + return []string{"#" + reg.Name + " has no key."}, nil + } + return []string{"The key of #" + reg.Name + " is " + reg.Key + "."}, nil +} + func csClear(n *Node, u *store.User, args []string) ([]string, error) { if len(args) < 2 || !strings.EqualFold(args[1], "users") { return nil, errSyntax diff --git a/internal/bbs/chat.go b/internal/bbs/chat.go index 80e2568..e031cec 100644 --- a/internal/bbs/chat.go +++ b/internal/bbs/chat.go @@ -29,6 +29,7 @@ const ( Topic // a room's topic (set, or shown on coming in) Mode // ops or voice given or taken (Text "+o", Target whose) Kicked // Target put out of the room by From (Text: why) + Invited // From asks Target into Room (an IRC INVITE) ) // Event is something for a node to show its caller. @@ -58,6 +59,8 @@ func Plain(e Event) []Event { switch e.Kind { case Mode: return []Event{{Kind: Notice, Room: e.Room, Text: e.String(), Time: e.Time}} + case Invited: + return []Event{{Kind: Notice, Text: e.String(), Time: e.Time}} case Kicked: return []Event{{Kind: Notice, Room: e.Room, Text: e.String(), Time: e.Time}, {Kind: Left, Room: e.Room, From: e.Target, Node: e.TargetNode, Text: e.Text, Time: e.Time}} @@ -89,9 +92,14 @@ func (e Event) String() string { "+v": "gave %s a voice", "-v": "took the voice from %s", }[e.Text] if what == "" { - return fmt.Sprintf("%s set %s %s", e.From, e.Text, e.Target) + if word := modeWords[e.Text]; word != "" { + return fmt.Sprintf("%s %s %s", e.From, fmt.Sprintf(word, e.Room), e.Target) + } + return strings.TrimSpace(fmt.Sprintf("%s set %s in %s %s", e.From, e.Text, e.Room, e.Target)) } return e.From + " " + fmt.Sprintf(what, e.Target) + " in " + e.Room + case Invited: + return fmt.Sprintf("%s invites %s into %s (/join %s)", e.From, e.Target, e.Room, e.Room) case Kicked: s := e.From + " put " + e.Target + " out of " + e.Room if e.Text != "" { @@ -132,9 +140,10 @@ type chatState struct { also map[string]bool // rooms an IRC client is in besides (JoinAlso) busy bool // a sysop not to be paged sent []time.Time - handle string // a CompuServe CB handle ("": none) - paging string // why this caller pages the sysop ("": not) - pagedAt time.Time // when + handle string // a CompuServe CB handle ("": none) + paging string // why this caller pages the sysop ("": not) + pagedAt time.Time // when + knocked map[string]time.Time // when this node last knocked on each room } // room is a chat room's members and its last lines. @@ -145,6 +154,8 @@ type room struct { topic string // a permanent room's // in a registered room, the users given ops or voice (stOp, stVoice) status map[int64]uint8 + // the users invited in, and when + invites map[int64]time.Time } // hub is the BBS's chat: its rooms. @@ -263,7 +274,7 @@ func (n *Node) name() string { func pageRoom(node int) string { return fmt.Sprintf("sysop-%d", node) } // mayJoin checks a room's name, and that the node may go in. -func (n *Node) mayJoin(name string) (string, error) { +func (n *Node) mayJoin(name, key string) (string, error) { name = strings.ToLower(strings.TrimSpace(name)) if !roomName.MatchString(name) { return "", ErrNoRoom @@ -285,13 +296,23 @@ func (n *Node) mayJoin(name string) (string, error) { if n.b.banned(name, u) { return "", ErrBanned } + invited, err := n.mayEnter(name, u, key) + if err != nil { + return "", err + } + if invited { + n.b.useInvite(name, u.ID) + } return name, nil } // JoinRoom takes the node into a room (leaving the one it is in), and // gives it the room's last lines. -func (n *Node) JoinRoom(name string) ([]Event, error) { - name, err := n.mayJoin(name) +func (n *Node) JoinRoom(name string) ([]Event, error) { return n.JoinRoomKey(name, "") } + +// JoinRoomKey is JoinRoom, with a key for a room that has one. +func (n *Node) JoinRoomKey(name, key string) ([]Event, error) { + name, err := n.mayJoin(name, key) if err != nil { return nil, err } @@ -309,8 +330,11 @@ func (n *Node) JoinRoom(name string) ([]Event, error) { // JoinAlso takes the node into a room as well as those it is in (an IRC // client's channels), and gives it the room's last lines. -func (n *Node) JoinAlso(name string) ([]Event, error) { - name, err := n.mayJoin(name) +func (n *Node) JoinAlso(name string) ([]Event, error) { return n.JoinAlsoKey(name, "") } + +// JoinAlsoKey is JoinAlso, with a key for a room that has one. +func (n *Node) JoinAlsoKey(name, key string) ([]Event, error) { + name, err := n.mayJoin(name, key) if err != nil { return nil, err } @@ -513,14 +537,37 @@ func (n *Node) Say(text string, emote bool) error { } // SayIn says a line in a room the node is in. -func (n *Node) SayIn(name, text string, emote bool) error { +func (n *Node) SayIn(name, text string, emote bool) error { return n.say(name, text, emote, false) } + +// SayOutside says a line in a room the node is not in: one whose modes +// let lines in from outside (-n). +func (n *Node) SayOutside(name, text string, emote bool) error { + if n.InRoom(name) { + return n.say(name, text, emote, false) + } + if n.b.RoomReg(name) == nil || n.b.RoomHas(name, 'n') { + return ErrNotInRoom + } + return n.say(name, text, emote, true) +} + +// say says a line in a room: one the node is in, or (outside) one that +// takes lines from outside. m, b and q stop it (to the ops alone, with z). +func (n *Node) say(name, text string, emote, outside bool) error { text = Clean(text, MaxChatLine) if text == "" { return nil } - if !n.InRoom(name) { + if !outside && !n.InRoom(name) { return ErrNotInRoom } + toOps := false + if err := n.mayTalk(name, n.User()); err != nil { + if !n.b.RoomHas(name, 'z') { + return err + } + toOps = true + } relay := n.b.relayFor(name) if relay != nil && len(text) > 1 && text[0] == '!' && text[1] != ' ' && text[1] != '!' { // !COMMAND: for the network's server, not the room @@ -541,6 +588,18 @@ func (n *Node) SayIn(name, text string, emote bool) error { e.Kind = Emoted } n.b.Stats.ChatLines.Add(1) + if toOps { + // stopped (m, b, q) in a +z room: to its ops alone, and back to its + // sayer + seen := map[*Node]bool{} + for _, m := range append(n.b.opsOf(name), n) { + if !seen[m] { + seen[m] = true + m.deliver(e) + } + } + return nil + } h := n.b.hub() h.mu.Lock() r := h.rooms[name] @@ -556,6 +615,9 @@ func (n *Node) SayIn(name, text string, emote bool) error { for _, m := range members { m.deliver(e) } + if outside { + n.deliver(e) // the sayer is not in the room to see it + } if relay != nil { relay.Said(name, n.name(), text, emote) } @@ -589,6 +651,18 @@ func (b *BBS) rooms(u *store.User, node int) []RoomInfo { if strings.HasPrefix(name, "sysop-") && (node == 0 || name != pageRoom(node)) && (u == nil || !u.Sysop) { continue } + if reg := h.regs[name]; reg != nil && strings.ContainsRune(reg.Modes, 's') && (u == nil || !u.Sysop) { + // secret: only to those in it + in := false + for m := range r.members { + if m.user != nil && u != nil && m.user.ID == u.ID { + in = true + } + } + if !in { + continue + } + } ri := RoomInfo{Name: name, Permanent: r.permanent, Topic: h.topicOf(name, r), Registered: h.regs[name] != nil} for m := range r.members { ri.Users = append(ri.Users, fmt.Sprintf("%s (%d)", m.name(), m.Num)) diff --git a/internal/bbs/chatcmd.go b/internal/bbs/chatcmd.go index 2b8cc0b..70800de 100644 --- a/internal/bbs/chatcmd.go +++ b/internal/bbs/chatcmd.go @@ -21,6 +21,8 @@ var ChatHelp = []string{ " /cs COMMAND ChanServ: register a room, its access list (/cs HELP)", " /topic TEXT set the topic (a registered room's ops)", " /kick WHO [WHY] put one out of the room (its ops)", + " /mode [+m-i...] a registered room's modes (its ops) /invite WHO ask one in", + " /join ROOM KEY a room with a key /knock ROOM [WHY] ask its ops in", "Sysops: /pages callers paging /answer [NODE] answer one /busy pages on or off", " /topic TEXT set a permanent room's topic", } @@ -84,6 +86,53 @@ func (n *Node) ChatCommand(line string) (out []string, leave bool, err error) { return nil, false, n.SetTopic(room, arg) case "cs", "chanserv": return n.ChanServ(arg), false, nil + case "mode": + room := n.Room() + if room == "" { + return nil, false, ErrNotInRoom + } + f := strings.Fields(arg) + if len(f) == 0 { + modes, args := n.b.RoomModes(room, true) + return []string{strings.TrimSpace("The modes of " + room + ": " + modes + " " + strings.Join(args, " "))}, false, nil + } + changes := ParseModes(f[0], f[1:]) + if len(changes) == 0 { + // a list: /mode +b + for _, k := range f[0] { + if strings.ContainsRune(RoomListModes, k) { + out = append(out, fmt.Sprintf("The +%c list of %s:", k, room)) + for _, e := range n.b.RoomList(room, k) { + out = append(out, fmt.Sprintf(" %-40s set by %s, %s", e.Mask, e.SetBy, e.SetAt.Format("Jan 2 2006"))) + } + } + } + if out == nil { + return nil, false, fmt.Errorf("/mode +m, -m, +k KEY, +l N, +b MASK ...: see /cs HELP") + } + return out, false, nil + } + _, errs := n.SetModes(room, changes) + for _, err := range errs { + out = append(out, capital(err.Error())+".") + } + return out, false, nil + case "invite": + room := n.Room() + if room == "" { + return nil, false, ErrNotInRoom + } + t, err := n.Invite(room, strings.TrimSpace(arg)) + if err != nil { + return nil, false, err + } + return []string{Nick(t.Name) + " is invited into " + room + "."}, false, nil + case "knock": + room, why, _ := strings.Cut(arg, " ") + if err := n.Knock(strings.ToLower(strings.TrimPrefix(room, "#")), why); err != nil { + return nil, false, err + } + return []string{"You knocked: its ops are told."}, false, nil case "kick": room := n.Room() if room == "" { @@ -98,7 +147,8 @@ func (n *Node) ChatCommand(line string) (out []string, leave bool, err error) { } return nil, false, nil case "join", "j": - hist, err := n.JoinRoom(arg) + room, key, _ := strings.Cut(arg, " ") + hist, err := n.JoinRoomKey(room, strings.TrimSpace(key)) if err != nil { return nil, false, err } diff --git a/internal/bbs/roommodes.go b/internal/bbs/roommodes.go new file mode 100644 index 0000000..8d8a143 --- /dev/null +++ b/internal/bbs/roommodes.go @@ -0,0 +1,689 @@ +package bbs + +import ( + "errors" + "fmt" + "path" + "sort" + "strconv" + "strings" + "time" + + "github.com/D-Modem/bbs/internal/store" +) + +// Channel modes, as Solanum's (Libera.Chat's ircd): a registered room's, +// set by its ops. They are the room's, so they hold however one comes in. +// +// n no lines from outside (IRC's PRIVMSG to a room one is not in) +// t only ops (and those with t) set the topic +// s secret: not in the room lists, nor its members to those outside +// p private: no KNOCK +// m moderated: only ops and voices talk +// i invite only: by INVITE, an I mask, or the i flag +// z op moderated: lines m, b or q stop go to the ops +// g anyone in the room may INVITE +// T no IRC NOTICEs to the room +// k a key to come in l how many accounts may be in +// b bans q quiets e exceptions to both I exceptions to i +// +// c (formatting stripped) and C (no CTCPs) are always on: the rooms are so. + +// RoomFlagModes are the modes on or off, without a parameter. +const RoomFlagModes = "Tgimnpstz" + +// RoomFixedModes are always on. +const RoomFixedModes = "Cc" + +// RoomListModes are the lists. +const RoomListModes = "Ibeq" + +// MaxRoomList is the most entries on each of a room's lists. +const MaxRoomList = 100 + +// MaxRoomKey is the longest key. +const MaxRoomKey = 23 + +// Refusals of the modes. +var ( + ErrInviteOnly = errors.New("that room is invite only") + ErrBadKey = errors.New("that room needs a key") + ErrFull = errors.New("that room is full") + ErrModerated = errors.New("that room is moderated: only its ops and voices talk") + ErrQuieted = errors.New("you may not talk in that room") + ErrNoModes = errors.New("only registered rooms have modes (/cs REGISTER #room)") + ErrNoNotices = errors.New("that room takes no notices") +) + +// ModeChange is one mode given (On) or taken: its letter, and its +// parameter (a nick for o and v, a mask for the lists, the key, the +// limit). +type ModeChange struct { + On bool + Mode rune + Arg string +} + +// String is the change as IRC writes it: "+b mask". +func (m ModeChange) String() string { + s := "-" + if m.On { + s = "+" + } + s += string(m.Mode) + if m.Arg != "" { + s += " " + m.Arg + } + return s +} + +// ModeTakesArg: the mode has a parameter when given (on) or taken. +func ModeTakesArg(m rune, on bool) bool { + switch m { + case 'o', 'v', 'b', 'q', 'e', 'I', 'k': + return true + case 'l': + return on + } + return false +} + +// RoomModes are a room's modes as IRC shows them ("+Cnt", with "k", "l"), +// and their parameters (the key, shown only if showKey, and the limit). +// A room not registered: "+Cnt" (the BBS's rooms are so). +func (b *BBS) RoomModes(name string, showKey bool) (string, []string) { + reg := b.RoomReg(name) + modes := "nt" + var args []string + if reg != nil { + modes = reg.Modes + } + letters := []rune(modes + RoomFixedModes) + sort.Slice(letters, func(i, j int) bool { return letters[i] < letters[j] }) + s := "+" + string(letters) + if reg != nil && reg.Key != "" { + s += "k" + if showKey { + args = append(args, reg.Key) + } else { + args = append(args, "*") + } + } + if reg != nil && reg.Limit > 0 { + s += "l" + args = append(args, strconv.Itoa(reg.Limit)) + } + return s, args +} + +// RoomHas: a registered room has a mode on (a room not registered: n and t +// alone). +func (b *BBS) RoomHas(name string, mode rune) bool { + reg := b.RoomReg(name) + if reg == nil { + return mode == 'n' || mode == 't' + } + return strings.ContainsRune(reg.Modes, mode) +} + +// RoomList is a registered room's entries of a list (nil: none). +func (b *BBS) RoomList(name string, kind rune) []*store.RoomListEntry { + if reg := b.RoomReg(name); reg != nil { + return reg.List(string(kind)) + } + return nil +} + +// subject is one a mask is matched against: nick!via@nodeN, and their +// account. +type subject struct { + nick, user, host, account string + sysop bool +} + +// subjectOf is a node's user as masks see them. +func (n *Node) subjectOf() subject { + n.b.mu.Lock() + u, via := n.user, n.Caller.Via + n.b.mu.Unlock() + s := subject{user: via, host: fmt.Sprintf("node%d", n.Num)} + if u != nil { + s.nick, s.account, s.sysop = Nick(u.Name), u.Name, u.Sysop + } + return s +} + +// NormalMask is a mask as a list keeps it: nick!user@host filled in with +// *s ("alice" is alice!*@*), or an extban ($a, $a:mask, $o, negated with +// ~). "": not a mask. +func NormalMask(m string) string { + m = strings.TrimSpace(m) + if m == "" || len(m) > 100 || strings.ContainsAny(m, " ,") { + return "" + } + if strings.HasPrefix(m, "$") { + body := m[1:] + neg := strings.HasPrefix(body, "~") + body = strings.TrimPrefix(body, "~") + if body == "" { + return "" + } + kind, data, hasData := strings.Cut(body, ":") + kind = strings.ToLower(kind) + switch { + case kind == "a" && (!hasData || data != ""): + case kind == "o" && !hasData: + default: + return "" + } + out := "$" + if neg { + out += "~" + } + out += kind + if hasData { + out += ":" + data + } + return out + } + if !strings.Contains(m, "!") && !strings.Contains(m, "@") { + return m + "!*@*" + } + if !strings.Contains(m, "@") { + return m + "@*" + } + if !strings.Contains(m, "!") { + return "*!" + m + } + return m +} + +// glob matches s with a mask's * and ? (case aside). +func glob(mask, s string) bool { + mask = strings.NewReplacer("[", "\\[", "]", "\\]", "\\", "\\\\").Replace(strings.ToLower(mask)) + ok, err := path.Match(mask, strings.ToLower(s)) + return err == nil && ok +} + +// matches: a mask matches the subject. +func (s subject) matches(mask string) bool { + if strings.HasPrefix(mask, "$") { + body := mask[1:] + neg := strings.HasPrefix(body, "~") + body = strings.TrimPrefix(body, "~") + kind, data, hasData := strings.Cut(body, ":") + var hit bool + switch kind { + case "a": + hit = s.account != "" && (!hasData || glob(data, s.nick) || glob(data, s.account)) + case "o": + hit = s.sysop + default: + return false + } + return hit != neg + } + return glob(mask, s.nick+"!"+s.user+"@"+s.host) +} + +// matchesAny: one of a room's entries of a kind matches. +func (s subject) matchesAny(reg *store.RoomReg, kind string) bool { + for _, e := range reg.Lists { + if e.Kind == kind && s.matches(e.Mask) { + return true + } + } + return false +} + +// mayEnter checks a registered room's modes for one coming in: bans (but +// exceptions), invite only, the key and the limit. Sysops and the +// founder come in always; the i flag gets past i, k and l, as an invite +// does. It gives whether an invite was used. +func (n *Node) mayEnter(name string, u *store.User, key string) (bool, error) { + b := n.b + reg := b.RoomReg(name) + if reg == nil || u.Sysop || reg.FounderID == u.ID { + return false, nil + } + if b.inRoom(name, u.ID) { + return false, nil // another node of theirs is in already + } + flags := b.ownFlags(reg, u) + s := n.subjectOf() + if s.matchesAny(reg, "b") && !s.matchesAny(reg, "e") && !has(flags, FlagExempt) { + return false, ErrBanned + } + invited := b.invited(name, u.ID) || has(flags, FlagInvite) + if strings.ContainsRune(reg.Modes, 'i') && !invited && !s.matchesAny(reg, "I") { + return false, ErrInviteOnly + } + if reg.Key != "" && key != reg.Key && !invited { + return false, ErrBadKey + } + if reg.Limit > 0 && !invited && b.accountsIn(name) >= reg.Limit { + return false, ErrFull + } + return invited, nil +} + +// accountsIn counts the users in a room (one on two nodes once). +func (b *BBS) accountsIn(name string) int { + seen := map[int64]bool{} + for _, m := range b.roomNodes(name) { + if u := m.User(); u != nil { + seen[u.ID] = true + } + } + return len(seen) +} + +// inviteFor is how long an invite lasts. +const inviteFor = time.Hour + +// invited: the user has an invite to the room, not yet used. +func (b *BBS) invited(name string, id int64) bool { + h := b.hub() + h.mu.Lock() + defer h.mu.Unlock() + r := h.rooms[name] + return r != nil && time.Since(r.invites[id]) < inviteFor +} + +// useInvite takes the user's invite to a room: they came in. +func (b *BBS) useInvite(name string, id int64) { + h := b.hub() + h.mu.Lock() + if r := h.rooms[name]; r != nil { + delete(r.invites, id) + } + h.mu.Unlock() +} + +// invite gives a user an invite to a room, kept (open) for the hour. +func (b *BBS) invite(name string, id int64) { + h := b.hub() + h.mu.Lock() + r := h.rooms[name] + if r == nil { + r = &room{members: map[*Node]bool{}} + h.rooms[name] = r + } + if r.invites == nil { + r.invites = map[int64]time.Time{} + } + r.invites[id] = time.Now() + h.mu.Unlock() +} + +// mayTalk checks a registered room's modes for a line: m, and bans and +// quiets (but exceptions). Ops, voices and sysops talk always. It gives +// nil, or why not. +func (n *Node) mayTalk(name string, u *store.User) error { + b := n.b + reg := b.RoomReg(name) + if reg == nil || u == nil || u.Sysop { + return nil + } + h := b.hub() + h.mu.Lock() + st := h.statusOf(name, h.rooms[name], u) + h.mu.Unlock() + if st != 0 { + return nil + } + if strings.ContainsRune(reg.Modes, 'm') { + return ErrModerated + } + s := n.subjectOf() + if (s.matchesAny(reg, "b") || s.matchesAny(reg, "q")) && !s.matchesAny(reg, "e") && !has(b.ownFlags(reg, u), FlagExempt) { + return ErrQuieted + } + return nil +} + +// opsOf are the nodes in a room of its ops (and sysops). +func (b *BBS) opsOf(name string) []*Node { + h := b.hub() + h.mu.Lock() + defer h.mu.Unlock() + r := h.rooms[name] + if r == nil { + return nil + } + var out []*Node + for m := range r.members { + if h.statusOf(name, r, m.user)&stOp != 0 || m.user != nil && m.user.Sysop { + out = append(out, m) + } + } + return out +} + +// SetModes is MODE on a registered room by one of its ops (or a sysop): +// each change made, told to those in the room. It gives the changes made +// and why any were not. +func (n *Node) SetModes(name string, changes []ModeChange) ([]ModeChange, []error) { + u := n.User() + if u == nil { + return nil, []error{ErrNoUser} + } + if n.b.RoomReg(name) == nil { + return nil, []error{ErrNoModes} + } + if !u.Sysop && !n.b.IsOp(name, u) { + return nil, []error{ErrNoPrivs} + } + var done []ModeChange + var errs []error + for _, c := range changes { + applied, err := n.setMode(name, u, c) + if err != nil { + errs = append(errs, err) + continue + } + if applied { + done = append(done, c) + } + } + return done, errs +} + +// ModeError is a refused change, with its mode. +type ModeError struct { + Mode rune + Err error +} + +func (e *ModeError) Error() string { return e.Err.Error() } +func (e *ModeError) Unwrap() error { return e.Err } + +// setMode makes one change (allowed): whether anything changed. +func (n *Node) setMode(name string, u *store.User, c ModeChange) (bool, error) { + b := n.b + modeErr := func(err error) (bool, error) { return false, &ModeError{c.Mode, err} } + switch { + case c.Mode == 'o' || c.Mode == 'v': + t, err := b.UserByNick(c.Arg) + if err != nil { + return false, err + } + if !b.inRoom(name, t.ID) { + return false, ErrNotThere + } + st := stVoice + if c.Mode == 'o' { + st = stOp + } + b.give(name, n.name(), n.Num, t, st, c.On, false) + return false, nil // told by give + case strings.ContainsRune(RoomFixedModes, c.Mode): + if !c.On { + return modeErr(fmt.Errorf("+%c is always on in the BBS's rooms", c.Mode)) + } + return false, nil + case strings.ContainsRune(RoomFlagModes, c.Mode): + reg := b.RoomReg(name) + on := strings.ContainsRune(reg.Modes, c.Mode) + if on == c.On { + return false, nil + } + modes := strings.ReplaceAll(reg.Modes, string(c.Mode), "") + if c.On { + modes += string(c.Mode) + } + if err := b.saveModes(name, &modes, nil, nil); err != nil { + return false, err + } + c.Arg = "" + case c.Mode == 'k': + key := "" + if c.On { + key = c.Arg + if key == "" || len(key) > MaxRoomKey || strings.ContainsAny(key, " ,:") { + return modeErr(fmt.Errorf("a key is 1 to %d letters, with no spaces, commas or colons", MaxRoomKey)) + } + } + if b.RoomReg(name).Key == key { + return false, nil + } + if err := b.saveModes(name, nil, &key, nil); err != nil { + return false, err + } + c.Arg = key + if !c.On { + c.Arg = "*" + } + case c.Mode == 'l': + limit := 0 + if c.On { + l, err := strconv.Atoi(c.Arg) + if err != nil || l < 1 || l > 10000 { + return modeErr(errors.New("a limit is 1 to 10000")) + } + limit = l + c.Arg = strconv.Itoa(l) + } + if b.RoomReg(name).Limit == limit { + return false, nil + } + if err := b.saveModes(name, nil, nil, &limit); err != nil { + return false, err + } + case strings.ContainsRune(RoomListModes, c.Mode): + mask := NormalMask(c.Arg) + if mask == "" { + return modeErr(fmt.Errorf("%q is not a mask (nick!user@host, or $a:account, $o)", c.Arg)) + } + c.Arg = mask + kind := string(c.Mode) + if c.On { + if len(b.RoomList(name, c.Mode)) >= MaxRoomList { + return modeErr(fmt.Errorf("the +%c list is full (%d)", c.Mode, MaxRoomList)) + } + err := b.Store.AddRoomList(name, kind, mask, Nick(u.Name)) + if errors.Is(err, store.ErrExists) { + return false, nil + } + if err != nil { + return false, err + } + b.updateReg(name, func(r *store.RoomReg) { + r.Lists = append(r.Lists, &store.RoomListEntry{Room: name, Kind: kind, Mask: mask, SetBy: Nick(u.Name), SetAt: time.Now()}) + }) + } else { + // as given, or as normalised + found := "" + for _, e := range b.RoomList(name, c.Mode) { + if strings.EqualFold(e.Mask, mask) || strings.EqualFold(e.Mask, strings.TrimSpace(c.Arg)) { + found = e.Mask + } + } + if found == "" { + return false, nil + } + if err := b.Store.DelRoomList(name, kind, found); err != nil && !errors.Is(err, store.ErrNotFound) { + return false, err + } + c.Arg = found + b.updateReg(name, func(r *store.RoomReg) { + keep := r.Lists[:0] + for _, e := range r.Lists { + if !(e.Kind == kind && e.Mask == found) { + keep = append(keep, e) + } + } + r.Lists = keep + }) + } + default: + return modeErr(fmt.Errorf("%c is not a mode the BBS's rooms have", c.Mode)) + } + b.tellMode(name, n.name(), n.Num, c) + return true, nil +} + +// saveModes changes a registered room's modes, key or limit (nil: as it +// is), stored and cached. +func (b *BBS) saveModes(name string, modes, key *string, limit *int) error { + reg := b.RoomReg(name) + if reg == nil { + return ErrNoModes + } + if modes != nil { + letters := []rune(*modes) + sort.Slice(letters, func(i, j int) bool { return letters[i] < letters[j] }) + reg.Modes = string(letters) + } + if key != nil { + reg.Key = *key + } + if limit != nil { + reg.Limit = *limit + } + if err := b.Store.SetRoomModes(name, reg.Modes, reg.Key, reg.Limit); err != nil { + return err + } + b.updateReg(name, func(r *store.RoomReg) { r.Modes, r.Key, r.Limit = reg.Modes, reg.Key, reg.Limit }) + return nil +} + +// tellMode tells those in a room of a change. +func (b *BBS) tellMode(name, by string, byNode int, c ModeChange) { + sign := "-" + if c.On { + sign = "+" + } + e := Event{Kind: Mode, Room: name, From: by, Node: byNode, Text: sign + string(c.Mode), Target: c.Arg, Time: time.Now()} + for _, m := range b.roomNodes(name) { + m.deliver(e) + } +} + +// Invite is INVITE: one in a room (an op there if it is invite only, but +// with g; a sysop anywhere) asks another in. Invited, they get past i, +// k and l for the hour; they are told. +func (n *Node) Invite(name, who string) (*store.User, error) { + u := n.User() + if u == nil { + return nil, ErrNoUser + } + if !n.InRoom(name) && !u.Sysop { + return nil, ErrNotInRoom + } + reg := n.b.RoomReg(name) + if reg != nil && strings.ContainsRune(reg.Modes, 'i') && !strings.ContainsRune(reg.Modes, 'g') && + !u.Sysop && !n.b.IsOp(name, u) && !has(n.b.RoomFlags(name, u), FlagInvite) { + return nil, ErrNoPrivs + } + t, err := n.b.UserByNick(who) + if err != nil { + return nil, err + } + if n.b.inRoom(name, t.ID) { + return t, ErrAlreadyIn + } + nodes := n.b.nodesOfUser(t.ID) + if len(nodes) == 0 { + return t, ErrNotOn + } + n.b.invite(name, t.ID) + e := Event{Kind: Invited, Room: name, From: n.name(), Node: n.Num, Target: t.Name, Time: time.Now()} + for _, o := range nodes { + o.deliver(e) + } + n.b.Log.Printf("chat: %s invited %s into #%s", u.Name, t.Name, name) + return t, nil +} + +// More refusals: of INVITE and KNOCK. +var ( + ErrAlreadyIn = errors.New("they are in that room already") + ErrNotOn = errors.New("they are not on") + ErrRoomOpen = errors.New("that room is open: just come in") + ErrNoKnock = errors.New("that room takes no knocks") + ErrKnocked = errors.New("you knocked a moment ago") +) + +// Knock is KNOCK: one kept out of a registered room (invite only, keyed +// or full) asks its ops in, once a minute. A +p room takes none. +func (n *Node) Knock(name, text string) error { + u := n.User() + if u == nil { + return ErrNoUser + } + reg := n.b.RoomReg(name) + switch { + case n.InRoom(name): + return ErrAlreadyIn + case reg == nil || !strings.ContainsRune(reg.Modes, 'i') && reg.Key == "" && (reg.Limit == 0 || n.b.accountsIn(name) < reg.Limit): + return ErrRoomOpen + case strings.ContainsRune(reg.Modes, 'p'): + return ErrNoKnock + } + cs := n.chat() + cs.mu.Lock() + if time.Since(cs.knocked[name]) < time.Minute { + cs.mu.Unlock() + return ErrKnocked + } + if cs.knocked == nil { + cs.knocked = map[string]time.Time{} + } + cs.knocked[name] = time.Now() + cs.mu.Unlock() + line := fmt.Sprintf("%s (node %d) knocks on %s, asking to come in", Nick(u.Name), n.Num, name) + if text = Clean(text, MaxTopic); text != "" { + line += ": " + text + } + e := Event{Kind: Notice, Room: "", From: n.name(), Node: n.Num, Text: line + fmt.Sprintf(" (INVITE %s #%s)", Nick(u.Name), name), Time: time.Now()} + for _, o := range n.b.opsOf(name) { + o.deliver(e) + } + return nil +} + +// modeWords are modes given and taken, in words for the text front ends +// ("%s" the room; the mode's parameter follows). +var modeWords = map[string]string{ + "+m": "made %s moderated", "-m": "made %s unmoderated", + "+i": "made %s invite only", "-i": "opened %s to all", + "+k": "gave %s a key", "-k": "took the key from %s", + "+l": "limited %s to", "-l": "took the limit from %s", + "+b": "banned from %s:", "-b": "lifted a ban in %s:", + "+q": "quieted in %s:", "-q": "lifted a quiet in %s:", + "+s": "made %s secret", "-s": "made %s public", +} + +// RoomSecret: a registered room is +s. +func (b *BBS) RoomSecret(name string) bool { return b.RoomReg(name) != nil && b.RoomHas(name, 's') } + +// ParseModes reads changes as MODE has them ("+mk-i", then their +// parameters); b, q, e and I with no mask left are not changes (they ask +// for the list). +func ParseModes(modes string, args []string) []ModeChange { + on := true + var out []ModeChange + for _, m := range modes { + switch m { + case '+': + on = true + continue + case '-': + on = false + continue + } + c := ModeChange{On: on, Mode: m} + if ModeTakesArg(m, on) { + if len(args) == 0 { + if m == 'k' && !on { + out = append(out, c) + } + continue + } + c.Arg, args = args[0], args[1:] + } + out = append(out, c) + } + return out +} diff --git a/internal/bbs/roomreg.go b/internal/bbs/roomreg.go index abeea29..4490ede 100644 --- a/internal/bbs/roomreg.go +++ b/internal/bbs/roomreg.go @@ -443,7 +443,10 @@ func (n *Node) SetTopic(name, topic string) error { } if reg := n.b.RoomReg(name); reg != nil { flags := n.b.RoomFlags(name, u) - if !has(flags, FlagTopic) && (reg.Has("topiclock") || !n.b.IsOp(name, u)) { + // t (the flag) always; with TOPICLOCK only it; else ops, or anyone + // in a -t room + anyone := !strings.ContainsRune(reg.Modes, 't') && n.InRoom(name) + if !has(flags, FlagTopic) && (reg.Has("topiclock") || !n.b.IsOp(name, u) && !anyone) { return errors.New("you may not set that room's topic") } } else if _, permanent := n.b.RoomTopic(name); !permanent { diff --git a/internal/ircd/chanserv.go b/internal/ircd/chanserv.go index 24800f7..c48201f 100644 --- a/internal/ircd/chanserv.go +++ b/internal/ircd/chanserv.go @@ -1,7 +1,6 @@ package ircd import ( - "errors" "strings" "github.com/D-Modem/bbs/internal/bbs" @@ -57,42 +56,3 @@ func (c *client) nodeOfUser(name string) int { } return 0 } - -// chanMode is MODE #room with changes: +o, -o, +v and -v (up to MODES of -// them) by the room's ops; the rest are not the BBS's yet. -func (c *client) chanMode(name, modes string, args []string) { - on, changes := true, 0 - for _, m := range modes { - switch m { - case '+': - on = true - case '-': - on = false - case 'o', 'v': - if len(args) == 0 { - continue - } - nick := args[0] - args = args[1:] - if changes++; changes > 4 { - return - } - err := c.n.SetStatus(name, nick, m == 'o', on) - switch { - case err == nil: - case errors.Is(err, bbs.ErrNoUser): - c.reply(ERR_NOSUCHNICK, nick, "No such nick") - case errors.Is(err, bbs.ErrNotThere): - c.reply(ERR_USERNOTINCHANNEL, nick, "#"+name, "They aren't on that channel") - default: - c.reply(ERR_CHANOPRIVSNEEDED, "#"+name, capital(err.Error())) - } - case 'n', 't': - if !on { - c.reply(ERR_CHANOPRIVSNEEDED, "#"+name, "The BBS's rooms are always +nt") - } - default: - c.reply(ERR_UNKNOWNMODE, string(m), "is not a mode the BBS's rooms have") - } - } -} diff --git a/internal/ircd/commands.go b/internal/ircd/commands.go index 221221f..76b9877 100644 --- a/internal/ircd/commands.go +++ b/internal/ircd/commands.go @@ -31,7 +31,7 @@ func (c *client) command(m *ircmsg.Message) { c.reply(ERR_ERRONEUSNICKNAME, nick, "Your nick is your BBS name") } case "JOIN": - c.join(param(m, 0)) + c.join(param(m, 0), param(m, 1)) case "PART": for _, ch := range strings.Split(param(m, 0), ",") { c.part(ch) @@ -100,7 +100,11 @@ func (c *client) command(m *ircmsg.Message) { c.reply(RPL_ENDOFINFO, "End of INFO") case "KICK": c.kick(param(m, 0), param(m, 1), param(m, 2)) - case "INVITE", "OPER", "KILL", "KNOCK": + case "INVITE": + c.invite(param(m, 0), param(m, 1)) + case "KNOCK": + c.knock(param(m, 0), param(m, 1)) + case "OPER", "KILL": c.reply(ERR_NOPRIVILEGES, "Permission denied") default: for _, svc := range []*service{c.s.svc, c.s.cs} { @@ -135,17 +139,22 @@ func (c *client) joined() []string { // join is JOIN: each channel's room joined, with its topic, names and // last lines; "0" parts them all. A sysop joining #sysop-N answers node // N's page. -func (c *client) join(list string) { +func (c *client) join(list, keyList string) { if list == "0" { for _, r := range c.joined() { c.part("#" + r) } return } - for _, ch := range strings.Split(list, ",") { + keys := strings.Split(keyList, ",") + for i, ch := range strings.Split(list, ",") { if ch == "" { continue } + key := "" + if i < len(keys) { + key = keys[i] + } name := room(ch) if name == "" { c.reply(ERR_NOSUCHCHANNEL, ch, "No such channel (channels begin with #)") @@ -164,10 +173,10 @@ func (c *client) join(list string) { // a sysop going into a paging caller's room answers the page num, _ := strconv.Atoi(pager) if hist, _, err = c.n.AnswerAlso(num); err != nil { - hist, err = c.n.JoinAlso(name) + hist, err = c.n.JoinAlsoKey(name, key) } } else { - hist, err = c.n.JoinAlso(name) + hist, err = c.n.JoinAlsoKey(name, key) } switch { case errors.Is(err, bbs.ErrNoRoom): @@ -176,6 +185,15 @@ func (c *client) join(list string) { case errors.Is(err, bbs.ErrBanned): c.reply(ERR_BANNEDFROMCHAN, ch, "Cannot join channel (+b): "+err.Error()) continue + case errors.Is(err, bbs.ErrInviteOnly): + c.reply(ERR_INVITEONLYCHAN, ch, "Cannot join channel (+i): "+err.Error()) + continue + case errors.Is(err, bbs.ErrBadKey): + c.reply(ERR_BADCHANNELKEY, ch, "Cannot join channel (+k): "+err.Error()) + continue + case errors.Is(err, bbs.ErrFull): + c.reply(ERR_CHANNELISFULL, ch, "Cannot join channel (+l): "+err.Error()) + continue case errors.Is(err, bbs.ErrNotYours), errors.Is(err, bbs.ErrNotAllowed): c.reply(ERR_INVITEONLYCHAN, ch, "Cannot join channel: "+err.Error()) continue @@ -240,7 +258,7 @@ func (c *client) roomServices(name string) []*service { // sysops as ops; a sysop- room's only to those in it. func (c *client) names(ch string) { name := room(ch) - if name != "" && (c.n.InRoom(name) || !strings.HasPrefix(name, "sysop-")) { + if name != "" && (c.n.InRoom(name) || !strings.HasPrefix(name, "sysop-") && (!c.s.B.RoomSecret(name) || c.u.Sysop)) { var line []string seen := map[string]bool{} for _, svc := range c.roomServices(name) { @@ -314,7 +332,7 @@ func (c *client) userOfNick(nick string) *store.User { // or a nick's nodes. func (c *client) who(mask string) { if name := room(mask); name != "" { - if c.n.InRoom(name) || !strings.HasPrefix(name, "sysop-") { + if c.n.InRoom(name) || !strings.HasPrefix(name, "sysop-") && (!c.s.B.RoomSecret(name) || c.u.Sysop) { for _, svc := range c.roomServices(name) { c.reply(RPL_WHOREPLY, "#"+name, svc.Name, c.s.S.ServerName, c.s.S.ServerName, svc.Name, "H@", "0 "+c.s.serviceReal(svc)) @@ -474,14 +492,12 @@ func (c *client) sendTopic(ch, name string) { func (c *client) mode(m *ircmsg.Message) { target := param(m, 0) if name := room(target); name != "" { - switch { - case len(m.Params) == 1: - c.reply(RPL_CHANNELMODEIS, "#"+name, "+nt") - case strings.Trim(param(m, 1), "+") == "b": - c.reply(RPL_ENDOFBANLIST, "#"+name, "End of channel ban list") - default: - c.chanMode(name, m.Params[1], m.Params[2:]) + if len(m.Params) == 1 { + modes, args := c.s.B.RoomModes(name, c.n.InRoom(name) || c.u.Sysop) + c.reply(RPL_CHANNELMODEIS, append([]string{"#" + name, modes}, args...)...) + return } + c.chanMode(name, m.Params[1], m.Params[2:]) return } if fold(target) != fold(c.nick) { @@ -522,9 +538,16 @@ func (c *client) privmsg(command, target, text string) { } text = stripped(text) if name := room(target); name != "" { + if notice && c.s.B.RoomHas(name, 'T') { + return // +T: no notices (and a NOTICE is never answered) + } if !c.n.InRoom(name) { - if !notice { - c.reply(ERR_CANNOTSENDTOCHAN, target, "Cannot send to channel (join it first)") + if err := c.n.SayOutside(name, text, emote); err != nil && !notice { + if errors.Is(err, bbs.ErrNotInRoom) { + c.reply(ERR_CANNOTSENDTOCHAN, target, "Cannot send to channel (join it first)") + } else { + c.reply(ERR_CANNOTSENDTOCHAN, target, "Cannot send to channel: "+err.Error()) + } } return } @@ -677,7 +700,16 @@ func (c *client) event(e bbs.Event) { } c.send(tags, source, "TOPIC", "#"+e.Room, e.Text) case bbs.Mode: - c.send(tags, c.eventSource(e), "MODE", "#"+e.Room, e.Text, Nick(e.Target)) + switch { + case strings.HasSuffix(e.Text, "o"), strings.HasSuffix(e.Text, "v"): + c.send(tags, c.eventSource(e), "MODE", "#"+e.Room, e.Text, Nick(e.Target)) + case e.Target != "": + c.send(tags, c.eventSource(e), "MODE", "#"+e.Room, e.Text, e.Target) + default: + c.send(tags, c.eventSource(e), "MODE", "#"+e.Room, e.Text) + } + case bbs.Invited: + c.send(tags, c.eventSource(e), "INVITE", Nick(e.Target), "#"+e.Room) case bbs.Kicked: c.send(tags, c.eventSource(e), "KICK", "#"+e.Room, Nick(e.Target), e.Text) case bbs.Private: diff --git a/internal/ircd/modes.go b/internal/ircd/modes.go new file mode 100644 index 0000000..8e66576 --- /dev/null +++ b/internal/ircd/modes.go @@ -0,0 +1,157 @@ +package ircd + +import ( + "errors" + "strconv" + "strings" + + "github.com/D-Modem/bbs/internal/bbs" +) + +// The channel modes on IRC: MODE's changes and lists, INVITE and KNOCK. +// The modes themselves are the rooms' (bbs.Node.SetModes). + +// numerics of Solanum's that ergo's list lacks +const ( + RPL_QUIETLIST = "728" + RPL_ENDOFQUIETLIST = "729" + RPL_KNOCK = "710" + RPL_KNOCKDLVR = "711" + ERR_TOOMANYKNOCK = "712" + ERR_CHANOPEN = "713" + ERR_KNOCKONCHAN = "714" + ERR_CANNOTKNOCK = "480" +) + +// chanMode is MODE #room with changes (up to 4 with parameters) by the +// room's ops; b, q, e or I with no mask lists that list. +func (c *client) chanMode(name, modes string, args []string) { + on := true + var changes []bbs.ModeChange + withArg := 0 + for _, m := range modes { + switch { + case m == '+': + on = true + continue + case m == '-': + on = false + continue + case strings.ContainsRune(bbs.RoomListModes, m) && len(args) == 0: + c.sendList(name, m) + continue + } + ch := bbs.ModeChange{On: on, Mode: m} + if bbs.ModeTakesArg(m, on) { + if len(args) == 0 { + if m == 'k' && !on { + changes = append(changes, ch) // -k needs no key here + } + continue + } + ch.Arg, args = args[0], args[1:] + if withArg++; withArg > 4 { + break + } + } + changes = append(changes, ch) + } + if len(changes) == 0 { + return + } + _, errs := c.n.SetModes(name, changes) + for _, err := range errs { + var me *bbs.ModeError + switch { + case errors.Is(err, bbs.ErrNoUser): + c.reply(ERR_NOSUCHNICK, "*", "No such nick") + case errors.Is(err, bbs.ErrNotThere): + c.reply(ERR_USERNOTINCHANNEL, "*", "#"+name, "They aren't on that channel") + case errors.As(err, &me) && strings.Contains(me.Error(), "not a mode"): + c.reply(ERR_UNKNOWNMODE, string(me.Mode), "is not a mode the BBS's rooms have") + case errors.As(err, &me) && strings.Contains(me.Error(), "list is full"): + c.reply(ERR_BANLISTFULL, "#"+name, string(me.Mode), capital(me.Error())) + default: + c.reply(ERR_CHANOPRIVSNEEDED, "#"+name, capital(err.Error())) + } + } +} + +// sendList is a room's list of a kind: bans (367), quiets (728), +// exceptions (348), invite exceptions (346). +func (c *client) sendList(name string, kind rune) { + ch := "#" + name + if c.s.B.RoomSecret(name) && !c.n.InRoom(name) && !c.u.Sysop { + kind = 0 // a secret room's lists are its own + } + entries := c.s.B.RoomList(name, kind) + row := func(e string, by string, at int64) []string { + return []string{ch, e, by, strconv.FormatInt(at, 10)} + } + switch kind { + case 'q': + for _, e := range entries { + c.reply(RPL_QUIETLIST, ch, "q", e.Mask, e.SetBy, strconv.FormatInt(e.SetAt.Unix(), 10)) + } + c.reply(RPL_ENDOFQUIETLIST, ch, "q", "End of channel quiet list") + case 'e': + for _, e := range entries { + c.reply(RPL_EXCEPTLIST, row(e.Mask, e.SetBy, e.SetAt.Unix())...) + } + c.reply(RPL_ENDOFEXCEPTLIST, ch, "End of channel exception list") + case 'I': + for _, e := range entries { + c.reply(RPL_INVITELIST, row(e.Mask, e.SetBy, e.SetAt.Unix())...) + } + c.reply(RPL_ENDOFINVITELIST, ch, "End of channel invite exception list") + default: + for _, e := range entries { + c.reply(RPL_BANLIST, row(e.Mask, e.SetBy, e.SetAt.Unix())...) + } + c.reply(RPL_ENDOFBANLIST, ch, "End of channel ban list") + } +} + +// invite is INVITE nick #room. +func (c *client) invite(nick, ch string) { + name := room(ch) + if nick == "" || name == "" { + c.reply(ERR_NEEDMOREPARAMS, "INVITE", "Not enough parameters") + return + } + t, err := c.n.Invite(name, nick) + switch { + case err == nil: + c.reply(RPL_INVITING, Nick(t.Name), "#"+name) + case errors.Is(err, bbs.ErrNoUser), errors.Is(err, bbs.ErrNotOn): + c.reply(ERR_NOSUCHNICK, nick, "No such nick") + case errors.Is(err, bbs.ErrNotInRoom): + c.reply(ERR_NOTONCHANNEL, "#"+name, "You're not on that channel") + case errors.Is(err, bbs.ErrAlreadyIn): + c.reply(ERR_USERONCHANNEL, nick, "#"+name, "is already on channel") + default: + c.reply(ERR_CHANOPRIVSNEEDED, "#"+name, capital(err.Error())) + } +} + +// knock is KNOCK #room [why]. +func (c *client) knock(ch, text string) { + name := room(ch) + if name == "" { + c.reply(ERR_NEEDMOREPARAMS, "KNOCK", "Not enough parameters") + return + } + err := c.n.Knock(name, text) + switch { + case err == nil: + c.reply(RPL_KNOCKDLVR, "#"+name, "Your KNOCK has been delivered") + case errors.Is(err, bbs.ErrAlreadyIn): + c.reply(ERR_KNOCKONCHAN, "#"+name, "You're already on that channel") + case errors.Is(err, bbs.ErrRoomOpen): + c.reply(ERR_CHANOPEN, "#"+name, "Channel is open") + case errors.Is(err, bbs.ErrKnocked): + c.reply(ERR_TOOMANYKNOCK, "#"+name, "Too many KNOCKs (channel)") + default: + c.reply(ERR_CANNOTKNOCK, "#"+name, "Cannot knock: "+err.Error()) + } +} diff --git a/internal/ircd/modes_test.go b/internal/ircd/modes_test.go new file mode 100644 index 0000000..5b7c0fc --- /dev/null +++ b/internal/ircd/modes_test.go @@ -0,0 +1,172 @@ +package ircd + +import ( + "strings" + "testing" +) + +// TestChannelModes: a registered room's modes by its op: m and voices, i +// and INVITE, k, l, b and e, q and z, s, t, n, T, KNOCK; the lists; a +// caller on the BBS bound as an IRC user is; and the modes kept. +func TestChannelModes(t *testing.T) { + e := start(t) + a := e.dial(t) + a.login("alice", "alice") + b := e.dial(t) + b.login("bob", "bob") + a.send("JOIN #den", "CS REGISTER #den") + a.expect("MODE #den +o alice") + a.send("MODE #den") + a.expect("324 alice #den :+Ccnt") + + // only ops set modes; unregistered rooms have none + b.send("JOIN #den") + b.expect("366 bob #den") + b.send("MODE #den +m") + b.expect("482 bob #den :You are not an operator in that room") + b.send("JOIN #open", "MODE #open +m") + b.expect("482 bob #open :Only registered rooms have modes") + + // m: bob is quiet until voiced; a caller on the BBS too + carol := e.caller(t, "Carol Ann") + if _, err := carol.JoinRoom("den"); err != nil { + t.Fatal(err) + } + a.send("MODE #den +m") + b.expect(":alice!irc@node1 MODE #den +m") + b.send("PRIVMSG #den :hello?") + b.expect("404 bob #den :Cannot send to channel: that room is moderated") + if err := carol.Say("me too?", false); err == nil { + t.Error("a caller talked in a +m room") + } + a.send("MODE #den +v bob") + b.expect("MODE #den +v bob") + b.send("PRIVMSG #den :voiced") + a.expect(":bob!irc@node2 PRIVMSG #den :voiced") + a.send("MODE #den -m") + b.expect("MODE #den -m") + + // i: carol, out, is kept out until invited + carol.LeaveRoom() + a.send("MODE #den +i") + b.expect("MODE #den +i") + if _, err := carol.JoinRoom("den"); err == nil || !strings.Contains(err.Error(), "invite only") { + t.Errorf("+i: %v", err) + } + b.send("INVITE Carol_Ann #den") + b.expect("482 bob #den :You are not an operator in that room") + a.send("INVITE Carol_Ann #den") + a.expect("341 alice Carol_Ann :#den") + waitEvent(t, carol, "alice invites Carol Ann into den") + if _, err := carol.JoinRoom("den"); err != nil { + t.Errorf("invited: %v", err) + } + carol.LeaveRoom() + if _, err := carol.JoinRoom("den"); err == nil { + t.Error("an invite used twice") + } + a.send("MODE #den -i") + b.expect("MODE #den -i") + + // k and l + a.send("MODE #den +kl sesame 2") + b.expect("MODE #den +k sesame") + b.expect("MODE #den +l 2") + a.send("MODE #den") + a.expect("324 alice #den +Ccntkl sesame :2") + if _, err := carol.JoinRoom("den"); err == nil || !strings.Contains(err.Error(), "key") { + t.Errorf("+k: %v", err) + } + if _, err := carol.JoinRoomKey("den", "sesame"); err == nil || !strings.Contains(err.Error(), "full") { + t.Errorf("+l: %v", err) + } + a.send("MODE #den -l") + b.expect("MODE #den -l") + if _, err := carol.JoinRoomKey("den", "sesame"); err != nil { + t.Errorf("the key: %v", err) + } + b.send("PART #den", "JOIN #den") + b.expect("475 bob #den :Cannot join channel (+k)") + b.send("JOIN #den sesame") + b.expect("366 bob #den") + a.send("MODE #den -k *") + b.expect("MODE #den -k *") + + // b and e; the lists + a.send("MODE #den +b bob", "MODE #den b") + a.expectAll("MODE #den +b bob!*@*", "367 alice #den bob!*@* alice ", "368 alice #den") + b.send("PRIVMSG #den :banned?") + b.expect("404 bob #den :Cannot send to channel: you may not talk in that room") + b.send("PART #den", "JOIN #den") + b.expect("474 bob #den") + a.send("MODE #den +e $a:bob") + a.expect("MODE #den +e $a:bob") + b.send("JOIN #den") + b.expect("366 bob #den") + a.send("MODE #den -be bob $a:bob", "MODE #den +q *!telnet@*") + a.expect("MODE #den -e $a:bob") + a.expect("MODE #den +q *!telnet@*") + if err := carol.Say("from the terminal", false); err == nil { + t.Error("a quieted caller talked") + } + // z: what q stops goes to the ops + a.send("MODE #den +z") + a.expect("MODE #den +z") + if err := carol.Say("to the ops", false); err != nil { + t.Errorf("+z: %v", err) + } + a.expect(":Carol_Ann!telnet@node3 PRIVMSG #den :to the ops") + a.send("MODE #den q") + a.expect("728 alice #den q *!telnet@* alice ") + + // t off: anyone in the room sets the topic + b.send("TOPIC #den :bob's topic") + b.expect("482 bob #den") + a.send("MODE #den -t") + b.expect("MODE #den -t") + b.send("TOPIC #den :bob's topic") + a.expect("TOPIC #den :bob's topic") + + // n off: lines from outside; T: no notices + o := e.dial(t) + o.login("sysop", "sysop") + o.send("PRIVMSG #den :from outside") + o.expect("404 sysop #den :Cannot send to channel (join it first)") + a.send("MODE #den -n+T") + a.expect("MODE #den -n") + a.expect("MODE #den +T") + o.send("PRIVMSG #den :from outside") + a.expect(":sysop!irc@node4 PRIVMSG #den :from outside") + b.send("NOTICE #den :a notice", "PRIVMSG #den :a line") + if l := a.expect("#den :a line"); strings.Contains(l, "notice") { + t.Error(l) + } + + // s: not in LIST to those outside; KNOCK on an invite-only room + a.send("MODE #den +si") + a.expect("MODE #den +i") + d := e.dial(t) + d.send("PASS sysop:password1", "NICK x", "USER u 0 * :x") + d.expect(" 376 ") + c := e.dial(t) + c.login("Carol Ann", "Carol_Ann") + c.send("LIST") + if l := c.expect("323 Carol_Ann"); strings.Contains(l, "den") { + t.Error("a secret room listed") + } + carol.LeaveRoom() + c.send("KNOCK #den :let me in") + c.expect("711 Carol_Ann #den :Your KNOCK has been delivered") + a.expect("Carol_Ann (node") + c.send("KNOCK #den") + c.expect("712 Carol_Ann #den") + + // kept: in the store + reg, err := e.b.Store.RoomReg("den") + if err != nil { + t.Fatal(err) + } + if reg.Modes != "Tisz" || len(reg.Lists) != 1 || reg.Lists[0].Mask != "*!telnet@*" { + t.Errorf("kept %q %+v", reg.Modes, reg.Lists) + } +} diff --git a/internal/ircd/numerics.go b/internal/ircd/numerics.go index 788856d..c44dd15 100644 --- a/internal/ircd/numerics.go +++ b/internal/ircd/numerics.go @@ -84,6 +84,8 @@ const ( RPL_SUMMONING = "342" RPL_INVEXLIST = "346" RPL_ENDOFINVEXLIST = "347" + RPL_INVITELIST = "346" + RPL_ENDOFINVITELIST = "347" RPL_EXCEPTLIST = "348" RPL_ENDOFEXCEPTLIST = "349" RPL_VERSION = "351" diff --git a/internal/ircd/server.go b/internal/ircd/server.go index d424acc..91ab86d 100644 --- a/internal/ircd/server.go +++ b/internal/ircd/server.go @@ -104,7 +104,13 @@ func New(b *bbs.BBS, s Settings) (*Server, error) { "NICKLEN": strconv.Itoa(bbs.MaxNameLen), "NETWORK": s.Network, "PREFIX": "(ov)@+", - "CHANMODES": ",,,nt", + "CHANMODES": bbs.RoomListModes + ",k,l," + bbs.RoomFixedModes + bbs.RoomFlagModes, + "EXCEPTS": "e", + "INVEX": "I", + "EXTBAN": "$,ao", + "MAXLIST": bbs.RoomListModes + ":" + strconv.Itoa(bbs.MaxRoomList), + "KEYLEN": strconv.Itoa(bbs.MaxRoomKey), + "KNOCK": "", "MODES": "4", "TOPICLEN": "0", "TARGMAX": "PRIVMSG:1,NOTICE:1,JOIN:,PART:,NAMES:1,WHOIS:1", diff --git a/internal/store/copy.go b/internal/store/copy.go index 5cf6b07..961eab6 100644 --- a/internal/store/copy.go +++ b/internal/store/copy.go @@ -12,7 +12,7 @@ import ( // copyOrder is the tables in an order their references allow. var copyOrder = []string{"users", "areas", "messages", "votes", "poll_answers", "poll_votes", "lastread", "scan_off", "mail", "mailbox", "mail_uids", "mail_queue", "file_areas", "files", - "history", "peer_groups", "peer_push", "netmail_out", "api_tokens", "ssh_keys", "script_data", "calls", "qwk_seen", "qwk_msgs", "chat_rooms", "room_reg", "room_access", "topic_read", "fido_subs", + "history", "peer_groups", "peer_push", "netmail_out", "api_tokens", "ssh_keys", "script_data", "calls", "qwk_seen", "qwk_msgs", "chat_rooms", "room_reg", "room_access", "room_lists", "topic_read", "fido_subs", "chan_boards", "chan_posts", "chan_bans", "chan_reports", "oscar_keys", "feedbag", "cis_keys", "chats", "friends", "oscar_buddies", "msn_keys", "blocks", "address_book", "ntlm_keys", "ymsg_keys"} var columnPat = regexp.MustCompile(`(?m)^\s*("?\w+"?)\s+(\{\w+\})`) diff --git a/internal/store/roomreg.go b/internal/store/roomreg.go index 01b9782..f85960c 100644 --- a/internal/store/roomreg.go +++ b/internal/store/roomreg.go @@ -24,6 +24,33 @@ type RoomReg struct { Topic string TopicBy string TopicAt time.Time + // the channel modes: the letters on ("ntm"), the key and the limit + Modes string + Key string + Limit int + // the ban, quiet, exception and invite-exception lists + Lists []*RoomListEntry +} + +// RoomListEntry is a mask on one of a room's lists: kind b (bans), q +// (quiets), e (exceptions) or I (invite exceptions). +type RoomListEntry struct { + Room string + Kind string + Mask string + SetBy string + SetAt time.Time +} + +// List is the room's entries of a kind. +func (r *RoomReg) List(kind string) []*RoomListEntry { + var out []*RoomListEntry + for _, e := range r.Lists { + if e.Kind == kind { + out = append(out, e) + } + } + return out } // Has: the room has that setting on. @@ -46,12 +73,12 @@ type RoomAccess struct { SetAt time.Time } -const roomRegCols = `r.name, r.founder_id, COALESCE(u.name, ''), r.registered, r.last_used, r.settings, r.descr, r.url, r.entrymsg, r.topic, r.topic_by, r.topic_at` +const roomRegCols = `r.name, r.founder_id, COALESCE(u.name, ''), r.registered, r.last_used, r.settings, r.descr, r.url, r.entrymsg, r.topic, r.topic_by, r.topic_at, r.modes, r.mode_key, r.mode_limit` func scanRoomReg(sc interface{ Scan(...any) error }) (*RoomReg, error) { var r RoomReg var reg, used, tat int64 - if err := sc.Scan(&r.Name, &r.FounderID, &r.Founder, ®, &used, &r.Settings, &r.Descr, &r.URL, &r.EntryMsg, &r.Topic, &r.TopicBy, &tat); err != nil { + if err := sc.Scan(&r.Name, &r.FounderID, &r.Founder, ®, &used, &r.Settings, &r.Descr, &r.URL, &r.EntryMsg, &r.Topic, &r.TopicBy, &tat, &r.Modes, &r.Key, &r.Limit); err != nil { return nil, err } r.Registered, r.LastUsed, r.TopicAt = unix(reg), unix(used), unix(tat) @@ -73,7 +100,24 @@ func (s *Store) RoomRegs() ([]*RoomReg, error) { } out = append(out, r) } - return out, rows.Err() + if err := rows.Err(); err != nil { + return nil, err + } + rows.Close() + lists, err := s.roomLists(``) + if err != nil { + return nil, err + } + byName := map[string]*RoomReg{} + for _, r := range out { + byName[r.Name] = r + } + for _, e := range lists { + if r := byName[e.Room]; r != nil { + r.Lists = append(r.Lists, e) + } + } + return out, nil } // RoomReg is a registered room; ErrNotFound if it is not registered. @@ -82,9 +126,53 @@ func (s *Store) RoomReg(name string) (*RoomReg, error) { if errors.Is(err, sql.ErrNoRows) { return nil, ErrNotFound } + if err != nil { + return nil, err + } + r.Lists, err = s.roomLists(`WHERE room = ?`, name) return r, err } +// roomLists are rooms' list entries, oldest first. +func (s *Store) roomLists(where string, args ...any) ([]*RoomListEntry, error) { + rows, err := s.db.Query(`SELECT room, kind, mask, set_by, set_at FROM room_lists `+where+` ORDER BY set_at, mask`, args...) + if err != nil { + return nil, err + } + defer rows.Close() + var out []*RoomListEntry + for rows.Next() { + var e RoomListEntry + var at int64 + if err := rows.Scan(&e.Room, &e.Kind, &e.Mask, &e.SetBy, &at); err != nil { + return nil, err + } + e.SetAt = unix(at) + out = append(out, &e) + } + return out, rows.Err() +} + +// SetRoomModes sets a registered room's modes, key and limit. +func (s *Store) SetRoomModes(name, modes, key string, limit int) error { + _, err := s.db.Exec(`UPDATE room_reg SET modes = ?, mode_key = ?, mode_limit = ? WHERE name = ?`, modes, key, limit, name) + return err +} + +// AddRoomList puts a mask on a room's list; ErrExists if it is on it. +func (s *Store) AddRoomList(name, kind, mask, by string) error { + _, err := s.db.Exec(`INSERT INTO room_lists (room, kind, mask, set_by, set_at) VALUES (?, ?, ?, ?, ?)`, name, kind, mask, by, now()) + if isUnique(err) { + return ErrExists + } + return err +} + +// DelRoomList takes a mask off a room's list; ErrNotFound if it is not on it. +func (s *Store) DelRoomList(name, kind, mask string) error { + return s.exec1(`DELETE FROM room_lists WHERE room = ? AND kind = ? AND mask = ?`, name, kind, mask) +} + // RegisterRoom registers a room to its founder, who is put on its access // list with flags; ErrExists if it is registered already. func (s *Store) RegisterRoom(name string, founder int64, flags, by string) error { @@ -97,6 +185,7 @@ func (s *Store) RegisterRoom(name string, founder int64, flags, by string) error return err } _, _ = s.db.Exec(`DELETE FROM room_access WHERE room = ?`, name) // left over + _, _ = s.db.Exec(`DELETE FROM room_lists WHERE room = ?`, name) return s.SetRoomAccess(name, founder, flags, by) } @@ -105,7 +194,10 @@ func (s *Store) DropRoom(name string) error { if err := s.exec1(`DELETE FROM room_reg WHERE name = ?`, name); err != nil { return err } - _, err := s.db.Exec(`DELETE FROM room_access WHERE room = ?`, name) + if _, err := s.db.Exec(`DELETE FROM room_access WHERE room = ?`, name); err != nil { + return err + } + _, err := s.db.Exec(`DELETE FROM room_lists WHERE room = ?`, name) return err } diff --git a/internal/store/schema.go b/internal/store/schema.go index 665593d..fff8a90 100644 --- a/internal/store/schema.go +++ b/internal/store/schema.go @@ -124,7 +124,18 @@ CREATE TABLE IF NOT EXISTS room_reg ( entrymsg {str} NOT NULL DEFAULT '', topic {str} NOT NULL DEFAULT '', topic_by {str} NOT NULL DEFAULT '', - topic_at {int} NOT NULL DEFAULT 0 + topic_at {int} NOT NULL DEFAULT 0, + modes {str} NOT NULL DEFAULT 'nt', + mode_key {str} NOT NULL DEFAULT '', + mode_limit {int} NOT NULL DEFAULT 0 +)`, ` +CREATE TABLE IF NOT EXISTS room_lists ( + room {key} NOT NULL, + kind {key} NOT NULL, + mask {key} NOT NULL, + set_by {str} NOT NULL DEFAULT '', + set_at {int} NOT NULL, + PRIMARY KEY (room, kind, mask) )`, ` CREATE TABLE IF NOT EXISTS room_access ( room {key} NOT NULL, @@ -557,6 +568,9 @@ var added = []struct{ table, column, decl string }{ {"users", "geo_place", "{str} NOT NULL DEFAULT ''"}, {"users", "geo_by", "{str} NOT NULL DEFAULT ''"}, {"users", "geo_at", "{int} NOT NULL DEFAULT 0"}, + {"room_reg", "modes", "{str} NOT NULL DEFAULT 'nt'"}, + {"room_reg", "mode_key", "{str} NOT NULL DEFAULT ''"}, + {"room_reg", "mode_limit", "{int} NOT NULL DEFAULT 0"}, } // migrate makes the schema, or brings an older database up to it.