Skip to content

General-pupose Web Socket server for hosting multiplayer games, written in C#. Set up in seconds.

License

Notifications You must be signed in to change notification settings

TiltedGames/one-click-server

Repository files navigation

What is this project?

This project aims to make the process of integrating multiplayer into your game just one click away. This project is completely free, covered by the MIT license, and imposes no restrictions on the server or client whatsoever.


Goals and Technical Details

The core of this server is the Web Socket protocol. It is implemented in C# using the .NET Sockets API. This API was recently adopted by Microsoft into the .NET core framework, meaning this will be supported, stable, and maintained for the forseeable future. It is based on the Transmission Control Protocol (TCP), which receives a lot of negative attention in the gaming community. However, we considered some critical improvements made when creating Web Sockets, and decided it was fit for the project. We aim to show the viability of C# and web sockets as a general purpose game server.

During the initial development, we are only offering a graphical version of the server application. The first release will also include a truly bare-bones console application with identical functionality.


Program Screenshot


Capture


Getting Started (Windows 32/64-bit)

  1. If you're going to host online, choose a TCP port to host on (we use 5050)
  2. Make sure the selected port is available to outside connections Quick guide for Windows...
    • Click start, and search for "Windows Defender Firewall"
    • Click "Advanced settings"
    • Click "Inbound rules"
    • Click "New Rule..."
    • Select "Port"
    • Select "Specific local ports"
    • Enter your chosen port (default is 5050)
    • Select "Create Rule"
  3. Download this git repository as a .zip using the green code button.
  4. Extract it wherever you'd like your server program to be stored
  5. Run the 'gameserver.exe' from the extracted directory
  6. Configure your settings, using the newly-opened port
  7. Go back to the server program
  8. Click 'Apply and Start Server'

Requirements to rebuild (not necessary to run it!)

  1. First make sure you have the following requirements:
  2. Once server files have been configured, simply open, modify, rebuild, and run the solution

Understanding the project files

1. /Gameserver/bin/Release/netcoreapp3.1/WebSocketServer.exe

Show/hide

This is where the compiled program will be. Run this to start the server.

2. /Gameserver/bin/Release/netcoreapp3.1/WebSocketServer.dll

Show/hide

This is also made by VS but you shouldn't need to touch it. No need to link it to Unity, as it's separate from the client entirely.


Understanding the server files

1. /Gameserver/Program.cs

Show/hide

The main method of server is here. It just initializes network packages, sets up the server, and waits for input so the console doesn't close.

2. /Gameserver/Constants.cs

Show/hide Find constants like the server IP, port, and maximum connection queue size, here.

3. /Gameserver/NetworkPackets.cs

Show/hide

The types of network packets we can send from client to server and server to client are defined here. Each is in its own enum. The integer associated each determines the handler function that is executed in ServerPackHandler.cs.

4. /Gameserver/ServerPacketHandler.cs

Show/hide

This file has our InitializeNetworkPackages method, which fills our dictionary assiociating our packets with their handler functions. It defines each packet handler (i.e. what to do with each type of packet it gets from the client).

5. /Gameserver/PacketBuffer.cs
Show/hide

This is out network packet buffer.


Understanding the client files

Show/hide

1. /Assets/Scripts/Network/WebSocketClient


What is actually on the network?

Answers to the whole universe.


How is physics and user input handled?

Magic.