示例#1
0
 internal Scoreboard(MinecraftServer server, string name, string displayName)
 {
     Server      = server;
     Name        = name;
     DisplayName = displayName;
     Scores      = new Dictionary <string, int>();
 }
示例#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;
 }
示例#3
0
 public EntityManager(MinecraftServer server)
 {
     NextEntityId = 1;
     Server = server;
     Entities = new List<Entity>();
     MarkedForDespawn = new ConcurrentQueue<int>();
 }
示例#4
0
 public EntityManager(MinecraftServer server)
 {
     NextEntityId     = 1;
     Server           = server;
     Entities         = new List <Entity>();
     MarkedForDespawn = new ConcurrentQueue <int>();
 }
示例#5
0
 internal ScoreboardManager(MinecraftServer server)
 {
     Server = server;
     Scoreboards = new List<Scoreboard>();
     Teams = new List<Team>();
     Server.PlayerLoggedIn += ServerOnPlayerLoggedIn;
 }
示例#6
0
 internal Scoreboard(MinecraftServer server, string name, string displayName)
 {
     Server = server;
     Name = name;
     DisplayName = displayName;
     Scores = new Dictionary<string, int>();
 }
示例#7
0
 internal ScoreboardManager(MinecraftServer server)
 {
     Server                 = server;
     Scoreboards            = new List <Scoreboard>();
     Teams                  = new List <Team>();
     Server.PlayerLoggedIn += ServerOnPlayerLoggedIn;
 }
示例#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();
        }
示例#9
0
 public WeatherManager(World world, MinecraftServer server)
 {
     Server = server;
     World  = world;
     random = new Random();
     ScheduleChange(true);
     ScheduleChange(false);
 }
示例#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;
 }
示例#11
0
 public WeatherManager(World world, MinecraftServer server)
 {
     Server = server;
     World = world;
     random = new Random();
     ScheduleChange(true);
     ScheduleChange(false);
 }
示例#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;
 }
示例#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;
 }
示例#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;
 }
示例#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>();
 }
示例#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>();
 }
示例#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;
 }
示例#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();
        }
示例#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();
 }
示例#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);
 }
示例#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();
 }
示例#22
0
文件: Main.cs 项目: keneo/Craft.Net
        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();
        }
示例#23
0
文件: Server.cs 项目: CServer/CServer
		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;
		}
示例#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;
 }
示例#25
0
 public override void ChannelRegistered(MinecraftServer server)
 {
 }
示例#26
0
 public ConsoleClient(MinecraftServer server)
     : base(null)
 {
     Username = "******";
     Tags["PartyCraft.UserGroups"] = new List<string>(new[] { "server.default", "server.op", "server.console" });
 }
示例#27
0
 /// <summary>
 /// Sends the packet to a client.
 /// </summary>
 public abstract void SendPacket(MinecraftServer server, MinecraftClient client);
示例#28
0
 /// <summary>
 /// Handles the server-side logic for recieving the packet.
 /// </summary>
 public abstract void HandlePacket(MinecraftServer server, MinecraftClient client);
示例#29
0
 public virtual void ChannelRegistered(MinecraftServer server)
 {
 }
示例#30
0
 public WeatherManager(World world, MinecraftServer server)
 {
     Server = server;
     World = world;
 }
示例#31
0
 public WeatherManager(MinecraftServer server)
 {
     Server = server;
 }
示例#32
0
 public EntityManager(MinecraftServer server)
 {
     this.server = server;
 }
示例#33
0
 /// <summary>
 /// Run when the channel is successfully registered.
 /// </summary>
 public abstract void ChannelRegistered(MinecraftServer server);
示例#34
0
 public override void ChannelRegistered(MinecraftServer server)
 {
     this.server = (LocalServer)server;
 }
示例#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>();
 }
示例#36
0
 public WeatherManager(World world, MinecraftServer server)
 {
     Server = server;
     World  = world;
 }
示例#37
0
 /// <summary>
 /// Run when the channel is successfully registered.
 /// </summary>
 public abstract void ChannelRegistered(MinecraftServer server);
示例#38
0
 public EntityManager(MinecraftServer server)
 {
     this.server = server;
 }
示例#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;
 }