Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/clinet.c File Reference

Freeciv-3.2

Loading...
Searching...
No Matches
Macros | Functions | Variables
clinet.c File Reference
`#include "fc_prehdrs.h"`
`#include <errno.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "capstr.h"`
`#include "dataio.h"`
`#include "fcintl.h"`
`#include "log.h"`
`#include "mem.h"`
`#include "netintf.h"`
`#include "registry.h"`
`#include "support.h"`
`#include "game.h"`
`#include "packets.h"`
`#include "version.h"`
`#include "agents.h"`
`#include "attribute.h"`
`#include "audio.h"`
`#include "chatline_g.h"`
`#include "client_main.h"`
`#include "climisc.h"`
`#include "connectdlg_common.h"`
`#include "connectdlg_g.h"`
`#include "dialogs_g.h"`
`#include "gui_main_g.h"`
`#include "mapview_common.h"`
`#include "menu_g.h"`
`#include "messagewin_g.h"`
`#include "options.h"`
`#include "packhand.h"`
`#include "pages_g.h"`
`#include "plrdlg_g.h"`
`#include "repodlgs_g.h"`
`#include "clinet.h"`

Go to the source code of this file.

## Macros

#define | AUTOCONNECT_INTERVAL 500
#define | MAX_AUTOCONNECT_ATTEMPTS 100

## Functions

static void | close_socket_nomessage (struct connection *pc)
static void | client_conn_close_callback (struct connection *pconn)
static int | get_server_address (const char *hostname, int port, char *errbuf, int errbufsize)
static int | try_to_connect (const char *username, char *errbuf, int errbufsize)
int | connect_to_server (const char *username, const char *hostname, int port, char *errbuf, int errbufsize)
void | make_connection (int sock, const char *username)
void | disconnect_from_server (bool leaving_sound)
static int | read_from_connection (struct connection *pc, bool block)
void | input_from_server (int fd)
void | input_from_server_till_request_got_processed (int fd, int expected_request_id)
double | try_to_autoconnect (void)
void | start_autoconnecting_to_server (void)

## Variables

static struct fc_sockaddr_list * | list = NULL
static bool | autoconnecting = FALSE

## Macro Definition Documentation

## ◆ AUTOCONNECT_INTERVAL

#define AUTOCONNECT_INTERVAL 500

Definition at line 97 of file clinet.c.

## ◆ MAX_AUTOCONNECT_ATTEMPTS

#define MAX_AUTOCONNECT_ATTEMPTS 100

Definition at line 100 of file clinet.c.

## Function Documentation

## ◆ client_conn_close_callback()

static void client_conn_close_callback | ( | struct connection * | pconn | ) |

static

Client connection close socket callback. It shouldn't be called directy. Use connection_close() instead.

Definition at line 122 of file clinet.c.

Referenced by try_to_connect().

## ◆ close_socket_nomessage()

static void close_socket_nomessage | ( | struct connection * | pc | ) |

static

Close socket and cleanup. This one doesn't print a message, so should do so before-hand if necessary.

Definition at line 108 of file clinet.c.

Referenced by client_conn_close_callback(), and disconnect_from_server().

## ◆ connect_to_server()

int connect_to_server | ( | const char * | username,
|  | const char * | hostname,
|  | int | port,
|  | char * | errbuf,
|  | int | errbufsize
| ) |  |

Connect to a freeciv-server instance – or at least try to. On success, return 0; on failure, put an error message in ERRBUF and return -1.

Definition at line 249 of file clinet.c.

Referenced by client_start_server(), connect_callback(), connect_callback(), and fc_client::slot_connect().

## ◆ disconnect_from_server()

void disconnect_from_server | ( | bool | leaving_sound | ) |

Get rid of server connection. This also kills internal server if it's used.

Definition at line 306 of file clinet.c.

Referenced by mr_menu::back_to_menu(), cancel_passwd_callback(), client_packet_input(), disconnect_callback(), disconnect_conn_callback(), exit_callback(), leave_callback(), leave_callback(), leave_local_game_response(), main_callback(), popup_quit_dialog(), quit_dialog_response(), fc_client::slot_disconnect(), and fc_client::switch_page().

## ◆ get_server_address()

static int get_server_address | ( | const char * | hostname,
|  | int | port,
|  | char * | errbuf,
|  | int | errbufsize
| ) |  |

static

Get ready to [try to] connect to a server:

