Freeciv21
Develop your civilization from humble roots to a global empire
connectdlg_common.cpp File Reference
#include <fc_config.h>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QProcess>
#include <QStandardPaths>
#include <QTcpServer>
#include <QUrl>
#include <QUuid>
#include <cstring>
#include "fcintl.h"
#include "log.h"
#include "rand.h"
#include "registry.h"
#include "registry_ini.h"
#include "shared.h"
#include "support.h"
#include "chatline_common.h"
#include "client_main.h"
#include "clinet.h"
#include "connectdlg_common.h"
#include "packhand_gen.h"
#include "qtg_cxxside.h"
+ Include dependency graph for connectdlg_common.cpp:

Go to the source code of this file.

Classes

class  serverProcess
 

Macros

#define WAIT_BETWEEN_TRIES   100000
 
#define NUMBER_OF_TRIES   500
 

Functions

bool is_server_running ()
 The general chain of events: More...
 
bool can_client_access_hack ()
 Returns TRUE if the client has hack access. More...
 
void client_kill_server (bool force)
 Kills the server if the client has started it. More...
 
bool client_start_server (const QString &user_name)
 Forks a server if it can. More...
 
static void randomize_string (char *str, size_t n)
 Generate a random string. More...
 
void send_client_wants_hack (const char *filename)
 If the client is capable of 'wanting hack', then the server will send the client a filename in the packet_join_game_reply packet. More...
 
void handle_single_want_hack_reply (bool you_have_hack)
 Handle response (by the server) if the client has got hack or not. More...
 
void send_save_game (const char *filename)
 Send server command to save game. More...
 
void handle_ruleset_choices (const struct packet_ruleset_choices *packet)
 Handle the list of rulesets sent by the server. More...
 
void set_ruleset (const char *ruleset)
 Called by the GUI code when the user sets the ruleset. More...
 

Variables

bool server_quitting = false
 
static char challenge_fullname [MAX_LEN_PATH]
 
static bool client_has_hack = false
 
int internal_server_port
 

Macro Definition Documentation

◆ NUMBER_OF_TRIES

#define NUMBER_OF_TRIES   500

Definition at line 47 of file connectdlg_common.cpp.

◆ WAIT_BETWEEN_TRIES

#define WAIT_BETWEEN_TRIES   100000

Definition at line 46 of file connectdlg_common.cpp.

Function Documentation

◆ can_client_access_hack()

bool can_client_access_hack ( )

Returns TRUE if the client has hack access.

Definition at line 136 of file connectdlg_common.cpp.

Referenced by mr_menu::nonunit_sensitivity(), and page_pregame::update_buttons().

◆ client_kill_server()

void client_kill_server ( bool  force)

Kills the server if the client has started it.

If the 'force' parameter is unset, we just do a /quit. If it's set, then we'll send a signal to the server to kill it (use this when the socket is disconnected already).

Definition at line 145 of file connectdlg_common.cpp.

Referenced by client_conn_close_callback(), client_start_server(), disconnect_from_server(), emergency_exit(), and handle_single_want_hack_reply().

◆ client_start_server()

bool client_start_server ( const QString &  user_name)

Forks a server if it can.

Returns FALSE if we find we couldn't start the server.

Definition at line 179 of file connectdlg_common.cpp.

Referenced by client_start_server_and_set_page(), client_state(), fc_client::start_from_file(), fc_client::start_new_game(), and fc_client::start_tutorial().

◆ handle_ruleset_choices()

void handle_ruleset_choices ( const struct packet_ruleset_choices *  packet)

Handle the list of rulesets sent by the server.

Definition at line 398 of file connectdlg_common.cpp.

◆ handle_single_want_hack_reply()

void handle_single_want_hack_reply ( bool  you_have_hack)

Handle response (by the server) if the client has got hack or not.

Definition at line 358 of file connectdlg_common.cpp.

◆ is_server_running()

bool is_server_running ( )

The general chain of events:

Two distinct paths are taken depending on the choice of mode:

if the user selects the multi- player mode, then a packet_req_join_game packet is sent to the server. It is either successful or not. The end.

If the user selects a single- player mode (either a new game or a save game) then:

  1. the packet_req_join_game is sent.
  2. on receipt, if we can join, then a challenge packet is sent to the server, so we can get hack level control.
  3. if we can't get hack, then we get dumped to multi- player mode. If we can, then: a. for a new game, we send a series of packet_generic_message packets with commands to start the game. b. for a saved game, we send the load command with a packet_generic_message, then we send a PACKET_PLAYER_LIST_REQUEST. the response to this request will tell us if the game was loaded or not. if not, then we send another load command. if so, then we send a series of packet_generic_message packets with commands to start the game. Tests if the client has started the server.

Definition at line 125 of file connectdlg_common.cpp.

Referenced by mr_menu::back_to_menu(), client_kill_server(), fc_client::current_page(), handle_server_join_reply(), handle_single_want_hack_reply(), chat_widget::set_chat_visible(), fc_client::start_from_file(), fc_client::start_new_game(), and chat_widget::update_widgets().

◆ randomize_string()

static void randomize_string ( char *  str,
size_t  n 
)
static

Generate a random string.

Definition at line 299 of file connectdlg_common.cpp.

Referenced by send_client_wants_hack().

◆ send_client_wants_hack()

void send_client_wants_hack ( const char *  filename)

If the client is capable of 'wanting hack', then the server will send the client a filename in the packet_join_game_reply packet.

This function creates the file with a suitably random string in it and then sends the string to the server. If the server can open and read the string, then the client is given hack access.

Definition at line 319 of file connectdlg_common.cpp.

Referenced by handle_server_join_reply().

◆ send_save_game()

void send_save_game ( const char *  filename)

Send server command to save game.

Definition at line 386 of file connectdlg_common.cpp.

Referenced by mr_menu::save_game(), and mr_menu::save_game_as().

◆ set_ruleset()

void set_ruleset ( const char *  ruleset)

Called by the GUI code when the user sets the ruleset.

The ruleset passed in here should match one of the strings given to set_rulesets().

Definition at line 419 of file connectdlg_common.cpp.

Referenced by pregame_options::ruleset_change().

Variable Documentation

◆ challenge_fullname

char challenge_fullname[MAX_LEN_PATH]
static

Definition at line 51 of file connectdlg_common.cpp.

Referenced by handle_single_want_hack_reply(), and send_client_wants_hack().

◆ client_has_hack

bool client_has_hack = false
static

◆ internal_server_port

int internal_server_port

Definition at line 54 of file connectdlg_common.cpp.

◆ server_quitting

bool server_quitting = false