16 |
|
#include <unistd.h> |
17 |
|
} |
18 |
|
|
19 |
< |
Collector::Collector(const ext::String& login, ext::String& password, const |
20 |
< |
std::set<Buddy>& buddies, const Database& database, bool start) : |
21 |
< |
login(login), password(password), buddies(buddies), database(database), |
19 |
> |
Collector::Collector(const ext::String& login, ext::String& password, const std::set<Buddy>& buddies, |
20 |
> |
const Database& database, bool start) : login(login), password(password), buddies(buddies), database(database), |
21 |
|
start(start), prompted(false) |
22 |
|
{ |
23 |
|
if (start) |
52 |
|
|
53 |
|
net::Oscar::StringSet buddies; |
54 |
|
|
55 |
< |
for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy != |
56 |
< |
this->buddies.end(); ++buddy) buddies.Insert(*buddy); |
55 |
> |
for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy != this->buddies.end(); ++buddy) |
56 |
> |
buddies.Insert(*buddy); |
57 |
|
|
58 |
|
buddy.Insert(buddies); |
59 |
|
icbm.RequestParams(); |
61 |
|
net::Oscar::Capabilities capabilities; |
62 |
|
|
63 |
|
capabilities.Insert(net::Oscar::ChatCapability); |
64 |
< |
info.SetProfile(ext::String("<font face=\"Tahoma\" size=2>I am <a href=\"h") |
65 |
< |
+ "ttp://computers.douglasthrift.net/zoe.xml\">Zoe</a>.</font> :-*", "<" |
67 |
< |
+ ext::String("font face=\"Tahoma\" size=3>Mommy told me not to talk t") |
68 |
< |
+ "o strangers.</font> O:-)", capabilities); |
64 |
> |
info.SetProfile("<font face=\"Tahoma\" size=2>I am <a href=\"http://computers.douglasthrift.net/zoe.xml\">Zoe</a>." |
65 |
> |
"</font> :-*", "<font face=\"Tahoma\" size=3>Mommy told me not to talk to strangers.</font> O:-)", capabilities); |
66 |
|
|
67 |
|
// figure out whether or not we logged in |
68 |
|
|
78 |
|
|
79 |
|
this->password = password; |
80 |
|
|
81 |
< |
for (size_t index(std::strlen(password)); index > 0; --index) |
85 |
< |
password[index - 1] = '\0'; |
81 |
> |
for (size_t index(std::strlen(password)); index > 0; --index) password[index - 1] = '\0'; |
82 |
|
} |
83 |
|
|
84 |
|
void Collector::status(const net::Oscar::UserInfo& user) |
88 |
|
|
89 |
|
if (!ext::String(message).IsEmpty()) // XXX |
90 |
|
{ |
91 |
< |
cerr << bright << red << "Collector::status(" << blue << buddy << red |
92 |
< |
<< ", " << reset << message << bright << red << ")\n" << reset; |
91 |
> |
ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host, database.user, database.password, |
92 |
> |
database.db)); |
93 |
> |
ext::Handle<dbi::ResultSet> previous(db->Execute("SELECT message FROM messages WHERE stamp=(SELECT MAX(stamp) " |
94 |
> |
"FROM messages WHERE id='" + lexical_cast<ext::String>(buddy.getId()) + "') AND id='" |
95 |
> |
+ lexical_cast<ext::String>(buddy.getId()) + "'")); |
96 |
|
|
97 |
< |
ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, |
99 |
< |
database.host, database.user, database.password, database.db)); |
97 |
> |
if (previous->MoveNext()) if (ext::String(message) == previous->GetString("message")) return; |
98 |
|
|
99 |
< |
db->Execute("INSERT INTO messages (stamp, message, id) VALUES ('" + |
100 |
< |
message.getStamp() + "', '" + db->Escape(message) + "', '" + |
101 |
< |
buddy.getId() + "')"); |
99 |
> |
cerr << bright << red << "Collector::status(" << blue << buddy << red << ", " << reset << message << bright << red |
100 |
> |
<< ")\n" << reset; |
101 |
> |
|
102 |
> |
db->Execute("INSERT INTO messages (stamp, message, id) VALUES ('" + ext::String(message.getStamp()) + "', '" |
103 |
> |
+ db->Escape(message) + "', '" + lexical_cast<ext::String>(buddy.getId()) + "')"); |
104 |
|
} |
105 |
|
} |
106 |
|
|
107 |
|
void Collector::receive(const ext::String& buddy, const ext::String& message) |
108 |
|
{ |
109 |
< |
cerr << bright << red << "Collector::receive(" << blue << Buddy(buddy) |
110 |
< |
<< red << ", " << reset << message << bright << red << ")\n" << reset; |
109 |
> |
cerr << bright << red << "Collector::receive(" << blue << Buddy(buddy) << red << ", " << reset << message << bright |
110 |
> |
<< red << ")\n" << reset; |
111 |
|
|
112 |
|
if (buddies.find(buddy) != buddies.end()) |
113 |
|
{ |
121 |
|
{ |
122 |
|
sleep(1); |
123 |
|
|
124 |
< |
icbm->Simple(buddy, ext::String("<font face=\"Tahoma\" size=2>Mommy to") |
125 |
< |
+ "ld me not to talk to strangers. O:-)"); |
124 |
> |
icbm->Simple(buddy, "<font face=\"Tahoma\" size=2>Mommy told me not to talk to strangers. O:-)"); |
125 |
|
} |
126 |
|
} |