Freeciv21
Develop your civilization from humble roots to a global empire
freeciv::server Class Reference

A Freeciv21 server. More...

#include <server.h>

+ Inheritance diagram for freeciv::server:
+ Collaboration diagram for freeciv::server:

Public Member Functions

 server ()
 Creates a server. More...
 
 ~server () override
 Shut down a server. More...
 
bool is_ready () const
 Checks if the server is ready for the event loop to start. More...
 

Private Slots

void error_on_socket ()
 Called when there was an error on a socket. More...
 
void input_on_socket ()
 Called when there's something to read on a socket. More...
 
void accept_local_connections ()
 Server accepts connections over local socket: Low level socket stuff, and basic-initialize the connection struct. More...
 
void accept_tcp_connections ()
 Server accepts connections from client: Low level socket stuff, and basic-initialize the connection struct. More...
 
void send_pings ()
 Sends pings to clients if needed. More...
 
bool prepare_game ()
 Prepares for a new game. More...
 
void begin_turn ()
 Do everything needed to start a new turn on top of calling begin_turn. More...
 
void begin_phase ()
 Do everything needed to start a new phase on top of calling begin_phase. More...
 
void end_phase ()
 Do everything needed to end a phase on top of calling end_phase. More...
 
void end_turn ()
 Do everything needed to end a turn on top of calling end_turn. More...
 
void update_game_state ()
 Checks if the game state has changed and take action if appropriate. More...
 
bool shut_game_down ()
 Shuts a game down when all players have left. More...
 
void quit_idle ()
 Quit because we're idle (ie no one was connected in the last srvarg.quitidle seconds). More...
 
void pulse ()
 Called every second. More...
 
void input_on_stdin ()
 Called when there's something to read on stdin. More...
 

Private Member Functions

void init_interactive ()
 Initializes interactive handling of stdin with libreadline. More...
 

Private Attributes

bool m_ready = false
 
bool m_interactive = false
 
QObject * m_stdin_notifier = nullptr
 
socket_server m_server = socket_server()
 
civtimerm_eot_timer = nullptr
 
civtimerm_between_turns_timer = nullptr
 
bool m_is_new_turn {false}
 
bool m_need_send_pending_events {false}
 
bool m_skip_mapimg {false}
 
int m_save_counter = 0
 
bool m_someone_ever_connected = false
 
QTimer * m_quitidle_timer = nullptr
 
QTimer * m_pulse_timer = nullptr
 

Detailed Description

A Freeciv21 server.

Definition at line 68 of file server.h.

Constructor & Destructor Documentation

◆ server()

server::server ( )
explicit

Creates a server.

It starts working as soon as there is an event loop.

Definition at line 269 of file server.cpp.

◆ ~server()

server::~server ( )
override

Shut down a server.

Definition at line 361 of file server.cpp.

Member Function Documentation

◆ accept_local_connections

void server::accept_local_connections ( )
privateslot

Server accepts connections over local socket: Low level socket stuff, and basic-initialize the connection struct.

Definition at line 437 of file server.cpp.

Referenced by server().

◆ accept_tcp_connections

void server::accept_tcp_connections ( )
privateslot

Server accepts connections from client: Low level socket stuff, and basic-initialize the connection struct.

Definition at line 474 of file server.cpp.

Referenced by server().

◆ begin_phase

void server::begin_phase ( )
privateslot

Do everything needed to start a new phase on top of calling begin_phase.

Definition at line 790 of file server.cpp.

Referenced by begin_turn(), and end_phase().

◆ begin_turn

void server::begin_turn ( )
privateslot

Do everything needed to start a new turn on top of calling begin_turn.

Definition at line 775 of file server.cpp.

Referenced by end_turn(), and update_game_state().

◆ end_phase

void server::end_phase ( )
privateslot

Do everything needed to end a phase on top of calling end_phase.

Definition at line 867 of file server.cpp.

Referenced by update_game_state().

◆ end_turn

void server::end_turn ( )
privateslot

Do everything needed to end a turn on top of calling end_turn.

Definition at line 910 of file server.cpp.

Referenced by end_phase().

◆ error_on_socket

void server::error_on_socket ( )
privateslot

Called when there was an error on a socket.

Definition at line 600 of file server.cpp.

Referenced by accept_local_connections(), and accept_tcp_connections().

◆ init_interactive()