- translate HOSTNAME and PORT (with defaults of "localhost" and DEFAULT_SOCK_PORT respectively) to a raw IP address and port number, and store them in the ‘names’ variable
- return 0 on success or put an error message in ERRBUF and return -1 on failure

Definition at line 148 of file clinet.c.

Referenced by connect_to_server(), and start_autoconnecting_to_server().

## ◆ input_from_server()

void input_from_server | ( | int | fd | ) |

This function is called when the client received a new input from the server.

Definition at line 411 of file clinet.c.

Referenced by get_net_input(), gui_event_loop(), and fc_client::server_input().

## ◆ input_from_server_till_request_got_processed()

void input_from_server_till_request_got_processed | ( | int | fd,
|  | int | expected_request_id
| ) |  |

This function will sniff at the given fd, get the packet and call client_packet_input. It will return if there is a network error or if the PACKET_PROCESSING_FINISHED packet for the given request is received.

Definition at line 447 of file clinet.c.

Referenced by wait_till_request_got_processed().

## ◆ make_connection()

void make_connection | ( | int | sock,
|  | const char * | username
| ) |  |

Called after a connection is completed (e.g., in try_to_connect).

Definition at line 275 of file clinet.c.

Referenced by try_to_connect().

## ◆ read_from_connection()

static int read_from_connection | ( | struct connection * | pc,
|  | bool | block
| ) |  |

static

A wrapper around read_socket_data() which also handles the case the socket becomes writeable and there is still data which should be sent to the server.

Returns: -1 : an error occurred - you should close the socket -2 : the connection was closed >0 : number of bytes read =0 : no data read, would block

Definition at line 345 of file clinet.c.

Referenced by input_from_server(), and input_from_server_till_request_got_processed().

## ◆ start_autoconnecting_to_server()

void start_autoconnecting_to_server | ( | void |  | ) |

Start trying to autoconnect to freeciv-server. Calls get_server_address(), then arranges for try_to_autoconnect(), which calls try_to_connect(), to be called roughly every AUTOCONNECT_INTERVAL milliseconds, until success, fatal error or user intervention.

Definition at line 553 of file clinet.c.

Referenced by set_client_state().

## ◆ try_to_autoconnect()

double try_to_autoconnect | ( | void |  | ) |

Make an attempt to autoconnect to the server. It returns number of seconds it should be called again.

Definition at line 498 of file clinet.c.

Referenced by gui_event_loop(), and real_timer_callback().

## ◆ try_to_connect()

static int try_to_connect | ( | const char * | username,
|  | char * | errbuf,
|  | int | errbufsize
| ) |  |

static

Try to connect to a server (get_server_address() must be called first!):

- try to create a TCP socket and connect it to ‘names’
- if successful:
  - start monitoring the socket for packets from the server
  - send a "login request" packet to the server and - return 0
- if unable to create the connection, close the socket, put an error message in ERRBUF and return the Unix error code (ie., errno, which will be non-zero).

Definition at line 194 of file clinet.c.

Referenced by connect_to_server(), and try_to_autoconnect().

## Variable Documentation

## ◆ autoconnecting

bool autoconnecting = FALSE

static

Definition at line 493 of file clinet.c.

Referenced by start_autoconnecting_to_server(), and try_to_autoconnect().

## ◆ list

struct fc_sockaddr_list* list = NULL

static

Definition at line 102 of file clinet.c.

Referenced by combat_bonus_against(), create_list_of_nations_in_group(), create_races_dialog(), create_worklists_report(), city_dialog::display_worklist_menu(), city_widget::gen_cma_labels(), city_widget::gen_production_labels(), city_widget::gen_worklist_labels(), get_server_address(), get_theme_list(), get_tileset_list(), gui_dialog_set_default_response(), gui_dialog_set_response_sensitive(), gui_dialog_show_all(), helptext_extra(), helptext_nation(), helptext_terrain(), helptext_unit(), is_on_allowed_list(), lookup_cbonus_list(), menu_remove_previous_entries(), move_toolkit(), non_allied_not_listed_at(), option_dialog_option_add(), path_to_nation_on_list(), popup_info_text(), races_toggles_set_sensitive(), real_menus_init(), real_menus_update(), req_text_insert(), sdl_create_server_list(), select_nation_on_tab(), server_open_socket(), help_widget::set_topic_unit(), themespec_try_read(), tilespec_try_read(), try_to_connect(), update_server_list(), fc_client::update_server_list(), update_source_label(), waiting_queue_add_pending_request(), and waiting_queue_execute_pending_requests().