Example #1
0
        private static bool HandlePlayerUpdate(GetDataHandlerArgs args)
        {
            // int Index = (int)args.Data.ReadByte();
            //TShock player = TShock.Players[args.Player.Index];
            var player = TShock.Players[args.Player.Index];
            VKPlayer vkplyr = new VKPlayer(player.Index);

            //args.Player.SendMessage("Hello from HandlePlayerUpdate: " + vkplyr.X, Color.Yellow);

            if ( vkplyr.X < Votekick.config.WestPosition )
            {
                vkplyr.Connect(Votekick.config.WestServer);
            }

            //args.Player.SendMessage("Hello from HandlePlayerUpdate: ", Color.Yellow);
            return false;
        }
Example #2
0
        private void UpdateTimer(object sender, ElapsedEventArgs args)
        {
            if (Votekick.VoteKickRunning)
            {
                double active = TShock.Utils.ActivePlayers();
                double percentageofactive = ((active) * (Votekick.config.PercentofPlayersVoteYesToKick / 100));
                double totalvoters = Votekick.poll.voters.Count;

                    if (Votekick.poll.votedyes.Count > Votekick.poll.votedno.Count && Votekick.poll.votedyes.Count >= percentageofactive)
                    {
                        //TShock.Utils.Kick(Votekick.poll.votedplayer, Votekick.config.KickMessage, true, false);
                        //Instead of kicking we are going to use our new Connect method. Which for now just sends a new packet type
                        VKPlayer vkplyr = new VKPlayer(Votekick.poll.votedplayer.Index);
                        // TODO get this IP from the config.json file
                        // Load the IP when a player reaches coordinates X and Y
                        // obviously THIS is not the place to do that, but leaving
                        // the comment here
                        vkplyr.Connect("67.186.57.60:7778");
                        //vkplyr.Connect("Hello World");

                        Votekick.VoteKickRunning = false;
                        Votekick.poll.voters.Clear();
                        Votekick.poll.votedno.Clear();
                        Votekick.poll.votedyes.Clear();
                        Votekick.poll.votedplayer = null;
                        VKTimerNotify.Stop();
                    }

                    else
                    {
                        TSPlayer.All.SendInfoMessage("[VoteKick] The votekick on " + Votekick.poll.votedplayer.Name + " has failed.");
                        Votekick.VoteKickRunning = false;
                        Votekick.poll.voters.Clear();
                        Votekick.poll.votedno.Clear();
                        Votekick.poll.votedyes.Clear();
                        Votekick.poll.votedplayer = null;
                        VKTimerNotify.Stop();
                    }
            }

            if (Votekick.VoteMuteRunning)
            {
                double active = TShock.Utils.ActivePlayers();
                double percentageofactive = ((active) * (Votekick.config.PercentofPlayersVoteYesToMute / 100));
                double totalvoters = Votekick.poll.voters.Count;

                    if (Votekick.poll.votedyes.Count > Votekick.poll.votedno.Count && Votekick.poll.votedyes.Count >= percentageofactive)
                    {
                        TSPlayer.All.SendInfoMessage("[VoteMute] The vote to mute {0} has succeeded.", Votekick.poll.votedplayer.Name);
                        Votekick.poll.votedplayer.mute = true;
                        Votekick.VoteMuteRunning = false;
                        Votekick.poll.voters.Clear();
                        Votekick.poll.votedno.Clear();
                        Votekick.poll.votedyes.Clear();
                        Votekick.poll.votedplayer = null;
                        VKTimerNotify.Stop();
                    }

                    else
                    {
                        TSPlayer.All.SendInfoMessage("[VoteMute] The vote to mute " + Votekick.poll.votedplayer.Name + " has failed.");
                        Votekick.VoteMuteRunning = false;
                        Votekick.poll.voters.Clear();
                        Votekick.poll.votedno.Clear();
                        Votekick.poll.votedyes.Clear();
                        Votekick.poll.votedplayer = null;
                        VKTimerNotify.Stop();
                    }
            }

            if (Votekick.VoteBanRunning)
            {
                double active = TShock.Utils.ActivePlayers();
                double percentageofactive = ((active) * (Votekick.config.PercentofPlayersVoteYesToBan / 100));
                double totalvoters = Votekick.poll.voters.Count;

                    if (Votekick.poll.votedyes.Count > Votekick.poll.votedno.Count && Votekick.poll.votedyes.Count >= percentageofactive)
                    {
                        TShock.Utils.Kick(Votekick.poll.votedplayer, Votekick.config.BanMessage, true, false);
                        TShock.Bans.AddBan(Votekick.poll.votedplayer.IP, Votekick.poll.votedplayer.Name, Votekick.poll.votedplayer.UUID, Votekick.config.BanMessage, false, "Server Vote", DateTime.UtcNow.AddDays(Votekick.config.BanTimeInDays).ToString("s"));
                        Votekick.VoteBanRunning = false;
                        Votekick.poll.voters.Clear();
                        Votekick.poll.votedno.Clear();
                        Votekick.poll.votedyes.Clear();
                        Votekick.poll.votedplayer = null;
                        VKTimerNotify.Stop();
                    }

                    else
                    {
                        TSPlayer.All.SendInfoMessage("[VoteBan] The vote to ban " + Votekick.poll.votedplayer.Name + " has failed.");
                        Votekick.VoteBanRunning = false;
                        Votekick.poll.voters.Clear();
                        Votekick.poll.votedno.Clear();
                        Votekick.poll.votedyes.Clear();
                        Votekick.poll.votedplayer = null;
                        VKTimerNotify.Stop();
                    }
            }
        }