mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
irc operators
This commit is contained in:
parent
6367e4b654
commit
8a90634c0a
@ -15,6 +15,7 @@ type Client struct {
|
|||||||
hostname string
|
hostname string
|
||||||
invisible bool
|
invisible bool
|
||||||
nick string
|
nick string
|
||||||
|
operator bool
|
||||||
realname string
|
realname string
|
||||||
registered bool
|
registered bool
|
||||||
replies chan<- Reply
|
replies chan<- Reply
|
||||||
@ -109,6 +110,10 @@ func (c *Client) ModeString() (str string) {
|
|||||||
if c.invisible {
|
if c.invisible {
|
||||||
str += Invisible.String()
|
str += Invisible.String()
|
||||||
}
|
}
|
||||||
|
if c.operator {
|
||||||
|
str += Operator.String()
|
||||||
|
}
|
||||||
|
|
||||||
if len(str) > 0 {
|
if len(str) > 0 {
|
||||||
str = "+" + str
|
str = "+" + str
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ var (
|
|||||||
"JOIN": NewJoinCommand,
|
"JOIN": NewJoinCommand,
|
||||||
"MODE": NewModeCommand,
|
"MODE": NewModeCommand,
|
||||||
"NICK": NewNickCommand,
|
"NICK": NewNickCommand,
|
||||||
|
"OPER": NewOperCommand,
|
||||||
"PART": NewPartCommand,
|
"PART": NewPartCommand,
|
||||||
"PASS": NewPassCommand,
|
"PASS": NewPassCommand,
|
||||||
"PING": NewPingCommand,
|
"PING": NewPingCommand,
|
||||||
@ -541,3 +542,25 @@ func NewWhoCommand(args []string) (editableCommand, error) {
|
|||||||
func (msg *WhoCommand) String() string {
|
func (msg *WhoCommand) String() string {
|
||||||
return fmt.Sprintf("WHO(mask=%s, operatorOnly=%s)", msg.mask, msg.operatorOnly)
|
return fmt.Sprintf("WHO(mask=%s, operatorOnly=%s)", msg.mask, msg.operatorOnly)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OperCommand struct {
|
||||||
|
BaseCommand
|
||||||
|
name string
|
||||||
|
password string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *OperCommand) String() string {
|
||||||
|
return fmt.Sprintf("OPER(name=%s, password=%s)", msg.name, msg.password)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OPER <name> <password>
|
||||||
|
func NewOperCommand(args []string) (editableCommand, error) {
|
||||||
|
if len(args) < 2 {
|
||||||
|
return nil, NotEnoughArgsError
|
||||||
|
}
|
||||||
|
|
||||||
|
return &OperCommand{
|
||||||
|
name: args[0],
|
||||||
|
password: args[1],
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
@ -9,9 +9,15 @@ type Config struct {
|
|||||||
Name string
|
Name string
|
||||||
Listen string
|
Listen string
|
||||||
Password string
|
Password string
|
||||||
|
Operators []OperatorConfig
|
||||||
Debug map[string]bool
|
Debug map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OperatorConfig struct {
|
||||||
|
Name string
|
||||||
|
Password string
|
||||||
|
}
|
||||||
|
|
||||||
func LoadConfig() (config *Config, err error) {
|
func LoadConfig() (config *Config, err error) {
|
||||||
config = &Config{}
|
config = &Config{}
|
||||||
|
|
||||||
|
@ -206,9 +206,9 @@ func RplEndOfNames(channel *Channel) Reply {
|
|||||||
"%s :End of NAMES list", channel.name)
|
"%s :End of NAMES list", channel.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// :You are now an IRC operator
|
||||||
func RplYoureOper(server *Server) Reply {
|
func RplYoureOper(server *Server) Reply {
|
||||||
return NewNumericReply(server, RPL_YOUREOPER,
|
return NewNumericReply(server, RPL_YOUREOPER, ":You are now an IRC operator")
|
||||||
":You are now an IRC operator")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplWhoisUser(server *Server, client *Client) Reply {
|
func RplWhoisUser(server *Server, client *Client) Reply {
|
||||||
|
@ -15,6 +15,7 @@ type Server struct {
|
|||||||
ctime time.Time
|
ctime time.Time
|
||||||
hostname string
|
hostname string
|
||||||
name string
|
name string
|
||||||
|
operators map[string]string
|
||||||
password string
|
password string
|
||||||
clients ClientNameMap
|
clients ClientNameMap
|
||||||
}
|
}
|
||||||
@ -27,8 +28,14 @@ func NewServer(config *Config) *Server {
|
|||||||
commands: commands,
|
commands: commands,
|
||||||
ctime: time.Now(),
|
ctime: time.Now(),
|
||||||
name: config.Name,
|
name: config.Name,
|
||||||
|
operators: make(map[string]string),
|
||||||
password: config.Password,
|
password: config.Password,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, opConf := range config.Operators {
|
||||||
|
server.operators[opConf.Name] = opConf.Password
|
||||||
|
}
|
||||||
|
|
||||||
go server.receiveCommands(commands)
|
go server.receiveCommands(commands)
|
||||||
go server.listen(config.Listen)
|
go server.listen(config.Listen)
|
||||||
return server
|
return server
|
||||||
@ -352,3 +359,17 @@ func (msg *WhoCommand) HandleServer(server *Server) {
|
|||||||
|
|
||||||
client.Reply(RplEndOfWho(server, mask))
|
client.Reply(RplEndOfWho(server, mask))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (msg *OperCommand) HandleServer(server *Server) {
|
||||||
|
client := msg.Client()
|
||||||
|
|
||||||
|
if server.operators[msg.name] != msg.password {
|
||||||
|
client.Reply(ErrPasswdMismatch(server))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client.operator = true
|
||||||
|
|
||||||
|
client.Reply(RplYoureOper(server))
|
||||||
|
client.Reply(RplUModeIs(server, client))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user