コード例 #1
0
 internal void RenameByMineControl(string name, RegionList regions)
 {
     Log.WritePlayer("Mine Control", "Region renamed " + Name + " to " + name);
     TellResidentsSystem(null, Chat.Blue, "Server renamed " + Name + " to " + name);
     Name = name;
     RegionLoader.Save(regions);
 }
コード例 #2
0
        internal void AddPlayer(string residentPlayer, string newResident, RegionList region)
        {
            Residents.Add(newResident);
            RegionLoader.Save(region);
            Log.WritePlayer(residentPlayer, "Region added resident " + newResident);
            Client nr = PlayerList.GetPlayerByName(newResident);

            if (nr != null)
            {
                nr.TellSystem(Chat.Aqua, residentPlayer + " added you to " + Name);
                RegionCrossing.SetRegion(nr.Session);
            }
        }
コード例 #3
0
        internal void Rename(Client player, string name)
        {
            RegionList region = player.Session.World.Regions;

            if (ResidentPermissions(player) == false)
            {
                player.TellSystem(Chat.Yellow, " You are not a resident of this region");
                return;
            }

            Log.WritePlayer(player, "Region renamed " + Name + " to " + name);
            TellResidentsSystem(null, Chat.Blue, player.Name + " renamed " + Name + " to " + name);
            Name = name;
            RegionLoader.Save(region);
            Entering(player);
        }
コード例 #4
0
        /// <summary>
        /// Change the region protection type
        /// </summary>
        public void SetType(Client player, string type)
        {
            if (ResidentPermissions(player) == false)
            {
                player.TellSystem(Chat.Yellow, " You are not a resident of this region");
                return;
            }

            type = type.ToLowerInvariant().Trim();

            switch (type)
            {
            case "":     //public
            case PublicType.Type:
            case Protected.Type:
            case Adventure.Type:
            case SpawnRegion.Type:
                break;     //OK

            default:
                if (player.Admin() == false)
                {
                    player.TellSystem(Chat.Red, "Unknown type: " + type);
                    player.TellSystem(Chat.Yellow, "Choose one of: public, protected, adventure, night");
                    return;
                }
                else
                {
                    player.TellSystem(Chat.Yellow, "Custom type: " + type);
                }
                break;
            }
            Type = type;
            player.TellSystem(Chat.Aqua, "Region type is now: " + type);
            RegionLoader.Save(player.Session.World.Regions);

            //Update all players
            foreach (Client c in PlayerList.List)
            {
                if (c.Session.CurrentRegion == this)
                {
                    RegionCrossing.SetRegion(c.Session);
                }
            }
        }
コード例 #5
0
        internal void SetReport(Client player, string state)
        {
            RegionList regions = player.Session.World.Regions;

            if (ResidentPermissions(player) == false)
            {
                player.TellSystem(Chat.Yellow, " You are not a resident of this region");
                return;
            }

            if (state == "on")
            {
                ReportVisits = true;
            }
            if (state == "off")
            {
                ReportVisits = false;
            }
            RegionLoader.Save(regions);
        }
コード例 #6
0
        internal void SetMessage(Client player, string message)
        {
            RegionList regions = player.Session.World.Regions;

            if (ResidentPermissions(player) == false)
            {
                player.TellSystem(Chat.Yellow, " You are not a resident of this region");
                return;
            }

            if (message == "-" || message == "off" || message == "rem" || message == "remove")
            {
                message = null;
            }
            Message = message;
            Log.WritePlayer(player, "Message for " + Name + " set to " + Message);
            RegionLoader.Save(regions);

            TellResidentsSystem(null, Chat.Blue, player.Name + " changed region message to " + Message);
        }
コード例 #7
0
        internal void RemovePlayer(Client player, string removeUsername)
        {
            RegionList regions = player.Session.World.Regions;

            if (ResidentPermissions(player) == false)
            {
                Log.WritePlayer(player, "Failed to remove " + removeUsername + " from region " + Name);
                player.TellSystem(Chat.Yellow, " You are not a resident of this region");
                return;
            }

            removeUsername = removeUsername.ToLowerInvariant();
            foreach (string s in Residents)
            {
                if (s.ToLowerInvariant() == removeUsername)
                {
                    removeUsername = s;
                    break;
                }
            }
            if (Residents.Remove(removeUsername) == false)
            {
                player.TellSystem(Chat.Red, removeUsername + " not found in region " + Name);
                return;
            }

            Log.WritePlayer(player, "Region: removed resident " + removeUsername);
            RegionLoader.Save(regions);
            player.TellSystem(Chat.Aqua, removeUsername + " removed from " + Name);
            Client p = PlayerList.GetPlayerByName(removeUsername);

            if (p != null && p != player)
            {
                p.TellSystem(Chat.Aqua, player.Name + " removed you from " + Name);
            }
        }
