Example #1
0
 internal Scoreboard(MinecraftServer server, string name, string displayName)
 {
     Server      = server;
     Name        = name;
     DisplayName = displayName;
     Scores      = new Dictionary <string, int>();
 }
Example #2
0
 public Server(ISettingsProvider settingsProvider)
 {
     SettingsProvider = settingsProvider;
     // Touch TerrainGeneration to load it into app domain
     FlatlandGenerator.DefaultGeneratorOptions.ToString();
     var generator = Level.GetGenerator(SettingsProvider.Get<string>("level.type"));
     if (generator == null)
         generator = new FlatlandGenerator();
     Level level;
     if (Directory.Exists(SettingsProvider.Get<string>("level.name")))
         level = Level.LoadFrom(SettingsProvider.Get<string>("level.name"));
     else
     {
         level = new Level(generator, SettingsProvider.Get<string>("level.name"));
         level.AddWorld("overworld");
         level.SaveTo(SettingsProvider.Get<string>("level.name"));
     }
     MinecraftServer = new MinecraftServer(level);
     MinecraftServer.Settings.MotD = SettingsProvider.Get<string>("server.motd");
     MinecraftServer.Settings.OnlineMode = SettingsProvider.Get<bool>("server.onlinemode");
     MinecraftServer.ChatMessage += MinecraftServerOnChatMessage;
     MinecraftServer.PlayerLoggedIn += MinecraftServerOnPlayerLoggedIn;
     MinecraftServer.PlayerLoggedOut += MinecraftServerOnPlayerLoggedOut;
     //MinecraftServer.TabComplete += MinecraftServer_TabComplete;
 }
Example #3
0
 public EntityManager(MinecraftServer server)
 {
     NextEntityId = 1;
     Server = server;
     Entities = new List<Entity>();
     MarkedForDespawn = new ConcurrentQueue<int>();
 }
Example #4
0
 public EntityManager(MinecraftServer server)
 {
     NextEntityId     = 1;
     Server           = server;
     Entities         = new List <Entity>();
     MarkedForDespawn = new ConcurrentQueue <int>();
 }
 internal ScoreboardManager(MinecraftServer server)
 {
     Server = server;
     Scoreboards = new List<Scoreboard>();
     Teams = new List<Team>();
     Server.PlayerLoggedIn += ServerOnPlayerLoggedIn;
 }
Example #6
0
 internal Scoreboard(MinecraftServer server, string name, string displayName)
 {
     Server = server;
     Name = name;
     DisplayName = displayName;
     Scores = new Dictionary<string, int>();
 }
 internal ScoreboardManager(MinecraftServer server)
 {
     Server                 = server;
     Scoreboards            = new List <Scoreboard>();
     Teams                  = new List <Team>();
     Server.PlayerLoggedIn += ServerOnPlayerLoggedIn;
 }
Example #8
0
        public static void Main(string[] args)
        {
            // Create a server on 0.0.0.0:25565
            minecraftServer = new MinecraftServer(
                new IPEndPoint(IPAddress.Any, 25565));
            minecraftServer.Settings.OnlineMode = false;
            minecraftServer.Settings.EnableEncryption = true;
            // Add a console logger
            LogProvider.RegisterProvider(new ConsoleLogWriter(LogImportance.Medium));
            LogProvider.RegisterProvider(new FileLogWriter("packetLog.txt", LogImportance.Low));
            // Add a flatland world
#if DEBUG
            // Use a fresh world each time
            if (Directory.Exists("world"))
                Directory.Delete("world", true);
#endif
            IWorldGenerator generator = new FlatlandGenerator();
            minecraftServer.AddLevel(new Level(generator, Path.Combine(Directory.GetCurrentDirectory(), "world")));
            minecraftServer.DefaultLevel.GameMode = GameMode.Creative;
            // Register the chat handler
            minecraftServer.ChatMessage += HandleOnChatMessage;
            // Start the server
            minecraftServer.Start();
            Console.WriteLine("Press 'q' key to exit.");
            while (Console.ReadKey(true).Key != ConsoleKey.Q) { }
            // Stop the server
            minecraftServer.Stop();
            minecraftServer.DefaultLevel.Save();
        }
Example #9
0
 public WeatherManager(World world, MinecraftServer server)
 {
     Server = server;
     World  = world;
     random = new Random();
     ScheduleChange(true);
     ScheduleChange(false);
 }
Example #10
0
 /// <summary>
 /// Creates a new MinecraftClient with the specified socket to be
 /// managed by the given <see cref="MinecraftServer"/>.
 /// </summary>
 public MinecraftClient(TcpClient client, MinecraftServer server) : this()
 {
     TcpClient                = client;
     NetworkStream            = client.GetStream();
     client.ReceiveBufferSize = 32768;
     Stream = new MinecraftStream(new BufferedStream(client.GetStream()));
     Server = server;
 }
