Giter VIP home page Giter VIP logo

flufwars's Introduction

Flufwars

A capture the flag (CTF) style, online multiplayer game. The game is made with the game engine Godot and based on the template GodotClientServer by Wavesonics.

Compilation

The game can be compiled from the godot editor > project > export > export all.

The compiled files will be exported to export/client and export/server

Running the game

Server

The server can be run in two ways, either by running the dedicated binary in the export/server folder

Linux:

./Server.x86_64

or by running the client binary with the --server flag. from export/client.

Linux:

./Client.x86_64 --server

Client

The client binary can be run from the export/client.

Linux:

./Client.x86_64

From GodotClientServer README

A project template for a Dedicated Server & Client within a single project.

Why?

There is already a good tutorial out there showing how to set up a dedicated server in Godot using two separate projects. This has a number of advantages. However, it has in my view one huge disadvantage: Maintainability.

In a two project setup, you have to somehow keep shared logic in sync between the two projects. You can imagine a number of ways to do this, but I would massively prefer to just fix a bug once, and not have any steps to remember. Because I'll forget.

So this idea here is to have one Godot project, and keep as much of the code shared between client and server as possible.

High level design

This relies on an aspect of Godot's export system called "Features." Each export template specifies which Features it supports, such as Windows, 64 bit, PC vs Mobile, etc.

These are the built-in features, but Godot also allows you to specify your own custom features. So you could, for instance, have two different Windows Export Presets, and they could each contain different custom Features that you specify.

Importantly, the presence of these features can be queried at runtime:

OS.has_feature("X")

You probably see where this is going now.

We can have two different export templates, and each has it's own custom feature: client for one, and server for the other.

Our Main Scene will be a simple Entry scene that detects which feature is present, and then launches into a different Scene accordingly.

The Client will launch into a Main Menu, and the Server will launch into a Lobby scene, where it will open a port and begin listening for clients.

Project Structure

root/
|
- common
- client
- server

common contains the bulk of the game code. This is all of the code that runs on both client and server. This is where the real benefit of this architecture comes from.

Client/Server specific code

Each scene in common will have a corresponding inherited scene in both client and server. This allows you to do client or server specific stuff quite easily.

The scenes are named to prevent confusion in an editor so:

common/Lobby.tscn
client/ClientLobby.tscn
server/ServerLobby.tscn

So the only trick here is that scene transitions must be in the inherited scenes, since the server will change to ServerGame.tscn and clients will change to ClientGame.tscn. This can be accomplished easily with overriden methods or signals.

Running on a headless machine

If this was for some real game, the server likely would be on a headless machine. To accommodate this, we can use Godot's server export template. It is a graphicless version of Godot, and will not attempt to open a window or use any graphics API.

This means you can easily run the dedicated server on a headless Linux box.

https://godotengine.org/download/server

Exporting the Linux Server

In the Export Project dialog, click on the Linux Server preset. Then export the pack file, not the full Export Template.

You can then run the dedicated server as such:

./Godot_v3.2-stable_linux_server.64 --main-pack Server.pck

Down sides

  • This will still load all of the graphical assets, so it will not be as slim in memory as it could possibly be in the two project approach.

Misc

  • This is shown working with a Lobby based game, but it could just as easily work with a join-in-progress type of game.
  • I'm not completely happy with how I split up the Network classes (BaseNetwork, ClientNetwork, ServerNetwork). So I may actualy get rid of that.
  • This is NOT Server authoratative. It could be in theory, and that is one big advantage I see is that all of the game logic is already running on the server.

flufwars's People

Contributors

alexnortung avatar daresoul avatar irladdergoat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.