Networking

From WinBolo

Revision as of 16:22, 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

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);



netJoinInit(); is called. does setup, , checks password, checks name netJoinFinalise(); is the point of no return. gets player number at the end...


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