~ubuntu-branches/ubuntu/trusty/charybdis/trusty-proposed

« back to all changes in this revision

Viewing changes to modules/m_whowas.c

  • Committer: Package Import Robot
  • Author(s): Antoine Beaupré
  • Date: 2011-11-10 23:07:37 UTC
  • Revision ID: package-import@ubuntu.com-20111110230737-kqo6qsglp5oh02hr
Tags: upstream-3.3.0
Import upstream version 3.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  ircd-ratbox: A slightly useful ircd.
 
3
 *  m_whois.c: Shows who a user was.
 
4
 *
 
5
 *  Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
 
6
 *  Copyright (C) 1996-2002 Hybrid Development Team
 
7
 *  Copyright (C) 2002-2005 ircd-ratbox development team
 
8
 *
 
9
 *  This program is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  (at your option) any later version.
 
13
 *
 
14
 *  This program is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with this program; if not, write to the Free Software
 
21
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 
22
 *  USA
 
23
 *
 
24
 *  $Id: m_whowas.c 1717 2006-07-04 14:41:11Z jilles $
 
25
 */
 
26
 
 
27
#include "stdinc.h"
 
28
#include "whowas.h"
 
29
#include "client.h"
 
30
#include "common.h"
 
31
#include "hash.h"
 
32
#include "match.h"
 
33
#include "ircd.h"
 
34
#include "ircd_defs.h"
 
35
#include "numeric.h"
 
36
#include "s_serv.h"
 
37
#include "s_user.h"
 
38
#include "send.h"
 
39
#include "s_conf.h"
 
40
#include "msg.h"
 
41
#include "parse.h"
 
42
#include "modules.h"
 
43
 
 
44
static int m_whowas(struct Client *, struct Client *, int, const char **);
 
45
 
 
46
struct Message whowas_msgtab = {
 
47
        "WHOWAS", 0, 0, 0, MFLG_SLOW,
 
48
        {mg_unreg, {m_whowas, 2}, mg_ignore, mg_ignore, mg_ignore, {m_whowas, 2}}
 
49
};
 
50
 
 
51
mapi_clist_av1 whowas_clist[] = { &whowas_msgtab, NULL };
 
52
DECLARE_MODULE_AV1(whowas, NULL, NULL, whowas_clist, NULL, NULL, "$Revision: 1717 $");
 
53
 
 
54
/*
 
55
** m_whowas
 
56
**      parv[1] = nickname queried
 
57
*/
 
58
static int
 
59
m_whowas(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 
60
{       
 
61
        struct Whowas *temp;
 
62
        int cur = 0;
 
63
        int max = -1, found = 0;
 
64
        char *p;
 
65
        const char *nick;
 
66
        char tbuf[26];
 
67
 
 
68
        static time_t last_used = 0L;
 
69
 
 
70
        if(!IsOper(source_p))
 
71
        {
 
72
                if((last_used + ConfigFileEntry.pace_wait_simple) > rb_current_time())
 
73
                {
 
74
                        sendto_one(source_p, form_str(RPL_LOAD2HI),
 
75
                                   me.name, source_p->name, "WHOWAS");
 
76
                        sendto_one(source_p, form_str(RPL_ENDOFWHOWAS),
 
77
                                   me.name, source_p->name, parv[1]);
 
78
                        return 0;
 
79
                }
 
80
                else
 
81
                        last_used = rb_current_time();
 
82
        }
 
83
 
 
84
 
 
85
        if(parc > 2)
 
86
                max = atoi(parv[2]);
 
87
 
 
88
#if 0
 
89
        if(parc > 3)
 
90
                if(hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv))
 
91
                        return 0;
 
92
#endif
 
93
 
 
94
        if((p = strchr(parv[1], ',')))
 
95
                *p = '\0';
 
96
 
 
97
        nick = parv[1];
 
98
 
 
99
        temp = WHOWASHASH[hash_whowas_name(nick)];
 
100
        found = 0;
 
101
        for (; temp; temp = temp->next)
 
102
        {
 
103
                if(!irccmp(nick, temp->name))
 
104
                {
 
105
                        sendto_one(source_p, form_str(RPL_WHOWASUSER),
 
106
                                   me.name, source_p->name, temp->name,
 
107
                                   temp->username, temp->hostname, temp->realname);
 
108
                        if (MyOper(source_p) && !EmptyString(temp->sockhost))
 
109
#if 0
 
110
                                sendto_one(source_p, form_str(RPL_WHOWASREAL),
 
111
                                           me.name, source_p->name, temp->name,
 
112
                                           "<untracked>", temp->sockhost);
 
113
#else
 
114
                                sendto_one_numeric(source_p, RPL_WHOISACTUALLY,
 
115
                                                   form_str(RPL_WHOISACTUALLY),
 
116
                                                   temp->name, temp->sockhost);
 
117
#endif
 
118
                        if (!EmptyString(temp->suser))
 
119
                                sendto_one_numeric(source_p, RPL_WHOISLOGGEDIN,
 
120
                                                   "%s %s :was logged in as",
 
121
                                                   temp->name, temp->suser);
 
122
                        sendto_one_numeric(source_p, RPL_WHOISSERVER,
 
123
                                           form_str(RPL_WHOISSERVER),
 
124
                                           temp->name, temp->servername,
 
125
                                           rb_ctime(temp->logoff, tbuf, sizeof(tbuf)));
 
126
                        cur++;
 
127
                        found++;
 
128
                }
 
129
                if(max > 0 && cur >= max)
 
130
                        break;
 
131
        }
 
132
 
 
133
        if(!found)
 
134
                sendto_one(source_p, form_str(ERR_WASNOSUCHNICK), 
 
135
                           me.name, source_p->name, nick);
 
136
 
 
137
        sendto_one(source_p, form_str(RPL_ENDOFWHOWAS), 
 
138
                   me.name, source_p->name, parv[1]);
 
139
        return 0;
 
140
}