Esempio n. 1
0
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            bool canrun = CommandManager.CanRun(sender, PlayerPermissions.FacilityManagement, out response);

            if (!canrun)
            {
                return(canrun);
            }

            isLightsout = !isLightsout;
            foreach (FlickerableLightController lightController in Object.FindObjectsOfType <FlickerableLightController>())
            {
                Scp079Interactable interactable = lightController.GetComponent <Scp079Interactable>();
                if (interactable == null || interactable.type != Scp079Interactable.InteractableType.LightController)
                {
                    continue;
                }

                lightController.ServerFlickerLights(isLightsout ? 100000f : 0f);
            }

            if (isLightsout)
            {
                foreach (var player in ReferenceHub.GetAllHubs())
                {
                    player.Value.inventory.AddNewItem(ItemType.Flashlight);
                }
            }

            response = $"Facility lights have been {(isLightsout ? "disabled" : "enabled")}!";
            return(canrun);
        }
Esempio n. 2
0
        private string Playerlist()
        {
            if (PlayerManager.players.Count < 1)
            {
                if ((DateTime.Now - Events.RoundEnded).TotalSeconds < 45)
                {
                    return("*The round has recently restarted, so the playercount may not be accurate*\n**No online players**");
                }
                else
                {
                    return("**No online players**");
                }
            }

            List <string> players = new List <string>();

            foreach (var hub in ReferenceHub.GetAllHubs().Values)
            {
                if (string.Equals(hub.nicknameSync.MyNick, "Dedicated Server", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                else if (!hub.serverRoles.DoNotTrack)
                {
                    players.Add(_filterNames.Replace(hub.nicknameSync.MyNick, string.Empty));
                }
                else
                {
                    players.Add("DNTUser");
                }
            }

            return($"**{PlayerManager.players.Count()}/{ConfigFile.ServerConfig.GetInt("max_players", 20)}**\n```\n{string.Join(", ", players)}```");
        }
        private static bool Prefix(RespawnTickets __instance, ref SpawnableTeamType __result)
        {
            bool flag = false;

            foreach (KeyValuePair <GameObject, ReferenceHub> allHub in ReferenceHub.GetAllHubs())
            {
                if ((allHub.Value.characterClassManager.CurClass == RoleType.Spectator &&
                     !allHub.Value.serverRoles.OverwatchEnabled) || API.IsGhost(Player.Get(allHub.Value)))
                {
                    flag = true;
                    break;
                }
            }

            if (!flag)
            {
                __result = SpawnableTeamType.None;
            }
            List <SpawnableTeamType> list1 = ListPool <SpawnableTeamType> .Shared.Rent();

            List <SpawnableTeamType> list2 = ListPool <SpawnableTeamType> .Shared.Rent();

            foreach (KeyValuePair <SpawnableTeamType, int> ticket in __instance._tickets)
            {
                if (ticket.Value > 0)
                {
                    for (int index = 0; index < ticket.Value; ++index)
                    {
                        list1.Add(ticket.Key);
                    }
                }
                else
                {
                    if (ticket.Value == 0 &&
                        RespawnWaveGenerator.SpawnableTeams.TryGetValue(ticket.Key, out var spawnableTeam) &&
                        spawnableTeam.LockUponZero)
                    {
                        list2.Add(ticket.Key);
                    }
                }
            }

            while (list2.Count > 0)
            {
                __instance._tickets[list2[0]] = -1;
                list2.RemoveAt(0);
            }

            int num = list1.Count == 0 ? 1 : (int)list1[Random.Range(0, list1.Count)];

            ListPool <SpawnableTeamType> .Shared.Return(list1);

            ListPool <SpawnableTeamType> .Shared.Return(list2);

            __result = (SpawnableTeamType)num;
            return(false);
        }
Esempio n. 4
0
        public new bool BanUser(GameObject user, int duration, string reason, string issuer, bool isGlobalBan)
        {
            bool result = orig_BanUser(user, duration, reason, issuer, isGlobalBan);

            if (result)
            {
                try
                {
                    var hubs  = ReferenceHub.GetAllHubs().ToList();
                    int index = hubs.FindIndex(plr => plr.Value.nicknameSync.MyNick == issuer);

                    if (index > -1)
                    {
                        if (isGlobalBan)
                        {
                            try
                            {
                                Base.Debug("Triggering GlobalBanEvent");
                                PluginManager.TriggerEvent <IEventHandlerGlobalBan>(new GlobalBanEvent(new PheggPlayer(user)));
                            }
                            catch (Exception e)
                            {
                                Base.Error($"Error triggering GlobalBanEvent: {e.InnerException}");
                            }
                        }
                        else if (duration < 1)
                        {
                            try
                            {
                                Base.Debug("Triggering PlayerKickEvent");
                                PluginManager.TriggerEvent <IEventHandlerPlayerKick>(new PlayerKickEvent(new PheggPlayer(user), new PheggPlayer(hubs[index].Key), reason));
                            }
                            catch (Exception e)
                            {
                                Base.Error($"Error triggering PlayerKickEvent: {e.InnerException}");
                            }
                        }
                        else
                        {
                            try
                            {
                                Base.Debug("Triggering PlayerBanEvent");
                                PluginManager.TriggerEvent <IEventHandlerPlayerBan>(new PlayerBanEvent(new PheggPlayer(user), duration, new PheggPlayer(hubs[index].Key), reason));
                            }
                            catch (Exception e)
                            {
                                Base.Error($"Error triggering PlayerBanEvent: {e.InnerException}");
                            }
                        }
                    }
                }
                catch (Exception) { }
            }

            return(result);
        }
Esempio n. 5
0
        private static bool Prefix(ShootingTarget __instance, ref bool __result, float damage, DamageHandlerBase handler, Vector3 exactHit)
        {
            try
            {
                if (handler is not AttackerDamageHandler attackerDamageHandler)
                {
                    __result = false;
                    return(false);
                }

                if (attackerDamageHandler.Attacker.Hub is null)
                {
                    __result = false;
                    return(false);
                }

                DamagingShootingTargetEventArgs ev = new(
                    Player.Get(attackerDamageHandler.Attacker.Hub),
                    damage,
                    Vector3.Distance(attackerDamageHandler.Attacker.Hub.transform.position, __instance._bullsEye.position),
                    exactHit,
                    __instance,
                    handler);
                Handlers.Player.OnDamagingShootingTarget(ev);

                if (!ev.IsAllowed)
                {
                    __result = false;
                    return(false);
                }

                foreach (ReferenceHub referenceHub in ReferenceHub.GetAllHubs().Values)
                {
                    if (__instance._syncMode || referenceHub == attackerDamageHandler.Attacker.Hub)
                    {
                        __instance.TargetRpcReceiveData(referenceHub.characterClassManager.connectionToClient, ev.Amount, ev.Distance, exactHit, handler);
                    }
                }

                __result = true;
                return(false);
            }
            catch (Exception exception)
            {
                Log.Error($"{typeof(DamagingShootingTarget).FullName}.{nameof(Prefix)}:\n{exception}");
                return(false);
            }
        }
Esempio n. 6
0
        private static List <ReferenceHub> GetNearbyPlayersGrenade(Vector3 position)
        {
            List <ReferenceHub> nearbyPlayers = new List <ReferenceHub>();

            foreach (var hub in ReferenceHub.GetAllHubs().Values)
            {
                float distance = Vector3.Distance(position, hub.playerMovementSync.RealModelPosition);

                if (distance < 8.5)
                {
                    nearbyPlayers.Add(hub);
                }
            }

            return(nearbyPlayers);
        }
Esempio n. 7
0
        //Only Debug Events
        private void OnKey(KeyPressEvent ev)
        {
            if (ev.Key == KeyCode.Alpha1)
            {
                var dm = new Dummy(ev.Player.Position, Quaternion.identity, ev.Player.Role, "first", "First", "yellow");
                dm.Name     = "second";
                dm.HeldItem = ItemType.GunLogicer;
                var pos = ev.Player.Position;
                pos.y      += 2;
                dm.Position = pos;
                dm.Role     = RoleType.Scientist;

                Timing.CallDelayed(2f, () =>
                {
                    dm.Scale     = Vector3.one * 2;
                    dm.BadgeName = "TestBadge";
                });

                Timing.CallDelayed(5f, () =>
                {
                    dm.BadgeColor = "red";
                });

                Timing.CallDelayed(10f, () => dm.Destroy());
            }
            if (ev.Key == KeyCode.Alpha2)
            {
                var msg = "";
                foreach (var player in Player.GetAllPlayers())
                {
                    msg += $"\n{player}";
                }

                ev.Player.SendConsoleMessage(msg);
            }
            if (ev.Key == KeyCode.Alpha3)
            {
                var msg = "";
                foreach (var player in ReferenceHub.GetAllHubs())
                {
                    msg += $"\n{player}";
                }

                ev.Player.SendConsoleMessage(msg);
            }
        }
Esempio n. 8
0
        public static bool Prefix(Scp096 __instance)
        {
            if (__instance._flash.IsEnabled)
            {
                return(false);
            }

            Vector3 vector = __instance.Hub.transform.TransformPoint(Scp096._headOffset);

            foreach (KeyValuePair <GameObject, ReferenceHub> keyValuePair in ReferenceHub.GetAllHubs())
            {
                ReferenceHub          value = keyValuePair.Value;
                CharacterClassManager characterClassManager = value.characterClassManager;
                if (characterClassManager.CurClass != RoleType.Spectator &&
                    !value.isDedicatedServer &&
                    !(value == __instance.Hub) &&
                    !characterClassManager.IsAnyScp() &&
                    Vector3.Dot((value.PlayerCameraReference.position - vector).normalized, __instance.Hub.PlayerCameraReference.forward) >= 0.1f)
                {
                    VisionInformation visionInformation = VisionInformation.GetVisionInformation(value, vector, -0.1f, 60f, true, true, __instance.Hub.localCurrentRoomEffects, 0);
                    bool toEnrage = visionInformation.IsLooking;

                    //Add touch check
                    if (!toEnrage && SanyaPlugin.Instance.Config.Scp096TouchEnrageDistance > visionInformation.Distance)
                    {
                        toEnrage = !Physics.Linecast(value.PlayerCameraReference.position, vector, VisionInformation.VisionLayerMask);
                    }

                    if (toEnrage)
                    {
                        float delay = visionInformation.LookingAmount / 0.25f * (visionInformation.Distance * 0.1f);
                        if (!__instance.Calming)
                        {
                            __instance.AddTarget(value.gameObject);
                        }
                        if (__instance.CanEnrage && value.gameObject != null)
                        {
                            __instance.PreWindup(delay);
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 9
0
        private static List <ReferenceHub> GetNearbyPlayers(FFInfo ffInfo)
        {
            List <ReferenceHub> nearbyPlayers = new List <ReferenceHub>();

            PlayerMovementSync pms = ffInfo.Attacker.playerMovementSync;
            float distanceCheck    = ffInfo.Attacker.playerMovementSync.RealModelPosition.y > 900 ? 90 : 40;

            foreach (var hub in ReferenceHub.GetAllHubs().Values)
            {
                float angle    = Vector3.Angle(pms.transform.forward, pms.transform.position - hub.playerMovementSync.transform.position);
                float distance = Vector3.Distance(pms.RealModelPosition, hub.playerMovementSync.RealModelPosition);

                if (distance <= distanceCheck && angle > 130 || distance < 5)
                {
                    nearbyPlayers.Add(hub);
                }
            }

            return(nearbyPlayers);
        }
Esempio n. 10
0
        private IEnumerator <float> timeowo()
        {
            Cassie.DelayedMessage("pitch_0.98 Danger . Light Containment Zone overall decontamination in T minus 30 seconds . All checkpoint doors have been opened. Please evacuate immediately . . . . 20 .19 . 18 . 17 . 16 . 15 . 14 . 13 . 12 . 11 . 10 seconds 9 . 8 . 7 . 6 . 5 . 4 . 3 . 2 . 1 . . . . Light containment zone is lockdown and ready for decontamination the termination of all biological forms has now begun", 0f, false, true);
            yield return(Timing.WaitForSeconds(40f));

            Map.StartDecontamination();
            using (Dictionary <GameObject, ReferenceHub> .Enumerator enumerator = ReferenceHub.GetAllHubs().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    KeyValuePair <GameObject, ReferenceHub> keyValuePair = enumerator.Current;
                    ReferenceHub value = keyValuePair.Value;
                    if (value.transform.position.y < 100f && value.transform.position.y > 100f)
                    {
                        value.playerEffectsController.EnableEffect <Decontaminating>(0f, false);
                    }
                }
                yield break;
            }
        }
Esempio n. 11
0
 // Token: 0x06000015 RID: 21 RVA: 0x00002771 File Offset: 0x00000971
 private static IEnumerator <float> RunSelfHealing()
 {
     for (;;)
     {
         foreach (ReferenceHub hub in ReferenceHub.GetAllHubs().Values)
         {
             try
             {
                 EventHandlers.DoSelfHealing(hub);
             }
             catch (Exception arg)
             {
                 Log.Error(string.Format("Please report this error to Nekonyx#2752: {0}", arg));
             }
             yield return(float.NegativeInfinity);
         }
         Dictionary <GameObject, ReferenceHub> .ValueCollection.Enumerator enumerator = default(Dictionary <GameObject, ReferenceHub> .ValueCollection.Enumerator);
         yield return(Timing.WaitForSeconds(1f));
     }
 }
Esempio n. 12
0
        private static bool FirearmPlaySound(this Firearm firearm, byte clipId)
        {
            FirearmAudioClip firearmAudioClip = firearm.AudioClips[clipId];
            ReferenceHub     owner            = firearm.Owner;

            float num = firearmAudioClip.HasFlag(FirearmAudioFlags.ScaleDistance) ? (firearmAudioClip.MaxDistance * firearm.AttachmentsValue(AttachmentParam.GunshotLoudnessMultiplier)) : firearmAudioClip.MaxDistance;

            if (firearmAudioClip.HasFlag(FirearmAudioFlags.IsGunshot) && owner.transform.position.y > 900f)
            {
                num *= 2.3f;
            }

            float soundReach = num * num;

            foreach (ReferenceHub referenceHub in ReferenceHub.GetAllHubs().Values)
            {
                var player = referenceHub.GetPlayer();
                if (player == null || player.IsDummy)
                {
                    return(false);
                }
                if (referenceHub != firearm.Owner)
                {
                    RoleType curClass = referenceHub.characterClassManager.CurClass;
                    if (curClass == RoleType.Spectator || curClass == RoleType.Scp079 || (referenceHub.transform.position - owner.transform.position).sqrMagnitude <= soundReach)
                    {
                        referenceHub.networkIdentity.connectionToClient.Send(new GunAudioMessage(owner, clipId, (byte)Mathf.RoundToInt(Mathf.Clamp(num, 0f, 255f)), referenceHub), 0);
                    }
                }
            }

            Action <Firearm, byte, float> serverSoundPlayed = FirearmExtensions.ServerSoundPlayed;

            if (serverSoundPlayed == null)
            {
                return(false);
            }

            serverSoundPlayed.Invoke(firearm, clipId, num);
            return(false);
        }
Esempio n. 13
0
        private static bool Prefix(TeslaGateController __instance)
        {
            foreach (KeyValuePair<GameObject, ReferenceHub> allHub in ReferenceHub.GetAllHubs())
            {
                if (allHub.Value.characterClassManager.CurClass == RoleType.Spectator)
                    continue;
                foreach (TeslaGate teslaGate in __instance.TeslaGates)
                {
                    if (!teslaGate.PlayerInRange(allHub.Value) || teslaGate.InProgress)
                        continue;

                    var ev = new TriggeringTeslaEventArgs(API.Features.Player.Get(allHub.Key), teslaGate.PlayerInHurtRange(allHub.Key));
                    Player.OnTriggeringTesla(ev);

                    if (ev.IsTriggerable)
                        teslaGate.ServerSideCode();
                }
            }

            return false;
        }
Esempio n. 14
0
        private static bool PlayExplosionEffects(FlashbangGrenade __instance)
        {
            try
            {
                float time = __instance._blindingOverDistance.keys[__instance._blindingOverDistance.length - 1].time;
                float num  = time * time;
                foreach (KeyValuePair <GameObject, ReferenceHub> keyValuePair in ReferenceHub.GetAllHubs())
                {
                    if (!(keyValuePair.Value == null) && (__instance.transform.position - keyValuePair.Value.transform.position).sqrMagnitude <= num && !(keyValuePair.Value == __instance.PreviousOwner.Hub) && HitboxIdentity.CheckFriendlyFire(__instance.PreviousOwner.Hub, keyValuePair.Value, false))
                    {
                        __instance.ProcessPlayer(keyValuePair.Value);
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                Logger.Get.Error($"Synapse-FF: PlayExplosionFlash failed!!\n{ex}");
                return(true);
            }
        }
Esempio n. 15
0
        private static bool Prefix(TeslaGateController __instance)
        {
            try
            {
                foreach (KeyValuePair <GameObject, ReferenceHub> allHub in ReferenceHub.GetAllHubs())
                {
                    if (allHub.Value.characterClassManager.CurClass == RoleType.Spectator)
                    {
                        continue;
                    }
                    foreach (TeslaGate teslaGate in __instance.TeslaGates)
                    {
                        if (!teslaGate.PlayerInRange(allHub.Value) || teslaGate.InProgress)
                        {
                            continue;
                        }

                        var ev = new TriggeringTeslaEventArgs(API.Features.Player.Get(allHub.Key), teslaGate.PlayerInHurtRange(allHub.Key));
                        Player.OnTriggeringTesla(ev);

                        if (ev.IsTriggerable)
                        {
                            teslaGate.ServerSideCode();
                        }
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                Exiled.API.Features.Log.Error($"Exiled.Events.Patches.Events.Player.TriggeringTesla: {e}\n{e.StackTrace}");

                return(true);
            }
        }
Esempio n. 16
0
        public static bool Prefix(RespawnManager __instance)
        {
            try
            {
                if (!RespawnWaveGenerator.SpawnableTeams.TryGetValue(__instance.NextKnownTeam, out var spawnableTeam) || __instance.NextKnownTeam == SpawnableTeamType.None)
                {
                    ServerConsole.AddLog("Fatal error. Team '" + __instance.NextKnownTeam.ToString() + "' is undefined.", (ConsoleColor)12);
                    return(false);
                }
                var list = ReferenceHub.GetAllHubs().Values.Where((item) => item.characterClassManager.CurClass == RoleType.Spectator && !item.serverRoles.OverwatchEnabled).ToList();
                if (__instance._prioritySpawn)
                {
                    list = list.OrderBy((item) => item.characterClassManager.DeathTime).ToList();
                }
                else
                {
                    list.ShuffleList();
                }
                var singleton = RespawnTickets.Singleton;
                var num       = singleton.GetAvailableTickets(__instance.NextKnownTeam);
                if (num == 0)
                {
                    num = singleton.DefaultTeamAmount;
                    RespawnTickets.Singleton.GrantTickets(singleton.DefaultTeam, singleton.DefaultTeamAmount, true);
                }
                var num2 = Mathf.Min(num, spawnableTeam.MaxWaveSize);
                while (list.Count > num2)
                {
                    list.RemoveAt(list.Count - 1);
                }
                list.ShuffleList();
                var list2 = ListPool <ReferenceHub> .Shared.Rent();

                var playerList = list.Select(hub => hub.GetPlayer()).ToList();

                Events.InvokeTeamRespawnEvent(ref playerList, ref __instance.NextKnownTeam);

                if (__instance.NextKnownTeam == SpawnableTeamType.None)
                {
                    return(false);
                }

                foreach (var player in playerList)
                {
                    try
                    {
                        var classId = spawnableTeam.ClassQueue[Mathf.Min(list2.Count, spawnableTeam.ClassQueue.Length - 1)];
                        player.ClassManager.SetPlayersClass(classId, player.gameObject);
                        list2.Add(player.Hub);
                        ServerLogs.AddLog(ServerLogs.Modules.ClassChange, string.Concat(new string[]
                        {
                            "Player ",
                            player.Hub.LoggedNameFromRefHub(),
                            " respawned as ",
                            classId.ToString(),
                            "."
                        }), ServerLogs.ServerLogType.GameEvent);
                    }
                    catch (Exception ex)
                    {
                        if (player != null)
                        {
                            ServerLogs.AddLog(ServerLogs.Modules.ClassChange, "Player " + player.Hub.LoggedNameFromRefHub() + " couldn't be spawned. Err msg: " + ex.Message, ServerLogs.ServerLogType.GameEvent);
                        }
                        else
                        {
                            ServerLogs.AddLog(ServerLogs.Modules.ClassChange, "Couldn't spawn a player - target's ReferenceHub is null.", ServerLogs.ServerLogType.GameEvent);
                        }
                    }
                }
                if (list2.Count > 0)
                {
                    ServerLogs.AddLog(ServerLogs.Modules.ClassChange, string.Concat(new object[]
                    {
                        "RespawnManager has successfully spawned ",
                        list2.Count,
                        " players as ",
                        __instance.NextKnownTeam.ToString(),
                        "!"
                    }), ServerLogs.ServerLogType.GameEvent);
                    RespawnTickets.Singleton.GrantTickets(__instance.NextKnownTeam, -list2.Count * spawnableTeam.TicketRespawnCost);
                    if (UnitNamingRules.TryGetNamingRule(__instance.NextKnownTeam, out var unitNamingRule))
                    {
                        unitNamingRule.GenerateNew(__instance.NextKnownTeam, out var text);
                        foreach (ReferenceHub referenceHub2 in list2)
                        {
                            referenceHub2.characterClassManager.NetworkCurSpawnableTeamType = (byte)__instance.NextKnownTeam;
                            referenceHub2.characterClassManager.NetworkCurUnitName          = text;
                        }
                        unitNamingRule.PlayEntranceAnnouncement(text);
                    }
                    RespawnEffectsController.ExecuteAllEffects(RespawnEffectsController.EffectType.UponRespawn, __instance.NextKnownTeam);
                }
                __instance.NextKnownTeam = SpawnableTeamType.None;

                return(false);
            }
            catch (Exception e)
            {
                Log.Error($"TeamRespawnEvent Error: {e}");
                return(true);
            }
        }
Esempio n. 17
0
        private static bool Spawn(RespawnManager __instance)
        {
            try
            {
                if (!RespawnWaveGenerator.SpawnableTeams.TryGetValue(__instance.NextKnownTeam, out var spawnableTeam) || __instance.NextKnownTeam == SpawnableTeamType.None)
                {
                    ServerConsole.AddLog("Fatal error. Team '" + __instance.NextKnownTeam + "' is undefined.", ConsoleColor.Red);
                    return(false);
                }
                List <ReferenceHub> list = (from item in ReferenceHub.GetAllHubs().Values
                                            where item.characterClassManager.CurClass == RoleType.Spectator && !item.serverRoles.OverwatchEnabled
                                            select item).ToList <ReferenceHub>();

                if (__instance._prioritySpawn)
                {
                    list = (from item in list
                            orderby item.characterClassManager.DeathTime
                            select item).ToList <ReferenceHub>();
                }
                else
                {
                    list.ShuffleList <ReferenceHub>();
                }

                var num = RespawnTickets.Singleton.GetAvailableTickets(__instance.NextKnownTeam);

                if (RespawnTickets.Singleton.IsFirstWave)
                {
                    RespawnTickets.Singleton.IsFirstWave = false;
                }

                if (num == 0)
                {
                    num = 5;
                    RespawnTickets.Singleton.GrantTickets(SpawnableTeamType.ChaosInsurgency, 5, true);
                }
                var num2 = Mathf.Min(num, spawnableTeam.MaxWaveSize);

                while (list.Count > num2)
                {
                    list.RemoveAt(list.Count - 1);
                }

                list.ShuffleList();

                var list2 = ListPool <ReferenceHub> .Shared.Rent();

                var players = list.Select(x => x.GetPlayer()).ToList();
                var team    = __instance.NextKnownTeam;

                SynapseController.Server.Events.Round.InvokeTeamRespawn(ref players, ref team, out var allow, out var id);

                if (!allow)
                {
                    return(false);
                }

                if (team == SpawnableTeamType.None)
                {
                    Server.Get.TeamManager.SpawnTeam(id, players);
                    return(false);
                }

                list = players.Select(x => x.Hub).ToList();
                __instance.NextKnownTeam = team;

                var que = new Queue <RoleType>();
                spawnableTeam.GenerateQueue(que, list.Count);

                foreach (ReferenceHub referenceHub in list)
                {
                    try
                    {
                        RoleType classid = que.Dequeue();
                        referenceHub.characterClassManager.SetPlayersClass(classid, referenceHub.gameObject, CharacterClassManager.SpawnReason.Respawn, false);
                        list2.Add(referenceHub);
                        ServerLogs.AddLog(ServerLogs.Modules.ClassChange, string.Concat(new string[]
                        {
                            "Player ",
                            referenceHub.LoggedNameFromRefHub(),
                            " respawned as ",
                            classid.ToString(),
                            "."
                        }), ServerLogs.ServerLogType.GameEvent, false);
                    }
                    catch (Exception ex)
                    {
                        if (referenceHub != null)
                        {
                            ServerLogs.AddLog(ServerLogs.Modules.ClassChange, "Player " + referenceHub.LoggedNameFromRefHub() + " couldn't be spawned. Err msg: " + ex.Message, ServerLogs.ServerLogType.GameEvent, false);
                        }
                        else
                        {
                            ServerLogs.AddLog(ServerLogs.Modules.ClassChange, "Couldn't spawn a player - target's ReferenceHub is null.", ServerLogs.ServerLogType.GameEvent, false);
                        }
                    }
                }
                if (list2.Count > 0)
                {
                    ServerLogs.AddLog(ServerLogs.Modules.ClassChange, string.Concat(new object[]
                    {
                        "RespawnManager has successfully spawned ",
                        list2.Count,
                        " players as ",
                        __instance.NextKnownTeam.ToString(),
                        "!"
                    }), ServerLogs.ServerLogType.GameEvent, false);
                    RespawnTickets.Singleton.GrantTickets(__instance.NextKnownTeam, -list2.Count * spawnableTeam.TicketRespawnCost, false);
                    if (Respawning.NamingRules.UnitNamingRules.TryGetNamingRule(__instance.NextKnownTeam, out var unitNamingRule))
                    {
                        unitNamingRule.GenerateNew(__instance.NextKnownTeam, out string text);
                        foreach (ReferenceHub referenceHub2 in list2)
                        {
                            referenceHub2.characterClassManager.NetworkCurSpawnableTeamType = (byte)__instance.NextKnownTeam;
                            referenceHub2.characterClassManager.NetworkCurUnitName          = text;
                        }
                        unitNamingRule.PlayEntranceAnnouncement(text);
                    }
                    RespawnEffectsController.ExecuteAllEffects(RespawnEffectsController.EffectType.UponRespawn, __instance.NextKnownTeam);
                }
                ListPool <ReferenceHub> .Shared.Return(list2);

                __instance.NextKnownTeam = SpawnableTeamType.None;

                return(false);
            }
            catch (Exception e)
            {
                SynapseController.Server.Logger.Error($"Synapse-Event: TeamRespawn failed!!\n{e}");
                return(true);
            }
        }
        public void FixedUpdate()
        {
            if (NetworkServer.active)
            {
                using (Dictionary <GameObject, ReferenceHub> .Enumerator enumerator = ReferenceHub.GetAllHubs().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        KeyValuePair <GameObject, ReferenceHub> keyValuePair = enumerator.Current;
                        ReferenceHub hub = keyValuePair.Value;

                        if (hub.characterClassManager.CurClass != RoleType.Spectator && hub.characterClassManager.CurClass != RoleType.Tutorial && !hub.isDedicatedServer && hub.Ready)
                        {
                            foreach (TeslaGate teslaGate in this.TeslaGates)
                            {
                                if (teslaGate.PlayerInRange(hub) && !teslaGate.InProgress)
                                {
                                    teslaGate.ServerSideCode();
                                }
                            }
                        }
                    }
                    return;
                }
            }
            foreach (TeslaGate teslaGate2 in this.TeslaGates)
            {
                teslaGate2.ClientSideCode();
            }
        }
Esempio n. 19
0
        private static IEnumerator<float> Process(RoundSummary roundSummary)
        {
            float time = Time.unscaledTime;
            while (roundSummary is not null)
            {
                yield return Timing.WaitForSeconds(2.5f);

                while (RoundSummary.RoundLock || !RoundSummary.RoundInProgress() || Time.unscaledTime - time < 15f || (roundSummary._keepRoundOnOne && PlayerManager.players.Count < 2))
                    yield return Timing.WaitForOneFrame;

                RoundSummary.SumInfo_ClassList newList = default;
                foreach (KeyValuePair<GameObject, ReferenceHub> keyValuePair in ReferenceHub.GetAllHubs())
                {
                    if (keyValuePair.Value is null)
                        continue;

                    CharacterClassManager component = keyValuePair.Value.characterClassManager;
                    if (component.Classes.CheckBounds(component.CurClass))
                    {
                        switch (component.CurRole.team)
                        {
                            case Team.SCP:
                                if (component.CurClass == RoleType.Scp0492)
                                    newList.zombies++;
                                else
                                    newList.scps_except_zombies++;
                                continue;
                            case Team.MTF:
                                newList.mtf_and_guards++;
                                continue;
                            case Team.CHI:
                                newList.chaos_insurgents++;
                                continue;
                            case Team.RSC:
                                newList.scientists++;
                                continue;
                            case Team.CDP:
                                newList.class_ds++;
                                continue;
                            default:
                                continue;
                        }
                    }
                }

                yield return Timing.WaitForOneFrame;
                newList.warhead_kills = AlphaWarheadController.Host.detonated ? AlphaWarheadController.Host.warheadKills : -1;
                yield return Timing.WaitForOneFrame;
                newList.time = (int)Time.realtimeSinceStartup;
                yield return Timing.WaitForOneFrame;
                RoundSummary.roundTime = newList.time - roundSummary.classlistStart.time;
                int num1 = newList.mtf_and_guards + newList.scientists;
                int num2 = newList.chaos_insurgents + newList.class_ds;
                int num3 = newList.scps_except_zombies + newList.zombies;
                int num4 = newList.class_ds + RoundSummary.EscapedClassD;
                int num5 = newList.scientists + RoundSummary.EscapedScientists;
                float num6 = (roundSummary.classlistStart.class_ds == 0) ? 0f : (num4 / roundSummary.classlistStart.class_ds);
                float num7 = (roundSummary.classlistStart.scientists == 0) ? 1f : (num5 / roundSummary.classlistStart.scientists);

                RoundSummary.SurvivingSCPs = newList.scps_except_zombies;

                if (newList.class_ds <= 0 && num1 <= 0)
                {
                    roundSummary.RoundEnded = true;
                }
                else
                {
                    int num8 = 0;
                    if (num1 > 0)
                        num8++;
                    if (num2 > 0)
                        num8++;
                    if (num3 > 0)
                        num8++;
                    if (num8 <= 1)
                        roundSummary.RoundEnded = true;
                }

                EndingRoundEventArgs endingRoundEventArgs = new(LeadingTeam.Draw, newList, roundSummary.RoundEnded);

                if (num1 > 0)
                    endingRoundEventArgs.LeadingTeam = RoundSummary.EscapedScientists >= RoundSummary.EscapedClassD ? LeadingTeam.FacilityForces : LeadingTeam.Draw;
                else if (num3 > 0)
                    endingRoundEventArgs.LeadingTeam = RoundSummary.EscapedClassD > RoundSummary.SurvivingSCPs ? LeadingTeam.ChaosInsurgency : (RoundSummary.SurvivingSCPs > RoundSummary.EscapedScientists ? LeadingTeam.Anomalies : LeadingTeam.Draw);
                else if (num2 > 0)
                    endingRoundEventArgs.LeadingTeam = RoundSummary.EscapedClassD >= RoundSummary.EscapedScientists ? LeadingTeam.ChaosInsurgency : LeadingTeam.Draw;

                Server.OnEndingRound(endingRoundEventArgs);

                roundSummary.RoundEnded = endingRoundEventArgs.IsRoundEnded && endingRoundEventArgs.IsAllowed;

                if (roundSummary.RoundEnded)
                {
                    FriendlyFireConfig.PauseDetector = true;
                    string str = "Round finished! Anomalies: " + num3 + " | Chaos: " + num2 + " | Facility Forces: " + num1 + " | D escaped percentage: " + num6 + " | S escaped percentage: : " + num7;
                    Console.AddLog(str, Color.gray, false);
                    ServerLogs.AddLog(ServerLogs.Modules.Logger, str, ServerLogs.ServerLogType.GameEvent);
                    yield return Timing.WaitForSeconds(1.5f);
                    int timeToRoundRestart = Mathf.Clamp(ConfigFile.ServerConfig.GetInt("auto_round_restart_time", 10), 5, 1000);

                    if (roundSummary is not null)
                    {
                        RoundEndedEventArgs roundEndedEventArgs = new(endingRoundEventArgs.LeadingTeam, newList, timeToRoundRestart);

                        Server.OnRoundEnded(roundEndedEventArgs);

                        roundSummary.RpcShowRoundSummary(roundSummary.classlistStart, roundEndedEventArgs.ClassList, (RoundSummary.LeadingTeam)roundEndedEventArgs.LeadingTeam, RoundSummary.EscapedClassD, RoundSummary.EscapedScientists, RoundSummary.KilledBySCPs, roundEndedEventArgs.TimeToRestart);
                    }

                    yield return Timing.WaitForSeconds(timeToRoundRestart - 1);
                    roundSummary.RpcDimScreen();
                    yield return Timing.WaitForSeconds(1f);
                    RoundRestart.InitiateRoundRestart();
                    yield break;
                }
            }
        }
Esempio n. 20
0
        private string BanCommand(string[] arg, JObject jObject)
        {
            try
            {
                if (arg.Count() < 5)
                {
                    return($"```{arg[1]} [UserID/Ip] [Duration] [Reason]```");
                }

                bool validUID = arg[2].Contains('@');
                bool validIP  = IPAddress.TryParse(arg[2], out IPAddress ip);

                if (!validIP && !validUID)
                {
                    return($"```diff\n- Invalid UserID or IP given```");
                }

                var chars = arg[3].Where(Char.IsLetter).ToArray();

                //return string.Join(" ", chars);

                if (chars.Length < 1 || !int.TryParse(new string(arg[3].Where(Char.IsDigit).ToArray()), out int amount) || !validUnits.Contains(chars[0]) || amount < 1)
                {
                    return("```diff\n- Invalid duration```");
                }

                TimeSpan duration = GetBanDuration(chars[0], amount);
                string   reason   = string.Join(" ", arg.Skip(4));

                ReferenceHub player = null;
                if (validIP)
                {
                    var list = ReferenceHub.GetAllHubs().Where(p => p.Value.characterClassManager.connectionToClient.address == arg[2]);
                    if (list.Count() > 0)
                    {
                        player = list.First().Value;
                    }
                }
                else
                {
                    var list = ReferenceHub.GetAllHubs().Where(p => p.Value.characterClassManager.UserId == arg[2]);
                    if (list.Count() > 0)
                    {
                        player = list.First().Value;
                    }
                }

                if (player != null)
                {
                    BanHandler.IssueBan(new BanDetails
                    {
                        OriginalName = player.nicknameSync.MyNick,
                        Id           = player.characterClassManager.UserId,
                        Issuer       = jObject["Staff"].ToString(),
                        IssuanceTime = DateTime.UtcNow.Ticks,
                        Expires      = DateTime.UtcNow.Add(duration).Ticks,
                        Reason       = reason
                    }, BanHandler.BanType.UserId);

                    BanHandler.IssueBan(new BanDetails
                    {
                        OriginalName = player.nicknameSync.MyNick,
                        Id           = player.characterClassManager.connectionToClient.address,
                        Issuer       = jObject["Staff"].ToString(),
                        IssuanceTime = DateTime.UtcNow.Ticks,
                        Expires      = DateTime.UtcNow.Add(duration).Ticks,
                        Reason       = reason
                    }, BanHandler.BanType.IP);

                    ServerConsole.Disconnect(player.gameObject, reason);

                    return($"`{player.nicknameSync.MyNick} ({player.characterClassManager.UserId})` was banned for {arg[3]} with reason: {reason}");
                }
                else
                {
                    BanHandler.IssueBan(new BanDetails
                    {
                        OriginalName = "Offline player",
                        Id           = arg[2],
                        Issuer       = jObject["Staff"].ToString(),
                        IssuanceTime = DateTime.UtcNow.Ticks,
                        Expires      = DateTime.UtcNow.Add(duration).Ticks,
                        Reason       = reason
                    }, (validUID ? BanHandler.BanType.UserId : BanHandler.BanType.IP));
                    return($"`{arg[2]}` was banned for {arg[3]} with reason {reason}!");
                }
            }
            catch (Exception e)
            {
                return(e.ToString());
            }
        }
Esempio n. 21
0
        private static bool Prefix(TeslaGateController __instance)
        {
            try
            {
                foreach (TeslaGate teslaGate in __instance.TeslaGates)
                {
                    if (!teslaGate.isActiveAndEnabled || teslaGate.InProgress)
                    {
                        continue;
                    }

                    if (teslaGate.NetworkInactiveTime > 0f)
                    {
                        teslaGate.NetworkInactiveTime = Mathf.Max(0f, teslaGate.InactiveTime - Time.fixedDeltaTime);
                        continue;
                    }

                    bool inIdleRange   = false;
                    bool isTriggerable = false;
                    foreach (KeyValuePair <GameObject, ReferenceHub> allHub in ReferenceHub.GetAllHubs())
                    {
                        if (allHub.Value.isDedicatedServer || allHub.Value.characterClassManager.CurClass == RoleType.Spectator)
                        {
                            continue;
                        }

                        if (teslaGate.PlayerInIdleRange(allHub.Value))
                        {
                            TriggeringTeslaEventArgs ev = new TriggeringTeslaEventArgs(API.Features.Player.Get(allHub.Key), teslaGate, teslaGate.PlayerInHurtRange(allHub.Key), teslaGate.PlayerInRange(allHub.Value));
                            Player.OnTriggeringTesla(ev);

                            if (ev.IsTriggerable && !isTriggerable)
                            {
                                isTriggerable = ev.IsTriggerable;
                            }

                            if (!inIdleRange)
                            {
                                inIdleRange = ev.IsInIdleRange;
                            }
                        }
                    }

                    if (isTriggerable)
                    {
                        teslaGate.ServerSideCode();
                    }

                    if (inIdleRange != teslaGate.isIdling)
                    {
                        teslaGate.ServerSideIdle(inIdleRange);
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                API.Features.Log.Error($"Exiled.Events.Patches.Events.Player.TriggeringTesla: {e}\n{e.StackTrace}");

                return(true);
            }
        }