]>
Commit | Line | Data |
---|---|---|
a7bce950 | 1 | #include "../localuser/localuser.h" |
2 | #include "../localuser/localuserchannel.h" | |
3 | #include "../core/schedule.h" | |
4 | #include "../lib/irc_string.h" | |
5 | ||
6 | #define HOMECHANNEL "#twilightzone" | |
7 | #define NICK "Clonemaster" | |
8 | #define MAXCLONES 1000 | |
9 | ||
10 | nick *clones[MAXCLONES]; | |
11 | unsigned int nclones; | |
12 | nick *cmnick; | |
13 | ||
14 | void makenick(void *); | |
15 | ||
16 | void clonehandler(nick *np, int message, void **args) { | |
17 | unsigned int i; | |
18 | ||
19 | switch(message) { | |
20 | case LU_KILLED: | |
21 | for (i=0;i<nclones;i++) { | |
22 | if (clones[i]==np) { | |
23 | clones[i]=clones[nclones-1]; | |
24 | nclones--; | |
25 | break; | |
26 | } | |
27 | } | |
28 | break; | |
29 | } | |
30 | } | |
31 | ||
32 | void spam(unsigned int lines) { | |
33 | char message[100]; | |
34 | unsigned int i,j,k,l,m; | |
35 | channel **cps; | |
36 | ||
37 | message[99]='\0'; | |
38 | ||
39 | for (i=0;i<nclones;i++) { | |
40 | cps=clones[i]->channels->content; | |
41 | for(j=1;j<clones[i]->channels->cursi;j++) { | |
42 | for (k=0;k<lines;k++) { | |
43 | for (l=0;l<99;l++) { | |
44 | m=rand()%27; | |
45 | message[l]=m?(m-1)+'a':' '; | |
46 | } | |
47 | sendmessagetochannel(clones[i], cps[j], "%s", message); | |
48 | } | |
49 | } | |
50 | } | |
51 | } | |
52 | ||
53 | void join(char *chan) { | |
54 | channel *cp; | |
55 | unsigned int i; | |
56 | ||
57 | if (!(cp=findchannel(chan))) | |
58 | return; | |
59 | ||
60 | for(i=0;i<nclones;i++) { | |
61 | localjoinchannel(clones[i], cp); | |
62 | } | |
63 | } | |
64 | ||
65 | void spawnclones(unsigned int count) { | |
66 | nick *np; | |
67 | unsigned int i,j; | |
0555113a | 68 | char nick[11], ident[11], host[40]; |
a7bce950 | 69 | channel *cp; |
70 | ||
71 | for (i=0;i<count;i++) { | |
72 | if (nclones >= MAXCLONES) | |
73 | return; | |
74 | ||
75 | for (j=0;j<10;j++) { | |
76 | nick[j]=(rand()%26)+'a'; | |
77 | ident[j]=(rand()%26)+'a'; | |
78 | host[j]=(rand()%26)+'a'; | |
79 | host[j+11]=(rand()%26)+'a'; | |
80 | host[j+22]=(rand()%26)+'a'; | |
81 | } | |
82 | ||
83 | host[10]=host[21]='.'; | |
84 | host[32]=nick[10]=ident[10]='\0'; | |
85 | ||
86 | np=clones[nclones++]=registerlocaluser(nick, ident, host, host, "", 0, clonehandler); | |
87 | ||
88 | if ((cp=findchannel(HOMECHANNEL))) { | |
89 | localjoinchannel(np, cp); | |
90 | } | |
91 | } | |
92 | } | |
93 | ||
94 | void masterhandler(nick *np, int message, void **args) { | |
95 | char *msg; | |
96 | ||
97 | switch(message) { | |
98 | case LU_KILLED: | |
99 | cmnick=NULL; | |
100 | scheduleoneshot(time(NULL)+1, makenick, NULL); | |
101 | break; | |
102 | ||
103 | case LU_CHANMSG: | |
104 | msg=args[2]; | |
105 | ||
106 | if (!ircd_strncmp(msg, "!spawn ",7)) { | |
107 | spawnclones(strtoul(msg+7,NULL,10)); | |
108 | } | |
109 | ||
110 | if (!ircd_strncmp(msg,"!join ",6)) { | |
111 | join(msg+6); | |
112 | } | |
113 | ||
114 | if (!ircd_strncmp(msg,"!spam ", 6)) { | |
115 | spam(strtoul(msg+6, NULL, 10)); | |
116 | } | |
117 | break; | |
118 | ||
119 | } | |
120 | } | |
121 | void makenick(void *arg) { | |
122 | channel *cp; | |
123 | ||
124 | cmnick=registerlocaluser(NICK, "clone", "master", "Clone Master", "", 0, masterhandler); | |
125 | ||
126 | if ((cp=findchannel(HOMECHANNEL))) { | |
127 | localjoinchannel(cmnick, cp); | |
128 | } else { | |
129 | localcreatechannel(cmnick, HOMECHANNEL); | |
130 | } | |
131 | } | |
132 | ||
133 | void _init(void) { | |
134 | scheduleoneshot(time(NULL)+1, makenick, NULL); | |
135 | } | |
136 | ||
137 | void _fini(void) { | |
138 | unsigned int i; | |
139 | ||
140 | if (cmnick) { | |
141 | deregisterlocaluser(cmnick, NULL); | |
142 | } | |
143 | ||
144 | for(i=0;i<nclones;i++) { | |
145 | deregisterlocaluser(clones[i], NULL); | |
146 | } | |
0555113a | 147 | } |