Esempio n. 1
0
        public static void AddPlayer(ReferenceHub player)
        {
            try
            {
                if (LiteDatabase.GetCollection <Player>().Exists(x => x.Id == DatabasePlayer.GetRawUserId(player)))
                {
                    return;
                }

                LiteDatabase.GetCollection <Player>().Insert(new Player()
                {
                    Id                   = DatabasePlayer.GetRawUserId(player),
                    Name                 = player.GetNickname(),
                    Authentication       = DatabasePlayer.GetAuthentication(player),
                    ScpSuicideCount      = 0,
                    TotalScpGamesPlayed  = 0,
                    TotalScpSuicideKicks = 0,
                    TotalScpSuicideBans  = 0,
                    FirstJoin            = DateTime.Now,
                    LastSeen             = DateTime.Now,
                    ColorPreference      = "",
                    CustomNickName       = "",
                    BadgeName            = "",
                    BadgeExpire          = DateTime.MinValue,
                    HideBadge            = false
                });
                Log.Info("Trying to add ID: " + player.GetUserId().Split('@')[0] + " Discriminator: " + player.GetUserId().Split('@')[1] + " to Database");
            }
            catch (Exception ex)
            {
                Log.Error($"Cannot add new user to Database: {player.GetNickname()} ({player.GetUserId().Split('@')[0]})!\n{ex.ToString()}");
            }
        }
Esempio n. 2
0
        public (string response, string color) OnCall(ReferenceHub sender, string[] args)
        {
            (string message, bool isValid) = CheckMessageValidity(args.GetMessage(), sender);

            if (!isValid)
            {
                return(message, "red");
            }

            message = $"[{sender.GetNickname()}][{Language.Team} ({sender.GetRole().ToString().ToUpper()})]: {message}";

            IEnumerable <ReferenceHub>     targets     = Player.GetHubs().Where(chatPlayer => chatPlayer != sender && chatPlayer.GetTeam() == sender.GetTeam());
            List <Collections.Chat.Player> chatTargets = targets.GetChatPlayers();

            if (chatTargets.Count == 0)
            {
                return(Language.NoAvailablePlayersToChatWithError, "red");
            }

            color = sender.GetColor();

            if (Configs.saveChatToDatabase)
            {
                SaveMessage(message, sender.GetChatPlayer(), chatTargets, type);
            }

            SendMessage(ref message, sender, targets);

            return(message, color);
        }
Esempio n. 3
0
        public (string response, string color) OnCall(ReferenceHub sender, string[] args)
        {
            (string message, bool isValid) = CheckMessageValidity(args.GetMessage(), sender);

            if (!isValid)
            {
                return(message, "red");
            }

            message = $"[{sender.GetNickname()}][{Language.Public}]: {message}";

            IEnumerable <ReferenceHub> targets = Player.GetHubs().Where(target =>
            {
                return(sender != target && (Configs.canSpectatorSendMessagesToAlive || sender.GetTeam() != Team.RIP || target.GetTeam() == Team.RIP));
            });

            List <Collections.Chat.Player> chatPlayers = targets.GetChatPlayers();

            if (chatPlayers.Count == 0)
            {
                return(Language.NoAvailablePlayersToChatWithError, "red");
            }

            if (Configs.saveChatToDatabase)
            {
                SaveMessage(message, sender.GetChatPlayer(), chatPlayers, type);
            }

            SendMessage(ref message, sender, targets);

            return(message, color);
        }
Esempio n. 4
0
        public static GameObject SpawnDummyModel(ReferenceHub hub, Vector3 position, Quaternion rotation, RoleType role, float x, float y, float z)
        {
            GameObject            gameObject = Object.Instantiate(NetworkManager.singleton.spawnPrefabs.FirstOrDefault((GameObject p) => p.gameObject.name == "Player"));
            CharacterClassManager component  = gameObject.GetComponent <CharacterClassManager>();

            component.CurClass = role;
            component.RefreshPlyModel(role);
            gameObject.GetComponent <NicknameSync>().Network_myNickSync = $"{hub.GetNickname()}'s Pet";
            gameObject.GetComponent <QueryProcessor>().PlayerId         = 9999;
            gameObject.GetComponent <QueryProcessor>().NetworkPlayerId  = 9999;
            gameObject.transform.localScale = new Vector3(x, y, z);
            gameObject.transform.position   = position;
            gameObject.transform.rotation   = rotation;
            return(gameObject);
        }
