Skip to content

Commit

Permalink
Merge pull request #14 from hx-w/dev-1.2.3
Browse files Browse the repository at this point in the history
Dev 1.2.3
  • Loading branch information
hx-w authored Mar 17, 2021
2 parents dde2039 + 26377db commit 33eba3c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 88 deletions.
Binary file modified plugins/csgowiki-pack.smx
Binary file not shown.
14 changes: 2 additions & 12 deletions scripting/csgowiki-pack.sp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "csgowiki/menus.sp"

#include "csgowiki/steam_bind.sp"
#include "csgowiki/server_monitor.sp"
#include "csgowiki/utility_submit.sp"
#include "csgowiki/utility_wiki.sp"
#include "csgowiki/utility_modify.sp"
Expand All @@ -16,7 +15,7 @@ public Plugin:myinfo = {
name = "[CSGO Wiki] Plugin-Pack",
author = "CarOL",
description = "Provide interactive method between www.csgowiki.top and game server",
version = "v1.2.0",
version = "v1.2.3",
url = "https://github.com/hx-w/CSGOWiki-Plugins"
};

Expand All @@ -40,9 +39,6 @@ public OnPluginStart() {

RegAdminCmd("sm_vel", Command_Velocity, ADMFLAG_GENERIC);

// global timer
CreateTimer(10.0, ServerMonitorTimerCallback, _, TIMER_REPEAT);

// post fix
g_iServerTickrate = GetServerTickrate();

Expand All @@ -54,7 +50,6 @@ public OnPluginStart() {
g_hCSGOWikiEnable = FindOrCreateConvar("sm_csgowiki_enable", "0", "Set wether enable csgowiki plugins or not. Set 0 will disable all modules belong to CSGOWiki.");
g_hOnUtilitySubmit = FindOrCreateConvar("sm_utility_submit_on", "1", "Set module: <utility_submit> on/off.");
g_hOnUtilityWiki = FindOrCreateConvar("sm_utility_wiki_on", "1", "Set module: <utility_wiki> on/off.");
g_hOnServerMonitor = FindOrCreateConvar("sm_server_monitor_on", "0", "Set module: <server_monitor> on/off");
g_hCSGOWikiToken = FindOrCreateConvar("sm_csgowiki_token", "", "Make sure csgowiki token valid. Some modules will be disabled if csgowiki token invalid");
g_hWikiReqLimit = FindOrCreateConvar("sm_wiki_request_limit", "1", "Limit cooling time(second) for each player's `!wiki` request. Set 0 to unlimit", 0.0, 10.0);
g_hChannelEnable = FindOrCreateConvar("sm_qqchat_enable", "0", "Set wether enable qqchat or not, use `!qq <msg>` trigger qqchat when convar set 1");
Expand All @@ -80,6 +75,7 @@ public OnMapStart() {
if (GetConVarBool(g_hChannelEnable)) {
CreateTimer(1.0, ChannelPullTimerCallback, _, TIMER_REPEAT);
}
PluginVersionCheck();
}

public OnClientPutInServer(client) {
Expand All @@ -92,23 +88,17 @@ public OnClientPutInServer(client) {
ResetSingleClientSubmitState(client);
ClearPlayerToken(client);
ResetReqLock(client);
updateServerMonitor();
}

public OnClientDisconnect(client) {

ResetSingleClientSubmitState(client);
updateServerMonitor(-1);
ClearPlayerToken(client);
ResetReqLock(client);
// reset bind_flag
ResetSteamBindFlag(client);
}

public OnPluginEnd() {
updateServerMonitor(-1);
}

public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[DATA_DIM], Float:angles[DATA_DIM], &weapon) {
// for utility submit
if (!buttons) return;
Expand Down
75 changes: 0 additions & 75 deletions scripting/csgowiki/server_monitor.sp

This file was deleted.

2 changes: 2 additions & 0 deletions scripting/csgowiki/utility_wiki.sp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// implement wiki

public Action:Command_Wiki(client, args) {
PluginVersionHint(client);

if (!check_function_on(g_hOnUtilityWiki, "\x02道具学习插件关闭,请联系服务器管理员", client)) {
return;
}
Expand Down
89 changes: 89 additions & 0 deletions scripting/csgowiki/utils.sp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,95 @@ void ResetReqLock(pclient = -1) {
}
}


// ----------------- server monitor json generator -------
JSON_Array encode_json_server_monitor(int exclient, bool inctoken=true, bool authType=true, bool incmap=false) {
JSON_Array monitor_json = new JSON_Array();
if (inctoken) {
char token[LENGTH_TOKEN];
GetConVarString(g_hCSGOWikiToken, token, LENGTH_TOKEN);
monitor_json.PushString(token);
}
if (exclient == -1) {
monitor_json.PushObject(new JSON_Array());
return monitor_json;
}
if (incmap) {
monitor_json.PushString(g_sCurrentMap);
}
for (int client_id = 0; client_id <= MaxClients; client_id++) {
if(!IsPlayer(client_id) || client_id == exclient) continue;
char client_name[LENGTH_NAME], steamid[LENGTH_STEAMID64], str_ping[4];
GetClientName(client_id, client_name, LENGTH_NAME);
if (authType) {
GetClientAuthId(client_id, AuthId_SteamID64, steamid, LENGTH_STEAMID64)
} else {
GetClientAuthId(client_id, AuthId_Steam2, steamid, LENGTH_STEAMID64)
}
float latency = GetClientAvgLatency(client_id, NetFlow_Both);
IntToString(RoundToNearest(latency * 500), str_ping, sizeof(str_ping));
// json encode
JSON_Array client_arr = new JSON_Array();
client_arr.PushString(client_name);
client_arr.PushString(steamid);
client_arr.PushString(str_ping);
monitor_json.PushObject(client_arr);
}
return monitor_json;
}

// ----------------- check version ----------------------
void PluginVersionHint(client) {
if (StrEqual(g_sLatestVersion, "")) {
PrintToChat(client, "%s 获取版本信息失败:[\x02%s\x01]", PREFIX, g_sLatestInfo);
}
else if (StrEqual(g_sCurrentVersion, g_sLatestVersion)) {
PrintToChat(client, "%s 当前csgowiki插件已为最新版本<\x09%s\x01>", PREFIX, g_sCurrentVersion);
}
else {
PrintToChat(client, "%s 当前服务器csgowiki插件版本<\x0F%s\x01>,最新版本为<\x09%s\x01>", PREFIX, g_sCurrentVersion, g_sLatestVersion);
PrintToChat(client, "%s \x06%s\x01", PREFIX, g_sLatestInfo);
PrintToChat(client, "%s 请及时更新插件避免已有功能失效", PREFIX);
}
}

void PluginVersionCheck(client = -1) {
GetPluginInfo(INVALID_HANDLE, PlInfo_Version, g_sCurrentVersion, LENGTH_VERSION);
System2HTTPRequest PluginVersionCheckRequest = new System2HTTPRequest (
PluginVersionCheckCallback,
"https://api.github.com/repos/hx-w/CSGOWiki-Plugins/releases/latest"
);
PluginVersionCheckRequest.SetHeader("User-Agent", "request");
PluginVersionCheckRequest.Any = client;
PluginVersionCheckRequest.GET();
delete PluginVersionCheckRequest;
}

public PluginVersionCheckCallback(bool success, const char[] error, System2HTTPRequest request, System2HTTPResponse response, HTTPRequestMethod method) {
if (success) {
char[] content = new char[response.ContentLength + 1];
int statusCode = response.StatusCode;
if (statusCode != 200) {
Format(g_sLatestInfo, sizeof(g_sLatestInfo), "github-api访问失败:状态码<%d>", statusCode);
}
else {
response.GetContent(content, response.ContentLength + 1);
JSON_Object resp_json = json_decode(content);
resp_json.GetString("tag_name", g_sLatestVersion, sizeof(g_sLatestVersion));
resp_json.GetString("name", g_sLatestInfo, sizeof(g_sLatestInfo));
json_cleanup_and_delete(resp_json);
}
}
else {
g_sLatestInfo = "github-api访问失败";
}
new client = request.Any;
if (client != -1) {
PluginVersionHint(client);
}
}


// ----------------- hint color message fix --------------
UserMsg g_TextMsg, g_HintText, g_KeyHintText;
static char g_sSpace[1024];
Expand Down
7 changes: 6 additions & 1 deletion scripting/include/global_define.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#define PREFIX "\x01[\x05CSGO Wiki\x01]"

#define LENGTH_VERSION 10
#define LENGTH_TOKEN 33
#define LENGTH_STEAMID64 20 // 17 for usuall
#define LENGTH_STATUS 16
Expand All @@ -29,7 +30,6 @@
Handle g_hCSGOWikiEnable = INVALID_HANDLE;
Handle g_hOnUtilitySubmit = INVALID_HANDLE;
Handle g_hOnUtilityWiki = INVALID_HANDLE;
Handle g_hOnServerMonitor = INVALID_HANDLE;
Handle g_hWikiReqLimit = INVALID_HANDLE;
Handle g_hWikiAutoKicker = INVALID_HANDLE;
Handle g_hChannelEnable = INVALID_HANDLE;
Expand All @@ -43,6 +43,11 @@ new Handle: g_hCSGOWikiToken;
char g_sCurrentMap[LENGTH_MAPNAME];
int g_iServerTickrate;

// 插件版本信息
char g_sCurrentVersion[LENGTH_VERSION];
char g_sLatestVersion[LENGTH_VERSION];
char g_sLatestInfo[LENGTH_MESSAGE];

// --------- steam_bind.sp define -----------
enum StateBind {
e_bUnknown = 0,
Expand Down

0 comments on commit 33eba3c

Please sign in to comment.