Example #11
0
 public WeatherManager(World world, MinecraftServer server)
 {
     Server = server;
     World = world;
     random = new Random();
     ScheduleChange(true);
     ScheduleChange(false);
 }
Example #12
0
 public PlayerManager(RemoteClient client, MinecraftServer server)
 {
     Client = client;
     Server = server;
     SendInventoryUpdates                  = true;
     client.Entity.PickUpItem             += Entity_PickUpItem;
     client.Entity.Inventory.WindowChange += Inventory_WindowChange;
     client.PropertyChanged               += client_PropertyChanged;
 }
Example #13
0
 public Server(ISettingsProvider settingsProvider)
 {
     SettingsProvider = settingsProvider;
     var port = SettingsProvider.Get<int>("Server.Port");
     MinecraftServer = new MinecraftServer(new IPEndPoint(IPAddress.Any, port));
     MinecraftServer.ChatMessage += MinecraftServerOnChatMessage;
     MinecraftServer.PlayerLoggedIn += MinecraftServerOnPlayerLoggedIn;
     MinecraftServer.PlayerLoggedOut += MinecraftServerOnPlayerLoggedOut;
 }
Example #14
0
 public PlayerManager(RemoteClient client, MinecraftServer server)
 {
     Client = client;
     Server = server;
     SendInventoryUpdates = true;
     client.Entity.PickUpItem += Entity_PickUpItem;
     client.Entity.Inventory.WindowChange += Inventory_WindowChange;
     client.PropertyChanged += client_PropertyChanged;
 }
Example #15
0
 internal Team(MinecraftServer server, ScoreboardManager scoreboardManager, string name,
               string displayName, bool allowFriendlyFire, string playerPrefix, string playerSuffix)
 {
     Server            = server;
     ScoreboardManager = scoreboardManager;
     Name = name;
     _allowFriendlyFire = allowFriendlyFire;
     _displayName       = displayName;
     _playerPrefix      = playerPrefix;
     _playerSuffix      = playerSuffix;
     Players            = new List <string>();
 }
Example #16
0
 internal Team(MinecraftServer server, ScoreboardManager scoreboardManager, string name, 
     string displayName, bool allowFriendlyFire, string playerPrefix, string playerSuffix)
 {
     Server = server;
     ScoreboardManager = scoreboardManager;
     Name = name;
     _allowFriendlyFire = allowFriendlyFire;
     _displayName = displayName;
     _playerPrefix = playerPrefix;
     _playerSuffix = playerSuffix;
     Players = new List<string>();
 }
Example #17
0
 public Server(ISettingsProvider settingsProvider)
 {
     SettingsProvider = settingsProvider;
     var port = SettingsProvider.Get<int>("server.port");
     MinecraftServer = new MinecraftServer(new IPEndPoint(IPAddress.Any, port));
     MinecraftServer.Settings.MotD = SettingsProvider.Get<string>("server.motd");
     MinecraftServer.Settings.OnlineMode = SettingsProvider.Get<bool>("server.onlinemode");
     MinecraftServer.ChatMessage += MinecraftServerOnChatMessage;
     MinecraftServer.PlayerLoggedIn += MinecraftServerOnPlayerLoggedIn;
     MinecraftServer.PlayerLoggedOut += MinecraftServerOnPlayerLoggedOut;
     MinecraftServer.TabComplete += MinecraftServer_TabComplete;
 }
Example #18
0
        public Server()
        {
            Config = new ServerConfig();
            JsonSerializerSettings settings = new JsonSerializerSettings();
            settings.MissingMemberHandling = MissingMemberHandling.Error;
            //Parse the config file. If the config isn't valid, throw an error.
            if (File.Exists("config.json"))
                try { Config = JsonConvert.DeserializeObject<ServerConfig>(File.ReadAllText("config.json"), settings); }
                catch (JsonException e) { Logger.Log("Config file is invalid!", LogType.Error); }
            else
                File.WriteAllText("config.json", JsonConvert.SerializeObject(Config, Formatting.Indented));

            //Parse the IP from the config file.
            if (!string.IsNullOrWhiteSpace(Config.IP))
            {
                if (!IPAddress.TryParse(Config.IP, out ServerIP))
                    ServerIP = IPAddress.Any;
            }
            else
                ServerIP = IPAddress.Any;
            ServerPort = Config.Port;
            MCServer = new MinecraftServer(new IPEndPoint(ServerIP, ServerPort));
            LogProvider.RegisterProvider(new MCServerLogger());

            //Choose the world generator based on the config file.
            if (string.IsNullOrWhiteSpace(Config.World))
                Config.World = "world";
            switch (Config.WorldType)
            {
                case LevelGenerator.Debug:
                    Generator = new DebugGenerator();
                    break;
                case LevelGenerator.Flatland:
                    Generator = new FlatlandGenerator();
                    break;
                default:
                    //No default generator yet!
                    Generator = new DebugGenerator();
                    break;
            }
            Level l = new Level(Generator, Config.World);
            l.GameMode = GameMode.Survival;
            if (Config.Gamemode == Gamemode.Creative) l.GameMode = GameMode.Creative;
            MCServer.AddLevel(l);

            MCServer.Settings.MotD = Config.MOTD;
            MCServer.Settings.MaxPlayers = Config.MaxPlayers;
            MCServer.Settings.OnlineMode = Config.Online;
            MCServer.Settings.Difficulty = Config.Difficulty;

            MCServer.PlayerLoggedIn += new EventHandler<Craft.Net.Server.Events.PlayerLogInEventArgs>(PlayerLoggedIn);
            MCServer.Start();
        }