Esempio n. 5
0
        public (string response, string color) OnCall(ReferenceHub sender, string[] args)
        {
            (string message, bool isValid) = CheckMessageValidity(args.GetMessage(1), sender);

            if (!isValid)
            {
                return(message, "red");
            }

            message = $"[{sender.GetNickname()}][{Language.Private}]: {message}";

            ReferenceHub target = Player.GetPlayer(args[0]);

            if (target == null)
            {
                return(string.Format(Language.PlayerNotFoundError, args[0]), "red");
            }
            else if (sender == target)
            {
                return(Language.CannotSendMessageToThemselvesError, "red");
            }
            else if (!Configs.canSpectatorSendMessagesToAlive && sender.GetTeam() == Team.RIP && target.GetTeam() != Team.RIP)
            {
                return(Language.CannotSendMessageToAlivePlayersError, "red");
            }

            if (Configs.saveChatToDatabase)
            {
                SaveMessage(message, sender.GetChatPlayer(), new List <Collections.Chat.Player>()
                {
                    sender.GetChatPlayer()
                }, type);
            }

            SendMessage(ref message, sender, new List <ReferenceHub>()
            {
                target
            });

            if (Configs.showPrivateMessageNotificationBroadcast)
            {
                target.ClearBroadcasts();
                target.Broadcast(Configs.privateMessageNotificationBroadcastDuration, Configs.privateMessageNotificationBroadcast, false);
            }

            return(message, color);
        }
Esempio n. 6
0
        public static void Postfix(ConsumableAndWearableItems __instance, int mid)
        {
            ReferenceHub player   = ReferenceHub.GetHub(__instance.gameObject);
            ItemType     itemtype = __instance.usableItems[mid].inventoryID;

            Log.Debug($"[MedicalUsedPatch] {player?.GetNickname()} mid:{mid}/{itemtype}");

            if (itemtype == ItemType.Medkit || itemtype == ItemType.SCP500)
            {
                if (Coroutines.DOTDamages.TryGetValue(player, out CoroutineHandle handle))
                {
                    Log.Debug($"[939DOT] Removed {player.GetNickname()}");
                    Timing.KillCoroutines(handle);
                    Coroutines.DOTDamages.Remove(player);
                }
            }
        }
Esempio n. 7
0
        public static void SendReport(ReferenceHub reported, string reason, ReferenceHub reporter)
        {
            var hookdata = new WebhookData();
            var embed    = new Embed
            {
                title     = "ゲームサーバーからの報告",
                timestamp = DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss.fffZ")
            };

            embed.footer.text = $"報告者:{reporter.GetNickname()} [{reporter.GetUserId()}]";
            embed.fields.Add(new EmbedField()
            {
                name = "発見サーバー", value = $"{FormatServerName()}"
            });
            embed.fields.Add(new EmbedField()
            {
                name = "対象プレイヤー名", value = $"{reported.GetNickname()}", inline = true
            });
            embed.fields.Add(new EmbedField()
            {
                name = "対象プレイヤーID", value = $"{reported.GetUserId()}", inline = true
            });
            embed.fields.Add(new EmbedField()
            {
                name = "内容", value = $"{reason}"
            });
            hookdata.embeds.Add(embed);

            var json   = Utf8Json.JsonSerializer.ToJsonString <WebhookData>(hookdata);
            var data   = new StringContent(json, Encoding.UTF8, "application/json");
            var result = httpClient.PostAsync(Configs.report_webhook, data).Result;

            Log.Debug($"{json}");

            if (result.IsSuccessStatusCode)
            {
                Log.Info($"[SendReport] Send Report.");
            }
            else
            {
                Log.Error($"[SendReport] Error. {result.StatusCode}");
            }
        }
Esempio n. 8
0
        public static bool Prefix(CheaterReport __instance, int playerId, string reason)
        {
            ReferenceHub reported = Player.GetPlayer(playerId);
            ReferenceHub reporter = Player.GetPlayer(__instance.gameObject);

            Log.Debug($"[ReportPatch] Reported:{reported.GetNickname()} Reason:{reason} Reporter:{reporter.GetNickname()}");

            if (!string.IsNullOrEmpty(Configs.report_webhook) &&
                !string.IsNullOrEmpty(reporter.GetUserId()) &&
                !string.IsNullOrEmpty(reported.GetUserId()) &&
                reported.GetPlayerId() != reporter.GetPlayerId())
            {
                Methods.SendReport(reported, reason, reporter);
                __instance.GetComponent <GameConsoleTransmission>().SendToClient(__instance.connectionToClient, "Player report successfully sent.", "green");
                return(false);
            }

            return(true);
        }
Esempio n. 9
0
        public static IEnumerator <float> DOTDamage(ReferenceHub target, int perDamage, int maxLimitDamage, float interval, DamageTypes.DamageType type)
        {
            int      curDamageAmount = 0;
            Vector3  curDeathPos     = target.characterClassManager.NetworkDeathPosition;
            RoleType curRole         = target.GetRole();

            while (curDamageAmount < maxLimitDamage)
            {
                if (target.characterClassManager.NetworkDeathPosition != curDeathPos || target.GetRole() != curRole)
                {
                    break;
                }
                target.playerStats.HurtPlayer(new PlayerStats.HitInfo(perDamage, "WORLD", type, 0), target.gameObject);
                curDamageAmount += perDamage;
                yield return(Timing.WaitForSeconds(interval));
            }
            if (DOTDamages.ContainsKey(target))
            {
                Log.Debug($"[939DOT] Removed {target.GetNickname()}");
                DOTDamages.Remove(target);
            }
            yield break;
        }
