· 6 years ago · Jul 21, 2019, 12:34 PM
1#define PLUGIN_VERSION "1.6"
2#define MAX 200
3
4#include <sourcemod>
5
6#pragma semicolon 1
7#pragma newdecls required
8
9Handle hDatabase;
10
11public const char DBQueriesLogs[2][] =
12{
13 "CREATE TABLE IF NOT EXISTS `logging_logs` (`id` INT(10) NOT NULL AUTO_INCREMENT, `servername` VARCHAR(50) NOT NULL, `name` VARCHAR(50) NOT NULL, `steamid` VARCHAR(50) NOT NULL, `command` VARCHAR(200) NOT NULL, `date` VARCHAR(50) NOT NULL, PRIMARY KEY (`id`)) COLLATE='latin1_swedish_ci' ENGINE=MyISAM;",
14 "INSERT INTO `logging_logs` (`servername`, `steamid`, `name`, `command`, `date`) VALUES ('%s', '%s', '%s', '%s', '%s')"
15};
16
17public Plugin myinfo =
18{
19 name = "logging",
20 author = "kekes",
21 description = "Admins time + commands - results in a database.",
22 version = PLUGIN_VERSION,
23 url = ""
24};
25
26public void OnPluginStart()
27{
28 char error[255];
29 hDatabase = SQL_Connect("logging", true, error, sizeof(error));
30
31 if (hDatabase == INVALID_HANDLE)
32 {
33 LogError("Unable to connect to the database. Error: %s", error);
34 LogMessage("[Logging] - Unable to connect to the database.");
35 }
36
37 SQL_TQuery(hDatabase, DBNoAction, DBQueriesLogs[0], DBPrio_High);
38}
39
40public void OnPluginEnd()
41{
42 CloseHandle(hDatabase);
43}
44
45public Action OnLogAction(Handle source, Identity ident, int client, int target, const char[] message)
46{
47 if (client < 1 || !CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
48 {
49 return Plugin_Continue;
50 }
51
52 char query[400], authid[32];
53 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
54
55 char name[30];
56 GetClientName(client, name, sizeof(name));
57
58 char hostname[60];
59 GetConVarString(FindConVar("hostname"), hostname, sizeof(hostname));
60
61 char bName[61], bHost[121], bTime[61];
62
63 SQL_EscapeString(hDatabase, name, bName, sizeof(bName));
64 SQL_EscapeString(hDatabase, hostname, bHost, sizeof(bHost));
65
66 FormatTime(bTime, 61, "%d/%m/%y %H:%M", GetTime({0,0}));
67
68 Format(query, sizeof(query), DBQueriesLogs[1], bHost, authid, bName, message, bTime);
69 SQL_TQuery(hDatabase, DBNoAction, query, client, DBPrio_High);
70
71 return Plugin_Handled;
72}
73
74public int DBNoAction(Handle owner, Handle hndl, const char[] error, any data)
75{
76 if (hndl == INVALID_HANDLE)
77 {
78 SetFailState(error);
79 }
80}