Network Communication & Implementation
Time: 180h
Engines: FaktalOktav (Custom Engine)
Language: C++
This Specialisation was done during my time at The Game Assembly. It focuses on the creation of a simple networking library for handling message passing/receiving and the implementation of network into a game. The Game that I chose for this project was The Negotiator.
Showcase
Creation of Library
I had three parts in mind, when I designed The Network Library to pass packets:
-
Creation
-
Binding
-
Packaging
Creation of Client/Server
Creation is a hub to create a client or a server and bind their respective functions in order to stream line the use case.
During the initialization of either the client or the server, an attempt is made to establish a connection, I refer to this step as the Binding. The server sets up an UDP protocol with a designated port number and subsequently the client tries to bind to that port number. "A hand shake" is done between the client and the server and if successful, a connection is established.
Packaging is based on a Builder Pattern to allow for quick, easy and visual understanding of what is being sent.
Processing and dispaching of packages are done through various threads. When a client has received a package it adds a pre-defined function to a list for execution. This is done to prevent a deadlock.
Samples from the Library
Message Package
Data Builder
Event Dispatcher
Server.h
Client.h
Implementation
The server initialiseras a lobby and the client connects by entering the Servers IP address. Once the client signals that it is ready, then the server can commence the game, dispatching a package to the client indicating that their game can begin.
Package Types for Passing
The various implementations done for this project was:
-
Player Movement
-
Player Action
-
Enemy Behaviors
-
Enemy Movement
-
Events
Package Creation for Player
Player Movement and Actions gets bundled into the same package to minimize traffic. At the end of each frame the server sends a package to the client for interpretation.
Enemy Acknowledge Client
Enemy Movement and Behaviors are bundled together within the AI controller, with only necessary data sent for the chosen behavior. Upon receiving a package the AI determines its behavior and fills it with the corresponding data.
Unit shooting is handled exclusively on the server side, regardless of whether the action appears to occur on the client. Any perceived enemy kills on the client are actually executed by a server side Mimic.
A Mimic in my code is an AI that solely listens for packages and chooses behaviors based on instructions from the AI controller.
Any Event in the game triggers the server to transmit essential information to the client, specifying which player, Event, and functions to execute.
Client receives Event call
Client kills Enemy