forked from AdKats/AdKats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adkats.sql
279 lines (247 loc) · 9.8 KB
/
adkats.sql
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
-- AdKats Database Setup Script by ColColonCleaner
-- This is run automatically if AdKats senses the database is not set up properly.
-- If you don't want the plugin changing tables/views in your database, you must run this beforehand.
CREATE TABLE IF NOT EXISTS `adkats_accesslist` (
`player_name` VARCHAR(20) NOT NULL,
`member_id` INT(11) UNSIGNED NOT NULL DEFAULT 0,
`player_email` VARCHAR(254) NOT NULL DEFAULT "[email protected]",
`access_level` INT(11) NOT NULL DEFAULT 6,
PRIMARY KEY (`player_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='AdKats Access List';
CREATE TABLE IF NOT EXISTS `adkats_records` (
`record_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`server_id` SMALLINT(5) UNSIGNED NOT NULL,
`command_type` VARCHAR(45) NOT NULL DEFAULT "DefaultCommand",
`command_action` VARCHAR(45) NOT NULL DEFAULT "DefaultAction",
`command_numeric` INT(11) NOT NULL DEFAULT 0,
`target_name` VARCHAR(45) NOT NULL DEFAULT "NoTarget",
`target_id` INT(11) UNSIGNED DEFAULT NULL,
`source_name` VARCHAR(45) NOT NULL DEFAULT "NoNameAdmin",
`record_message` VARCHAR(100) NOT NULL DEFAULT "NoMessage",
`record_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`adkats_read` ENUM('Y', 'N') NOT NULL DEFAULT 'N',
`adkats_web` BOOL NOT NULL DEFAULT 0,
PRIMARY KEY (`record_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='AdKats Records';
-- ALTER TABLE `adkats_records` ADD
-- CONSTRAINT `adkats_records_fk_server_id`
-- FOREIGN KEY (`server_id`)
-- REFERENCES tbl_server(ServerID)
-- ON DELETE CASCADE
-- ON UPDATE NO ACTION;
-- ALTER TABLE `adkats_records` ADD
-- CONSTRAINT `adkats_records_fk_target_id`
-- FOREIGN KEY (`target_id`)
-- REFERENCES tbl_playerdata(PlayerID)
-- ON DELETE CASCADE
-- ON UPDATE NO ACTION;
CREATE TABLE IF NOT EXISTS `adkats_serverPlayerPoints` (
`player_id` INT(11) UNSIGNED NOT NULL,
`server_id` SMALLINT(5) UNSIGNED NOT NULL,
`punish_points` INT(11) NOT NULL,
`forgive_points` INT(11) NOT NULL,
`total_points` INT(11) NOT NULL,
PRIMARY KEY (`player_id`, `server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='AdKats Server Specific Player Points';
-- ALTER TABLE `adkats_serverPlayerPoints` ADD
-- CONSTRAINT `adkats_serverPlayerPoints_fk_player_id`
-- FOREIGN KEY (`player_id`)
-- REFERENCES tbl_playerdata(PlayerID)
-- ON DELETE CASCADE
-- ON UPDATE NO ACTION;
-- ALTER TABLE `adkats_serverPlayerPoints` ADD
-- CONSTRAINT `adkats_serverPlayerPoints_fk_server_id`
-- FOREIGN KEY (`server_id`)
-- REFERENCES tbl_server(ServerID)
-- ON DELETE CASCADE
-- ON UPDATE NO ACTION;
CREATE TABLE IF NOT EXISTS `adkats_globalPlayerPoints` (
`player_id` INT(11) UNSIGNED NOT NULL,
`punish_points` INT(11) NOT NULL,
`forgive_points` INT(11) NOT NULL,
`total_points` INT(11) NOT NULL,
PRIMARY KEY (`player_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='AdKats Global Player Points';
-- ALTER TABLE `adkats_globalPlayerPoints` ADD
-- CONSTRAINT `adkats_globalPlayerPoints_fk_player_id`
-- FOREIGN KEY (`player_id`)
-- REFERENCES tbl_playerdata(PlayerID)
-- ON DELETE CASCADE
-- ON UPDATE NO ACTION;
CREATE TABLE IF NOT EXISTS `adkats_banlist` (
`ban_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`player_id` INT(11) UNSIGNED NOT NULL,
`latest_record_id` INT(11) UNSIGNED NOT NULL,
`ban_notes` VARCHAR(150) NOT NULL DEFAULT 'NoNotes',
`ban_status` enum('Active', 'Expired', 'Disabled') NOT NULL DEFAULT 'Active',
`ban_startTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`ban_endTime` DATETIME NOT NULL,
`ban_enforceName` ENUM('Y', 'N') NOT NULL DEFAULT 'N',
`ban_enforceGUID` ENUM('Y', 'N') NOT NULL DEFAULT 'Y',
`ban_enforceIP` ENUM('Y', 'N') NOT NULL DEFAULT 'N',
`ban_sync` VARCHAR(100) NOT NULL DEFAULT "-sync-",
PRIMARY KEY (`ban_id`),
UNIQUE KEY `player_id_UNIQUE` (`player_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='AdKats Ban Enforcer List';
-- ALTER TABLE `adkats_banlist` ADD
-- CONSTRAINT `adkats_banlist_fk_player_id`
-- FOREIGN KEY (`player_id`)
-- REFERENCES tbl_playerdata(PlayerID)
-- ON DELETE CASCADE
-- ON UPDATE NO ACTION;
-- ALTER TABLE `adkats_banlist` ADD
-- CONSTRAINT `adkats_banlist_fk_latest_record_id`
-- FOREIGN KEY (`latest_record_id`)
-- REFERENCES adkats_records(record_id)
-- ON DELETE CASCADE
-- ON UPDATE NO ACTION;
CREATE TABLE IF NOT EXISTS `adkats_settings` (
`server_id` SMALLINT(5) UNSIGNED NOT NULL,
`setting_name` VARCHAR(200) NOT NULL DEFAULT "SettingName",
`setting_type` VARCHAR(45) NOT NULL DEFAULT "SettingType",
`setting_value` VARCHAR(1500) NOT NULL DEFAULT "SettingValue",
PRIMARY KEY (`server_id`, `setting_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='AdKats Setting Sync';
-- ALTER TABLE `adkats_settings` ADD
-- CONSTRAINT `adkats_settings_fk_server_id`
-- FOREIGN KEY (`server_id`)
-- REFERENCES tbl_server(ServerID)
-- ON DELETE CASCADE
-- ON UPDATE NO ACTION;
DROP TRIGGER IF EXISTS adkats_update_point_insert;
DROP TRIGGER IF EXISTS adkats_update_point_delete;
DELIMITER |
CREATE TRIGGER adkats_update_point_insert BEFORE INSERT ON `adkats_records`
FOR EACH ROW
BEGIN
DECLARE command_type VARCHAR(45);
DECLARE server_id INT(11);
DECLARE player_id INT(11);
SET command_type = NEW.command_type;
SET server_id = NEW.server_id;
SET player_id = NEW.target_id;
IF(command_type = 'Punish') THEN
INSERT INTO `adkats_serverPlayerPoints`
(`player_id`, `server_id`, `punish_points`, `forgive_points`, `total_points`)
VALUES
(player_id, server_id, 1, 0, 1)
ON DUPLICATE KEY UPDATE
`punish_points` = `punish_points` + 1,
`total_points` = `total_points` + 1;
INSERT INTO `adkats_globalPlayerPoints`
(`player_id`, `punish_points`, `forgive_points`, `total_points`)
VALUES
(player_id, 1, 0, 1)
ON DUPLICATE KEY UPDATE
`punish_points` = `punish_points` + 1,
`total_points` = `total_points` + 1;
ELSEIF (command_type = 'Forgive') THEN
INSERT INTO `adkats_serverPlayerPoints`
(`player_id`, `server_id`, `punish_points`, `forgive_points`, `total_points`)
VALUES
(player_id, server_id, 0, 1, -1)
ON DUPLICATE KEY UPDATE
`forgive_points` = `forgive_points` + 1,
`total_points` = `total_points` - 1;
INSERT INTO `adkats_globalPlayerPoints`
(`player_id`, `punish_points`, `forgive_points`, `total_points`)
VALUES
(player_id, 0, 1, -1)
ON DUPLICATE KEY UPDATE
`forgive_points` = `forgive_points` + 1,
`total_points` = `total_points` - 1;
END IF;
END;
|
CREATE TRIGGER adkats_update_point_delete AFTER DELETE ON `adkats_records`
FOR EACH ROW
BEGIN
DECLARE command_type VARCHAR(45);
DECLARE server_id INT(11);
DECLARE player_id INT(11);
SET command_type = OLD.command_type;
SET server_id = OLD.server_id;
SET player_id = OLD.target_id;
IF(command_type = 'Punish') THEN
INSERT INTO `adkats_serverPlayerPoints`
(`player_id`, `server_id`, `punish_points`, `forgive_points`, `total_points`)
VALUES
(player_id, server_id, 0, 0, 0)
ON DUPLICATE KEY UPDATE
`punish_points` = `punish_points` - 1,
`total_points` = `total_points` - 1;
INSERT INTO `adkats_globalPlayerPoints`
(`player_id`, `punish_points`, `forgive_points`, `total_points`)
VALUES
(player_id, 0, 0, 0)
ON DUPLICATE KEY UPDATE
`punish_points` = `punish_points` - 1,
`total_points` = `total_points` - 1;
ELSEIF (command_type = 'Forgive') THEN
INSERT INTO `adkats_serverPlayerPoints`
(`player_id`, `server_id`, `punish_points`, `forgive_points`, `total_points`)
VALUES
(player_id, server_id, 0, 0, 0)
ON DUPLICATE KEY UPDATE
`forgive_points` = `forgive_points` - 1,
`total_points` = `total_points` + 1;
INSERT INTO `adkats_globalPlayerPoints`
(`player_id`, `punish_points`, `forgive_points`, `total_points`)
VALUES
(player_id, 0, 0, 0)
ON DUPLICATE KEY UPDATE
`forgive_points` = `forgive_points` - 1,
`total_points` = `total_points` + 1;
END IF;
END;
|
DELIMITER ;
CREATE OR REPLACE VIEW `adkats_totalcmdissued` AS
SELECT
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'Move' OR adkats_records.command_type = 'ForceMove') AS 'Moves',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'Teamswap') AS 'TeamSwaps',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'Kill') AS 'Kills',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'Kick') AS 'Kicks',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'TempBan' OR adkats_records.command_action = 'TempBan') AS 'TempBans',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'PermaBan' OR adkats_records.command_action = 'PermaBan') AS 'PermaBans',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'Punish') AS 'Punishes',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'Forgive') AS 'Forgives',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'Report' OR adkats_records.command_type = 'CallAdmin') AS 'Reports',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'ConfirmReport') AS 'UsedReports',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'AdminSay') AS 'AdminSays',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'PlayerSay') AS 'PlayerSays',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'AdminYell') AS 'AdminYells',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'PlayerYell') AS 'PlayerYells',
(SELECT COUNT(*)
FROM adkats_records
WHERE adkats_records.command_type = 'Mute') AS 'PlayerMutes',
(SELECT COUNT(*)
FROM adkats_records) AS 'TotalCommands';