Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Setting up a server

djacobus edited this page Mar 13, 2013 · 2 revisions

Craft.Net.Server makes it relatively easy to set up a Minecraft server. There are a number of things you need:

  • At least one level
  • An endpoint
  • Sever settings

The last one is optional - the default settings will be used if you do not specify your own. Here's a common server setup:

var minecraftServer = new MinecraftServer(new IPEndPoint(IPAddress.Any, 25565));
var generator = new FlatlandGenerator();
// Creates a level in the "world" directory, using the flatland generator
// You may omit "world" to create a level in memory.
minecraftServer.AddLevel(new Level(generator, "world"));
minecraftServer.Start();

This would start a server on port 25565, with a flatland world. The level will be saved periodically; the exact period can be customized with Level.SaveFrequency. There are also several events that you can take advantage of to customize the server.

  • MinecraftServer.PlayerLoggedIn fires when a player successfully logs in. Set PlayerLogInEventArgs.Handled to true to suppress the default "Player has joined the game" chat message.
  • MinecraftServer.PlayerLoggedOut is similar. Set PlayerLogInEventArgs.Handled to true to suppress the default "Player has left the game" chat message.
  • MinecraftServer.ChatMessage will fire when players chat on the server. Set ChatMessageEventArgs.Handled to prevent the default " message" chat from being sent to connected players.
  • MinecraftServer.PacketSent fires immediately after a packet is sent by the server, and includes the packet details.
  • MinecraftServer.PacketRecieved fires immediately after a packet is received by the server, before it is processed by the server packet handlers.
  • MinecraftServer.PlayerDeath fires when a player dies. Set PlayerDeathEventArgs.Handled to true to suppress the default death message.

Overriding Packet Handlers

You can add your own packet handlers to replace the default ones. Use MinecraftServer.RegisterPacketHandler to register a method whose signature is (MinecraftClient client, MinecraftServer server, IPacket packet).

Plugin Channels

Make a class that derives from Craft.Net.Server.PluginChannel and use MinecraftServer.RegisterPluginChannel to register your channel. Some plugin channels are included for you:

Clone this wiki locally