3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +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
invisible bool
nick string
operator bool
realname string
registered bool
replies chan<- Reply
@ -109,6 +110,10 @@ func (c *Client) ModeString() (str string) {
if c.invisible {
str += Invisible.String()
}
if c.operator {
str += Operator.String()
}
if len(str) > 0 {
str = "+" + str
}

View File

@ -21,6 +21,7 @@ var (
"JOIN": NewJoinCommand,
"MODE": NewModeCommand,
"NICK": NewNickCommand,
"OPER": NewOperCommand,
"PART": NewPartCommand,
"PASS": NewPassCommand,
"PING": NewPingCommand,
@ -541,3 +542,25 @@ func NewWhoCommand(args []string) (editableCommand, error) {
func (msg *WhoCommand) String() string {
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

@ -9,9 +9,15 @@ type Config struct {
Name string
Listen string
Password string
Operators []OperatorConfig
Debug map[string]bool
}
type OperatorConfig struct {
Name string
Password string
}
func LoadConfig() (config *Config, err error) {
config = &Config{}

View File

@ -206,9 +206,9 @@ func RplEndOfNames(channel *Channel) Reply {
"%s :End of NAMES list", channel.name)
}
// :You are now an IRC operator
func RplYoureOper(server *Server) Reply {
return NewNumericReply(server, RPL_YOUREOPER,
":You are now an IRC operator")
return NewNumericReply(server, RPL_YOUREOPER, ":You are now an IRC operator")
}
func RplWhoisUser(server *Server, client *Client) Reply {

View File

@ -15,6 +15,7 @@ type Server struct {
ctime time.Time
hostname string
name string
operators map[string]string
password string
clients ClientNameMap
}
@ -27,8 +28,14 @@ func NewServer(config *Config) *Server {
commands: commands,
ctime: time.Now(),
name: config.Name,
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.listen(config.Listen)
return server
@ -352,3 +359,17 @@ func (msg *WhoCommand) HandleServer(server *Server) {
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))
}