Mercurial > cabal
comparison sources/connection.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 |
comparison
equal
deleted
inserted
replaced
| 1:08d8cdf4fe7f | 2:19227b0b7cc1 |
|---|---|
| 1 /** | 1 /** |
| 2 * connection.cpp (2007-04-12) | 2 * connection.cpp (2007-04-12) |
| 3 * | 3 * |
| 4 * -- CABAL -- connection base (servers usage) | 4 * -- CABAL -- connection base (servers usage) |
| 5 * | 5 * |
| 6 * Copyright (c) 2007 Vlad Glagolev <enqlave@gmail.com> | 6 * Copyright (c) 2007-2008 Vlad Glagolev <enqlave@gmail.com> |
| 7 * All rights reserved. | 7 * All rights reserved. |
| 8 * | 8 * |
| 9 * Permission to use, copy, modify, and distribute this software for any | 9 * Permission to use, copy, modify, and distribute this software for any |
| 10 * purpose with or without fee is hereby granted, provided that the above | 10 * purpose with or without fee is hereby granted, provided that the above |
| 11 * copyright notice and this permission notice appear in all copies. | 11 * copyright notice and this permission notice appear in all copies. |
| 17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #include "cabal.h" // required: core.h | 22 #include "cabal.hpp" // required: core.h |
| 23 | 23 |
| 24 Connection::Connection() | 24 Connection::Connection(): |
| 25 : | |
| 26 nick(NICK), | 25 nick(NICK), |
| 27 user(USER), | 26 user(USER), |
| 28 name(NAME), | 27 name(NAME), |
| 29 chan(CHANNEL), | 28 chan(CHANNEL), |
| 30 key(CHANNEL_KEY) | 29 key(CHANNEL_KEY) |
| 84 ircConnect(); | 83 ircConnect(); |
| 85 | 84 |
| 86 return; | 85 return; |
| 87 } | 86 } |
| 88 | 87 |
| 89 string buffer = msgReceive(); | 88 string buffer = receiveMsg(); |
| 90 | 89 |
| 91 if (buffer != "") { | 90 if (buffer != "") { |
| 92 Parser *DATA = new Parser (this, buffer); | 91 Parser *DATA = new Parser(this, buffer); |
| 93 | 92 |
| 94 DATA->Parse (this); | 93 DATA->Parse (this); |
| 95 | 94 |
| 96 delete DATA; | 95 delete DATA; |
| 97 } | 96 } |
| 98 } | 97 } |
| 99 | 98 |
| 100 void Connection::ircPass (string pass) | 99 void Connection::ircPass(string pass) |
| 101 { | 100 { |
| 102 msgSend ("PASS " + pass); | 101 sendMsg("PASS " + pass); |
| 103 } | 102 } |
| 104 | 103 |
| 105 void Connection::ircNick (string nnick) | 104 void Connection::ircNick(string nnick) |
| 106 { | 105 { |
| 107 msgSend ("NICK " + (nnick != "" ? nnick : NICK)); | 106 sendMsg("NICK " + (nnick != "" ? nnick : NICK)); |
| 108 } | 107 } |
| 109 | 108 |
| 110 void Connection::ircUser (string nuser, string nname) | 109 void Connection::ircUser(string nuser, string nname) |
| 111 { | 110 { |
| 112 msgSend ("USER " + nuser + (virtualhost != 0 ? " " + (string)virtualhost + \ | 111 sendMsg("USER " + nuser + (virtualhost != 0 ? " " + (string)virtualhost + \ |
| 113 " " : " 0 ") + (string)current->host + " :" + nname); | 112 " " : " 0 ") + (string)current->host + " :" + nname); |
| 114 } | 113 } |
| 115 | 114 |
| 116 void Connection::ircAway (string away) | 115 void Connection::ircAway(string away) |
| 117 { | 116 { |
| 118 msgSend ("AWAY :" + away); | 117 sendMsg("AWAY :" + away); |
| 119 } | 118 } |
| 120 | 119 |
| 121 void Connection::ircJoin (string nchan, string nckey) | 120 void Connection::ircJoin(string nchan, string nckey) |
| 122 { | 121 { |
| 123 msgSend ("JOIN " + nchan + (nckey != "" ? " " + nckey : "")); | 122 sendMsg("JOIN " + nchan + (nckey != "" ? " " + nckey : "")); |
| 124 } | 123 } |
| 125 | 124 |
| 126 void Connection::ircPart (string nchan) | 125 void Connection::ircPart(string nchan) |
| 127 { | 126 { |
| 128 msgSend ("PART " + nchan); | 127 sendMsg("PART " + nchan); |
| 129 } | 128 } |
| 130 | 129 |
| 131 void Connection::ircCycle (string nchan) | 130 void Connection::ircCycle(string nchan) |
| 132 { | 131 { |
| 133 msgSend ("PART " + nchan); | 132 sendMsg("PART " + nchan); |
| 134 msgSend ("JOIN " + nchan); | 133 sendMsg("JOIN " + nchan); |
| 135 } | 134 } |
| 136 | 135 |
| 137 Connection::host_type * | 136 Connection::host_type * |
| 138 Connection::hostAdd (host_type *list, pchar host, int port, pchar password) | 137 Connection::addHost(host_type *list, pchar host, int port, pchar password) |
| 139 { | 138 { |
| 140 if (list == 0) | 139 if (!list) |
| 141 current = list = new host_type (host, port, password); | 140 current = list = new host_type(host, port, password); |
| 142 else if (list->next == current) | 141 else if (list->next == current) |
| 143 list->next = new host_type (host, port, password, current); | 142 list->next = new host_type(host, port, password, current); |
| 144 else | 143 else |
| 145 return hostAdd (list->next, host, port, password); | 144 return addHost(list->next, host, port, password); |
| 146 | 145 |
| 147 return list; | 146 return list; |
| 148 } | 147 } |
