summaryrefslogtreecommitdiff
path: root/src/core/os_staff.c
blob: d136cecbc2e1d235dde1391a91ed98ae3bedb9e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* OperServ core functions
 *
 * (C) 2003-2009 Anope Team
 * Contact us at team@anope.org
 *
 * Please read COPYING and README for further details.
 *
 * Based on the original code of Epona by Lara.
 * Based on the original code of Services by Andy Church.
 *
 * $Id$
 *
 */
/*************************************************************************/

#include "module.h"

int do_staff(User * u);
void myOperServHelp(User * u);
int opers_list_callback(SList * slist, int number, void *item,
						va_list args);
int opers_list(int number, NickCore * nc, User * u, char *level);

class OSStaff : public Module
{
 public:
	OSStaff(const std::string &modname, const std::string &creator) : Module(modname, creator)
	{
		Command *c;

		this->SetAuthor("Anope");
		this->SetVersion("$Id$");
		this->SetType(CORE);

		c = createCommand("STAFF", do_staff, NULL, OPER_HELP_STAFF, -1, -1, -1, -1);
		this->AddCommand(OPERSERV, c, MOD_UNIQUE);

		this->SetOperHelp(myOperServHelp);
	}
};


/**
 * Add the help response to anopes /os help output.
 * @param u The user who is requesting help
 **/
void myOperServHelp(User * u)
{
	notice_lang(s_OperServ, u, OPER_HELP_CMD_STAFF);
}

/**
 * The /os staff command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
int do_staff(User * u)
{
	int idx = 0;
	User *au = NULL;
	NickCore *nc;
	NickAlias *na;
	int found;
	int i;

	notice_lang(s_OperServ, u, OPER_STAFF_LIST_HEADER);
	slist_enum(&servopers, NULL, &opers_list_callback, u, "OPER");
	slist_enum(&servadmins, NULL, &opers_list_callback, u, "ADMN");

	for (idx = 0; idx < RootNumber; idx++) {
		found = 0;
		if ((au = finduser(ServicesRoots[idx]))) {	  /* see if user is online */
			found = 1;
			notice_lang(s_OperServ, u, OPER_STAFF_FORMAT, '*', "ROOT",
						ServicesRoots[idx]);
		} else if ((nc = findcore(ServicesRoots[idx]))) {
			for (i = 0; i < nc->aliases.count; i++) {   /* check all aliases */
				na = static_cast<NickAlias *>(nc->aliases.list[i]);
				if ((au = finduser(na->nick))) {		/* see if user is online */
					found = 1;
					notice_lang(s_OperServ, u, OPER_STAFF_AFORMAT,
								'*', "ROOT", ServicesRoots[idx], na->nick);
				}
			}
		}

		if (!found)
			notice_lang(s_OperServ, u, OPER_STAFF_FORMAT, ' ', "ROOT",
						ServicesRoots[idx]);

	}
	notice_lang(s_OperServ, u, END_OF_ANY_LIST, "Staff");
	return MOD_CONT;
}

/**
 * Function for the enumerator to call
 **/
int opers_list_callback(SList * slist, int number, void *item,
						va_list args)
{
	User *u = va_arg(args, User *);
	char *level = va_arg(args, char *);

	return opers_list(number, static_cast<NickCore *>(item), u, level);
}


/**
 * Display an Opers list Entry
 **/
int opers_list(int number, NickCore * nc, User * u, char *level)
{
	User *au = NULL;
	NickAlias *na;
	int found;
	int i;

	if (!nc)
		return 0;

	found = 0;
	if ((au = finduser(nc->display))) { /* see if user is online */
		found = 1;
		notice_lang(s_OperServ, u, OPER_STAFF_FORMAT, '*', level,
					nc->display);
	} else {
		for (i = 0; i < nc->aliases.count; i++) {	   /* check all aliases */
			na = static_cast<NickAlias *>(nc->aliases.list[i]);
			if ((au = finduser(na->nick))) {	/* see if user is online */
				found = 1;
				notice_lang(s_OperServ, u, OPER_STAFF_AFORMAT, '*', level,
							nc->display, na->nick);
			}
		}
	}

	if (!found)
		notice_lang(s_OperServ, u, OPER_STAFF_FORMAT, ' ', level,
					nc->display);

	return 1;
}

MODULE_INIT("os_staff", OSStaff)