-
Notifications
You must be signed in to change notification settings - Fork 0
/
Admins.cpp
147 lines (132 loc) · 2.02 KB
/
Admins.cpp
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
146
147
#pragma warning(disable : 4996)
#include "Admins.h"
#include "string.h"
#include <extdll.h>
#include <support_meta.h>
AdminList adminlist;
AdminList::admin* AdminList::FindAdmin(const char *value)
{
admin *ptr = AdmList;
while(ptr)
{
if(strcmp(ptr->name, value) == 0)
return ptr;
ptr = ptr->nxt;
}
return NULL;
}
void AdminList::AddAdmin(admin *data)
{
admin *ptr = AdmList;
if(!ptr)
{
AdmList = data;
return;
}
while(ptr->nxt)
ptr = ptr->nxt;
ptr->nxt = data;
}
bool AdminList::RemoveAdmin(const char *value)
{
admin *ptr = FindAdmin(value);
if(ptr == AdmList)
{
delete ptr;
AdmList = NULL;
return true;
}
if(ptr)
{
if(ptr->prv)
ptr->prv->nxt = ptr->nxt;
if(ptr->nxt)
ptr->nxt->prv = ptr->prv;
delete ptr;
return true;
}
return false;
}
void AdminList::CreateAdmin(const char *name, const char *acc)
{
admin *adm = new admin();
STRNCPY(adm->name, name, sizeof(adm->name));
for(int i = strlen(acc); i; i--)
{
switch(acc[i - 1])
{
case 'a':
adm->gen = true;
break;
case 'b':
adm->kick = true;
break;
case 'c':
adm->ban = true;
break;
case 'd':
adm->map = true;
break;
}
}
AddAdmin(adm);
}
bool AdminList::DeleteAdmin(const char *name)
{
return RemoveAdmin(name);
}
bool AdminList::IsAdmin(const char *name)
{
admin *ptr = FindAdmin(name);
if(ptr)
return true;
else return false;
}
bool AdminList::CheckRights(const char *name, ACC_RIGHT acc)
{
if(IsAdmin(name) == false)
return false;
admin *ptr = FindAdmin(name);
if(!ptr)
return false;
switch(acc)
{
case GEN:
if(ptr->gen)
return true;
break;
case KICK:
if(ptr->kick)
return true;
break;
case BAN:
if(ptr->ban)
return true;
break;
case MAP:
if(ptr->map)
return true;
break;
}
return false;
}
void AdminList::NextAdmin(const char **name)
{
if(!AdmList)
{
*name = NULL;
return;
}
if( !(*name) )
{
*name = AdmList->name;
return;
}
admin *ptr = FindAdmin(*name);
if(!ptr || !ptr->nxt)
{
*name = NULL;
return;
}
*name = ptr->nxt->name;
}