added FEAT_CHMODE_A_NOSET to prevent +a from being set by users
[ircu2.10.12-pk.git] / ircd / opercmds.c
1 /*
2  * IRC - Internet Relay Chat, ircd/opercmds.c (formerly ircd/s_serv.c)
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
5  *
6  * See file AUTHORS in IRC package for additional names of
7  * the programmers.
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 1, or (at your option)
12  * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23 /** @file
24  * @brief Implementation of AsLL ping helper commands.
25  * @version $Id: opercmds.c 1210 2004-10-03 16:34:03Z entrope $
26  */
27 #include "config.h"
28
29 #include "opercmds.h"
30 #include "class.h"
31 #include "client.h"
32 #include "ircd.h"
33 #include "ircd_chattr.h"
34 #include "ircd_reply.h"
35 #include "ircd_string.h"
36 #include "listener.h"
37 #include "match.h"
38 #include "msg.h"
39 #include "numeric.h"
40 #include "numnicks.h"
41 #include "s_conf.h"
42 #include "send.h"
43 #include "struct.h"
44
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <sys/time.h>
49
50 /** Calculate current time or elapsed time.
51  *
52  * If neither \a sec nor \a usec are NULL, calculate milliseconds
53  * elapsed since that time, and return a string containing that
54  * number.
55  *
56  * If either \a sec or \a usec are NULL, format a timestamp containing
57  * Unix timestamp and microseconds since that second (separated by
58  * spaces), and return a string containing that timestamp.
59  *
60  * @todo This should be made into two functions.
61  * @param[in] sec Either NULL or a Unix timestamp in seconds.
62  * @param[in] usec Either NULL or an offset to \a sec in microseconds.
63  * @return A static buffer with contents as described above.
64  */
65 char *militime(char* sec, char* usec)
66 {
67   struct timeval tv;
68   static char timebuf[18];
69
70   gettimeofday(&tv, NULL);
71   if (sec && usec)
72     sprintf(timebuf, "%ld",
73         (tv.tv_sec - atoi(sec)) * 1000 + (tv.tv_usec - atoi(usec)) / 1000);
74   else
75     sprintf(timebuf, "%ld %ld", tv.tv_sec, tv.tv_usec);
76   return timebuf;
77 }
78
79 /** Calculate current time or elapsed time.
80  *
81  * If \a start is NULL, create a timestamp containing Unix timestamp
82  * and microseconds since that second (separated by a period), and
83  * return a string containing that timestamp.
84  *
85  * Otherwise, if \a start does not contain a period, return a string
86  * equal to "0".
87  *
88  * Otherwise, calculate milliseconds elapsed since the Unix time
89  * described in \a start (in the format described above), and return a
90  * string containing that number.
91  *
92  * @todo This should be made into two functions.
93  * @param[in] start Either NULL or a Unix timestamp in
94  * pseudo-floating-point format.
95  * @return A static buffer with contents as described above.
96  */
97 char *militime_float(char* start)
98 {
99   struct timeval tv;
100   static char timebuf[18];
101   char *p;
102
103   gettimeofday(&tv, NULL);
104   if (start)
105   {
106     if ((p = strchr(start, '.')))
107     {
108       p++;
109       sprintf(timebuf, "%ld",
110           (tv.tv_sec - atoi(start)) * 1000 + (tv.tv_usec - atoi(p)) / 1000);
111     }
112     else
113       strcpy(timebuf, "0");
114   }
115   else
116     sprintf(timebuf, "%ld.%ld", tv.tv_sec, tv.tv_usec);
117   return timebuf;
118 }