68 lines
2.0 KiB
C++
68 lines
2.0 KiB
C++
#include "CommandValidator.hpp"
|
|
|
|
CommandValidator::CommandValidator(void) {}
|
|
CommandValidator::CommandValidator(const CommandValidator &other) { (void)other; }
|
|
CommandValidator &CommandValidator::operator=(const CommandValidator &other) { (void)other; return (*this); }
|
|
CommandValidator::~CommandValidator(void) {}
|
|
|
|
bool CommandValidator::isKnownCommand(const std::string &cmd)
|
|
{
|
|
return (cmd == "PASS"
|
|
|| cmd == "NICK"
|
|
|| cmd == "USER"
|
|
|| cmd == "JOIN"
|
|
|| cmd == "PART"
|
|
|| cmd == "PRIVMSG"
|
|
|| cmd == "NOTICE"
|
|
|| cmd == "QUIT"
|
|
|| cmd == "PING"
|
|
|| cmd == "PONG"
|
|
|| cmd == "KICK"
|
|
|| cmd == "INVITE"
|
|
|| cmd == "TOPIC"
|
|
|| cmd == "MODE");
|
|
}
|
|
|
|
/*
|
|
This is only syntactic/minimal validation.
|
|
The real command handler still checks:
|
|
- password correctness
|
|
- nickname already used
|
|
- channel exists
|
|
- permissions/operator status
|
|
- invite-only/key/limit modes
|
|
*/
|
|
bool CommandValidator::hasEnoughParams(const IrcMessage &msg)
|
|
{
|
|
const std::string &cmd = msg.getCommand();
|
|
|
|
if (cmd == "PASS") return (msg.paramCount() >= 1);
|
|
if (cmd == "NICK") return (msg.paramCount() >= 1);
|
|
if (cmd == "USER") return (msg.paramCount() >= 4);
|
|
if (cmd == "JOIN") return (msg.paramCount() >= 1);
|
|
if (cmd == "PART") return (msg.paramCount() >= 1);
|
|
if (cmd == "PRIVMSG") return (msg.paramCount() >= 2);
|
|
if (cmd == "NOTICE") return (msg.paramCount() >= 2);
|
|
if (cmd == "QUIT") return (true);
|
|
if (cmd == "PING") return (msg.paramCount() >= 1);
|
|
if (cmd == "PONG") return (msg.paramCount() >= 1);
|
|
if (cmd == "KICK") return (msg.paramCount() >= 2);
|
|
if (cmd == "INVITE") return (msg.paramCount() >= 2);
|
|
if (cmd == "TOPIC") return (msg.paramCount() >= 1);
|
|
if (cmd == "MODE") return (msg.paramCount() >= 1);
|
|
return (false);
|
|
}
|
|
|
|
/*
|
|
Before registration, usually only PASS, NICK, USER, PING/PONG/QUIT are useful.
|
|
*/
|
|
bool CommandValidator::needsRegistration(const std::string &cmd)
|
|
{
|
|
return !(cmd == "PASS"
|
|
|| cmd == "NICK"
|
|
|| cmd == "USER"
|
|
|| cmd == "PING"
|
|
|| cmd == "PONG"
|
|
|| cmd == "QUIT");
|
|
}
|