private static void OnEnemyConnected(SteamPlayer steamPlayer)
 {
     ChatManager.SendServerMessage(Main.Config.WelcomeMessage, steamPlayer, EChatMode.SAY,
                                   Main.Config.MessageIconUrl, true);
     CombatManager.Accuracies[steamPlayer] = new Accuracy(0, 0);
     CheckBan(steamPlayer);
 }
        private static IEnumerator UnbanPlayerCoroutine(SteamPlayer executor, string target)
        {
            PlayerTool.tryGetSteamPlayer(target, out var steamPlayer);
            PlayerTool.tryGetSteamID(target, out var cSteamID);

            var steamId = steamPlayer?.playerID.steamID ?? cSteamID;

            if (!steamId.IsValid())
            {
                if (executor != null)
                {
                    ChatManager.SendServerMessage("Target not found", executor, EChatMode.SAY);
                }
                else
                {
                    CommandWindow.LogError("Target not found");
                }
                yield break;
            }

            Provider.requestUnbanPlayer(Provider.server, steamId);
            var unbanData = new SocketData("UnbanPlayer", steamId.ToString());

            SocketManager.Emit(unbanData);
            ChatManager.SendServerMessage("Unbanned target successfully", executor, EChatMode.SAY);

            yield return(null);
        }
        private static IEnumerator BanPlayerCoroutine(SteamPlayer executor, string target)
        {
            var ip = 0u;

            if (PlayerTool.tryGetSteamPlayer(target, out var steamPlayer))
            {
                ip = steamPlayer.getIPv4AddressOrZero();
            }
            PlayerTool.tryGetSteamID(target, out var cSteamID);

            var steamId = steamPlayer?.playerID.steamID ?? cSteamID;

            if (!steamId.IsValid())
            {
                if (executor != null)
                {
                    ChatManager.SendServerMessage("Target not found", executor, EChatMode.SAY);
                }
                else
                {
                    CommandWindow.LogError("Target not found");
                }
                yield break;
            }

            Provider.requestBanPlayer(Provider.server, steamId, ip, "Banned", SteamBlacklist.PERMANENT);
            var banData = new SocketData("BanPlayer", steamId.ToString());

            SocketManager.Emit(banData);
            ChatManager.SendServerMessage("Banned target successfully", executor, EChatMode.SAY);

            yield return(null);
        }
        private static async Task MessageReceived(object sender, MessageReceivedEventArgs args)
        {
            try
            {
                if (Encoding.UTF8.GetString(args.Data) == "ack")
                {
                    _ack = Now();
                    return;
                }

                var socketData = JsonConvert.DeserializeObject <SocketData>(Encoding.UTF8.GetString(args.Data));
                switch (socketData.Event)
                {
                case "Close":
                    _forceClosed = true;
                    _client.Dispose();
                    CommandWindow.LogError("Connection Disposed Successfully");
                    break;

                case "Authorization":
                    var authorizationToken = new SocketData("Authorization", Main.Config.AuthorizationToken);
                    Emit(authorizationToken);
                    break;

                case "JoinResponse":
                    var response = JsonConvert.DeserializeObject <JoinResponse>(socketData.Data);
                    if (response.Banned)
                    {
                        PlayerManager.BanPlayer(PlayerTool.getSteamPlayer(Provider.server), response.SteamId);
                    }
                    else
                    {
                        UnityThread.executeCoroutine(BrowserRequest(response.SteamId));
                    }
                    break;

                case "ServerInfo":
                    var data = new ServerInfo(Provider.serverName, Provider.port, Provider.map,
                                              Provider.APP_VERSION, Provider.clients.ToList());
                    var newSocketData = new SocketData("ServerInfo", JsonConvert.SerializeObject(data));
                    Emit(newSocketData);
                    break;

                case "RemoteCommand":
                    var remoteCommand = JsonConvert.DeserializeObject <RemoteCommand>(socketData.Data);
                    UnityThread.executeCoroutine(ExecuteRemoteCommand(remoteCommand));
                    break;

                case "ChatMessage":
                    var remoteChat = JsonConvert.DeserializeObject <ChatMessage>(socketData.Data);
                    ChatManager.DiscordToServer(remoteChat);
                    break;

                case "LinkResponse":
                    var link = JsonConvert.DeserializeObject <Link>(socketData.Data);
                    if (!PlayerTool.tryGetSteamPlayer(link.Steam, out var steamPlayer))
                    {
                        return;
                    }
                    ChatManager.SendServerMessage(
                        link.Discord != ""
                                ? "You have already linked your account"
                                : $"Use ?link {link.Code} in discord!", steamPlayer, EChatMode.SAY);
                    break;

                default:
                    CommandWindow.LogError($"Unexpected Event Received: {socketData.Event}");
                    break;
                }
            }
            catch (Exception ex)
            {
                CommandWindow.LogError(ex);
            }
        }
Exemplo n.º 5
0
 private static async Task AnnounceMessage()
 {
     await ChatManager.SendServerMessage(Main.Config.ChatAnnouncement, null, EChatMode.GLOBAL);
 }