Esempio n. 10
0
        public static bool CheckPermission(ReferenceHub player, string permission)
        {
            if (player == null)
            {
                Log.Error("Reference hub was null, unable to check permissions.");
                return(false);
            }

            Log.Debug($"Player: {player.GetNickname()} UserID: {player.GetUserId()}");
            if (string.IsNullOrEmpty(permission))
            {
                Log.Error("Permission checked was null.");
                return(false);
            }

            Log.Debug($"Permission string: {permission}");
            UserGroup userGroup = ServerStatic.GetPermissionsHandler().GetUserGroup(player.GetUserId());
            Group     group     = null;

            if (userGroup != null)
            {
                Log.Debug($"UserGroup: {userGroup.BadgeText}");
                string groupName = ServerStatic.GetPermissionsHandler()._groups.FirstOrDefault(g => g.Value == player.serverRoles.Group).Key;
                Log.Debug($"GroupName: {groupName}");
                if (permissionsconfig == null)
                {
                    Log.Error("Permissions config is null.");
                    return(false);
                }

                if (!permissionsconfig.groups.Any())
                {
                    Log.Error("No permissionconfig groups.");
                    return(false);
                }

                if (!permissionsconfig.groups.TryGetValue(groupName, out group))
                {
                    Log.Error("Could not get permission value.");
                    return(false);
                }
                Log.Debug($"Got group.");
            }
            else
            {
                Log.Debug("user group is null, getting default..");
                group = GetDefaultGroup();
            }

            if (group != null)
            {
                Log.Debug("Group is not null!");
                if (permission.Contains("."))
                {
                    Log.Debug("Group contains perm seperator");
                    if (group.permissions.Any(s => s == ".*"))
                    {
                        Log.Debug("All perms granted for all nodes.");
                        return(true);
                    }
                    if (group.permissions.Contains(permission.Split('.')[0] + ".*"))
                    {
                        Log.Debug("Check 1: True, returning.");
                        return(true);
                    }
                }

                if (group.permissions.Contains(permission) || group.permissions.Contains("*"))
                {
                    Log.Debug("Check 2: True, returning.");
                    return(true);
                }
            }
            else
            {
                Log.Debug("Group is null, returning false.");
                return(false);
            }
            Log.Debug("No permissions found.");
            return(false);
        }
        public void RunOnRACommandSent(ref RACommandEvent RAComEv)
        {
            string[]     Arguments = RAComEv.Command.Split(' ');
            ReferenceHub Sender    = RAComEv.Sender.SenderId == "SERVER CONSOLE" || RAComEv.Sender.SenderId == "GAME CONSOLE" ? PlayerManager.localPlayer.GetPlayer() : Player.GetPlayer(RAComEv.Sender.SenderId);

            switch (Arguments[0].ToLower())
            {
            case "ri":
            case "removeinv":
            case "strip":
                RAComEv.Allow = false;
                if (!Sender.CheckPermission("ri.allow"))
                {
                    RAComEv.Sender.RAMessage("You are not authorized to use this command!");
                    return;
                }

                try
                {
                    if (!CheckIfIdIsValid(Int32.Parse(Arguments[1])))
                    {
                        RAComEv.Sender.RAMessage("Please enter in an ID from a player that exists in the game!");
                        return;
                    }

                    ReferenceHub ChosenPlayer = Player.GetPlayer(int.Parse(Arguments[1]));
                    ChosenPlayer.inventory.ServerDropAll();
                    RAComEv.Sender.RAMessage("All items in player \"" + ChosenPlayer.GetNickname() + "\"'s inventory has been removed!");
                }
                catch (Exception)
                {
                    RAComEv.Sender.RAMessage("Please enter a valid ID!");
                    return;
                }
                break;

            case "clear":
                RAComEv.Allow = false;
                if (!Sender.CheckPermission("ri.clear.allow"))
                {
                    RAComEv.Sender.RAMessage("You are not authorized to use this command!");
                    return;
                }

                try
                {
                    if (!CheckIfIdIsValid(Int32.Parse(Arguments[1])))
                    {
                        RAComEv.Sender.RAMessage("Please enter in an ID from a player that exists in the game!");
                        return;
                    }

                    ReferenceHub ChosenPlayer = Player.GetPlayer(int.Parse(Arguments[1]));
                    ChosenPlayer.ClearInventory();
                    RAComEv.Sender.RAMessage("All items in player \"" + ChosenPlayer.GetNickname() + "\"'s inventory has been cleared!");
                }
                catch (Exception)
                {
                    RAComEv.Sender.RAMessage("Please enter a valid ID!");
                    return;
                }
                break;
            }
        }