コード例 #8
0
        public void Resize(int minX, int maxX, int minY, int maxY, int minZ, int maxZ, Client player)
        {
            RegionList regions = player.Session.World.Regions;

            Region      test   = new Region(minX, maxX, minY, maxY, minZ, maxZ);
            WorldRegion parent = RegionCrossing.GetParentRegion(regions.List, this);

            if (parent == null)
            {
                player.TellSystem(Chat.Red, "parent not found");
                return;
            }

            if (player.Admin() == false)
            {
                if ((Donors.IsDonor(player) == false))
                {
                    player.TellSystem(Chat.Aqua, "Only for donors and admins may resize a region");
                    return;
                }
                //Useless since when only donors get this far:
                if (minY < 50 && (!player.Donor))
                {
                    player.TellSystem(Chat.Red, "Only admins and donors may make regions below Y=50");
                    return;
                }
                if (ResidentPermissions(player) == false)
                {
                    player.TellSystem(Chat.Yellow, "You are not a resident of this region");
                    return;
                }

                if (parent.ResidentPermissions(player) == false)
                {
                    player.TellSystem(Chat.Yellow, "You are not a resident of the parent region");
                    return;
                }
            }

            List <WorldRegion> list;

            if (parent == this)
            {
                list = player.Session.World.Regions.List;
            }
            else
            {
                list = parent.SubRegions;
            }

            //Make sure the new size overlaps the old one so we don't make huge mistakes
            if (test.Overlap(this) == false)
            {
                player.TellSystem(Chat.Red, "New size must overlap old one");
                player.TellSystem(Chat.Red, "New size " + test);
                player.TellSystem(Chat.Red, "Old size " + this.Coords());
                return;
            }

            //Check that the new size fits in the parent
            if (parent != this)
            {
                if (parent.Cover(test) == false)
                {
                    player.TellSystem(Chat.Red, "parent " + parent.Name + " is too small " + parent.Coords());
                    return;
                }
            }
            //else we are in the top level, no limit there

            //Make sure new size does not collide with siblings
            foreach (WorldRegion w in list)
            {
                if (w.Dimension != Dimension) //If toplevel "siblings" are all toplevel regions
                {
                    continue;
                }
                if (w == this)
                {
                    continue;
                }
                if (w.Overlap(test))
                {
                    player.TellSystem(Chat.Red, "new size overlap sibling " + w);
                    return;
                }
            }

            //Chech that subregions still fit into the new size
            if (SubRegions != null)
            {
                foreach (WorldRegion w in SubRegions)
                {
                    if (test.Cover(w) == false)
                    {
                        player.TellSystem(Chat.Red, "New size does not cover subregion:");
                        player.TellSystem(Chat.Red, w.ToString());
                        return;
                    }
                }
            }

            Log.WritePlayer(player, "Region Resized: from " + this + " to " + test);
            MinX = test.MinX;
            MaxX = test.MaxX;
            MinY = test.MinY;
            MaxY = test.MaxY;
            MinZ = test.MinZ;
            MaxZ = test.MaxZ;
            RegionLoader.Save(regions);
            player.TellSystem(Chat.Purple, "Region resized: " + this);
        }
コード例 #9
0
        public static void Main(string[] args)
        {
            //Bug workaround
            System.Web.Util.HttpEncoder.Current = System.Web.Util.HttpEncoder.Default;

            Directory.SetCurrentDirectory(MineSharp.Settings.BaseWorldsPath);
            Console.WriteLine();
            Console.WriteLine("Starting Mineproxy: " + DateTime.Now);
            Log.Init();

            //Init commands
            Commands.MainCommands.Init();

            System.Threading.Thread.CurrentThread.Name = "Player Listener";

            Console.CancelKeyPress += HandleConsoleCancelKeyPress;

            int controllerPort = 25465;

#if DEBUG
            //Only for debugging the live server
            //MinecraftServer.Port = 25665;

            //Debug.WriteLine(MinecraftProtocol.Minecraft.Protocol);
#endif


            //Load settings
            Banned.LoadBanned();
            MineProxy.Regions.WarpPortalVisuals.Init();

            //VoteListener.Start();
            ServerCommander.Startup();
            ControlListener.Start(controllerPort);
            BackupProxy.Start();

            try
            {
                PlayerList.StartUpdater();
                //SpawnRegion.Start ();
                Settings.Start();
                QueryListener.Start();
            } catch (Exception e)
            {
                Log.WriteServer(e);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }

            while (true)
            {
                Console.WriteLine(DateTime.Now + " Starting Main true loop");
                listener = new TcpListener(IPAddress.Any, MinecraftServer.MainPort);
                try
                {
                    listener.Start();

                    Console.WriteLine("Listening for players on " + MinecraftServer.MainPort);

                    while (Active)
                    {
                        TcpClient client = listener.AcceptTcpClient();
                        if (Active == false)
                        {
                            break;
                        }

                        //Console.WriteLine ("Got incoming");
                        try
                        {
                            //check banned ip
                            if (Banned.IsBanned(((IPEndPoint)client.Client.RemoteEndPoint).Address))
                            {
                                try
                                {
                                    client.Close();
                                } catch (Exception e)
                                {
                                    Log.WriteServer("Error closing banned ip", e);
                                }
                                continue;
                            }

                            Client proxy = new VanillaClient(client.Client);
                            proxy.Start();
                        } catch (SocketException)
                        {
                            try
                            {
                                client.Close();
                            } catch
                            {
                            }
                        }
                    }

                    //Program is exiting here
                    Console.WriteLine("Kicking all players: " + ShutdownMessage);
                    foreach (Client p in PlayerList.List)
                    {
                        p.Kick(ShutdownMessage);
                    }

                    Log.Flush();
                    ServerCommander.Shutdown();
                    ControlListener.Stop();
                    return;

#if !DEBUG
                } catch (Exception e)
                {
                    Console.WriteLine(DateTime.Now + " Main loop error: " + e.GetType().Name + " " + e.Message);
                    Log.WriteServer("MainClass.Main general", e);
                    System.Threading.Thread.Sleep(500);
#endif
                } finally
                {
                    Console.WriteLine(DateTime.Now + " Main loop finally Start");
                    try
                    {
                        //Save region stats
                        RegionLoader.Save(World.Main.Regions);
                        Regions.WarpPortalVisuals.Stop();
                    } catch (Exception e)
                    {
                        Log.WriteServer("Main closing region stats saving", e);
                    }
                    Console.WriteLine(DateTime.Now + " Main loop finally End");
                    Environment.Exit(0);
                }
            }
        }