Example #19
0
 static void Main(string[] args)
 {
     if (Directory.Exists("world"))
         Directory.Delete("world", true);
     level = new Level(new StandardGenerator(), "world");
     level.AddWorld("region");
     level.SaveTo("world");
     var server = new MinecraftServer(level);
     server.ChatMessage += server_ChatMessage;
     server.PlayerLoggedIn += server_PlayerLoggedIn;
     server.Settings.OnlineMode = true;
     server.Start(new IPEndPoint(IPAddress.Any, 25565));
     Console.WriteLine("Press 'q' to exit");
     ConsoleKeyInfo cki;
     do cki = Console.ReadKey(true);
     while (cki.KeyChar != 'q');
     server.Stop();
 }
Example #20
0
 public MinecraftClient(Socket Socket, MinecraftServer Server)
 {
     this.Socket = Socket;
     this.RecieveBuffer = new byte[1024];
     this.RecieveBufferIndex = 0;
     this.SendQueue = new Queue<Packet>();
     this.IsDisconnected = false;
     this.IsLoggedIn = false;
     this.EncryptionEnabled = false;
     this.Locale = "en_US";
     this.MaxViewDistance = 10;
     this.ViewDistance = 3;
     this.ReadyToSpawn = false;
     this.LoadedChunks = new List<Vector3>();
     this.Server = Server;
     this.WalkingSpeed = 12;
     this.FlyingSpeed = 25;
     this.Inventory = new Slot[44];
     this.LastKeepAlive = DateTime.MaxValue.AddSeconds(-120);
 }
Example #21
0
 static void Main(string[] args)
 {
     if (Directory.Exists("world"))
         Directory.Delete("world", true);
     level = new Level(new StandardGenerator(), "world");
     level.AddWorld("region");
     level.AddWorld("test", new FlatlandGenerator());
     level.Worlds[1].GenerateChunk(Coordinates2D.Zero);
     level.SaveTo("world");
     server = new MinecraftServer(level);
     server.ChatMessage += server_ChatMessage;
     server.Settings.OnlineMode = true;
     server.Settings.MotD = "Craft.Net Test Server";
     server.Start(new IPEndPoint(IPAddress.Any, 25565));
     Console.WriteLine("Press 'q' to exit");
     ConsoleKeyInfo cki;
     do cki = Console.ReadKey(true);
     while (cki.KeyChar != 'q');
     server.Stop();
 }
Example #22
0
        public static void Main(string[] args)
        {
            // Create a server on 0.0.0.0:25565
            minecraftServer = new MinecraftServer(
		        new IPEndPoint(IPAddress.Any, 25565));
            minecraftServer.OnlineMode = false;
            minecraftServer.EncryptionEnabled = false;
            // Add a console logger
            minecraftServer.AddLogProvider(new ConsoleLogWriter(LogImportance.High));
            minecraftServer.AddLogProvider(new FileLogWriter("packetLog.txt", LogImportance.Low));
            // Add a flatland world
            minecraftServer.AddWorld(new World(new DebugGenerator()));
            // Register the chat handler
            minecraftServer.OnChatMessage += HandleOnChatMessage;
            // Start the server
            minecraftServer.Start();
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey(true);
            // Stop the server
            minecraftServer.Stop();
        }
Example #23
0
		public Server (int port, bool onlineMode, int maxPlayers, String motd, int difficulty, String levelName, String levelType, GameMode gamemode, String ingameMOTD)
		{
			var level = new Level ();
			if (levelType == "FLAT") {
				var generator = new FlatlandGenerator ();
				level = new Level (generator);
			} else if (levelType == "NORMAL") {
				var generator = new StandardGenerator ();
				level = new Level (generator);
			}
			level.AddWorld ("overworld");
			this.server = new MinecraftServer (level);
			this.server.Settings.MotD = motd;
			this.server.Settings.OnlineMode = onlineMode;
			this.server.Settings.MaxPlayers = (byte)maxPlayers;
			this.server.Settings.Difficulty = (Difficulty)difficulty;
			this.server.PlayerLoggedIn += OnPlayerLoggedIn;
			this.server.ChatMessage += OnPlayerChatMessage;
			this.server.PlayerLoggedOut += OnPlayerLoggedOut;
			this.server.Level.GameMode = gamemode;
			this.port = port;
			this.ingameMOTD = ingameMOTD;
		}
