Mercurial > cabal
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 3:cd60300cae0b | 4:a7051ac7118b |
|---|---|
| 24 Parser::Parser(Connection *S, string parsing) | 24 Parser::Parser(Connection *S, string parsing) |
| 25 { | 25 { |
| 26 if (parsing.substr(0, 6) == "PING :") { | 26 if (parsing.substr(0, 6) == "PING :") { |
| 27 parsing[1] = 'O'; | 27 parsing[1] = 'O'; |
| 28 S->sendMsg(parsing); | 28 S->sendMsg(parsing); |
| 29 } else | 29 } else { |
| 30 cout << "Processed line" << endl; | 30 char *line = new char[parsing.length() + 1]; |
| 31 } | |
| 32 | 31 |
| 33 Parser::~Parser() | 32 strcpy(line, parsing.c_str()); |
| 34 { | 33 |
| 34 char *who = strtok(line, " "); | |
| 35 char *what = strtok(NULL, " "); | |
| 36 char *where = strtok(NULL, " "); | |
| 37 char *message = strtok(NULL, "\n"); | |
| 38 | |
| 39 if (strchr(who, '!')) { | |
| 40 alienID = strchr(who, '!'); | |
| 41 alienID = alienID.substr(1); | |
| 42 } | |
| 43 | |
| 44 if (strtok(who, "!")) | |
| 45 alien = strtok(who, "!"); | |
| 46 | |
| 47 alienAction = what; | |
| 48 | |
| 49 if (*where == ':') | |
| 50 alienLocation = ++where; | |
| 51 else { | |
| 52 alienLocation = where; | |
| 53 | |
| 54 if (message) { | |
| 55 if (alienLocation == S->nick) | |
| 56 alienLocation = alien; | |
| 57 | |
| 58 alienMessage = (*message == ':') ? ++message: message; | |
| 59 | |
| 60 if (*message == CABAL->commander && ++message) { | |
| 61 if (strchr(message, ' ')) { | |
| 62 alienCommand = strtok(message, " "); | |
| 63 alienMessage = strtok(NULL, "\n"); | |
| 64 } else | |
| 65 alienCommand = message; | |
| 66 } | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 delete[] line; | |
| 71 | |
| 72 /* DEBUG | |
| 73 cout | |
| 74 << "-----------------------------------\n" \ | |
| 75 << "Alien: \t" << alien << endl \ | |
| 76 << "Alien ID:\t" << alienID << endl \ | |
| 77 << "Alien action:\t" << alienAction << endl \ | |
| 78 << "Alien location:\t" << alienLocation << endl \ | |
| 79 << "Alien command:\t" << alienCommand << endl \ | |
| 80 << "Alien message:\t" << alienMessage << endl \ | |
| 81 << "-----------------------------------\n"; | |
| 82 */ } | |
| 35 } | 83 } |
| 36 | 84 |
| 37 void Parser::Parse(Connection *S) | 85 void Parser::Parse(Connection *S) |
| 38 { | 86 { |
| 87 if (alienCommand == "die" && alienID == "stealth@ru.raver") | |
| 88 shut("Requested shutdown"); | |
| 39 } | 89 } |