void server::init_interactive ( )
private

Initializes interactive handling of stdin with libreadline.

Definition at line 406 of file server.cpp.

Referenced by server().

◆ input_on_socket

void server::input_on_socket ( )
privateslot

Called when there's something to read on a socket.

Definition at line 629 of file server.cpp.

Referenced by accept_local_connections(), and accept_tcp_connections().

◆ input_on_stdin

void server::input_on_stdin ( )
privateslot

Called when there's something to read on stdin.

Definition at line 704 of file server.cpp.

Referenced by server().

◆ is_ready()

bool server::is_ready ( ) const

Checks if the server is ready for the event loop to start.

In practice, this is only false if opening the port failed.

Definition at line 431 of file server.cpp.

◆ prepare_game

bool server::prepare_game ( )
privateslot

Prepares for a new game.

Definition at line 739 of file server.cpp.

Referenced by server(), and update_game_state().

◆ pulse

void server::pulse ( )
privateslot

Called every second.

Definition at line 1109 of file server.cpp.

Referenced by server().

◆ quit_idle

void server::quit_idle ( )
privateslot

Quit because we're idle (ie no one was connected in the last srvarg.quitidle seconds).

Definition at line 1072 of file server.cpp.

Referenced by update_game_state().

◆ send_pings

void server::send_pings ( )
privateslot

Sends pings to clients if needed.

Definition at line 562 of file server.cpp.

Referenced by pulse().

◆ shut_game_down

bool server::shut_game_down ( )
privateslot

Shuts a game down when all players have left.

Returns whether a new game should be started.

Definition at line 1043 of file server.cpp.

Referenced by update_game_state().

◆ update_game_state

void server::update_game_state ( )
privateslot

Checks if the game state has changed and take action if appropriate.

Definition at line 964 of file server.cpp.

Referenced by begin_phase(), end_turn(), error_on_socket(), input_on_socket(), input_on_stdin(), prepare_game(), pulse(), and quit_idle().

Member Data Documentation

◆ m_between_turns_timer

civtimer * freeciv::server::m_between_turns_timer = nullptr
private

Definition at line 126 of file server.h.

Referenced by begin_phase(), end_phase(), end_turn(), and ~server().

◆ m_eot_timer

civtimer* freeciv::server::m_eot_timer = nullptr
private

Definition at line 126 of file server.h.

Referenced by begin_phase(), end_phase(), end_turn(), server(), update_game_state(), and ~server().

◆ m_interactive

bool freeciv::server::m_interactive = false
private

Definition at line 121 of file server.h.

Referenced by input_on_stdin(), server(), and ~server().

◆ m_is_new_turn

bool freeciv::server::m_is_new_turn {false}
private

Definition at line 128 of file server.h.

Referenced by begin_phase(), begin_turn(), and update_game_state().

◆ m_need_send_pending_events

bool freeciv::server::m_need_send_pending_events {false}
private

Definition at line 128 of file server.h.

Referenced by begin_phase(), and update_game_state().

◆ m_pulse_timer

QTimer* freeciv::server::m_pulse_timer = nullptr
private

Definition at line 135 of file server.h.

Referenced by server().

◆ m_quitidle_timer

QTimer* freeciv::server::m_quitidle_timer = nullptr
private

◆ m_ready

bool freeciv::server::m_ready = false
private

Definition at line 119 of file server.h.

Referenced by is_ready(), and server().

◆ m_save_counter

int freeciv::server::m_save_counter = 0
private

Definition at line 130 of file server.h.

Referenced by begin_phase(), and update_game_state().

◆ m_server

socket_server freeciv::server::m_server = socket_server()
private

Definition at line 124 of file server.h.

Referenced by accept_local_connections(), accept_tcp_connections(), and server().

◆ m_skip_mapimg

bool freeciv::server::m_skip_mapimg {false}
private

Definition at line 129 of file server.h.

Referenced by begin_phase(), and update_game_state().

◆ m_someone_ever_connected

bool freeciv::server::m_someone_ever_connected = false
private

Definition at line 132 of file server.h.

Referenced by accept_local_connections(), accept_tcp_connections(), and update_game_state().

◆ m_stdin_notifier

QObject* freeciv::server::m_stdin_notifier = nullptr
private

Definition at line 122 of file server.h.

Referenced by input_on_stdin(), server(), and ~server().