File Network.h

FileList > engine > include > Network.h

Go to the source code of this file

More...

  • #include "ThreadSafeQueue.h"
  • #include "SharedPtr.h"
  • #include "IntTypes.h"
  • #include <stdlib.h>

Classes

Type Name
struct ClientMatchmakingInfo
struct HostInfo
struct MatchMakingMessage
struct NetworkConnectionEvent
struct NetworkQueueItem
struct PeerAddress
struct PlayerInfo
struct ServerMatchmakingInfo

Public Types

Type Name
enum GameRole
enum MatchmakingProtocolMessageType
enum NetworkConnectionEventType

Public Functions

Type Name
bool NW_DequeueConnectionEvent (struct NetworkConnectionEvent * pOut)
bool NW_DequeueData (struct NetworkQueueItem * pOut)
void NW_EnqueueData (struct NetworkQueueItem * pIn)
enum GameRole NW_GetRole ()
void NW_Init ()

Macros

Type Name
define IP_AND_PORT_BUF_SIZE (15 + 3 + 1 + 5 + 1)

Detailed Description

  • game can be started with command line args to configure it as a server or a client (or singleplayer)

if server or client is chosen a thread is spawned to recieve date too and from the socket * it communicates with the game thread through 3 thread safe queues (named from the game threads perspective): * recieve data packets * transmit data packets * recieve connection events

  • A UDP based custom protocol using the netcode library to handle connecting and disconnecting:
  • data can be sent reliably or unreliably
  • packets larget than NETCODE_MAX_PACKET_SIZE + (a small header) are transmitted as multiple packets and only presented to the game thread when the full message is assembled
  • reliable packets should only be recieved by recipients game thread once
    • they'll be continually resent until reciept is acknowledged

This layer of the networking code ensures the game thread can transmit and recieve reliable and unreliable packets of any size and is informed when a client connects or they as a client is connected to the server or disconnected.

For the time being the game thread must create a shared pointer of the packet to be sent which the server thread will then free. For data received through the queue the game thread must call free() on it when done.

Some better memory usage arrangement needs to be come up with at some point.

Public Types Documentation

enum GameRole

enum GameRole {
    GR_Singleplayer,
    GR_Client,
    GR_ClientServer
};

enum MatchmakingProtocolMessageType

enum MatchmakingProtocolMessageType {
    MM_ClientSeekServer,
    MM_ServerSeekClient,
    MM_ServerPeerJoined,
    MM_GameConnection
};

enum NetworkConnectionEventType

enum NetworkConnectionEventType {
    NCE_ClientConnected,
    NCE_ClientDisconnected
};

Public Functions Documentation

function NW_DequeueConnectionEvent

bool NW_DequeueConnectionEvent (
    struct NetworkConnectionEvent * pOut
) 

function NW_DequeueData

bool NW_DequeueData (
    struct NetworkQueueItem * pOut
) 

function NW_EnqueueData

void NW_EnqueueData (
    struct NetworkQueueItem * pIn
) 

function NW_GetRole

enum GameRole NW_GetRole () 

function NW_Init

void NW_Init () 

Macro Definition Documentation

define IP_AND_PORT_BUF_SIZE

#define IP_AND_PORT_BUF_SIZE `(15 + 3 + 1 + 5 + 1)`


The documentation for this class was generated from the following file /home/runner/work/2DFarmingRPG/2DFarmingRPG/Stardew/engine/include/Network.h