The Battle for Wesnoth  1.19.5+dev
multiplayer.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2005 - 2024
3  by Philippe Plantier <ayin@anathas.org>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include <functional>
19 #include <string>
20 
22 class config;
23 
24 namespace ng { class connect_engine; }
25 
26 /** Main entry points of multiplayer mode. */
27 namespace mp
28 {
29 /** Max length of a player name. */
30 const std::size_t max_login_size = 20;
31 
32 /**
33  * Starts a multiplayer game in client mode.
34  *
35  * @param host The host to connect to.
36  */
37 void start_client(const std::string& host);
38 
39 /** Starts a multiplayer game in single-user mode. */
40 void start_local_game();
41 
42 /**
43  * Starts a multiplayer game in single-user mode using command line settings.
44  *
45  * @param cmdline_opts The commandline options.
46  */
47 void start_local_game_commandline(const commandline_options& cmdline_opts);
48 
49 /**
50  * Opens the MP Staging screen and sets the game state according to the changes made.
51  * Meant to be used between scenarios in a campaign.
52  *
53  * @param engine A connect_engine instance to pass to MP Staging.
54  */
56 
57 /**
58  * Opens the MP Join Game screen and sets the game state according to the changes made.
59  * Meant to be used between scenarios in a campaign.
60  *
61  * @param observe Whether entering as an observer or player.
62  */
63 bool goto_mp_wait(bool observe);
64 
65 /** Gets whether the currently logged-in user is a moderator. */
67 
68 /** Gets the forum profile link for the given user. */
69 std::string get_profile_link(int user_id);
70 
71 /** Returns the lobby_info object for the given session. */
72 class lobby_info* get_lobby_info();
73 
74 /** Attempts to send given data to server if a connection is open. */
75 void send_to_server(const config& data);
76 
77 /** RAII helper class to register a network handler. */
79 {
80 public:
81  using handler = std::function<void(const config&)>;
82 
85 
86 private:
87  std::function<void()> remove_handler{};
88 };
89 
90 } // namespace mp
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
This class represents the collective information the client has about the players and games on the se...
Definition: lobby_info.hpp:31
RAII helper class to register a network handler.
Definition: multiplayer.hpp:79
std::function< void()> remove_handler
Definition: multiplayer.hpp:87
std::function< void(const config &)> handler
Definition: multiplayer.hpp:81
network_registrar(handler func)
Main entry points of multiplayer mode.
Definition: lobby_data.cpp:50
lobby_info * get_lobby_info()
Returns the lobby_info object for the given session.
const std::size_t max_login_size
Max length of a player name.
Definition: multiplayer.hpp:30
void send_to_server(const config &data)
Attempts to send given data to server if a connection is open.
void start_local_game()
Starts a multiplayer game in single-user mode.
bool goto_mp_staging(ng::connect_engine &engine)
Opens the MP Staging screen and sets the game state according to the changes made.
void start_local_game_commandline(const commandline_options &cmdline_opts)
Starts a multiplayer game in single-user mode using command line settings.
std::string get_profile_link(int user_id)
Gets the forum profile link for the given user.
void start_client(const std::string &host)
Pubic entry points for the MP workflow.
bool logged_in_as_moderator()
Gets whether the currently logged-in user is a moderator.
bool goto_mp_wait(bool observe)
Opens the MP Join Game screen and sets the game state according to the changes made.
std::string_view data
Definition: picture.cpp:178