forked from hexa-core-eu/SteamWorks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUpdateCheck.sp
129 lines (106 loc) · 2.88 KB
/
UpdateCheck.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
#pragma semicolon 1
#include <sourcemod>
#include <SteamWorks>
new g_iPatchVersion = 0;
new g_iAppID = 0;
new Handle:g_hForward = INVALID_HANDLE;
public Plugin:myinfo =
{
name = "SteamWorks Update Check", /* https://www.youtube.com/watch?v=Tq_0ht8HCcM */
author = "Kyle Sanderson",
description = "Queries SteamWeb for Updates.",
version = "1.0b",
url = "https://AlliedMods.net"
};
static stock bool:ReadSteamINF(const String:sPath[], &iAppID, &iPatchVersion)
{
new Handle:hFile = OpenFile(sPath, "r");
if (hFile == INVALID_HANDLE)
{
return false;
}
decl String:sBuffer[256];
do
{
if (!ReadFileLine(hFile, sBuffer, sizeof(sBuffer)))
{
continue;
}
TrimString(sBuffer);
ReplaceString(sBuffer, sizeof(sBuffer), ".", ""); /* CS:GO uses decimals in steam.inf, WebAPI is Steam| style. */
new iPos = FindCharInString(sBuffer, '=');
if (iPos == -1)
{
continue;
}
sBuffer[iPos++] = '\0';
switch (CharToLower(sBuffer[0]))
{
case 'a':
{
if (!StrEqual(sBuffer, "appID", false))
{
continue;
}
iAppID = StringToInt(sBuffer[iPos]);
}
case 'p':
{
if (!StrEqual(sBuffer, "PatchVersion", false))
{
continue;
}
iPatchVersion = StringToInt(sBuffer[iPos]);
}
}
} while (!IsEndOfFile(hFile));
CloseHandle(hFile);
return true;
}
public OnPluginStart()
{
if (!ReadSteamINF("steam.inf", g_iAppID, g_iPatchVersion) && !ReadSteamINF("../steam.inf", g_iAppID, g_iPatchVersion))
{
SetFailState("Unable to read steam.inf");
}
g_hForward = CreateGlobalForward("SteamWorks_RestartRequested", ET_Ignore);
}
public OnMapStart()
{
CreateTimer(120.0, OnCheckForUpdate, _, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
}
public Action:OnCheckForUpdate(Handle:hTimer)
{
static String:sRequest[256];
if (sRequest[0] == '\0')
{
FormatEx(sRequest, sizeof(sRequest), "http://api.steampowered.com/ISteamApps/UpToDateCheck/v0001/?appid=%u&version=%u&format=xml", g_iAppID, g_iPatchVersion);
}
new Handle:hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest);
if (!hRequest || !SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) || !SteamWorks_SendHTTPRequest(hRequest))
{
CloseHandle(hRequest);
}
return Plugin_Continue;
}
public OnTransferComplete(Handle:hRequest, bool:bFailure, bool:bRequestSuccessful, EHTTPStatusCode:eStatusCode)
{
if (!bFailure && bRequestSuccessful && eStatusCode == k_EHTTPStatusCode200OK)
{
SteamWorks_GetHTTPResponseBodyCallback(hRequest, APIWebResponse);
}
CloseHandle(hRequest);
}
public APIWebResponse(const String:sData[])
{
new iPos = StrContains(sData, "<required_version>");
if (iPos == -1)
{
return;
}
if (g_iPatchVersion != StringToInt(sData[iPos+18]))
{
Call_StartForward(g_hForward);
Call_Finish();
}
}