Advertisement Jump to content
  • Advertisement

Project: Unsettled World

A Story of Some Servers and Their Game.



Unsettled World, makes a great title I think, but without a server, it's just a terribly lonely place indeed.

I've written many servers over the years and clients to go with them, and in lots of different languages(never before for games).  However,I've never been one to hang onto the proper semantics of communicating how a program works so, stick in there and I'll do my best. ;)  Please feel free to chime in if you see something technical that could be fixed or if it just looks at you funny, you can tell me that too.  I'm good with it. 


Multiple, functionally segmented, server applications / To many, identically functional clients.  To sum it up..  haha  It's important to say that all servers maintain an authoritative role in all matters of game play.  If the Avatar Server hasn't authorized that item in your inventory, it won't be there.  If the Economy Server has a 0.00 in your bank account, the game client will reflect that.

Avatar Server(Functional in all listed categories): C# UDP server application, game time keeper, controls authentication, resource access, player inventories, land ownership and mining claim ownership and is the "echo point" for network player data such as positioning and appearance data.

Economy Server(Currently in ACTIVE Dev): C# UDP server application, Communicates with the Avatar Server to coordinate time synchronization, and to update its list of active player id#s and their encryption keys. Its purpose is to house all the functionality that one would attribute to a game economy(aside from physical resource access).  Banking, Auctions and a Resource Stock Market.  My Player1 checked the balance on his bank account for the first time just yesterday in fact.  He was pleased to finally see the 2000.00 Settler Credits he was promised months ago.  lol.

NPC Server(s)(Currently Completely Imaginary): C# UDP server application that communicates the positions and coordinates the movements of NPCs that are instantiated into the world by their NPC Client applications.

NPC Client(s)(Currently Completely Imaginary): C#(or c#/unity) UDP Client applications that will control the movement and interactivity of one or many NPCs, all NPC code will interact with the server just like player code does, via a UDP connection.  However, since most of the NPC data will already be built into the client, these connections will be significantly less chatty than a real players connection.

Other Servers/Clients(Also Completely Imaginary): C# probably, UDP most likely.. the rest, who knows. ;)

So, how do I keep all these data bits ready for player interaction?  Data Structures!!  Everything in my servers runs from in-memory data structures, I have no database back end, nor a desire to ever need one.  I'm not saying databases aren't cool, or massively useful in similar scenarios.  I have built MANY of those too, but to get the response times I want, well that would require something in the range of an in-memory instance of mysql or another big hitter similarly configured.  I don't want to have to add that to the arena, and certainly not at this stage of the game.. heh..  stage of the game... Anyway!

Some of the Data Structures Currently Utilized in my Avatar Server:

 //This keeps track of the player ids and encryption strings
 //When a player logs on an encryption string is negotiated...
 Dictionary<int, string> playerKeys = new Dictionary<int, string>();
 //Reverse lookup for player ID#s to stored GUID ids.
 //ID#s are shorter and travel better in a compact UDP packet(1470ishbytes) than a big Ol'GUID!
 Dictionary<int, string> playerGUIDLookup = new Dictionary<int, string>();

 //"Table" of currently authenticated Player Save data for many uses here and there, but mostly for persistence purposes.
 //This gets updated by the client when the player makes changes and is saved on the server side.
 //Including the character's avatar description. (Avatar Server)
 Dictionary<int, AvatarSave> PlayerAuth = new Dictionary<int, AvatarSave>();
 //Seems redundant somehow, but it isn't. Just, a bad name. 
 //This keeps count of how long a player is idle from the server's perspective, so it can give them the BOOT when it goes too long.
 Dictionary<int, int> livePlayers = new Dictionary<int, int>();
 //Seperate "Table" of data specific to the player avatar movements and orientation, position/rotation/etc...
 Dictionary<int, AvatarAttitudeUpd> livePlayerData = new Dictionary<int, AvatarAttitudeUpd>();
 //This holds data recieved asynchronously from the game clients(or other servers) as well as the EndPoint it was recieved from, for replies.
 //Each recieved command in this Queue is given a Task to process and reply to the game client with.
 //One message/activity/request/command per packet and only ONE, so no complicated re-assembly is needed on either end of the wire.
 Queue<KeyValuePair<string, EndPoint>> UDPClientMessages = new Queue<KeyValuePair<string, EndPoint>>();
 //A less organized version of the above data structure.  These get filtered for players who aren't logged in anymore, commands out of order get skipped, and etc..  Essentially it's the RAW data from the asyncronous receiver.
 Dictionary<EndPoint, Queue<string>> UDPMessages = new Dictionary<EndPoint, Queue<string>>();

 //The collection of all known player IP/PORT end points, that haven't been booted for inactivity.
 Dictionary<int, EndPoint> playerEPs = new Dictionary<int, EndPoint>();


