· 5 years ago · Nov 12, 2020, 11:22 PM
1#include <sourcemod>
2#include <SteamWorks>
3
4#pragma semicolon 1
5#pragma newdecls required
6
7Database db;
8int g_iCounter;
9int g_iHowMany = 100; //Wpisz tu ile ma być wpisów.
10bool g_bClients[MAXPLAYERS + 1];
11
12public Plugin myinfo =
13{
14 name = "Jakieś gówno dla Krystyny",
15 description = "",
16 author = "Ch W.",
17 version = "1.0",
18 url = ""
19};
20
21public void OnPluginStart()
22{
23 RegConsoleCmd("sm_freeotm", CmdFreeOtm);
24}
25
26public void OnConfigsExecuted()
27{
28 if (db == null)
29 DbConnect();
30}
31
32public void OnMapStart()
33{
34 DBResultSet rs;
35 g_iCounter = 0; //tu be siur.
36
37 if ((rs = SQL_Query(db, "SELECT id FROM freeotm")) == null)
38 {
39 char error[255];
40 SQL_GetError(db, error, sizeof(error));
41 LogError("Error on count query: %s", error);
42 return;
43 }
44
45 g_iCounter = rs.RowCount;
46 delete rs;
47
48 for(int i = 1; i <= MaxClients; i++)
49 g_bClients[i] = false;
50}
51
52public void DbConnect()
53{
54 char error[255];
55 char query[512];
56
57 if(SQL_CheckConfig("freeotm"))
58 {
59 db = SQL_Connect("freeotm", true, error, 255);
60
61 if (db == null)
62 SetFailState("Error on start. Reason: %s", error);
63 }
64 else
65 SetFailState("Cant find `freeotm` on database.cfg");
66
67 Format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS `freeotm` ( `id` INT NOT NULL AUTO_INCREMENT, `auth` TEXT NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY (`id`)) ENGINE = MyISAM;");
68 db.Query(SQLT_Error, query);
69}
70
71public void SQLT_Error(Database database, DBResultSet results, const char[] error, any data)
72{
73 if(results == null)
74 LogError("Error: %s", error);
75}
76
77public Action CmdFreeOtm(int client, int args)
78{
79 if(!IsValidClient(client))
80 return Plugin_Handled;
81
82 if(IsClientAllowed(client))
83 MakeAVote(client);
84
85 return Plugin_Handled;
86}
87
88public void MakeAVote(int client)
89{
90 //!!!JEBAĆ ICH :) - tj. ruchać im matki :)
91 if(g_bClients[client])
92 return;
93
94 g_bClients[client] = true;
95
96 char error[255];
97 char query[255];
98 char auth[64];
99 DBResultSet rs;
100
101 if(GetClientAuthId(client, AuthId_SteamID64, auth, sizeof(auth)))
102 {
103 Format(query, sizeof(query), "SELECT id FROM freeotm WHERE auth = '%s' LIMIT 1", auth);
104 if ((rs = SQL_Query(db, query)) == null)
105 {
106 SQL_GetError(db, error, sizeof(error));
107 LogError("Error: %s", error);
108 return;
109 }
110 }
111
112 if(!rs.FetchRow())
113 {
114 //ciekawe czy musze to "usuwać"... :)
115 delete rs;
116 Format(query, sizeof(query), "INSERT INTO `freeotm` (`id`, `auth`, `name`) VALUES (NULL, '%s', '%N')", auth, client);
117
118 if((rs = SQL_Query(db, query)) == null)
119 {
120 SQL_GetError(db, error, sizeof(error));
121 LogError("Error: %s", error);
122 PrintToChat(client, "Coś nie pykło #error");
123 return;
124 }
125 else
126 {
127 g_iCounter++;
128 PrintToChat(client, "Pykło... jest to wpis: %i/%i", g_iCounter, g_iHowMany);
129 }
130
131 }
132 else
133 PrintToChat(client, "Drugi raz? No nie... jebać Ci matke. jest już wpisów: %i/%i", g_iCounter, g_iHowMany);
134
135 delete rs;
136}
137
138public bool IsClientAllowed(int client)
139{
140 if((k_EUserHasLicenseResultDoesNotHaveLicense != SteamWorks_HasLicenseForApp(client, 624820)) || hasVipAccess(client))
141 return true;
142 return false;
143}
144
145public bool hasVipAccess(int client)
146{
147 if(GetUserFlagBits(client) & ADMFLAG_CUSTOM3)
148 return true;
149 return false;
150}
151
152public bool IsValidClient(int client)
153{
154 if(client <= 0 ) return false;
155 if(client > MaxClients) return false;
156 if(!IsClientConnected(client)) return false;
157 if(IsClientReplay(client)) return false;
158 if(IsFakeClient(client)) return false;
159 if(IsClientSourceTV(client)) return false;
160 return IsClientInGame(client);
161}