Mercurial > cabal
diff sources/parser.cpp @ 4:a7051ac7118b
added primary parser implementation
renamed some functions to well-formed format
bool => false, pointers => NULL
removed useless eTime()
| author | Vlad Glagolev <enqlave@gmail.com> |
|---|---|
| date | Thu, 24 Jan 2008 19:38:34 +0300 |
| parents | 19227b0b7cc1 |
| children | 9be05a31b7f9 |
line wrap: on
line diff
--- a/sources/parser.cpp Mon Jan 21 01:17:06 2008 +0300 +++ b/sources/parser.cpp Thu Jan 24 19:38:34 2008 +0300 @@ -26,14 +26,64 @@ if (parsing.substr(0, 6) == "PING :") { parsing[1] = 'O'; S->sendMsg(parsing); - } else - cout << "Processed line" << endl; -} + } else { + char *line = new char[parsing.length() + 1]; + + strcpy(line, parsing.c_str()); + + char *who = strtok(line, " "); + char *what = strtok(NULL, " "); + char *where = strtok(NULL, " "); + char *message = strtok(NULL, "\n"); + + if (strchr(who, '!')) { + alienID = strchr(who, '!'); + alienID = alienID.substr(1); + } + + if (strtok(who, "!")) + alien = strtok(who, "!"); + + alienAction = what; + + if (*where == ':') + alienLocation = ++where; + else { + alienLocation = where; -Parser::~Parser() -{ + if (message) { + if (alienLocation == S->nick) + alienLocation = alien; + + alienMessage = (*message == ':') ? ++message: message; + + if (*message == CABAL->commander && ++message) { + if (strchr(message, ' ')) { + alienCommand = strtok(message, " "); + alienMessage = strtok(NULL, "\n"); + } else + alienCommand = message; + } + } + } + + delete[] line; + +/* DEBUG + cout + << "-----------------------------------\n" \ + << "Alien: \t" << alien << endl \ + << "Alien ID:\t" << alienID << endl \ + << "Alien action:\t" << alienAction << endl \ + << "Alien location:\t" << alienLocation << endl \ + << "Alien command:\t" << alienCommand << endl \ + << "Alien message:\t" << alienMessage << endl \ + << "-----------------------------------\n"; +*/ } } void Parser::Parse(Connection *S) { + if (alienCommand == "die" && alienID == "stealth@ru.raver") + shut("Requested shutdown"); }