Here's a quick run..

Avatar Server Application Starts:

udpServerThread = new Thread(new ThreadStart(UDPServer));
 //Starts up a standard UDP Socket Server here with an asynchronous receive mechanism which pumps into the UDPClientMessages Queue.
 	Loops here waiting for clients to send data.
		Increments Game Time, a double precision counter that keeps track of the total run time of the avatar server. 

		Parallel.ForEach() through the playerEPs sending them them the current server time.
		foreach() through the livePlayerData sending all relevant network player data to the clients who should see them.
		Some threadpool scaling to increase/decrease the pool size depending on # of users logged in.
		Requeueing of messages from UDPMessages into UDPClientMessages happens via some Task.Factor Tasks.
		And finally a new Task.Factory Task is created for every item in the UDPClientMessages Queue to process the incoming command from the player's game client.  (player's new coordinates, logins, inventory requests, changes,etc,etc,etc)...


I can't even call that pseudo-code but I think it conveys what I'm trying to share without going into too much gory detail.  If anybody wants some of that, feel free to comment below and I'll expand on anything I can.  But this describes the basic conceptual design of my server applications.

There are whole other layers of data structures in that server that I've omitted as it gets extremely gory in there...  But that's where the inventories / resources / and crafted items live and it's a bit messy right now.  I'm going to try to get those a little bit more finalized before I try to convey their madness to you.  Suffice to say, there's a lot more to it than this.  But that is less related to the "server" and more related to the game.

