Freeciv21
Develop your civilization from humble roots to a global empire
sernet.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 #include <memory>
14 #include <optional>
15 #include <variant>
16 
17 // Forward declarations
18 class QIODevice;
19 class QLocalServer;
20 class QTcpServer;
21 class QString;
22 
23 struct connection;
24 
25 #define BUF_SIZE 512
26 
27 #define SERVER_LAN_PORT 4555
28 #define SERVER_LAN_TTL 1
29 #define SERVER_LAN_VERSION 2
30 
32  std::variant<std::unique_ptr<QTcpServer>, std::unique_ptr<QLocalServer>>;
33 
34 std::optional<socket_server> server_open_socket();
35 void flush_packets();
39 void init_connections();
40 int server_make_connection(QIODevice *new_sock, const QString &client_addr,
41  const QString &ip_addr);
42 void finish_unit_waits();
43 void connection_ping(struct connection *pconn);
44 void handle_conn_pong(struct connection *pconn);
45 void handle_client_heartbeat(struct connection *pconn);
void connection_ping(struct connection *pconn)
Ping a connection.
Definition: sernet.cpp:527
void init_connections()
Initialize connection related stuff.
Definition: sernet.cpp:452
void handle_conn_pong(struct connection *pconn)
Handle response to ping.
Definition: sernet.cpp:541
void incoming_client_packets(connection *pconn)
Handle all incoming packets on a client connection.
Definition: sernet.cpp:229
void get_lanserver_announcement()
Listen for UDP packets multicasted from clients requesting announcement of servers on the LAN.
Definition: sernet.cpp:572
void close_connections_and_socket()
Close all network stuff: connections, listening sockets, metaserver connection...
Definition: sernet.cpp:106
void really_close_connections()
Now really close connections marked as 'is_closing'.
Definition: sernet.cpp:140
void handle_client_heartbeat(struct connection *pconn)
Handle client's regular hearbeat.
Definition: sernet.cpp:563
int server_make_connection(QIODevice *new_sock, const QString &client_addr, const QString &ip_addr)
Server accepts connection from client: Low level socket stuff, and basic-initialize the connection st...
Definition: sernet.cpp:310
void flush_packets()
Attempt to flush all information in the send buffers for upto 'netwait' seconds.
Definition: sernet.cpp:187
std::optional< socket_server > server_open_socket()
Open server socket to be used to accept client connections and open a server socket for server LAN an...
Definition: sernet.cpp:370
std::variant< std::unique_ptr< QTcpServer >, std::unique_ptr< QLocalServer > > socket_server
Definition: sernet.h:32
void finish_unit_waits()
Process all unit waits that are expired.
Definition: sernet.cpp:503