Changeset 293 in code for trunk/irc.go
- Timestamp:
- May 21, 2020, 8:36:54 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/irc.go
r292 r293 85 85 type channelModes map[byte]string 86 86 87 func (cm channelModes) Apply(modeTypes map[byte]channelModeType, modeStr string, arguments ...string) error { 87 // applyChannelModes parses a mode string and mode arguments from a MODE message, 88 // and applies the corresponding channel mode and user membership changes on that channel. 89 // 90 // If ch.modes is nil, channel modes are not updated. 91 // 92 // needMarshaling is a list of indexes of mode arguments that represent entities 93 // that must be marshaled when sent downstream. 94 func applyChannelModes(ch *upstreamChannel, modeStr string, arguments []string) (needMarshaling map[int]struct{}, err error) { 95 needMarshaling = make(map[int]struct{}, len(arguments)) 88 96 nextArgument := 0 89 97 var plusMinus byte 98 outer: 90 99 for i := 0; i < len(modeStr); i++ { 91 100 mode := modeStr[i] … … 95 104 } 96 105 if plusMinus != '+' && plusMinus != '-' { 97 return fmt.Errorf("malformed modestring %q: missing plus/minus", modeStr) 98 } 99 100 mt, ok := modeTypes[mode] 106 return nil, fmt.Errorf("malformed modestring %q: missing plus/minus", modeStr) 107 } 108 109 for _, membership := range ch.conn.availableMemberships { 110 if membership.Mode == mode { 111 if nextArgument >= len(arguments) { 112 return nil, fmt.Errorf("malformed modestring %q: missing mode argument for %c%c", modeStr, plusMinus, mode) 113 } 114 member := arguments[nextArgument] 115 if _, ok := ch.Members[member]; ok { 116 if plusMinus == '+' { 117 ch.Members[member].Add(ch.conn.availableMemberships, membership) 118 } else { 119 // TODO: for upstreams without multi-prefix, query the user modes again 120 ch.Members[member].Remove(membership) 121 } 122 } 123 needMarshaling[nextArgument] = struct{}{} 124 nextArgument++ 125 continue outer 126 } 127 } 128 129 mt, ok := ch.conn.availableChannelModes[mode] 101 130 if !ok { 102 131 continue … … 110 139 argument = arguments[nextArgument] 111 140 } 112 cm[mode] = argument 141 if ch.modes != nil { 142 ch.modes[mode] = argument 143 } 113 144 } else { 114 delete(c m, mode)145 delete(ch.modes, mode) 115 146 } 116 147 nextArgument++ 117 148 } else if mt == modeTypeC || mt == modeTypeD { 118 149 if plusMinus == '+' { 119 cm[mode] = "" 150 if ch.modes != nil { 151 ch.modes[mode] = "" 152 } 120 153 } else { 121 delete(c m, mode)122 } 123 } 124 } 125 return n il154 delete(ch.modes, mode) 155 } 156 } 157 } 158 return needMarshaling, nil 126 159 } 127 160
Note:
See TracChangeset
for help on using the changeset viewer.