/// <summary> /// Sets the rank of a <see cref="ReferenceHub">player</see> by giving a <paramref name="name"/>, <paramref name="color"/>, and setting if it should be shown with <paramref name="show"/>, as well as the <paramref name="rankName"/>, the server should use for permissions. /// </summary> public static void SetRank(this ReferenceHub player, string name, string color, bool show, string rankName) { // Developer note: I bet I just needed to use the show once. But hey, better be safe than sorry. if (ServerStatic.GetPermissionsHandler()._groups.ContainsKey(rankName)) { ServerStatic.GetPermissionsHandler()._groups[rankName].BadgeColor = color; ServerStatic.GetPermissionsHandler()._groups[rankName].BadgeText = name; ServerStatic.GetPermissionsHandler()._groups[rankName].HiddenByDefault = !show; ServerStatic.GetPermissionsHandler()._groups[rankName].Cover = show; player.serverRoles.SetGroup(ServerStatic.GetPermissionsHandler()._groups[rankName], false, false, show); } else { UserGroup ug = new UserGroup() { BadgeColor = color, BadgeText = name, HiddenByDefault = !show, Cover = show }; ServerStatic.GetPermissionsHandler()._groups.Add(rankName, ug); player.serverRoles.SetGroup(ug, false, false, show); } if (ServerStatic.GetPermissionsHandler()._members.ContainsKey(player.GetUserId())) { ServerStatic.GetPermissionsHandler()._members[player.GetUserId()] = rankName; } else { ServerStatic.GetPermissionsHandler()._members.Add(player.GetUserId(), rankName); } }
internal IEnumerator <float> RemoveBroadcasting(ReferenceHub attacker) { yield return(Timing.WaitForSeconds(5f)); if (broadcasting.Contains(attacker.GetUserId())) { broadcasting.Remove(attacker.GetUserId()); } }
internal void BroadCastToPlayer(ReferenceHub attacker, uint v1, string v2) { if (broadcasting.Contains(attacker.GetUserId())) { return; } attacker.Broadcast(v1, v2, false); broadcasting.Add(attacker.GetUserId()); Timing.RunCoroutine(RemoveBroadcasting(attacker)); }
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()}"); } }
public static IEnumerator <float> GrantedLevel(ReferenceHub player, PlayerData data) { yield return(Timing.WaitForSeconds(1f)); var group = player.serverRoles.Group?.Clone(); string level = data.level.ToString(); string rolestr = player.serverRoles.GetUncoloredRoleString(); string rolecolor = player.serverRoles.MyColor; string badge; rolestr = rolestr.Replace("[", string.Empty).Replace("]", string.Empty).Replace("<", string.Empty).Replace(">", string.Empty); if (rolecolor == "light_red") { rolecolor = "pink"; } if (data.level == -1) { level = "?????"; } if (string.IsNullOrEmpty(rolestr)) { badge = $"Level{level}"; } else { badge = $"Level{level} : {rolestr}"; } if (group == null) { group = new UserGroup() { BadgeText = badge, BadgeColor = "default", HiddenByDefault = false, Cover = true, KickPower = 0, Permissions = 0, RequiredKickPower = 0, Shared = false }; } else { group.BadgeText = badge; group.BadgeColor = rolecolor; group.HiddenByDefault = false; group.Cover = true; } player.serverRoles.SetGroup(group, false, false, true); Log.Debug($"[GrantedLevel] {player.GetUserId()} : Level{level}"); yield break; }
private void ResetRevengeTimer(ReferenceHub player) { foreach (var item in teamKillRevengeTimers) { if (item.UserId.Equals(player.GetUserId()) || item.NotRevengeUserId.Equals(player.GetUserId())) { teamKillRevengeTimers[teamKillRevengeTimers.IndexOf(item)].Time = Time.timeSinceLevelLoad; } } }
internal void RACmd(ref RACommandEvent ev) { string[] args = ev.Command.Split(' '); if (args[0].ToLower().StartsWith("mute")) { foreach (string str in args[1].Split('.')) { ReferenceHub hub = Player.GetPlayer(int.Parse(str)); notActualMutedPlayers.Remove(hub.GetUserId()); } } }
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}"); } }
/// <summary> /// Gets a <see cref="Collections.Chat.Player"/> from a <see cref="ReferenceHub"/> /// </summary> /// <param name="player"></param> /// <returns></returns> public static Collections.Chat.Player GetChatPlayer(this ReferenceHub player) { if (player == null || (string.IsNullOrEmpty(player.GetUserId()) && !player.IsHost())) { return(null); } else if (player.IsHost()) { return(ServerChatPlayer); } else if (ChatPlayers.TryGetValue(player, out Collections.Chat.Player chatPlayer)) { return(chatPlayer); } else { return(LiteDatabase.GetCollection <Collections.Chat.Player>().FindOne(queryPlayer => queryPlayer.Id == player.GetRawUserId())); } }
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); }
/// <summary> /// Gets the group name of a <see cref="ReferenceHub"/>. /// </summary> /// <param name="player"></param> /// <returns></returns> public static string GetGroupName(this ReferenceHub player) => ServerStatic.PermissionsHandler._members[player.GetUserId()];
public static string GetRawUserId(this ReferenceHub player) => player.GetUserId().GetRawUserId();
public static string GetAuthentication(this ReferenceHub player) => player.GetUserId().Split('@')[1];
internal void CheckKill(ref PlayerHurtEvent ev, Team team, Team target, ReferenceHub attacker, ReferenceHub player) { if (attacker == null || player == null) { SetAmountZero(ref ev); return; } bool ntf = (target == Team.MTF || target == Team.RSC || ((target == Team.CHI || target == Team.CDP) && player.IsHandCuffed())) && (team == Team.MTF || team == Team.RSC); bool ci = (target == Team.CHI || target == Team.CDP || ((target == Team.MTF || target == Team.RSC) && player.IsHandCuffed())) && (team == Team.CHI || team == Team.CDP); bool scpNear = plugin.useScpNear ? IsScpNearby(player, plugin.maxScpDist) : false; bool inElevator = plugin.useInElevator ? IsNearElevator(player, 20f) : false; if ((ntf || ci)) { if (!teamKills.ContainsKey(attacker.GetUserId())) { teamKills.Add(attacker.GetUserId(), 0); } if (!teamKillTimers.ContainsKey(attacker.GetUserId())) { teamKillTimers.Add(attacker.GetUserId(), 0f); } var curtks = teamKills[attacker.GetUserId()]; if (team == Team.RIP || Time.timeSinceLevelLoad - teamKillTimers[attacker.GetUserId()] <= plugin.TKInterval || scpNear || inElevator || IsTeamSquadNearby(player, team, target, plugin.maxTeamDist)) { SetAmountZero(ref ev); BroadCastToPlayer(attacker, 3, "You cannot teamkill now."); return; } else if (IsPossibleRevenge(ref ev)) { SetAmountZero(ref ev); BroadCastToPlayer(attacker, 3, "You cannot revengekill."); return; } else if (teamKills[attacker.GetUserId()] >= plugin.maxTK) { SetAmountZero(ref ev); BroadCastToPlayer(attacker, 3, "Max teamkills reached."); return; } else if (player.GetHealth() - ev.Amount <= 0f) { teamKills[attacker.GetUserId()]++; attacker.Broadcast(3, "Teamkills Left: " + (plugin.maxTK - (curtks + 1)), false); if (!teamKillTimers.ContainsKey(attacker.GetUserId())) { teamKillTimers.Add(attacker.GetUserId(), Time.timeSinceLevelLoad); } teamKillTimers[attacker.GetUserId()] = Time.timeSinceLevelLoad; var data = new TeamKillCoolDown() { NotRevengeUserId = attacker.GetUserId(), Time = Time.timeSinceLevelLoad, UserId = player.GetUserId() }; teamKillRevengeTimers.Add(data); } } /*else if ((ntf || ci) && (inElevator || scpNear)) * { * ev.Amount = 0f; * BroadCastToPlayer(ev.Attacker, 3, "You cannot teamkill now."); * return; * }*/ }
public void OnPocketDeath(PocketDimDeathEvent ev) { if (Instance.Scp106Healing) { ReferenceHub scp = Player.GetHubs().FirstOrDefault(r => r.GetRole() == RoleType.Scp106); Coroutines.Add(Timing.RunCoroutine(HealOverTime(scp, Instance.Scp106HealAmount), scp.GetUserId())); } }
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); }