Networking

From WinBolo

Revision as of 16:57, 2 December 2008 by John (Talk | contribs)
Jump to: navigation, search

This page provides some more details on WinBolo's networking.

WinBolo uses a client/server networking model where game clients join a server.


Contents

Client Functions

The network.c file contains all the logic for joining a game and managing sending/receiving packets.

The main functions called by the front end are:


Joining a game

/*********************************************************
*NAME:          netSetup
*AUTHOR:        John Morrison
*CREATION DATE: 21/02/99
*LAST MODIFIED: 01/04/02
*PURPOSE:
* Sets the network kind of game being played and sets up
* netClient
*
*ARGUMENTS:
*  value       - The network type of game being played
*  myPort      - netClient port on this machine
*  targetIP    - Target IP on a machine to join
*  targetPort  - Target port on that machine
*  password    - Password for the net game (NULL for none)
*  usCreate    - TRUE if we started the game, FALSE if we
*                joined
*  trackerAddr - Address of the tracker to use
*  trackerPort - Port of the tracker
*  useTracker  - Whether to use the tracker or not
*  wantRejoin  - TRUE if we want to rejoin the game else
*                just join
*  useWinboloNet - TRUE if we want to participate in
*                  WinBolo.net
*  wbnPassword   - Our WinBolo.net password
*********************************************************/
bool netSetup(netType value, unsigned short myPort, char *targetIp, unsigned short targetPort,
              char *password, bool usCreate, char *trackerAddr, unsigned short trackerPort,
              bool useTracker, bool wantRejoin, bool useWinboloNet, char *wbnPassword);


This is the function that setups the networking routines. It must be called for single player and multiplayer games. For single player games (netType = netSingle) all values can be 0 or NULL.

After networking is initialised it starts the join game process:

  • netJoinInit(); is called first
    • Sends an INFO_PACKET request to the targetIp and targetPort. Expects an INFO_PACKET back. (This can be sent to a server or a game client as the game client will include the servers details in the response)
    • Checks to see the game is not full and sets up the backend options (hidden mines, ai type)
    • If the game is passworded prompts for password and sends a BOLOPACKET_PASSWORDCHECK packet (Expects a BOLOPACKET_PASSWORDACCEPT packet back)
    • Checks the players name is avialable with a BOLOPACKET_NAMECHECK packet. Expects BOLOPACKET_NAMEACCEPT packet back
      • may fail with a game locked BOLOPACKET_GAMELOCKED packet or BOLOPACKET_NAMEFAIL name used packet.
  • netJoinFinalise(); is then called if we have not errored out.
    • Requests WBN server key with BOLOPACKET_SERVERKEYREQUEST packet. Expects BOLOPACKET_SERVERKEYRESPONSE back.
      • If the response packet contains a WBN key and this player is using WBN perform player name check via the WBN Protocol.
    • Sends BOLOPACKET_PLAYERNUMREQUEST to request a player number. Expects BOLOPACKET_PLAYERNUMRESPONSE packet back. This packet is the first packet to have a 16bit CRC appended to it.
    • Sends rejoin request packet BOLOREJOINREQUEST if a player rejoin is requested. This is a non-reliable packet.
    • Requests player data with a a BOLOPACKET_PLAYERDATAREQUEST packet. This contains information about each player in the game.



Server Functions

Helper Modules

netplayers.c

Netplayer.c is an extension of players.c but stores each players network details and udppackets reference. The typedef defines what is in it:

typedef struct { /* Obj */
  bool inUse[MAX_TANKS];                /* Is this in use */
  bool inGame[MAX_TANKS];               /* Have they entered the game or are they still joining? */
  struct sockaddr_in addr[MAX_TANKS];   /* Last packet from address */
  bool locked[MAX_TANKS];               /* Are they locked */
  bool passed[MAX_TANKS];               /* Have they entered the password (if required by the server) */
  udpPackets udpp[MAX_TANKS];           /* udppackets ADT reference */
  time_t lastHeard[MAX_TANKS];          /* When we last heard from them */
  time_t lastServerTime[MAX_TANKS];
  time_t lastClientTime[MAX_TANKS];
  BYTE cheatCount[MAX_TANKS];
} netPlayers;

udppackets.c

The udppackets ADT is used by both the client and the server to store copies of packets in case the network is interrupted and they need to be resent to the clients (or server) The udppackets.c header comment explains how it works best (below) It allows for saving up to 200 packets.

/*********************************************************
*Name:          UDP Packets
*Filename:      udppackets.h
*Author:        John Morrison
*Creation Date: 24/02/02
*Last Modified: 24/02/02
*Purpose:
* Handles keeping track of network packets for
* retransmission on errors
*
*  Process: Client to Server
* -------------------------
* Client--->
* 1. Build reliable packet and give it a sequence number
* 2. Send
* 3. Copy packet to sequence number position X of buffer.
* 4. Increment next packet sequence number.
* Server--->
* 5. Server Receives packet
* 6. Server checks sequence number. If valid increments to
*    next available sequence number and process packet.
* 7. If invalid sends back a packet request for missing
*    sequence number(s) and stores packets at sequence
*    position for processing.
*
*
* Process: Server to Client
* -------------------------
* Server-->
* 1. Build reliable packet.
* 2. For each client makes the correct sequence number
*    and sends it.
* 3. Copy packet to sequence number position x of buffer
* 4. Increment next packet sequence number
* Client--->
* 5. Client Receives packet
* 6. Client checks sequence number. If valid increments
*    to next available sequence number.
* 7. If invalid sends back a packet request for missing
*    sequence number(s) and stores packets at sequence
*    position for processing.
*********************************************************/
Personal tools