• Хостинг игровых серверов

    Максимальная производительность для ваших игровых серверов!

    Заказать сейчас

Обсудим Тревожный список

Kapri

18 Июн 2023
11
0
6
Не знаю может кому и подойдет, сделал код который создает на сервере тревожный список игроков, по наличию Вак бана на стим аккаунте
Прежде чем использовать этот код, замените "YOUR_STEAM_API_KEY" на свой ключ API Steam.
А так же должен быть установлен пакет NuGet SteamKit2.

Обратите внимание, что этот код использует анонимную авторизацию для подключения к Steam.
Для полноценной работы с Steam Web API требуется использование Steam-аккаунта разработчика и ключей API, а так же в зависимости от сборки сервера и модификаций, создается решение на основе Steam API

C#:
using SteamKit2;
using System;
using System.IO;

class Program
{
    static SteamClient steamClient;
    static CallbackManager manager;

    static SteamUser steamUser;
    static SteamFriends steamFriends;

    static string apiKey = "YOUR_STEAM_API_KEY"; // Steam API ключ

    static void Main(string[] args)
    {
        steamClient = new SteamClient();
        manager = new CallbackManager(steamClient);

        steamUser = steamClient.GetHandler<SteamUser>();
        steamFriends = steamClient.GetHandler<SteamFriends>();

        manager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
        manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);

        Console.Write("Enter your Steam username: ");
        string username = Console.ReadLine();

        Console.WriteLine("Connecting to Steam...");
        steamClient.Connect();

        while (true)
        {
            manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
        }
    }

    static void OnConnected(SteamClient.ConnectedCallback callback)
    {
        if (callback.Result != EResult.OK)
        {
            Console.WriteLine($"Failed to connect to Steam: {callback.Result}");
            return;
        }

        Console.WriteLine("Connected to Steam. Logging in...");

        steamUser.LogOnAnonymous();
    }

    static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
    {
        if (callback.Result != EResult.OK)
        {
            Console.WriteLine($"Failed to log in to Steam: {callback.Result}");
            return;
        }

        Console.WriteLine("Logged in to Steam.");

        Console.Write("Enter player's Steam username: ");
        string playerName = Console.ReadLine();

        ulong playerSteamId = GetSteamIdFromUsername(playerName);
        if (playerSteamId != 0)
        {
            CheckVacBan(playerSteamId);
        }
        else
        {
            Console.WriteLine("Failed to get Steam ID for the player.");
        }
    }

    static ulong GetSteamIdFromUsername(string playerName)
    {
        SteamID steamId = new SteamID();
        steamId.SetFromSteam2String(playerName);

        return steamId.ConvertToUInt64();
    }

    static void CheckVacBan(ulong steamId)
    {
        string url = $"https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key={apiKey}&steamids={steamId}";

        using (var webClient = new WebClient())
        {
            try
            {
                string jsonResult = webClient.DownloadString(url);
                dynamic jsonObject = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonResult);

                int vacBans = jsonObject.players[0].NumberOfVACBans;

                if (vacBans > 0)
                {
                    using (StreamWriter writer = File.AppendText("ban_list.txt"))
                    {
                        writer.WriteLine($"Steam ID: {steamId}");
                    }
                    Console.WriteLine("Player has VAC bans.");
                }
                else
                {
                    Console.WriteLine("Player has no VAC bans.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed to retrieve ban information: {ex.Message}");
            }
        }
    }
}
 
Пример кода уже с подключением по STEAM API
C#:
using SteamKit2;
using System;
using System.IO;

class Program
{
    static SteamClient steamClient;
    static CallbackManager manager;

    static SteamUser steamUser;
    static SteamFriends steamFriends;

    static string apiKey = "YOUR_STEAM_API_KEY"; // Steam API ключ

    static void Main(string[] args)
    {
        steamClient = new SteamClient();
        manager = new CallbackManager(steamClient);

        steamUser = steamClient.GetHandler<SteamUser>();
        steamFriends = steamClient.GetHandler<SteamFriends>();

        manager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
        manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);

        Console.Write("Enter your Steam username: ");
        string username = Console.ReadLine();

        Console.WriteLine("Connecting to Steam...");
        steamClient.Connect();

        while (true)
        {
            manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
        }
    }

    static void OnConnected(SteamClient.ConnectedCallback callback)
    {
        if (callback.Result != EResult.OK)
        {
            Console.WriteLine($"Failed to connect to Steam: {callback.Result}");
            return;
        }

        Console.WriteLine("Connected to Steam. Logging in...");

        steamUser.LogOnAnonymous();
    }

    static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
    {
        if (callback.Result != EResult.OK)
        {
            Console.WriteLine($"Failed to log in to Steam: {callback.Result}");
            return;
        }

        Console.WriteLine("Logged in to Steam.");

        Console.Write("Enter player's Steam username: ");
        string playerName = Console.ReadLine();

        ulong playerSteamId = GetSteamIdFromUsername(playerName);
        if (playerSteamId != 0)
        {
            CheckVacBan(playerSteamId);
        }
        else
        {
            Console.WriteLine("Failed to get Steam ID for the player.");
        }
    }

    static ulong GetSteamIdFromUsername(string playerName)
    {
        SteamID steamId = new SteamID();
        steamId.SetFromSteam2String(playerName);

        return steamId.ConvertToUInt64();
    }

    static void CheckVacBan(ulong steamId)
    {
        string url = $"https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key={apiKey}&steamids={steamId}";

        using (var webClient = new WebClient())
        {
            try
            {
                string jsonResult = webClient.DownloadString(url);
                dynamic jsonObject = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonResult);

                int vacBans = jsonObject.players[0].NumberOfVACBans;

                if (vacBans > 0)
                {
                    using (StreamWriter writer = File.AppendText("ban_list.txt"))
                    {
                        writer.WriteLine($"Steam ID: {steamId}");
                    }
                    Console.WriteLine("Player has VAC bans.");
                }
                else
                {
                    Console.WriteLine("Player has no VAC bans.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed to retrieve ban information: {ex.Message}");
            }
        }
    }
}
Интеграция кода с сервером РАСТ ВАНИЛА ( в зависимости от конфигурации сервера исполнение может отличаться)
C#:
using System;
using Steamworks;

class RustServer
{
    private void OnPlayerConnected(BasePlayer player)
    {
        ulong steamId = GetSteamIdFromPlayer(player);
        if (steamId != 0)
        {
            // Передача Steam ID клиентскому коду  с использованием сетевых сообщений или вызова метода клиентского кода
        }
    }

    private ulong GetSteamIdFromPlayer(BasePlayer player)
    {
        CSteamID steamId = player.userID;
        return steamId.m_SteamID;
    }
}
 
Активность
Пока никто не печатает сообщение