How to write a server?

Sponge is not the place to ask this question (at least not a good one). You are better off asking Forge (luckily I’m here). Sponge is not an implementation of a minecraft server, rather an implementation of SpongeAPI layered atop Forge, which is atop of Minecraft server (so none of the people at Sponge actually know how to make a server except for SpaceManiac).

I’m a TridentSDK developer. Since Trident is clean reimplementation of the minecraft server, I would be the most qualified to answer at the moment, so don’t call me out for trolling because I am not.

Trident was developed around game order. At first, we figured that we needed a base the server runs on. This means connections, world loading, processes, and plugins. We started out with connections because it is the easiest. Netty was the backend, and we open a server bootstrap bound to IP 127.0.0.1 and port 25565. This allows clients to connect to the target at the external IP that is redirected through the connection made by the server bootstrap on localhost. This is started using 2 NioEventLoops.

Next, we did loggin/CLI options. As we have not had the chance to fully control the server yet, we held back on command implementation until world loading finishes. Currently, JOptSimple parses /help and the other runtime parameters.

Then, the server object is constructed. This loads in all of the processes, including server task executor, scheduling, connection listeners, and various API libraries.

The most important is protocol. We were highly focused on protocol because that’s what makes a server, a a server. The ability to communicate with clients (after connection pools are initialized). Basically, we had to replicate all of the packets on the protocol spec on wiki.vg, and correct the encoding a tiny bit. I won’t go into much detail, but we also handled client logins and encryption, along with the decoders/encoders along the netty IO connections. This was the hardest part to figure out in my personal opinion. There is a nice protocol order on the protocol FAQ on wiki.vg, that was a good reference for player joining, which came next.

All of the packets have an action method that can be overridden to perform an action when the packet is reviewed by the server. Once the join game packet is sent by the client, the server can now send the world chunks, block lighting, entities, metadata, and other players. Also note that you need to listen for the player’s update packet (which I am pretty sure has KeepAlice somewhere in there) which prompts you to update the world and send tick modifications to the client.

We haven’t gotten to world loading as we are discussing API design and when to make decisions, so I don’t know much about that. What we have started is RegionFile decoding, which allows us to parse world folders of default minecraft maps, which is extremely cool (but difficult). We have the NBT decoding done, and are looking on Minecraft wiki for information on the world file format (heh clean room :P).

I was in charge of multithreading. This is central to the server, as the existing minecraft server did not have very advanced multithreading capabilities. Task handling is based on ConcurrentTaskExecutor which is a thread pool that only loops and has a set pool size, in order to utilize the CPU consistently. We discussed the amount of threads to use to be around 16, because most processors cannot support more than 16 threads at a single time. More threads, and they would compete for CPU cycles, which may degrade performance instead of increasing it. I am currently looking at a separate performance concurrent queue because the current one takes 500ns to take the last item out. I’ve also reimplemented the scheduler (but tests show that it is 2x slower than the Bukkit scheduler… Yeesh) which originally had synchronized everywhere, even on atomic variables (hehe, not to blame the other developer for that - he had a cool tick class though).

All in all, just start with the connections/protocol.

3 Likes

I was just reading through Sponge’s source when I noticed the entire thing was a Forge mod… Thanks for the exact explanation I needed! Does Trident have a forum? I saw the post on the Bukkit Forums and it seemed pretty cool.

You could look into the Glowstone source code

1 Like

Yes, you can find out where on the post on Bukkit, but I can’t tell you the link exactly because that would be advertising. You could also definitely look at Glowstone, its been around for 2-3 years I believe.

How’s it advertising? Bukkit is dead.

Bukkit and Sponge aren’t servers as such. They just hook into / are built on the vanilla minecraft server.

2 Likes

I guess it would be advertising as it’s described by @DarkArcana in his rules post

Don’t advertise in any form on any Sponge system. This includes […] some piece of software you use for fun […]

But I’d hafta say, if you came across Sponge without already knowing about Bukkit, I’d be very surprised XD Bit off-topic, sorry!

I doubt it would count as advertising, though.
Correct me, if I’m wrong, @DarkArcana.

Discussing things you use for fun, not in an effort to draw people away from where you are but to that other thing you use, is not a form of advertisement. It’s discussion. But we still retain the right to call something advertisement or discussion if it seems like it to us one way or the other.

