4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
+ |
#include "AwayMessage.hpp" |
8 |
|
#include "Collector.hpp" |
9 |
+ |
#include "Stamp.hpp" |
10 |
|
|
11 |
|
#include <cstring> |
12 |
+ |
|
13 |
+ |
extern "C" |
14 |
+ |
{ |
15 |
|
#include <pwd.h> |
16 |
|
#include <unistd.h> |
17 |
+ |
} |
18 |
|
|
19 |
|
Collector::Collector(const ext::String& login, ext::String& password, const |
20 |
< |
std::set<Buddy>& buddies, bool start) : login(login), password(password), |
21 |
< |
start(start) |
20 |
> |
std::set<Buddy>& buddies, const Database& database, bool start) : |
21 |
> |
login(login), password(password), buddies(buddies), database(database), |
22 |
> |
start(start), prompted(false) |
23 |
|
{ |
24 |
|
if (start) |
25 |
|
{ |
26 |
|
if (password.IsEmpty()) prompt(); |
27 |
|
|
28 |
< |
collector.Spawn(etl::BindAll(&Collector::collect, this, buddies)); |
28 |
> |
collector.Spawn(etl::Bind<0>(&Collector::collect, this)); |
29 |
|
} |
30 |
|
} |
31 |
|
|
32 |
< |
int Collector::collect(const std::set<Buddy>& buddies) |
32 |
> |
int Collector::collect() |
33 |
|
{ |
34 |
< |
cerr << "Collector::collect()\n"; |
34 |
> |
cerr << bright << green << "Collector::collect()\n" << reset; |
35 |
|
|
36 |
|
net::Oscar::Session session; |
37 |
|
net::Oscar::AuthTool auth(session); |
42 |
|
|
43 |
|
auth.Login(login, password); |
44 |
|
|
45 |
+ |
if (prompted) password.Clear(); |
46 |
+ |
|
47 |
|
this->buddy = &buddy; |
48 |
|
this->icbm = &icbm; |
49 |
+ |
this->info = &info; |
50 |
|
|
51 |
< |
icbm.OnIncomingIcbm += etl::bind<0>(&Collector::reply, this); |
51 |
> |
buddy.OnOnline += etl::Bind<0>(&Collector::status, this); |
52 |
> |
icbm.OnReceive += etl::Bind<0>(&Collector::receive, this); |
53 |
|
|
54 |
< |
// for (size_t index(password.GetSize()); index > 0; --index) password[index - |
44 |
< |
// 1] = '\0'; |
54 |
> |
net::Oscar::StringSet buddies; |
55 |
|
|
56 |
< |
net::Oscar::StringSet buddies_; |
56 |
> |
for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy != |
57 |
> |
this->buddies.end(); ++buddy) buddies.Insert(*buddy); |
58 |
|
|
59 |
< |
for (std::set<Buddy>::const_iterator buddy(buddies.begin()); buddy != |
49 |
< |
buddies.end(); ++buddy) buddies_.Insert(*buddy); |
50 |
< |
|
51 |
< |
buddy.Insert(buddies_); |
59 |
> |
buddy.Insert(buddies); |
60 |
|
icbm.RequestParams(); |
61 |
|
|
62 |
|
net::Oscar::Capabilities capabilities; |
63 |
|
|
64 |
|
capabilities.Insert(net::Oscar::ChatCapability); |
65 |
< |
info.SetProfile("<font size=3>I am <a href=\"http://computers.douglasthrift.net/zoe.xml\">Zoe</a>.</font> :-*", "", capabilities); |
65 |
> |
info.SetProfile("<font size=3>I am <a href=\"http://computers.douglasthrift.net/zoe.xml\">Zoe</a>.</font> :-*", "<font size=3>Mommy told me not to talk to strangers.</font> O:-)", capabilities); |
66 |
|
|
67 |
|
// figure out whether or not we logged in |
68 |
|
|
71 |
|
|
72 |
|
void Collector::prompt() |
73 |
|
{ |
74 |
+ |
if (!prompted) prompted = true; |
75 |
+ |
|
76 |
|
ext::String prompt(login + "'s AIM Password: "); |
77 |
|
char* password(getpass(prompt.NullTerminate())); |
78 |
|
|
79 |
|
this->password = password; |
80 |
|
|
81 |
< |
for (size_t index(strlen(password)); index > 0; --index) password[index - |
82 |
< |
1] = '\0'; |
81 |
> |
for (size_t index(std::strlen(password)); index > 0; --index) |
82 |
> |
password[index - 1] = '\0'; |
83 |
> |
} |
84 |
> |
|
85 |
> |
void Collector::status(const net::Oscar::UserInfo& user) |
86 |
> |
{ |
87 |
> |
Stamp stamp; |
88 |
> |
Buddy buddy(*buddies.find(user)); |
89 |
> |
|
90 |
> |
cerr << red << ext::String(stamp) << ' ' << blue << ext::String(buddy) |
91 |
> |
<< '\n' << reset; |
92 |
|
} |
93 |
|
|
94 |
< |
void Collector::reply(const ext::String& login, const ext::String& reply) |
94 |
> |
void Collector::receive(const ext::String& buddy, const ext::String& message) |
95 |
|
{ |
96 |
< |
icbm->Simple(login, reply); |
96 |
> |
if (buddies.find(buddy) != buddies.end()) |
97 |
> |
{ |
98 |
> |
Stamp stamp; |
99 |
> |
|
100 |
> |
sleep(1); |
101 |
> |
|
102 |
> |
icbm->Simple(buddy, stamp); |
103 |
> |
} |
104 |
> |
else |
105 |
> |
{ |
106 |
> |
sleep(1); |
107 |
> |
|
108 |
> |
icbm->Simple(buddy, "<font size=3>Mommy told me not to talk to strangers. O:-)"); |
109 |
> |
} |
110 |
|
} |