67 lines
1.7 KiB
Plaintext
67 lines
1.7 KiB
Plaintext
/* TWS moderation 1.0.0: native durable policy, connection-safe actions, HTTPS synchronization. */
|
|
#include maps\mp\_utility;
|
|
#include common_scripts\utility;
|
|
// T6 loader probes main and init; initialize only once.
|
|
main()
|
|
{
|
|
}
|
|
|
|
init()
|
|
{
|
|
|
|
scripts\zm\tws_t6_common::ensure_config();
|
|
level.moderation_ready = false;
|
|
scripts\zm\tws_t6_common::register_connect_handler(::moderation_connected);
|
|
level thread moderation_loop();
|
|
}
|
|
|
|
moderation_connected()
|
|
{
|
|
self endon("disconnect");
|
|
if (!level.moderation_ready)
|
|
return;
|
|
moderation_observe(self);
|
|
moderationPump();
|
|
}
|
|
|
|
moderation_observe(player)
|
|
{
|
|
if (!isDefined(player))
|
|
return;
|
|
guid = player.guid;
|
|
if (!isDefined(guid) || (typeof(guid) != "string" && typeof(guid) != "int"))
|
|
return;
|
|
// Preserve large identifiers as strings; native validation rejects ambiguous inputs.
|
|
guid = "" + guid;
|
|
name = player.name;
|
|
if (!isDefined(name))
|
|
name = "Unknown player";
|
|
player moderationObserve(guid, name);
|
|
}
|
|
|
|
moderation_loop()
|
|
{
|
|
for (;;)
|
|
{
|
|
if (GetDvar("tws_moderation_enabled") == "0")
|
|
{
|
|
moderationStop();
|
|
level.moderation_ready = false;
|
|
wait 3;
|
|
continue;
|
|
}
|
|
level.moderation_ready = moderationConfigure(GetDvar("tws_server_id"), GetDvar("tws_moderation_url"),
|
|
GetDvar("tws_moderation_token"), GetDvarInt("tws_moderation_generation"));
|
|
if (!level.moderation_ready)
|
|
{
|
|
wait 3;
|
|
continue;
|
|
}
|
|
players = getPlayers();
|
|
for (i = 0; i < players.size; i++)
|
|
moderation_observe(players[i]);
|
|
moderationPump();
|
|
wait 0.5;
|
|
}
|
|
}
|