If I post the link, is it advertising…?

Depends on context. Think of two competing models, or services, such as xbox vs playstation. You’re on xbox forums. It’s probably fine to discuss the playstation and how it operates in relation to the xbox, but it’s probably not alright to post links and try to persuade people to buy one there. Think of going to the Forge forums and advertising Sponge as a new alternative and trying to persuade users to abandon one for the other. That kind of behavior is generally unacceptable. In the case of server lists, the whole point is to get people to join your server versus another. So you present competing models and the point is to advertise.

When you look at the context, you can determine whether someone is advertising or just discussing something. For example:

Person A: “What server do you play on and why?”
Person B: “I play on XYZ server at IP address with ‘this’ gamemode because reasons.”

vs

Person A: “You should use X server host because Y!”

So this makes a clear distinction between what is obviously discussion and what is advertisement. Sometimes context can be a little hard to discern so it falls on a moderator to decide.

In that case…

@Phase
https://tridentsdk.net

1 Like

See this is fine because he asked if trident had a forum. So you linked the forum. You aren’t blatantly saying, “You should use Trident because it’s better than Sponge”, or some other random thing, haha. This is how we can all be civil, work together, and exchange ideas :smiley:.

5 Likes

Basically, what I was trying to say. :wink:

@PierreC

Old thread but I find it hilarious that this user made the claim that no one at Sponge knows how to write a server but himself (as he works on some trident project…thing) and the folks at Glowstone (they do).

Well @Phase I was a part of the Spout project which aimed to write the Spout voxel game engine where plugins drove all the game logic. We mostly re-wrote Minecraft in a plugin called Vanilla. I’m pretty qualified to give advice on the challenges you’ll face. I’ve also helped with Glowstone before (in their packets as well as Spout was originally forked from Glowstone) and can give you a lot of insight on what you’ll need to overcome in writing a Minecraft server.

Feel free to shoot questions my way.

Well, there isn’t any fixed implementation, is there? It’s all up to you how you make it. The only things that have to be the same are the output / input for networking and (if ou want interchangeable maps) the map and nbt format.

Also PM’ing links when people have asked for them is a thing.

  1. Sponge is not just a forge mod. Sponge is an entire API with many planned implementations. Don’t discount it.
  2. Again, sponge is an API from which implementations can be built off of. A forge mod just happens to be one that is planned. Glowstone plans to implement eventually and many others I am sure you could find just by searching these forums. I would think someone of your claimed experience with programming and minecraft would understand that.
  3. Didn’t everyone in this thread just tell you to fork an existing project? Didn’t you refuse every time? Now you decide to do it once its your idea? Cmon…
  4. Just do some basic research in some ways that post was just as bad as some of the amateur server owners that post on here looking for a download. If you want to build a Minecraft server from scratch go right ahead, but it will have to be something mighty special to make anyone use it over existing options such as Sponge, Spigot and Glowstone. Either way any server you write from scratch on your own is not going to be able to touch the capabilities of the aforementioned projects, I don’t know what you are planning on using this for, but to each his own. Just keep in mind its sometimes better to not reinvent the wheel. In my opinion, echoing many other people in this thread, you should fork a project that has the basics down, then strip it / improve it / change it however you want.
3 Likes

Don’t say “entire API”, you’re just stressing it can be used on anything. Which we all know.

Forge is the current plan, and is the only one being worked on ATM. I’d love to see work on a Glowstone implementation.

I didn’t want to fork one, as I wanted to learn how the servers actually work.

You sound like this is a fight between all the servers, duking it out in an arena. I don’t care if anyone “uses it over existing options”, it’s just a game, not a war. No server owners are going to care which server has the best performance, or the best developers. Unless they’re some big company, they’re better off using Spigot compared to anything else, as it uses the Bukkit API, which has hundreds of plugins available for it. I couldn’t care less who uses it, it’s just for fun. Isn’t that what Minecraft’s about, placing blocks & having fun?

I’m not trying to spruik Granite, but there is at least one plan being worked on out there to implement Sponge that does NOT involve using Forge.

There is actually a working release of Granite, which uses the Sponge API. It is not an official implementation, meaning that it isn’t developed or approved by the core Sponge team, so SpongeDev can give no assurances about its’ quality or safety. That may change, depending on negotiations between the teams.

1 Like