Changeset 563 in code


Ignore:
Timestamp:
Jun 23, 2021, 5:23:09 PM (4 years ago)
Author:
contact
Message:

Allow admins to broadcast message to all bouncer users

Typically done via:

/notice $<bouncer> <message>

Or, for a connection not bound to a specific network:

/notice $* <message>

The message is broadcast as BouncerServ, because that's the only
user that can be trusted to belong to the bouncer by users. Any
other prefix would conflict with the upstream network.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r562 r563  
    19141914
    19151915                for _, name := range strings.Split(targetsStr, ",") {
     1916                        if name == "$"+dc.srv.Hostname || (name == "$*" && dc.network == nil) {
     1917                                // "$" means a server mask follows. If it's the bouncer's
     1918                                // hostname, broadcast the message to all bouncer users.
     1919                                if !dc.user.Admin {
     1920                                        return ircError{&irc.Message{
     1921                                                Prefix:  dc.srv.prefix(),
     1922                                                Command: irc.ERR_BADMASK,
     1923                                                Params:  []string{dc.nick, name, "Permission denied to broadcast message to all bouncer users"},
     1924                                        }}
     1925                                }
     1926
     1927                                dc.logger.Printf("broadcasting bouncer-wide %v: %v", msg.Command, text)
     1928
     1929                                broadcastTags := tags.Copy()
     1930                                broadcastTags["time"] = irc.TagValue(time.Now().UTC().Format(serverTimeLayout))
     1931                                broadcastMsg := &irc.Message{
     1932                                        Tags:    broadcastTags,
     1933                                        Prefix:  servicePrefix,
     1934                                        Command: msg.Command,
     1935                                        Params:  []string{name, text},
     1936                                }
     1937                                dc.srv.forEachUser(func(u *user) {
     1938                                        u.events <- eventBroadcast{broadcastMsg}
     1939                                })
     1940                                continue
     1941                        }
     1942
    19161943                        if dc.network == nil && casemapASCII(name) == dc.nickCM {
    19171944                                dc.SendMessage(msg)
  • trunk/server.go

    r531 r563  
    125125}
    126126
     127func (s *Server) forEachUser(f func(*user)) {
     128        s.lock.Lock()
     129        for _, u := range s.users {
     130                f(u)
     131        }
     132        s.lock.Unlock()
     133}
     134
    127135func (s *Server) getUser(name string) *user {
    128136        s.lock.Lock()
  • trunk/upstream.go

    r561 r563  
    17691769        }
    17701770
     1771        // Don't store messages with a server mask target
     1772        if strings.HasPrefix(entity, "$") {
     1773                return ""
     1774        }
     1775
    17711776        entityCM := uc.network.casemap(entity)
    17721777        if entityCM == "nickserv" {
  • trunk/user.go

    r544 r563  
    5252        uc   *upstreamConn
    5353        name string
     54}
     55
     56type eventBroadcast struct {
     57        msg *irc.Message
    5458}
    5559
     
    634638                                dc.Close()
    635639                        }
     640                case eventBroadcast:
     641                        msg := e.msg
     642                        u.forEachDownstream(func(dc *downstreamConn) {
     643                                dc.SendMessage(msg)
     644                        })
    636645                case eventStop:
    637646                        u.forEachDownstream(func(dc *downstreamConn) {
Note: See TracChangeset for help on using the changeset viewer.