/[projects]/smsdaemon/plugins/oldSpamPlugin.cpp
ViewVC logotype

Annotation of /smsdaemon/plugins/oldSpamPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 142 - (hide annotations) (download)
Sun Dec 7 15:51:02 2008 UTC (15 years, 5 months ago) by torben
Original Path: smsdaemon/plugins/SpamPlugin.cpp
File size: 1079 byte(s)
Refacerored SMS class

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 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 44 void SpamPlugin::Execute(IGsmModem& 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     }

  ViewVC Help
Powered by ViewVC 1.1.20