Until next, Thanks for reading!


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • What is your GameDev Story?

    In 2019 we are celebrating 20 years of! Share your GameDev Story with us.

    (You must login to your account.)

  • Blog Entries

  • Similar Content

    • By adamhuman
      well Hello internet , greeting to all of you smart beautiful Developers people  
      its something i dream about to make my own simple 2D game engine from scratch
      and to make it Easy for my self i thought ill be able to use C# for the game coding and Basic manipulation and Animation ,
      and C++ for the Graphic Engine and the heavy stuff of Importing and exporting and rendering 
      but the problem is i only have Experience in C# and Graphic and Illustration Design ( that's = no worry about the Animation and Assets )
      so i don't Have any Experience in SDL/OpenGL or C++ i only know some Basic , 
      and since SDL/OpenGL tutorials are available in youtube i didnt find an advanced one talking about combining between C# and C++ like Unity3D did in their engine 
      any help in this will be Awesome  
    • By rh_galaxy
      Hi, I'm seeking people interested in help making "Galaxy Forces VR" a great game.
      I'm currently alone and like someone that can create simple 3D-models, and a programmer to join the team.
      The project is being developed using Unity/C#. It's a 2D game, but viewed in 3D.
      The game is based on my project "Galaxy Forces V2", but this will be single player only, and support the game modes race and mission. There will be global hi-scores on the website with replays of the record scores and ranking of top players, as it adds a lot to the game. And also keeps players interested for longer time.
      Everything is not written in stone, there are possibilities for someone creative to add their own ideas. In fact I encourage any team member to test and think about different options of how to make the game better.
      A change to the original is that this will be easier to play for beginners to make it more attractive but not easier to master fully.
      This is the original complete version:
      I'm new to Unity, and only have a little knowledge of how to create 3D models. I know C++ fully, but C# is mostly the same. I might get the coding done myself, but it would feel better to have one more person coding and testing their ideas.
      I share a picture from the development, and a demo version in current state, so you can decide if you want to join. The plan is to release it on the Oculus Store in half a year. I have a todo list, and I promise to do what I can and spend much time on this to get it done to completion. I like to share the profits with those who want to join and have actually done something that pushes the project forward. The demo runs on Windows without VR, but Oculus Rift is recommended to be able to choose level in the menu (otherwise press Return to play the default level)...

      Galaxy Forces VR v0.1
      The presentation right now may not be the final result, especially the menu needs a new look with more contents.
      It is true that it is a hobby project, but I think it has great chances to get accepted by Oculus. There is a large contents of 50 levels for one thing, and the levels don't need much work to reuse for this project. Also since VR is not main stream, and there aren't so many games released, it will not drown in the noise as easily. And I think VR people buy more games than most, at least I do.

      This is the full TODO list, that covers most of the needed work from now to release. I think the time plan is realistic...
      Map elements
      - Landing zone, hangar building - low poly model (only visual)
      - Landing zone, antenna - low poly model (only visual)
      - Map decorations, trees - low poly model (visual, and collision in map)
      - Map decorations, barrels - low poly model (visual, and collision in map)
      - Map decorations, red/green house in 3 parts (left, center, right) - low poly model (visual, and collision in map)
      - Z-objects for decoration. Objects that can be placed in a map that are larger and sticks out towards the player to make it more visually pleasing to play VR, for example brick walls in different shapes (only visual, placed inside walls not accessible to the ship) The levels
      - Now there are 23 race levels and 23 mission levels. There also exist levels for dogfight and mission_coop, take these levels and convert them to race and mission to get 50+ levels
      - Need to fix the editor to make it possible to place the new Z-objects in the maps and go through each map and add them Door element
      - A low poly model for the end points of the door (only one needs to be created, can be rotated in 4 different angles to make all parts)
      - Implement the door element in code Enemies
      - Create them in 3D [enemy 0..6]
      - Implement them in code Game Status
      - Race: show Time, Current checkpoint, Current lap/Total laps, Health bar
      - Mission: show Lives, Health bar, Fuel bar, Cargo bar, Score Sound
      - Add existing music to the menu and game
      - Add existing sound fx in the game Menu
      - More contents (could be Game Name text/logo, animated objects, clouds, anything really)
      - Better gfx (different textures for the level select elements)
      - Show your score vs the world best on each level, also show your rank (gold, silver or bronze)
      - Make part 2 of the menu - after a level is selected in part 1, shows 3 options - play, play your best replay, play the world record replay
      - Settings to turn the music on/off (+a minimum of other settings). The VR room around the player
      - More contents (could be clouds and a skybox, or a room, or blackness in space, anything really) Replay
      - Implement replays in code
      - Online hiscores - that is, be able to send/load the replays to the website (either HTTP or HTTPS if possible, maybe easy to do HTTPS with C# ?)
      - The hiscore implementation on the website. (mostly done already) Website
      - exists.
      - Better/more contents + the hi-scores Release
      - Images in different sizes for release on the Oculus Store
      - Game play promotion video
      - Test/fix it working on minimum req hardware The demo + the todo list should help get a picture of what this game will be and help you decide if you want to join and if you have the skills needed.
      Hope to hear from you.

    • By Naruto-kun
      Hi guys
      A while back I wrote a small app using C# and MoonSharp to execute a Lua script that would call functions from within my C# app, that would call GDI+ draw commands. This way I could see how my draw elements were being positioned in real time and adjust as I wished as can be seen in the image below. However, I am now looking at creating my own library that will use D3D11 instead of GDI+ to render 2D shapes, and I would like to create the same scripting tool, but this time I want it to use C#. Is there anything like this out there?

    • By Igor0111
      does anyone have an example of how to load skinned mesh from .x file with animations?
      I managed to load mesh but can't figure out how to load animations.
      For any example or at least some suggestion on how to deal with it, i would be very grateful.
      And should be done with slimdx and directx 9.

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!