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