My Project
Classes | Macros | Typedefs | Functions | Variables
ggs.c File Reference
#include "board.h"
#include "move.h"
#include "options.h"
#include "util.h"
#include "ui.h"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/tcp.h>

Classes

struct  Text
 
struct  GGSClock
 
struct  GGSPlayer
 
struct  GGSMatchType
 
struct  GGSMatchOff
 
struct  GGSMatchOn
 
struct  GGSRequest
 
struct  GGSBoard
 
struct  GGSAdmin
 
struct  GGSEvent
 
struct  GGSClient
 

Macros

#define WORD_SIZE   256
 
#define GGS_BOARD_SIZE   256
 
#define MOVELIST_SIZE   256
 

Typedefs

typedef struct Text Text
 
typedef struct GGSClock GGSClock
 
typedef struct GGSPlayer GGSPlayer
 
typedef struct GGSMatchType GGSMatchType
 
typedef struct GGSMatchOff GGSMatchOff
 
typedef struct GGSMatchOn GGSMatchOn
 
typedef struct GGSRequest GGSRequest
 
typedef struct GGSBoard GGSBoard
 
typedef struct GGSAdmin GGSAdmin
 
typedef struct GGSEvent GGSEvent
 
typedef struct GGSClient GGSClient
 

Functions

static void text_init (Text *text)
 text_init More...
 
static void text_add_line (Text *text, const char *line)
 text_add_line More...
 
static void text_print (Text *text, FILE *f)
 text_print More...
 
static void text_free (Text *text)
 text_free More...
 
static char * ggs_parse_line (const char *buffer, char **line)
 ggs_parse_line More...
 
static char * ggs_parse_text (const char *buffer, Text *text)
 ggs_parse_text More...
 
static bool ggs_parse_int (int *value, const char *word)
 ggs_parse_int More...
 
static bool ggs_parse_double (double *value, const char *word)
 ggs_parse_double More...
 
static bool ggs_parse_move (int *move, const char *word)
 ggs_parse_move More...
 
static bool ggs_parse_time (int *time, const char *word)
 ggs_parse_move More...
 
static bool ggs_parse_clock (GGSClock *ggsclock, const char *line)
 ggs_parse_clock More...
 
static bool ggs_player_set (GGSPlayer *player, const char *name, const char *rating)
 ggs_player_set More...
 
static void ggs_match_type_set (GGSMatchType *type, const char *word)
 ggs_match_type_set More...
 
static void ggs_player_free (GGSPlayer *player)
 ggs_player_free More...
 
static void ggs_MBR_free (void *v)
 ggs_MBR_free More...
 
static bool ggs_has_player (GGSPlayer *player, const char *me)
 ggs_match_check_destination More...
 
static bool ggs_request (GGSRequest *request, Text *text)
 ggs_request More...
 
static bool ggs_match_on (GGSMatchOn *match, Text *text)
 ggs_match_on More...
 
static bool ggs_match_off (GGSMatchOff *match, Text *text)
 ggs_match_off More...
 
static bool ggs_board (GGSBoard *board, Text *text)
 ggs_board More...
 
static bool ggs_os_on (Text *text)
 ggs_os_on More...
 
static bool ggs_os_off (Text *text)
 ggs_os_off More...
 
static bool ggs_saio_delay (Text *text, long long *delay)
 ggs_saio_delay More...
 
static int ggs_admin (GGSAdmin *admin, Text *text)
 ggs_admin More...
 
static bool ggs_ready (Text *text)
 ggs_ready More...
 
static bool ggs_alert (Text *text)
 ggs_alert More...
 
static bool ggs_login (Text *text)
 ggs_login More...
 
static bool ggs_password (Text *text)
 ggs_password More...
 
static void * ggs_event_loop (void *v)
 ggs_event_loop More...
 
static void ggs_event_init (GGSEvent *event)
 ggs_event_init More...
 
static void ggs_event_free (GGSEvent *event)
 ggs_event_free More...
 
static bool ggs_event_peek (GGSEvent *event, Text *text)
 ggs_event_peek More...
 
static void ggs_client_free (GGSClient *client)
 ggs_client_free More...
 
static void ggs_client_send (GGSClient *client, const char *fmt,...)
 ggs_client_send More...
 
