Reg SteamID, MySQL [PG]

  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
#pragma semicolon 1
#include <sourcemod>
/**
* Global Variables
*/
new Handle:g_hSQL;
new g_iReconnectCounter = 0;
public Plugin:myinfo =
{
name = "PG Layer",
author = "0wn3r | LenZ",
description = "Site and game compat layer",
version = "1.0",
url = "http://playground.org.ua/"
};
public OnPluginStart()
{
ConnectSQL();
RegConsoleCmd("sm_registerid", Command_RegisterID);
RegConsoleCmd("sm_changeid", Command_ChangeID);
RegConsoleCmd("sm_addsubid", Command_AddSubID);
}
public OnClientAuthorized(client, const String:auth[])
{
decl String:sQuery[256];
FormatEx(sQuery, sizeof(sQuery), "Check Query;", auth);
SQL_TQuery(g_hSQL, CheckSteamIDCallback, sQuery, client, DBPrio_High);
}
public CheckSteamIDCallback(Handle:owner, Handle:hndl, const String:error[], any:client)
{
if (hndl == INVALID_HANDLE)
{
PrintToChat(client, "Register your steam id by using command sm_register \"Site Login\"");
}
}
public Action:Command_RegisterID(client, args)
{
if (args < 1)
{
ReplyToCommand(client, "[PG] Usage: sm_registerid \"Site Login\"");
return Plugin_Handled;
}
decl String:sLogin[64];
GetCmdArgString(sLogin, sizeof(sLogin));
decl String:sAuthID[64];
GetClientAuthString(client, sAuthID, sizeof(sAuthID));
decl String:sQuery[256];
FormatEx(sQuery, sizeof(sQuery), "Register Query;");
SQL_TQuery(g_hSQL, RegisterSteamIDCallback, sQuery, client, DBPrio_High);
return Plugin_Handled;
}
public RegisterSteamIDCallback(Handle:owner, Handle:hndl, const String:error[], any:client)
{
if (hndl == INVALID_HANDLE)
{
LogError("SQL Error on RegisterID: %s", error);
PrintToChat(client, "There is no such login or SQL connection lost.");
return;
}
PrintToChat(client, "Your id was successfully registered.");
}
public Action:Command_ChangeID(client, args)
{
if (args < 1)
{
ReplyToCommand(client, "[PG] Usage: sm_changeid \"Site Login\"");
return Plugin_Handled;
}
decl String:sLogin[64];
GetCmdArgString(sLogin, sizeof(sLogin));
decl String:sAuthID[64];
GetClientAuthString(client, sAuthID, sizeof(sAuthID));
decl String:sQuery[256];
FormatEx(sQuery, sizeof(sQuery), "Change Query;");
SQL_TQuery(g_hSQL, ChangeSteamIDCallback, sQuery, client, DBPrio_High);
return Plugin_Handled;
}
public ChangeSteamIDCallback(Handle:owner, Handle:hndl, const String:error[], any:client)
{
if (hndl == INVALID_HANDLE)
{
LogError("SQL Error on ChangeID: %s", error);
PrintToChat(client, "There is no such login or SQL connection lost.");
return;
}
PrintToChat(client, "Your id was successfully changed.");
}
public Action:Command_AddSubID(client, args)
{
if (args < 1)
{
ReplyToCommand(client, "[PG] Usage: sm_addsubid \"Site Login\"");
return Plugin_Handled;
}
decl String:sLogin[64];
GetCmdArgString(sLogin, sizeof(sLogin));
decl String:sAuthID[64];
GetClientAuthString(client, sAuthID, sizeof(sAuthID));
decl String:sQuery[256];
FormatEx(sQuery, sizeof(sQuery), "AddSubID Query;");
SQL_TQuery(g_hSQL, AddSubSteamIDCallback, sQuery, client, DBPrio_High);
return Plugin_Handled;
}
public AddSubSteamIDCallback(Handle:owner, Handle:hndl, const String:error[], any:client)
{
if (hndl == INVALID_HANDLE)
{
LogError("SQL Error on AddSubID: %s", error);
PrintToChat(client, "There is no such login or SQL connection lost.");
return;
}
PrintToChat(client, "Your id was successfully added.");
}
ConnectSQL()
{
if (g_hSQL != INVALID_HANDLE)
{
CloseHandle(g_hSQL);
}
g_hSQL = INVALID_HANDLE;
if (SQL_CheckConfig("playground"))
{
SQL_TConnect(ConnectSQLCallback, "playground");
}
else
{
SetFailState("PLUGIN STOPPED - Reason: no config entry found for 'playground' in databases.cfg - PLUGIN STOPPED");
}
}
public ConnectSQLCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if (g_iReconnectCounter >= 5)
{
LogError("PLUGIN STOPPED - Reason: reconnect counter reached max - PLUGIN STOPPED");
return;
}
if (hndl == INVALID_HANDLE)
{
LogError("Connection to SQL database has failed, Reason: %s", error);
g_iReconnectCounter++;
ConnectSQL();
return;
}
g_hSQL = CloneHandle(hndl);
g_iReconnectCounter = 1;
}