commands: Simplify and unify minimum required number of args handling

This commit is contained in:
Daniel Oaks
2016-04-15 15:57:08 +10:00
parent 1bafaa0488
commit 9acdeedec6
2 changed files with 68 additions and 78 deletions
+14
View File
@@ -64,6 +64,14 @@ func NewServer(config *Config) *Server {
theaters: config.Theaters(),
}
// ensure that there is a minimum number of args specified for every command
for name, _ := range parseCommandFuncs {
_, exists := commandMinimumArgs[name]
if !exists {
log.Fatal("commandMinArgs not found for ", name)
}
}
if config.Server.MOTD != "" {
file, err := os.Open(config.Server.MOTD)
if err == nil {
@@ -162,6 +170,12 @@ func (server *Server) loadChannels() {
func (server *Server) processCommand(cmd Command) {
client := cmd.Client()
numCmd, ok := cmd.(*NeedMoreParamsCommand)
if ok {
client.ErrNeedMoreParams(numCmd.code)
return
}
if !client.registered {
regCmd, ok := cmd.(RegServerCommand)
if !ok {