Refactor Connection.handle
This commit is contained in:
parent
31c662dcbd
commit
16044982a1
|
@ -107,6 +107,8 @@ class Connection
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: If RFC-strictness is off, ignore command case
|
||||||
|
|
||||||
//NOTE: The RFCs don't specify what 'being idle' means
|
//NOTE: The RFCs don't specify what 'being idle' means
|
||||||
// We assume that it's sending any message that isn't a PING/PONG.
|
// We assume that it's sending any message that isn't a PING/PONG.
|
||||||
if(message.command != "PING" && message.command != "PONG")
|
if(message.command != "PING" && message.command != "PONG")
|
||||||
|
@ -116,7 +118,12 @@ class Connection
|
||||||
|
|
||||||
writeln("C> " ~ message.toString);
|
writeln("C> " ~ message.toString);
|
||||||
|
|
||||||
//TODO: If RFC-strictness is off, ignore case
|
if(!registered && !["NICK", "USER", "PING", "PONG", "QUIT"].canFind(message.command))
|
||||||
|
{
|
||||||
|
sendErrNotRegistered();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch(message.command)
|
switch(message.command)
|
||||||
{
|
{
|
||||||
case "NICK":
|
case "NICK":
|
||||||
|
@ -136,68 +143,52 @@ class Connection
|
||||||
onQuit(message);
|
onQuit(message);
|
||||||
break;
|
break;
|
||||||
case "JOIN":
|
case "JOIN":
|
||||||
if(!registered) sendErrNotRegistered();
|
onJoin(message);
|
||||||
else onJoin(message);
|
|
||||||
break;
|
break;
|
||||||
case "PART":
|
case "PART":
|
||||||
if(!registered) sendErrNotRegistered();
|
onPart(message);
|
||||||
else onPart(message);
|
|
||||||
break;
|
break;
|
||||||
case "PRIVMSG":
|
case "PRIVMSG":
|
||||||
if(!registered) sendErrNotRegistered();
|
onPrivMsg(message);
|
||||||
else onPrivMsg(message);
|
|
||||||
break;
|
break;
|
||||||
case "NOTICE":
|
case "NOTICE":
|
||||||
if(!registered) sendErrNotRegistered();
|
onNotice(message);
|
||||||
else onNotice(message);
|
|
||||||
break;
|
break;
|
||||||
case "WHO":
|
case "WHO":
|
||||||
if(!registered) sendErrNotRegistered();
|
onWho(message);
|
||||||
else onWho(message);
|
|
||||||
break;
|
break;
|
||||||
case "AWAY":
|
case "AWAY":
|
||||||
if(!registered) sendErrNotRegistered();
|
onAway(message);
|
||||||
else onAway(message);
|
|
||||||
break;
|
break;
|
||||||
case "TOPIC":
|
case "TOPIC":
|
||||||
if(!registered) sendErrNotRegistered();
|
onTopic(message);
|
||||||
else onTopic(message);
|
|
||||||
break;
|
break;
|
||||||
case "NAMES":
|
case "NAMES":
|
||||||
if(!registered) sendErrNotRegistered();
|
onNames(message);
|
||||||
else onNames(message);
|
|
||||||
break;
|
break;
|
||||||
case "LIST":
|
case "LIST":
|
||||||
if(!registered) sendErrNotRegistered();
|
onList(message);
|
||||||
else onList(message);
|
|
||||||
break;
|
break;
|
||||||
case "INVITE":
|
case "INVITE":
|
||||||
if(!registered) sendErrNotRegistered();
|
onInvite(message);
|
||||||
else onInvite(message);
|
|
||||||
break;
|
break;
|
||||||
case "VERSION":
|
case "VERSION":
|
||||||
if(!registered) sendErrNotRegistered();
|
onVersion(message);
|
||||||
else onVersion(message);
|
|
||||||
break;
|
break;
|
||||||
case "TIME":
|
case "TIME":
|
||||||
if(!registered) sendErrNotRegistered();
|
onTime(message);
|
||||||
else onTime(message);
|
|
||||||
break;
|
break;
|
||||||
case "MOTD":
|
case "MOTD":
|
||||||
if(!registered) sendErrNotRegistered();
|
onMotd(message);
|
||||||
else onMotd(message);
|
|
||||||
break;
|
break;
|
||||||
case "LUSERS":
|
case "LUSERS":
|
||||||
if(!registered) sendErrNotRegistered();
|
onLusers(message);
|
||||||
else onLusers(message);
|
|
||||||
break;
|
break;
|
||||||
case "ISON":
|
case "ISON":
|
||||||
if(!registered) sendErrNotRegistered();
|
onIson(message);
|
||||||
else onIson(message);
|
|
||||||
break;
|
break;
|
||||||
case "WHOIS":
|
case "WHOIS":
|
||||||
if(!registered) sendErrNotRegistered();
|
onWhois(message);
|
||||||
else onWhois(message);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
writeln("unknown command '", message.command, "'");
|
writeln("unknown command '", message.command, "'");
|
||||||
|
|
Loading…
Reference in New Issue