static void ggs_client_refresh (GGSClient *client)
 ggs_client_refresh More...
 
static void ui_login (UI *ui)
 ui_login More...
 
static void ui_ggs_ponder (UI *ui, int turn)
 ui_ggs_ponder More...
 
static void ui_ggs_play (UI *ui, int turn)
 ui_ggs_play More...
 
static void ui_ggs_join (UI *ui)
 ui_ggs_join More...
 
static void ui_ggs_update (UI *ui)
 ui_ggs_update More...
 
void ui_init_ggs (UI *ui)
 ui_init_ggs More...
 
void ui_loop_ggs (UI *ui)
 ui_loop_ggs More...
 
void ui_free_ggs (UI *ui)
 ui_free_ggs More...
 

Variables

static Log ggs_log [1]
 
static char admin_list [][16] = {"delorme", "dan", "mic", "romano", "HCyrano", "romelica", ""}
 
static const GGSClock GGS_CLOCK_INI = {0, 0, 0, 0, 0, 0, 0, 0, 0}
 
static const GGSMatchType GGS_MATCH_TYPE_INI = {0, 0, 0, 0, 0, 0, 0, 0}
 

Detailed Description

A ggs client in C language.

Date
2002 - 2017
Author
Richard Delorme
Version
4.4

Macro Definition Documentation

◆ GGS_BOARD_SIZE

#define GGS_BOARD_SIZE   256

Board Size

◆ MOVELIST_SIZE

#define MOVELIST_SIZE   256

Move list size

◆ WORD_SIZE

#define WORD_SIZE   256

Word size

Typedef Documentation

◆ GGSAdmin

typedef struct GGSAdmin GGSAdmin

◆ GGSBoard

typedef struct GGSBoard GGSBoard

◆ GGSClient

typedef struct GGSClient GGSClient

◆ GGSClock

typedef struct GGSClock GGSClock

GGS clock (to play a game)

◆ GGSEvent

typedef struct GGSEvent GGSEvent

◆ GGSMatchOff

typedef struct GGSMatchOff GGSMatchOff

◆ GGSMatchOn

typedef struct GGSMatchOn GGSMatchOn

◆ GGSMatchType

typedef struct GGSMatchType GGSMatchType

Match type description

◆ GGSPlayer

typedef struct GGSPlayer GGSPlayer

GGS player

◆ GGSRequest

typedef struct GGSRequest GGSRequest

◆ Text

typedef struct Text Text

Text (set of lines) representation

Function Documentation

◆ ggs_admin()

static int ggs_admin ( GGSAdmin admin,
Text text 
)
static

ggs_admin

Parse an admin command from a GGS input text. Admin are authorised people (see list above) that can interact with Edax. Usually, edax will repeat the command to GGS.

Parameters
adminAn authorised person.
textGGS input text.
Returns
'true' if the text is an authorised admin.

◆ ggs_alert()

static bool ggs_alert ( Text text)
static

ggs_alert

Parse a "ALERT" from a GGS input text.

Parameters
textGGS input text.
Returns
'true' if the text is "ALERT".

◆ ggs_board()

static bool ggs_board ( GGSBoard board,
Text text 
)
static

ggs_board

Parse a "GGS board" from a GGS input text.

Parameters
boardGGS board.
textGGS input text.
Returns
'true' if the text is a valid board.

◆ ggs_client_free()

static void ggs_client_free ( GGSClient client)
static

ggs_client_free

Free the GGS client structure.

Parameters
clientGGS client.

◆ ggs_client_refresh()

static void ggs_client_refresh ( GGSClient client)
static

ggs_client_refresh

Periodically send a message to the GGS server. This is a workaround to avoid spurious deconnection from GGS.

Parameters
clientGGS client.

◆ ggs_client_send()

static void ggs_client_send ( GGSClient client,
const char *  fmt,
  ... 
)
static

ggs_client_send

Send a message to the GGS server. This function uses vnsprintf with some workaround for MS-Windows incorrect behaviour.

Parameters
clientGGS client.
fmtText format.
...other args.

◆ ggs_event_free()

static void ggs_event_free ( GGSEvent event)
static

ggs_event_free

GGS event free.

Parameters
eventEvent.

◆ ggs_event_init()

