예제 #1
0
        public void OnPlayerDie(PlayerDeathEvent ev)
        {
            if (!this.plugin.DuringRound)
            {
                this.plugin.Info("Skipping OnPlayerDie for being outside of a round.");
                return;
            }

            Player killer       = ev.Killer;
            string killerOutput = killer.Name + " " + killer.SteamId + " " + killer.IpAddress;
            Player victim       = ev.Player;
            string victimOutput = victim.Name + " " + victim.SteamId + " " + victim.IpAddress;

            if (this.plugin.isTeamkill(killer, victim))
            {
                if (this.plugin.enable)
                {
                    Teamkill teamkill = new Teamkill(killer.Name, killer.SteamId, killer.TeamRole, victim.Name, victim.SteamId, victim.TeamRole, victim.IsHandcuffed(), ev.DamageTypeVar, this.plugin.Server.Round.Duration);
                    this.plugin.TeamkillVictims[ev.Player.SteamId] = teamkill;

                    if (this.plugin.Teamkillers.ContainsKey(killer.SteamId))
                    {
                        this.plugin.Teamkillers[killer.SteamId].Teamkills.Add(teamkill);
                        plugin.Info("Player " + killerOutput + " " + killer.TeamRole.Team.ToString() + " teamkilled " +
                                    victimOutput + " " + victim.TeamRole.Team.ToString() + ", for a total of " + this.plugin.Teamkillers[killer.SteamId].Teamkills.Count + " teamkills.");
                    }
                    else
                    {
                        this.plugin.Teamkillers[killer.SteamId] = new Teamkiller(killer.PlayerId, killer.Name, killer.SteamId, killer.IpAddress);
                        this.plugin.Teamkillers[killer.SteamId].Teamkills.Add(teamkill);
                        plugin.Info("Player " + killerOutput + " " + killer.TeamRole.Team.ToString() + " teamkilled " +
                                    victimOutput + " " + victim.TeamRole.Team.ToString() + ", for a total of 1 teamkill.");
                    }

                    victim.PersonalBroadcast(10, string.Format(this.plugin.GetTranslation("victim_message"), killer.Name), false);

                    if (this.plugin.warntk != -1)
                    {
                        string broadcast = string.Format(this.plugin.GetTranslation("killer_message"), victim.Name, teamkill.GetRoleDisplay()) + " ";
                        if (this.plugin.warntk > 0)
                        {
                            int teamkillsBeforeBan = this.plugin.amount - this.plugin.Teamkillers[killer.SteamId].Teamkills.Count;
                            if (teamkillsBeforeBan <= this.plugin.warntk)
                            {
                                broadcast += string.Format(this.plugin.GetTranslation("killer_warning"), teamkillsBeforeBan) + " ";
                            }
                        }
                        else
                        {
                            broadcast += this.plugin.GetTranslation("killer_request") + " ";
                        }
                        killer.PersonalBroadcast(5, broadcast, false);
                    }

                    this.plugin.OnCheckRemoveGuns(ev.Killer);

                    this.plugin.OnCheckToSpectator(ev.Killer);

                    this.plugin.OnCheckKick(ev.Killer);

                    this.plugin.OnVoteTeamkill(ev.Killer);

                    /*
                     * If ban system is #1, do not create timers and perform a ban based on a static number of teamkills
                     */
                    if (this.plugin.system == 1 && this.plugin.Teamkillers[killer.SteamId].Teamkills.Count >= this.plugin.amount)
                    {
                        this.plugin.OnBan(killer, killer.Name, this.plugin.length, this.plugin.Teamkillers[killer.SteamId].Teamkills);
                    }
                    else
                    {
                        Timer t;
                        if (this.plugin.TeamkillTimers.ContainsKey(killer.SteamId))
                        {
                            /*
                             * If ban system is #3, allow the player to continue teamkilling
                             */
                            t = this.plugin.TeamkillTimers[killer.SteamId];
                            t.Stop();
                            t.Interval = this.plugin.expire * 1000;
                            t.Start();
                        }
                        else
                        {
                            t = new Timer
                            {
                                Interval  = this.plugin.expire * 1000,
                                AutoReset = true,
                                Enabled   = true
                            };
                            t.Elapsed += delegate
                            {
                                if (this.plugin.enable)
                                {
                                    /*
                                     * If ban system is #3, every player teamkill cancels and restarts the timer
                                     * Wait until the timer expires after the teamkilling has ended to find out
                                     * how much teamkilling the player has done.
                                     */
                                    if (this.plugin.system == 3)
                                    {
                                        int banLength = this.plugin.GetScaledBanAmount(killer.SteamId);
                                        if (banLength > 0)
                                        {
                                            this.plugin.OnBan(killer, killer.Name, banLength, this.plugin.Teamkillers[killer.SteamId].Teamkills);
                                        }
                                        else
                                        {
                                            if (this.plugin.outall)
                                            {
                                                this.plugin.Info("Player " + killer.SteamId + " " + this.plugin.Teamkillers[killer.SteamId].Teamkills.Count + " teamkills is not bannable.");
                                            }
                                        }
                                    }

                                    if (this.plugin.Teamkillers[killer.SteamId].Teamkills.Count > 0)
                                    {
                                        Teamkill firstTeamkill = this.plugin.Teamkillers[killer.SteamId].Teamkills[0];
                                        this.plugin.Teamkillers[killer.SteamId].Teamkills.RemoveAt(0);
                                        this.plugin.Info("Player " + killerOutput + " " + killer.TeamRole.Team.ToString() + " teamkill expired, counter now at " + this.plugin.Teamkillers[killer.SteamId].Teamkills.Count + ".");
                                    }
                                    else
                                    {
                                        t.Enabled = false;
                                    }
                                }
                                else
                                {
                                    t.Enabled = false;
                                }
                            };
                            this.plugin.TeamkillTimers[killer.SteamId] = t;
                        }

                        /*
                         * If ban system is #2, allow the teamkills to expire
                         */
                        if (this.plugin.system == 2 && this.plugin.Teamkillers[killer.SteamId].Teamkills.Count >= this.plugin.amount)
                        {
                            t.Stop();
                            this.plugin.OnBan(killer, killer.Name, this.plugin.length, this.plugin.Teamkillers[killer.SteamId].Teamkills);
                        }
                    }
                }
                else
                {
                    plugin.Info("Player " + killerOutput + " " + killer.TeamRole.Team.ToString() + " teamkilled " +
                                victimOutput + " " + victim.TeamRole.Team.ToString() + ".");
                }
            }
            else
            {
                if (this.plugin.outall)
                {
                    this.plugin.Info("Player " + killerOutput + " " + killer.TeamRole.Team.ToString() + " killed " +
                                     victimOutput + " " + victim.TeamRole.Team.ToString() + " and it was not detected as a teamkill.");
                }
            }
        }
        public void OnPlayerDie(PlayerDeathEvent ev)
        {
            if (!this.plugin.DuringRound)
            {
                this.plugin.Info("Skipping OnPlayerDie for being outside of a round.");
                return;
            }

            Player killer       = ev.Killer;
            string killerOutput = killer.Name + " " + killer.UserId + " " + killer.IpAddress;
            Player victim       = ev.Player;
            string victimOutput = victim.Name + " " + victim.UserId + " " + victim.IpAddress;

            if (this.plugin.enable)
            {
                if (!this.plugin.Teamkillers.ContainsKey(victim.UserId))
                {
                    this.plugin.Teamkillers[victim.UserId] = new Teamkiller(victim.PlayerId, victim.Name, victim.UserId, victim.IpAddress);
                }
                this.plugin.Teamkillers[victim.UserId].Deaths++;

                if (!this.plugin.Teamkillers.ContainsKey(killer.UserId))
                {
                    this.plugin.Teamkillers[killer.UserId] = new Teamkiller(killer.PlayerId, killer.Name, killer.UserId, killer.IpAddress);
                }

                if (this.plugin.isTeamkill(killer, victim))
                {
                    this.plugin.Teamkillers[killer.UserId].Kills--;

                    Teamkill teamkill = new Teamkill(killer.Name, killer.UserId, killer.TeamRole, victim.Name, victim.UserId, victim.TeamRole, victim.IsHandcuffed(), ev.DamageTypeVar, this.plugin.Server.Round.Duration);
                    this.plugin.TeamkillVictims[ev.Player.UserId] = teamkill;
                    this.plugin.Teamkillers[killer.UserId].Teamkills.Add(teamkill);

                    this.plugin.Info("Player " + killerOutput + " " + killer.TeamRole.Team.ToString() + " teamkilled " +
                                     victimOutput + " " + victim.TeamRole.Team.ToString() + ", for a total of " + this.plugin.Teamkillers[killer.UserId].Teamkills.Count + " teamkills.");

                    victim.PersonalBroadcast(10, string.Format(this.plugin.GetTranslation("victim_message"), killer.Name, DateTime.Today.ToString("yyyy-MM-dd hh:mm tt")), false);

                    if (!this.plugin.banWhitelist.Contains(killer.UserId))
                    {
                        float kdr = this.plugin.Teamkillers[killer.UserId].GetKDR();
                        // If kdr is greater than K/D safe amount, AND if the number of kils is greater than kdsafe to exclude low K/D values
                        if (this.plugin.outall)
                        {
                            this.plugin.Info("kdsafe set to: " + this.plugin.kdsafe);
                            this.plugin.Info("Player " + killerOutput + " KDR: " + kdr);
                            this.plugin.Info("Is KDR greater than kdsafe? " + (kdr > (float)this.plugin.kdsafe));
                            this.plugin.Info("Are kills greater than kdsafe? " + (this.plugin.Teamkillers[killer.UserId].Kills > this.plugin.kdsafe));
                        }

                        if (this.plugin.kdsafe > 0 && kdr > (float)this.plugin.kdsafe && this.plugin.Teamkillers[killer.UserId].Kills > this.plugin.kdsafe)
                        {
                            killer.PersonalBroadcast(5, string.Format(this.plugin.GetTranslation("killer_kdr_message"), victim.Name, teamkill.GetRoleDisplay(), kdr), false);
                            return;
                        }
                        else if (this.plugin.warntk != -1)
                        {
                            string broadcast = string.Format(this.plugin.GetTranslation("killer_message"), victim.Name, teamkill.GetRoleDisplay()) + " ";
                            if (this.plugin.warntk > 0)
                            {
                                int teamkillsBeforeBan = this.plugin.amount - this.plugin.Teamkillers[killer.UserId].Teamkills.Count;
                                if (teamkillsBeforeBan <= this.plugin.warntk)
                                {
                                    broadcast += string.Format(this.plugin.GetTranslation("killer_warning"), teamkillsBeforeBan) + " ";
                                }
                            }
                            else
                            {
                                broadcast += this.plugin.GetTranslation("killer_request") + " ";
                            }
                            killer.PersonalBroadcast(5, broadcast, false);
                        }

                        this.plugin.OnCheckRemoveGuns(ev.Killer);

                        this.plugin.OnCheckToSpectator(ev.Killer);

                        this.plugin.OnCheckUndead(ev.Killer, ev.Player);

                        this.plugin.OnCheckKick(ev.Killer);

                        this.plugin.OnVoteTeamkill(ev.Killer);
                    }
                    else
                    {
                        this.plugin.Info("Player " + killerOutput + " not being punished by FFA because the player is whitelisted.");
                        return;
                    }

                    /*
                     * If ban system is #1, do not create timers and perform a ban based on a static number of teamkills
                     */
                    if (this.plugin.system == 1 && this.plugin.Teamkillers[killer.UserId].Teamkills.Count >= this.plugin.amount)
                    {
                        this.plugin.OnBan(killer, killer.Name, this.plugin.length, this.plugin.Teamkillers[killer.UserId].Teamkills);
                    }
                    else
                    {
                        Timer t;
                        if (this.plugin.TeamkillTimers.ContainsKey(killer.UserId))
                        {
                            /*
                             * If ban system is #3, allow the player to continue teamkilling
                             */
                            t = this.plugin.TeamkillTimers[killer.UserId];
                            t.Stop();
                            t.Interval = this.plugin.expire * 1000;
                            t.Start();
                        }
                        else
                        {
                            t = new Timer
                            {
                                Interval  = this.plugin.expire * 1000,
                                AutoReset = true,
                                Enabled   = true
                            };
                            t.Elapsed += delegate
                            {
                                if (this.plugin.enable)
                                {
                                    /*
                                     * If ban system is #3, every player teamkill cancels and restarts the timer
                                     * Wait until the timer expires after the teamkilling has ended to find out
                                     * how much teamkilling the player has done.
                                     */
                                    if (this.plugin.system == 3)
                                    {
                                        int banLength = this.plugin.GetScaledBanAmount(killer.UserId);
                                        if (banLength > 0)
                                        {
                                            this.plugin.OnBan(killer, killer.Name, banLength, this.plugin.Teamkillers[killer.UserId].Teamkills);
                                        }
                                        else
                                        {
                                            if (this.plugin.outall)
                                            {
                                                this.plugin.Info("Player " + killer.UserId + " " + this.plugin.Teamkillers[killer.UserId].Teamkills.Count + " teamkills is not bannable.");
                                            }
                                        }
                                    }

                                    if (this.plugin.Teamkillers[killer.UserId].Teamkills.Count > 0)
                                    {
                                        Teamkill firstTeamkill = this.plugin.Teamkillers[killer.UserId].Teamkills[0];
                                        this.plugin.Teamkillers[killer.UserId].Teamkills.RemoveAt(0);
                                        this.plugin.Info("Player " + killerOutput + " " + killer.TeamRole.Team.ToString() + " teamkill expired, counter now at " + this.plugin.Teamkillers[killer.UserId].Teamkills.Count + ".");
                                    }
                                    else
                                    {
                                        t.Enabled = false;
                                    }
                                }
                                else
                                {
                                    t.Enabled = false;
                                }
                            };
                            this.plugin.TeamkillTimers[killer.UserId] = t;
                        }

                        /*
                         * If ban system is #2, allow the teamkills to expire
                         */
                        if (this.plugin.system == 2 && this.plugin.Teamkillers[killer.UserId].Teamkills.Count >= this.plugin.amount)
                        {
                            t.Stop();
                            this.plugin.OnBan(killer, killer.Name, this.plugin.length, this.plugin.Teamkillers[killer.UserId].Teamkills);
                        }
                    }
                }
                else
                {
                    if (this.plugin.outall)
                    {
                        this.plugin.Info("Player " + killerOutput + " " + killer.TeamRole.Team.ToString() + " killed " +
                                         victimOutput + " " + victim.TeamRole.Team.ToString() + " and it was not detected as a teamkill.");
                    }

                    this.plugin.Teamkillers[killer.UserId].Kills++;
                }
            }
            else
            {
                plugin.Info("Player " + killerOutput + " " + killer.TeamRole.Team.ToString() + " killed " +
                            victimOutput + " " + victim.TeamRole.Team.ToString() + ".");
            }
        }