]> jfr.im git - irc/quakenet/newserv.git/blob - spawnuser/spawnuser.c
macros
[irc/quakenet/newserv.git] / spawnuser / spawnuser.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <stdarg.h>
4 #include <string.h>
5 #include "../channel/channel.h"
6 #include "../control/control.h"
7 #include "../core/config.h"
8 #include "../localuser/localuser.h"
9 #include "../localuser/localuserchannel.h"
10 #include "../nick/nick.h"
11 #include "../irc/irc.h"
12
13 typedef struct spawnuser_user
14 {
15 nick *user;
16 struct spawnuser_user *next;
17 } spawnuser_user;
18
19 spawnuser_user *spawnuser_users;
20
21 void spawnuser_handlemessages(nick *target, int messagetype, void **args)
22 {
23 spawnuser_user *spawnuser;
24
25 switch ( messagetype )
26 {
27 case LU_KILLED:
28 for ( spawnuser = spawnuser_users; spawnuser; spawnuser = spawnuser->next )
29 {
30 if ( target == spawnuser->user )
31 {
32 Error("spawnuser", ERR_WARNING, "A SpawnUser got killed");
33 spawnuser->user = NULL;
34 break;
35 }
36 }
37 default:
38 break;
39 }
40 }
41
42 void _init()
43 {
44 char nickbuf[NICKLEN + 1], hostbuf[HOSTLEN + 1];
45 int i;
46 spawnuser_user *spawnuser;
47 channel *spawnchannel;
48
49 spawnuser_users = NULL;
50
51 for ( i = 0; i < 3000; i++ )
52 {
53 snprintf(nickbuf, NICKLEN, "SU-%s-%d", mynick->nick, i);
54 nickbuf[NICKLEN] = '\0';
55 snprintf(hostbuf, HOSTLEN, "SpawnUser-%s.netsplit.net", mynick->nick);
56 hostbuf[HOSTLEN] = '\0';
57 spawnuser = malloc(sizeof(spawnuser_user));
58 spawnuser->user = registerlocaluser(nickbuf, "SpawnUser", hostbuf, "SpawnUser", NULL, UMODE_INV, &spawnuser_handlemessages);
59
60 spawnchannel = findchannel("#twilightzone");
61
62 if ( !spawnchannel )
63 localcreatechannel(spawnuser->user, "#twilightzone");
64 else
65 localjoinchannel(spawnuser->user, spawnchannel);
66
67 spawnuser->next = spawnuser_users;
68 spawnuser_users = spawnuser;
69 }
70 }
71
72 void _fini()
73 {
74 spawnuser_user *temp_spawnuser;
75
76 while ( spawnuser_users )
77 {
78 temp_spawnuser = spawnuser_users;
79 spawnuser_users = temp_spawnuser->next;
80
81 if ( temp_spawnuser->user )
82 deregisterlocaluser(temp_spawnuser->user, "SpawnUser Unloaded");
83
84 free(temp_spawnuser);
85 }
86 }