Jump to content

Looking back at a multiplayer mod attempt


Recommended Posts

With don't starve together keys being given out every day, I though I might take a moment and talk about my attempt and creating a multiplayer mod.


After having played the game quite a bit, I wanted to dive into modding, (as I often do with any game that supports it). At the time I was really excited about DST as I wanted to play with a friend who had introduced me to game originally. So I decided to try and make my own quick multiplayer mod.


My first priority was to determine how feasible an external connect to a server could be when done through modding. Luckily LuaSocket was already included with the build of Don't Starve. So I set up a read and write connection on map load.


The next step was to set up an external server that would be able to receive and respond to the clients. I chose to write it in Java as I am very familiar with the Java socket API. I made a quick test program that could take multiple client connections and could send text from stdin to the clients from the server.


Now that I had a working connection, I just had to work on creating a protocol and code the reactions to packets on both the client and server side. The first and most obvious thing to do was to create a player protocol so two players could see each other and move around. The main problem here was that I was not yet syncing worlds, so the visible location of one player would not be the same for the other. As a way to ignore this problem right now, we will render the players relative to each other.


To do this I would send the players current location and subtract if from the other players location. So that they would be able to see each other and move around. When a player joined the server would alert all connected clients and an entity would be spawned for that player in each world. Then the entity would be told to walk to the location relative to the original player. Now that I had the players in each world, the next step was to send the player's current animation. This was as simple as sending the current animation name to the other entities. 


I then decided to try and sync the worlds. To do this I started by sending all entities within the radius of the first player to the server. Then when the second player connects, all entities near them would be removed and then replaced by the server's entities. This did not perverse entity data, but did help reconstruct the world somewhat. I then attempted to catch some events such as entities being removed or spawned and sync those across the server as well. 


The final task I attempted was syncing the world tiles themselves, which I did in a much similar way to the world entities. The tiles would be sent to the server and the second client would replace theirs with the servers. However this created a lot of lag on both clients. I also wasn't syncing world boarders, so the ocean boarders would remain. 


This was as far as I got in my endeavor to create a multiplayer mod. I would say that it was a mostly successful attempt and a great experience. I am excited to see what I can do with the official DST.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

  • Create New...