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