Esempio n. 1
0
        public static void Kick(string username, string reason)
        {
            Client pp = PlayerList.GetPlayerByUsernameOrName(username);

            if (pp != null)
            {
                pp.Kick(reason);
                return;
            }
        }
Esempio n. 2
0
        public static void Ban(Client admin, string username, DateTime bannedUntil, string reason)
        {
            if (admin != null && admin.Admin(Permissions.Ban) == false)
            {
                admin.TellSystem(Chat.Yellow, "Disabled");
                return;
            }

            if (Donors.IsDonor(username) && bannedUntil < DateTime.Now.AddMinutes(35))
            {
                Log.WritePlayer(username, "Donor not Banned: " + reason);
                if (admin != null)
                {
                    admin.TellSystem(Chat.Gold, "Donor not banned for: " + reason);
                }
                return;
            }

            bool      newban = false;
            BadPlayer b      = GetBanHistory(username);

            if (b == null)
            {
                //Make sure we spelled correctly
                if (admin != null)
                {
                    if (File.Exists("proxy/players/" + Path.GetFileName(username) + ".json") == false)
                    {
                        admin.TellSystem(Chat.Red, "No such player: " + username);
                        return;
                    }
                }

                newban        = true;
                b             = new BadPlayer();
                b.Username    = username;
                b.BannedUntil = bannedUntil;
                b.Reason      = reason;
                lock (blacklist)
                    blacklist.List.Add(b);
            }
            else
            {
                if (b.BannedUntil < DateTime.Now)
                {
                    newban = true;
                }

                //Make sure longer bans are not removed by a shorter violation
                if (b.BannedUntil > bannedUntil)
                {
                    return;
                }
                b.BannedUntil = bannedUntil;
                b.Reason      = reason;
            }
            SaveBanned();

            //Console.WriteLine ("Banning " + b.Username + " for " + b.Reason);
            double banMinutes = (b.BannedUntil - DateTime.Now).TotalMinutes;
            string banlength  = "forever";

            if (banMinutes < 24 * 60 * 30)
            {
                banlength = banMinutes.ToString("0") + " minutes";
            }

            if (admin != null)
            {
                Log.WritePlayer(b.Username, "Banned " + banlength + " by " + admin.MinecraftUsername + ": " + reason);
            }
            else
            {
                Log.WritePlayer(b.Username, "Banned " + banlength + ": " + reason);
            }

            Client pp = PlayerList.GetPlayerByUsernameOrName(username);

            if (pp != null)
            {
                if (newban)
                {
                    Chatting.Parser.Say(Chat.Purple, pp.Name + " is banned " + banlength + ": " + reason);
                }
                if (pp.Session is HellSession == false)
                {
                    pp.SetWorld(World.HellBanned);
                }
            }
            else
            {
                admin.TellSystem(Chat.Purple, username + " was banned(offline): " + reason);
            }
        }
Esempio n. 3
0
        void RunController()
        {
            BinaryReader r = new BinaryReader(stream);
            BinaryWriter w = new BinaryWriter(stream);

            while (Program.Active)
            {
                int            length = r.ReadInt32();
                byte[]         packet = r.ReadBytes(length);
                string         json   = Encoding.UTF8.GetString(packet);
                ControlMessage c      = JsonConvert.DeserializeObject <ControlMessage>(json);
                if (Program.Active == false)
                {
                    return;
                }

                try
                {
                    //Console.WriteLine ("Got from controller " + c);
                    if (c.Kick != null)
                    {
                        //Console.WriteLine ("Kick");
                        Client p = PlayerList.GetPlayerByUsername(c.Kick.Username);
                        if (p != null)
                        {
                            p.Kick(c.Kick.Reason);
                        }
                    }

                    if (c.Ban != null)
                    {
                        Banned.Ban(null, c.Ban.Username, c.Ban.BannedUntil, c.Ban.Reason);
                    }

                    if (c.Pardon != null)
                    {
                        Banned.Pardon(null, c.Pardon.Username);
                    }

                    if (c.PlayerUpdate)
                    {
                        //Console.WriteLine ("Update");
                        //Send complete player status update
                        PlayersUpdate pu = new PlayersUpdate();
                        pu.List      = new List <Control.Player>();
                        pu.MessageID = messageID;
                        messageID   += 2;
                        foreach (Client pp in PlayerList.List)
                        {
                            pu.List.Add(new Control.Player(pp));
                        }

                        byte[] buffer = Json.Serialize(pu);

                        w.Write((int)buffer.Length);
                        w.Write(buffer);
                        w.Flush();
                        //Console.WriteLine ("Update Sent");
                    }

                    if (c.TP != null)
                    {
                        var p = PlayerList.GetPlayerByUsernameOrName(c.TP.Username);
                        if (p == null)
                        {
                            return;
                        }
                        if (c.TP.ToUsername != null)
                        {
                            var pTo = PlayerList.GetPlayerByUsernameOrName(c.TP.ToUsername);
                            if (pTo == null)
                            {
                                return;
                            }
                            p.Session.World.Send("tp " + p.MinecraftUsername + " " + pTo.MinecraftUsername);
                            continue;
                        }
                        if (c.TP.Position != null)
                        {
                            p.Warp(c.TP.Position, (Dimensions)c.TP.Dimension, Worlds.World.Main);
                            continue;
                        }
                    }
                } catch (Exception ie)
                {
                    Log.WriteServer(ie);
                }
            }
        }