Anope IRC Services  Version 1.8
hs_group.c
Go to the documentation of this file.
1 /* HostServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
17 static int do_group(User * u);
18 static void myHostServHelp(User * u);
19 extern int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask,
20  char *creator, time_t time);
21 
22 
29 int AnopeInit(int argc, char **argv)
30 {
31  Command *c;
32 
33  moduleAddAuthor("Anope");
34  moduleAddVersion(VERSION_STRING);
36 
37  c = createCommand("GROUP", do_group, NULL, HOST_HELP_GROUP, -1, -1, -1,
38  -1);
40 
42 
43  return MOD_CONT;
44 }
45 
49 void AnopeFini(void)
50 {
51 
52 }
53 
54 
55 
60 static void myHostServHelp(User * u)
61 {
62  notice_lang(s_HostServ, u, HOST_HELP_CMD_GROUP);
63 }
64 
70 static int do_group(User * u)
71 {
72  NickAlias *na;
73  HostCore *tmp;
74  char *vHost = NULL;
75  char *vIdent = NULL;
76  char *creator = NULL;
77  HostCore *head = NULL;
78  time_t time;
79  boolean found = false;
80 
81  head = hostCoreListHead();
82 
83  if ((na = findnick(u->nick))) {
84  if (na->status & NS_IDENTIFIED) {
85 
86  tmp = findHostCore(head, u->nick, &found);
87  if (found) {
88  if (tmp == NULL) {
89  tmp = head; /* incase first in list */
90  } else if (tmp->next) { /* we dont want the previous entry were not inserting! */
91  tmp = tmp->next; /* jump to the next */
92  }
93 
94  vHost = sstrdup(tmp->vHost);
95  if (tmp->vIdent)
96  vIdent = sstrdup(tmp->vIdent);
97  creator = sstrdup(tmp->creator);
98  time = tmp->time;
99 
100  do_hs_sync(na->nc, vIdent, vHost, creator, time);
101  if (tmp->vIdent) {
102  notice_lang(s_HostServ, u, HOST_IDENT_GROUP,
103  na->nc->display, vIdent, vHost);
104  } else {
105  notice_lang(s_HostServ, u, HOST_GROUP, na->nc->display,
106  vHost);
107  }
108  alog("%s: %s!%s@%s grouped their vhost",
109  s_HostServ, u->nick, u->username, u->host);
110  free(vHost);
111  if (vIdent)
112  free(vIdent);
113  free(creator);
114 
115  } else {
116  notice_lang(s_HostServ, u, HOST_NOT_ASSIGNED);
117  }
118  } else {
119  notice_lang(s_HostServ, u, HOST_ID);
120  }
121  } else {
122  notice_lang(s_HostServ, u, HOST_NOT_REGED);
123  }
124  return MOD_CONT;
125 }
time_t time
Definition: services.h:1113
static int do_group(User *u)
Definition: hs_group.c:70
static void myHostServHelp(User *u)
Definition: hs_group.c:60
char nick[NICKMAX]
Definition: services.h:875
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
void AnopeFini(void)
Definition: hs_group.c:49
int AnopeInit(int argc, char **argv)
Definition: hs_group.c:29
HostCore * head
Definition: hostserv.c:24
char * host
Definition: services.h:878
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E HostCore * findHostCore(HostCore *head, char *nick, boolean *found)
Definition: hostserv.c:180
#define HOSTSERV
Definition: modules.h:56
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
E char * sstrdup(const char *s)
Definition: memory.c:105
NickCore * nc
Definition: services.h:533
char * display
Definition: services.h:542
uint16 status
Definition: services.h:532
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
HostCore * next
Definition: services.h:1108
Command * c
Definition: ns_recover.c:17
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
char * vHost
Definition: services.h:1111
E char * s_HostServ
Definition: extern.h:303
char * username
Definition: services.h:877
char * vIdent
Definition: services.h:1110
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
#define NS_IDENTIFIED
Definition: services.h:1275
int do_hs_sync(NickCore *nc, char *vIdent, char *hostmask, char *creator, time_t time)
Definition: hostserv.c:568
char * creator
Definition: services.h:1112
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
E HostCore * hostCoreListHead()
Definition: hostserv.c:116
MDE void moduleSetHostHelp(void(*func)(User *u))
Definition: modules.c:2138
#define MOD_UNIQUE
Definition: module.h:11