static void ggs_event_init ( GGSEvent event)
static

ggs_event_init

GGS event init.

Parameters
eventEvent.

◆ ggs_event_loop()

static void * ggs_event_loop ( void *  v)
static

ggs_event_loop

GGS event loop. Read all inputs from GGS within a thread.

Parameters
vEvent.
Returns
NULL.

◆ ggs_event_peek()

static bool ggs_event_peek ( GGSEvent event,
Text text 
)
static

ggs_event_peek

Check if an event occured. If so copy the GGS input to a text, i.e. a set of lines.

Parameters
eventEvent.
textText.
Returns
'true' if an event occured.

◆ ggs_has_player()

static bool ggs_has_player ( GGSPlayer player,
const char *  me 
)
static

ggs_match_check_destination

Check if Edax is concerned by the match.

Parameters
playerGGS player.
meEdax's login name.
Returns
'true' if Edax is playing that match.

◆ ggs_login()

static bool ggs_login ( Text text)
static

ggs_login

Parse a login request from a GGS input text.

Parameters
textGGS input text.
Returns
'true' if the text is "ALERT".

◆ ggs_match_off()

static bool ggs_match_off ( GGSMatchOff match,
Text text 
)
static

ggs_match_off

Parse a "match off" from a GGS input text.

Parameters
matchGGS match off.
textGGS input text.
Returns
'true' if the text is a valid match end.

◆ ggs_match_on()

static bool ggs_match_on ( GGSMatchOn match,
Text text 
)
static

ggs_match_on

Parse a "match on" from a GGS input text.

Parameters
matchGGS match on.
textGGS input text.
Returns
'true' if the text is a valid match start.

◆ ggs_match_type_set()

static void ggs_match_type_set ( GGSMatchType type,
const char *  word 
)
static

ggs_match_type_set

Translate input word into a type of match.

Parameters
typeGGS match type.
wordWord.

◆ ggs_MBR_free()

static void ggs_MBR_free ( void *  v)
static

ggs_MBR_free

Free a GGS MatchOn/Off / Board / Request structure.

Parameters
vGGS match/Board or Request structure.

◆ ggs_os_off()

static bool ggs_os_off ( Text text)
static

ggs_os_off

Parse a "os off" from a GGS input text. PS: os = (o)thello (s)ervice

Parameters
textGGS input text.
Returns
'true' if the text is a valid board.

◆ ggs_os_on()

static bool ggs_os_on ( Text text)
static

ggs_os_on

Parse a "os on" from a GGS input text. PS: os = (o)thello (s)ervice

Parameters
textGGS input text.
Returns
'true' if the text is a "os on".

◆ ggs_parse_clock()

static bool ggs_parse_clock ( GGSClock ggsclock,
const char *  line 
)
static

ggs_parse_clock

Translate input word into a GGS clock time.

Parameters
ggsclockGGS clock.
lineText.
Returns
true if parsing succeed.

◆ ggs_parse_double()

static bool ggs_parse_double ( double *  value,
const char *  word 
)
static

ggs_parse_double

Translate input word into a double.

Parameters
valuedouble.
wordWord.
Returns
true if parsing succeed.

◆ ggs_parse_int()

static bool ggs_parse_int ( int *  value,
const char *  word 
)
static

ggs_parse_int

Translate input word into an integer.

Parameters
valueinteger.
wordWord.
Returns
true if parsing succeed.

◆ ggs_parse_line()

static char * ggs_parse_line ( const char *  buffer,
char **  line 
)
static

ggs_parse_line

