Anope IRC Services  Version 1.8
bs_fantasy_seen.c
Go to the documentation of this file.
1 /* BotServ core fantasy 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_fantasy(int argc, char **argv);
18 
25 int AnopeInit(int argc, char **argv)
26 {
27  EvtHook *hook;
28 
29  moduleAddAuthor("Anope");
31  (VERSION_STRING);
33 
35  moduleAddEventHook(hook);
36 
37  return MOD_CONT;
38 }
39 
43 void AnopeFini(void)
44 {
45 
46 }
47 
54 static int do_fantasy(int argc, char **argv)
55 {
56  User *u;
57  ChannelInfo *ci;
58  User *u2;
59  NickAlias *na;
60  ChanAccess *access;
61  char buf[BUFSIZE];
62  char *target = NULL;
63 
64  if (argc < 4)
65  return MOD_CONT;
66 
67  if (stricmp(argv[0], "seen") == 0) {
68  u = finduser(argv[1]);
69  ci = cs_findchan(argv[2]);
70  if (!u || !ci)
71  return MOD_CONT;
72 
73  target = myStrGetToken(argv[3], ' ', 0);
74 
75  if (stricmp(ci->bi->nick, target) == 0) {
76  /* If we look for the bot */
77  snprintf(buf, sizeof(buf), getstring(u->na, BOT_SEEN_BOT),
78  u->nick);
79  anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", buf);
80  } else if (!(na = findnick(target)) || (na->status & NS_VERBOTEN)) {
81  /* If the nick is not registered or forbidden */
82  snprintf(buf, sizeof(buf), getstring(u->na, BOT_SEEN_UNKNOWN),
83  target);
84  anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", buf);
85  } else if ((u2 = nc_on_chan(ci->c, na->nc))) {
86  /* If the nick we're looking for is on the channel,
87  * there are three possibilities: it's yourself,
88  * it's the nick we look for, it's an alias of the
89  * nick we look for.
90  */
91  if (u == u2 || (u->na && u->na->nc == na->nc))
92  snprintf(buf, sizeof(buf), getstring(u->na, BOT_SEEN_YOU),
93  u->nick);
94  else if (!stricmp(u2->nick, target))
95  snprintf(buf, sizeof(buf),
96  getstring(u->na, BOT_SEEN_ON_CHANNEL), u2->nick);
97  else
98  snprintf(buf, sizeof(buf),
99  getstring(u->na, BOT_SEEN_ON_CHANNEL_AS), target,
100  u2->nick);
101 
102  anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", buf);
103  } else if ((access = get_access_entry(na->nc, ci))) {
104  /* User is on the access list but not present actually.
105  Special case: if access->last_seen is 0 it's that we
106  never seen the user.
107  */
108  if (access->last_seen) {
109  char durastr[192];
110  duration(u->na, durastr, sizeof(durastr),
111  time(NULL) - access->last_seen);
112  snprintf(buf, sizeof(buf), getstring(u->na, BOT_SEEN_ON),
113  target, durastr);
114  } else {
115  snprintf(buf, sizeof(buf),
116  getstring(u->na, BOT_SEEN_NEVER), target);
117  }
118  anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", buf);
119  } else if (na->nc == ci->founder) {
120  /* User is the founder of the channel */
121  char durastr[192];
122  duration(u->na, durastr, sizeof(durastr),
123  time(NULL) - na->last_seen);
124  snprintf(buf, sizeof(buf), getstring(u->na, BOT_SEEN_ON),
125  target, durastr);
126  anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", buf);
127  } else {
128  /* All other cases */
129  snprintf(buf, sizeof(buf), getstring(u->na, BOT_SEEN_UNKNOWN),
130  target);
131  anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", buf);
132  }
133  /* free myStrGetToken(ed) variable target (#851) */
134  Anope_Free(target);
135  }
136 
137  return MOD_CONT;
138 }
#define Anope_Free(x)
Definition: extern.h:1391
char nick[NICKMAX]
Definition: services.h:875
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
E char * duration(NickAlias *na, char *buf, int bufsize, time_t seconds)
Definition: misc.c:402
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
#define NS_VERBOTEN
Definition: services.h:1273
#define getstring(na, index)
Definition: extern.h:731
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
char name[CHANMAX]
Definition: services.h:654
MDE void moduleSetType(MODType type)
Definition: modules.c:818
NickCore * nc
Definition: services.h:533
time_t last_seen
Definition: services.h:596
static int do_fantasy(int argc, char **argv)
E User * finduser(const char *nick)
Definition: users.c:323
uint16 status
Definition: services.h:532
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
struct channel_ * c
Definition: services.h:692
MDE EvtHook * createEventHook(char *name, int(*func)(int argc, char **argv))
Definition: events.c:305
#define MOD_CONT
Definition: modules.h:54
#define EVENT_BOT_FANTASY
Definition: events.h:24
E User * nc_on_chan(Channel *c, NickCore *nc)
Definition: channels.c:533
Definition: modules.h:99
E char * myStrGetToken(const char *str, const char dilim, int token_number)
Definition: misc.c:654
E void anope_cmd_privmsg(char *source, char *dest, const char *fmt,...)
Definition: ircd.c:296
char * nick
Definition: services.h:573
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
E ChanAccess * get_access_entry(NickCore *nc, ChannelInfo *ci)
Definition: chanserv.c:2310
time_t last_seen
Definition: services.h:531
void AnopeFini(void)
BotInfo * bi
Definition: services.h:699
NickCore * founder
Definition: services.h:655
#define BUFSIZE
Definition: config.h:47
MDE int moduleAddEventHook(EvtHook *evh)
Definition: events.c:528
int AnopeInit(int argc, char **argv)
NickAlias * na
Definition: services.h:892