3
0
mirror of https://github.com/ergochat/ergo.git synced 2025-01-09 11:42:45 +01:00

irc operators

This commit is contained in:
Jeremy Latt 2014-02-09 10:07:40 -08:00
parent 6367e4b654
commit 8a90634c0a
5 changed files with 72 additions and 17 deletions

View File

@ -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
} }

View File

@ -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
}

View File

@ -6,10 +6,16 @@ import (
) )
type Config struct { type Config struct {
Name string
Listen string
Password string
Operators []OperatorConfig
Debug map[string]bool
}
type OperatorConfig struct {
Name string Name string
Listen string
Password string Password string
Debug map[string]bool
} }
func LoadConfig() (config *Config, err error) { func LoadConfig() (config *Config, err error) {

View File

@ -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 {

View File

@ -10,25 +10,32 @@ import (
) )
type Server struct { type Server struct {
channels ChannelNameMap channels ChannelNameMap
commands chan<- Command commands chan<- Command
ctime time.Time ctime time.Time
hostname string hostname string
name string name string
password string operators map[string]string
clients ClientNameMap password string
clients ClientNameMap
} }
func NewServer(config *Config) *Server { func NewServer(config *Config) *Server {
commands := make(chan Command) commands := make(chan Command)
server := &Server{ server := &Server{
channels: make(ChannelNameMap), channels: make(ChannelNameMap),
clients: make(ClientNameMap), clients: make(ClientNameMap),
commands: commands, commands: commands,
ctime: time.Now(), ctime: time.Now(),
name: config.Name, name: config.Name,
password: config.Password, operators: make(map[string]string),
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))
}