Parse a ('
' terminated) line from a buffer.

Parameters
bufferbuffer.
lineNewly allocated line of text.
Returns
buffer's remaining.

◆ ggs_parse_move()

static bool ggs_parse_move ( int *  move,
const char *  word 
)
static

ggs_parse_move

Translate input word into a move.

Parameters
moveMove.
wordWord.
Returns
true if parsing succeed.

◆ ggs_parse_text()

static char * ggs_parse_text ( const char *  buffer,
Text text 
)
static

ggs_parse_text

Parse a text (ie a set of lines) from a buffer.

Parameters
bufferBuffer.
textText.
Returns
buffer's remaining.

◆ ggs_parse_time()

static bool ggs_parse_time ( int *  time,
const char *  word 
)
static

ggs_parse_move

Translate input word into time (as ms).

Parameters
timeTime.
wordWord.
Returns
true if parsing succeed.

◆ ggs_password()

static bool ggs_password ( Text text)
static

ggs_password

Parse a login password from a GGS input text.

Parameters
textGGS input text.
Returns
'true' if the text is "ALERT".

◆ ggs_player_free()

static void ggs_player_free ( GGSPlayer player)
static

ggs_player_free

Free a GGS player structure.

Parameters
playerGGS player.

◆ ggs_player_set()

static bool ggs_player_set ( GGSPlayer player,
const char *  name,
const char *  rating 
)
static

ggs_player_set

Set player's name and rating.

Parameters
playerGGS player.
nameName.
ratingRating.
Returns
true if parsing succeed.

◆ ggs_ready()

static bool ggs_ready ( Text text)
static

ggs_ready

Parse a "READY" from a GGS input text.

Parameters
textGGS input text.
Returns
'true' if the text is "READY".

◆ ggs_request()

static bool ggs_request ( GGSRequest request,
Text text 
)
static

ggs_request

Parse a request from a GGS input text.

Parameters
requestGGS request.
textGGS input text.
Returns
'true' if the text is a valid request.

◆ ggs_saio_delay()

static bool ggs_saio_delay ( Text text,
long long *  delay 
)
static

ggs_saio_delay

Parse a "saio" from a GGS input text. When Saio is building is book, it tells when it will be available again. Edax will automatically re-start asking him to play again at the right moment.

Parameters
textGGS input text.
delayTime delay (in ms).
Returns
'true' if the text is a valid saio delay.

◆ text_add_line()

static void text_add_line ( Text text,
const char *  line 
)
static

text_add_line

Add a line to a Text.

Parameters
textText.
lineline of text.

◆ text_free()

static void text_free ( Text text)
static

text_free

Free a Text structure.

Parameters
textText.

◆ text_init()

static void text_init ( Text text)
static

text_init

Initialise a Text structure.

Parameters
textText.

◆ text_print()

static void text_print ( Text text,
FILE *  f 
)
static

text_print

Print a Text structure.

Parameters
textText.
fOutput stream.

◆ ui_free_ggs()

void ui_free_ggs ( UI ui)

ui_free_ggs

Free GGS.

Parameters
uiUser Interface.

◆ ui_ggs_join()

static void ui_ggs_join ( UI ui)
static

ui_ggs_join

Join a new game. This is a new game from Edax point of view. This may be a saved game from GGS side.

Parameters
uiUser Interface.

◆ ui_ggs_play()

static void ui_ggs_play ( UI ui,
int  turn 
)
static

ui_ggs_play

Search the best move.

Parameters
uiUser Interface.
turnEdax's color.

◆ ui_ggs_ponder()

static void ui_ggs_ponder ( UI ui,
int  turn 
)
static

ui_ggs_ponder

Ponder, ie search during opponent time.

Parameters
uiUser Interface.
turnEdax's color.

◆ ui_ggs_update()

static void ui_ggs_update ( UI ui)
static

ui_ggs_update

Update a game.

Parameters
uiUser Interface.

◆ ui_init_ggs()

void ui_init_ggs ( UI ui)

ui_init_ggs

Init GGS interface.

Parameters
uiUser Interface.

◆ ui_login()

static void ui_login ( UI ui)
static

ui_login

Connect to GGS.

Parameters
uiUser Interface.

◆ ui_loop_ggs()

void ui_loop_ggs ( UI ui)

ui_loop_ggs

GGS main loop. Here the input from both the user and GGS server is interpreted.

Parameters
uiUser Interface.

Variable Documentation

◆ admin_list

char admin_list[][16] = {"delorme", "dan", "mic", "romano", "HCyrano", "romelica", ""}
static

◆ GGS_CLOCK_INI

const GGSClock GGS_CLOCK_INI = {0, 0, 0, 0, 0, 0, 0, 0, 0}
static

◆ ggs_log

Log ggs_log[1]
static

◆ GGS_MATCH_TYPE_INI

const GGSMatchType GGS_MATCH_TYPE_INI = {0, 0, 0, 0, 0, 0, 0, 0}
static