Мини-скрипт, добавляющий команды getplayerpurchases steamid_32
и disablepurchase purchase_id
, позволяющие дать, например, персоналу возможность смотреть и отключать донат услуги игроков через клиентскую консоль
addons/igs-modification/lua/autorun/manage_player_purchases.lua
if SERVER then
util.AddNetworkString("IGS.RequestPlayerPurchases")
local function isPlayerHasAccess(pl)
return pl:IsSuperAdmin()
end
local function echoPlayerPurchases(pl, purchases)
net.Start("IGS.RequestPlayerPurchases")
net.WriteString(purchases[1] and purchases[1].Nick or "noname")
for i,purch in ipairs(purchases) do
purchases[i].Nick = nil -- unset nick for minify network size
end
net.WriteTable(purchases)
net.Send(pl)
end
net.Receive("IGS.RequestPlayerPurchases", function(_, pl)
if not isPlayerHasAccess(pl) then return end
IGS.GetPurchases(function(purchases)
echoPlayerPurchases(pl, purchases)
end, {
sid = net.ReadString(),
only_active = 1
})
end)
util.AddNetworkString("IGS.RequestDisablingPurchase")
local function echoDisablingResult(pl, bDisabled)
net.Start("IGS.RequestDisablingPurchase")
net.WriteBool(bDisabled)
net.Send(pl)
end
net.Receive("IGS.RequestDisablingPurchase", function(_, pl)
if not isPlayerHasAccess(pl) then return end
local purchase_id = net.ReadUInt(IGS.BIT_PURCH_ID)
IGS.DisablePurchase(purchase_id, function(bDisabled)
echoDisablingResult(pl, bDisabled)
end)
end)
return
end
local function echoPlayerPurchases(nick, purchases)
if #purchases == 0 then
print("У игрока нет активных покупок")
return
end
local line_patt = "ID: {purchase_id}\nName: {item_name}\nServer: {server_name}\nDate: {purchase_date}"
print("Purchases of " .. nick)
for _,purch in ipairs(purchases) do
local item_name = purch.Item
local ITEM = IGS.GetItemByUID(purch.Item)
if not ITEM.isnull then item_name = ITEM:Name() end
local str = line_patt
:gsub("{purchase_id}", purch.ID)
:gsub("{item_name}", item_name)
:gsub("{server_name}", IGS.ServerName(purch.Server))
:gsub("{purchase_date}", IGS.TimestampToDate(purch.Purchase, true) or "wtf? err")
print(str)
end
end
net.Receive("IGS.RequestPlayerPurchases", function()
local player_name = net.ReadString()
local purchases = net.ReadTable() -- нет нужды микрооптимизации
echoPlayerPurchases(player_name, purchases)
end)
local function requestPlayerPurchasesFromServer(s64)
net.Start("IGS.RequestPlayerPurchases")
net.WriteString(s64)
net.SendToServer()
end
local function isSteamID32(str) return str:match('^STEAM_%d:%d:%d+$') end
concommand.Add("getplayerpurchases", function(_, _, _, argss)
if not isSteamID32(argss or "") then print("Нужно указать SteamID игрока") return end
requestPlayerPurchasesFromServer(util.SteamIDTo64(argss))
end)
net.Receive("IGS.RequestDisablingPurchase", function()
local bDisabled = net.ReadBool()
print("Услуга " .. (bDisabled and "отключена" or "уже отключена"))
end)
local function requestDisablingPurchase(purchase_id)
net.Start("IGS.RequestDisablingPurchase")
net.WriteUInt(purchase_id, IGS.BIT_PURCH_ID)
net.SendToServer()
end
concommand.Add("disablepurchase", function(_, _, args)
if not tonumber(args[1]) then print("Нужно указать ID покупки, полученный через getplayerpurchases") return end
requestDisablingPurchase(args[1])
end)