1 |
torben |
28 |
#include "SpamPlugin.h" |
2 |
torben |
149 |
#include "ISmsTransceiver.h" |
3 |
torben |
90 |
#include "Sms.h" |
4 |
torben |
28 |
|
5 |
|
|
#include "util.h" |
6 |
|
|
#include "common.h" |
7 |
|
|
#include <sstream> |
8 |
torben |
114 |
#include <stdlib.h> |
9 |
torben |
28 |
|
10 |
|
|
|
11 |
|
|
using namespace std; |
12 |
|
|
|
13 |
|
|
|
14 |
|
|
SpamPlugin::SpamPlugin() |
15 |
|
|
: Plugin("spam", "Sends a number of messages to a given phone nr") |
16 |
|
|
{ |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
const string USAGE = "Usage: spam <recipient> <nr> message"; |
20 |
|
|
|
21 |
torben |
149 |
void SpamPlugin::Execute(ISmsTransceiver& modem, SMS& sms) |
22 |
torben |
28 |
{ |
23 |
torben |
142 |
string cmd = sms.ExtractParameters(); |
24 |
torben |
28 |
|
25 |
|
|
|
26 |
|
|
if (cmd == "") |
27 |
|
|
{ |
28 |
torben |
142 |
modem.SendSms(sms.GetSender(), USAGE, false); |
29 |
torben |
28 |
return; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
vector<string> parts = Util::str_split(cmd," "); |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
if (parts.size() < 2 ) |
36 |
|
|
{ |
37 |
torben |
142 |
modem.SendSms(sms.GetSender(), USAGE, false); |
38 |
torben |
28 |
return; |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
string nr = parts[0]; |
42 |
|
|
unsigned int count = atoi(parts[1].c_str()); |
43 |
|
|
if (count > 25) |
44 |
|
|
count = 25; |
45 |
|
|
|
46 |
|
|
ostringstream os; |
47 |
|
|
os << "Spamming " << nr << " " << count << " times."; |
48 |
|
|
Common::instance()->logMessage(os.str()); |
49 |
|
|
|
50 |
|
|
string message; |
51 |
|
|
for (unsigned i=2; i<parts.size(); ++i) |
52 |
|
|
{ |
53 |
|
|
if (message.length() > 0) |
54 |
|
|
message += " "; |
55 |
|
|
message += parts[i]; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
for (unsigned i=0; i<count; ++i) |
59 |
|
|
{ |
60 |
torben |
63 |
modem.SendSms(nr,message, false); |
61 |
torben |
28 |
} |
62 |
|
|
} |