Example #24
0
 /// <summary>
 /// Creates a new MinecraftClient with the specified socket to be
 /// managed by the given <see cref="MinecraftServer"/>.
 /// </summary>
 public MinecraftClient(TcpClient client, MinecraftServer server) : this()
 {
     TcpClient = client;
     NetworkStream = client.GetStream();
     client.ReceiveBufferSize = 32768;
     Stream = new MinecraftStream(new BufferedStream(client.GetStream()));
     Server = server;
 }
Example #25
0
 public override void ChannelRegistered(MinecraftServer server)
 {
 }
Example #26
0
 public ConsoleClient(MinecraftServer server)
     : base(null)
 {
     Username = "******";
     Tags["PartyCraft.UserGroups"] = new List<string>(new[] { "server.default", "server.op", "server.console" });
 }
Example #27
0
 /// <summary>
 /// Sends the packet to a client.
 /// </summary>
 public abstract void SendPacket(MinecraftServer server, MinecraftClient client);
Example #28
0
 /// <summary>
 /// Handles the server-side logic for recieving the packet.
 /// </summary>
 public abstract void HandlePacket(MinecraftServer server, MinecraftClient client);
Example #29
0
 public virtual void ChannelRegistered(MinecraftServer server)
 {
 }
Example #30
0
 public WeatherManager(World world, MinecraftServer server)
 {
     Server = server;
     World = world;
 }
Example #31
0
 public WeatherManager(MinecraftServer server)
 {
     Server = server;
 }
Example #32
0
 public EntityManager(MinecraftServer server)
 {
     this.server = server;
 }
Example #33
0
 /// <summary>
 /// Run when the channel is successfully registered.
 /// </summary>
 public abstract void ChannelRegistered(MinecraftServer server);
Example #34
0
 public override void ChannelRegistered(MinecraftServer server)
 {
     this.server = (LocalServer)server;
 }
Example #35
0
 /// <summary>
 /// Creates a new MinecraftClient with the specified socket to be
 /// managed by the given <see cref="MinecraftServer"/>.
 /// </summary>
 public MinecraftClient(Socket socket, MinecraftServer server)
 {
     this.Socket = socket;
     RecieveBuffer = new byte[4096];
     RecieveBufferIndex = 0;
     SendQueue = new ConcurrentQueue<Packet>();
     IsDisconnected = false;
     IsLoggedIn = false;
     EncryptionEnabled = false;
     Locale = CultureInfo.CurrentCulture;
     MaxViewDistance = 10;
     ViewDistance = 3;
     ReadyToSpawn = false;
     LoadedChunks = new List<Vector3>();
     Server = server;
     WalkingSpeed = 12;
     FlyingSpeed = 25;
     LastKeepAlive = DateTime.MaxValue.AddSeconds(-10);
     KnownEntities = new List<int>();
     PluginChannels = new List<string>();
     Tags = new Dictionary<string, object>();
 }
Example #36
0
 public WeatherManager(World world, MinecraftServer server)
 {
     Server = server;
     World  = world;
 }
Example #37
0
 /// <summary>
 /// Run when the channel is successfully registered.
 /// </summary>
 public abstract void ChannelRegistered(MinecraftServer server);
Example #38
0
 public EntityManager(MinecraftServer server)
 {
     this.server = server;
 }
Example #39
0
 /// <summary>
 /// Creates a new MinecraftClient with the specified socket to be
 /// managed by the given <see cref="MinecraftServer"/>.
 /// </summary>
 public MinecraftClient(TcpClient client, MinecraftServer server)
 {
     TcpClient = client;
     NetworkStream = client.GetStream();
     client.ReceiveBufferSize = 32768;
     Stream = new MinecraftStream(new BufferedStream(client.GetStream()));
     SendQueue = new ConcurrentQueue<IPacket>();
     IsLoggedIn = false;
     EncryptionEnabled = false;
     Locale = CultureInfo.CurrentCulture;
     MaxViewDistance = 10;
     ViewDistance = 3;
     LoadedChunks = new List<Vector3>();
     Server = server;
     WalkingSpeed = 12;
     FlyingSpeed = 25;
     LastKeepAlive = DateTime.MaxValue.AddSeconds(-10);
     KnownEntities = new List<int>();
     PluginChannels = new List<string>();
     Tags = new Dictionary<string, object>();
     DisconnectPending = false;
 }