diff sources/parser.cpp @ 2:19227b0b7cc1

.h => .hpp for the headers added year 2008 to copyright notes renamed some functions for better meaning prepared parser module for rewriting added showHelp() function some code clean up
author Vlad Glagolev <enqlave@gmail.com>
date Mon, 21 Jan 2008 01:14:10 +0300
parents bafff9de2a76
children a7051ac7118b
line wrap: on
line diff
--- a/sources/parser.cpp	Sun Jan 20 19:32:59 2008 +0300
+++ b/sources/parser.cpp	Mon Jan 21 01:14:10 2008 +0300
@@ -3,7 +3,7 @@
  *
  * -- CABAL -- irc commands parser
  *
- * Copyright (c) 2007 Vlad Glagolev <enqlave@gmail.com>
+ * Copyright (c) 2007-2008 Vlad Glagolev <enqlave@gmail.com>
  * All rights reserved.
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -19,109 +19,21 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include "cabal.h"	// required: parser.h
+#include "cabal.hpp" // required: parser.hpp
 
 Parser::Parser(Connection *S, string parsing)
-	:
-	alien(""),
-	alienid(""),
-	alienact(""),
-	alienloc(""),
-	aliencmd(""),
-	alienmsg ("")
 {
 	if (parsing.substr(0, 6) == "PING :") {
-		string pong = parsing;
-		pong[1] = 'O';
-		S->msgSend(pong);
-	} else {
-		char *query = new char[parsing.size() + 1];
-
-		int e = 0;
-
-		while ((query[e] = parsing[e]))
-			e++;
-
-		char *who = new char[e];
-		char *what = new char[e];
-		char *where = new char[e];
-		char *message = new char[e];
-
-		if (sscanf (query, "%s %s %s", who, what, where) == 3) {
-			alienact = what;
-
-			if ((alienid = strchr (who, '!'))) {
-				alienid++, alien = strtok (who, "!");
-
-				if (*where == ':')
-					alienloc = where + 1;
-				else {
-					alienloc = where;
-
-					if ((aliencmd = strchr (strstr (query, alienloc), ' ')) \
-						&& *++aliencmd == ':') {
-						if (!strcmp (alienloc, S->nick))
-							alienloc = alien;
-
-						if (*++aliencmd == CABAL->commander) {
-							if ((alienmsg = strchr (aliencmd, ' ')))
-								alienmsg++;
-							else
-								alienmsg = "";
-
-							aliencmd = strtok (aliencmd, " "), aliencmd++;
-						}
-						else
-							alienmsg = aliencmd, aliencmd = "";
-					}
-					else
-						alienmsg = strtok (aliencmd, " "), aliencmd = "";
-				}
-			}
-			else
-				alienid = "";
-/* DEBUG
-			cout
-				<< "-----------------------------------\n" \
-				<< "Alien:	\t" << alien << endl \
-				<< "Alien ID:\t" << alienid << endl \
-				<< "Alien action:\t" << alienact << endl \
-				<< "Alien location:\t" << alienloc << endl \
-				<< "Alien command:\t" << aliencmd << endl \
-				<< "Alien message:\t" << alienmsg << endl \
-				<< "-----------------------------------\n";
-*/		}
-
-		delete[] who;
-		delete[] what;
-		delete[] where;
-		delete[] message;
-		delete[] query;
-	}
+		parsing[1] = 'O';
+		S->sendMsg(parsing);
+	} else
+		cout << "Processed line" << endl;
 }
 
 Parser::~Parser()
 {
-	alien = alienid = alienact = alienloc = aliencmd = alienmsg = "";
 }
 
-void Parser::Parse (Connection *S)
+void Parser::Parse(Connection *S)
 {
-	if (!strcmp (aliencmd, "die") && !strcmp (alienid, "stealth@ru.raver"))
-		shut ("Requested shutdown");
-	else if (!strcmp (aliencmd, "hi"))
-		S->msgSend ("PRIVMSG " + (string)alienloc + " :" + "Hello, " + \
-			(string)alien + " (" + (string)alienid + ")");
-	else if (!strcmp (aliencmd, "nick"))
-		S->ircNick (alienmsg);
-	else if (!strcmp (aliencmd, "away"))
-		S->ircAway (alienmsg);
-	else if (!strcmp (aliencmd, "join"))
-		S->ircJoin (alienmsg, "");
-	else if (!strcmp (aliencmd, "part"))
-		S->ircPart (alienmsg);
-	else if (!strcmp (aliencmd, "cycle") && strcmp (alienloc, S->nick))
-		S->ircCycle (alienloc);
-	else if (!strcmp (alienact, "KICK") && !strcmp (alienmsg, S->nick))
-		S->ircJoin (alienloc, "");
 }