The Battle for Wesnoth  1.19.1+dev
playmp_controller.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2024
3  by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
4  Copyright (C) 2003 by David White <dave@whitevine.net>
5  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY.
13 
14  See the COPYING file for more details.
15 */
16 
17 #pragma once
18 
20 #include "syncmp_handler.hpp"
21 
22 struct mp_game_metadata;
24 {
25 public:
26  playmp_controller(const config& level, saved_game& state_of_game, mp_game_metadata* mp_info);
27  virtual ~playmp_controller();
28  void maybe_linger() override;
29  void process_oos(const std::string& err_msg) const override;
30 
31  void receive_actions() override;
32  void send_actions() override;
33  void surrender(int side_number);
34 
35  class hotkey_handler;
36 
37  bool is_networked_mp() const override;
38  void send_to_wesnothd(const config& cfg, const std::string& packet_type = "unknown") const override;
39  bool receive_from_wesnothd(config& cfg) const override;
40 
41 
42  void play_slice(bool is_delay_enabled = true) override;
43 protected:
44  virtual void handle_generic_event(const std::string& name) override;
45 
46  void start_network();
47  void stop_network();
48 
49  virtual void play_human_turn() override;
50  virtual void after_human_turn() override;
51  virtual void play_network_turn() override;
52  virtual void do_idle_notification() override;
53  virtual void play_idle_loop() override;
54 
55  /** Wait for the host to upload the next scenario. */
56  void wait_for_upload();
57 
60 
61  virtual void on_not_observer() override;
62  virtual bool is_host() const override;
63  void remove_blindfold();
64 
66 private:
68  {
69  CONTINUE,
70  /** when we couldn't handle the given action currently. */
72  };
73  /**
74  * @param unsync_only if false (default) this can exceute synced (gamestate changing) turn commands (recall, move, etc.)
75  */
76  void process_network_data(bool unsync_only = false);
77 
78  /// Check for and Handle incoming data from the multiplayer server
79  PROCESS_DATA_RESULT process_network_data_impl(const config& cfg, bool chat_only = false);
80 
81  /// Handle incoming [turn] from the multiplayer server
82  PROCESS_DATA_RESULT process_network_turn_impl(const config& t, bool chat_only = false);
83 
84  /// Handle incoming [side_drop] from the multiplayer server
86 
87  /// Handle incoming [change_controller] from the multiplayer server
89 
90  /// Send [change_controller] to the multiplayer server
91  void send_change_side_controller(int side, const std::string& player);
92 
93  /// Helper to preprocess infoming network data.
95  /// Information about our connection to the multiplayer server.
96  /// null when we are not connected to the multiplayer server
98 };
double t
Definition: astarsearch.cpp:63
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
void process_network_data(bool unsync_only=false)
void send_actions() override
Sends replay [command]s to the server.
void process_oos(const std::string &err_msg) const override
Asks the user whether to continue on an OOS error.
void process_network_side_drop_impl(const config &t)
Handle incoming [side_drop] from the multiplayer server.
void send_change_side_controller(int side, const std::string &player)
Send [change_controller] to the multiplayer server.
mp_game_metadata * mp_info_
Information about our connection to the multiplayer server.
virtual bool is_host() const override
void process_network_change_controller_impl(const config &)
Handle incoming [change_controller] from the multiplayer server.
virtual void do_idle_notification() override
Will handle sending a networked notification in descendent classes.
void maybe_linger() override
playturn_network_adapter network_reader_
Helper to preprocess infoming network data.
bool receive_from_wesnothd(config &cfg) const override
virtual void play_idle_loop() override
virtual void handle_generic_event(const std::string &name) override
virtual void play_human_turn() override
void send_to_wesnothd(const config &cfg, const std::string &packet_type="unknown") const override
PROCESS_DATA_RESULT process_network_data_impl(const config &cfg, bool chat_only=false)
Check for and Handle incoming data from the multiplayer server.
virtual void on_not_observer() override
virtual void after_human_turn() override
bool is_networked_mp() const override
PROCESS_DATA_RESULT process_network_turn_impl(const config &t, bool chat_only=false)
Handle incoming [turn] from the multiplayer server.
@ CANNOT_HANDLE
when we couldn't handle the given action currently.
virtual void play_network_turn() override
Will handle networked turns in descendent classes.
void receive_actions() override
Reads and executes replay [command]s from the server.
void surrender(int side_number)
void wait_for_upload()
Wait for the host to upload the next scenario.
playmp_controller(const config &level, saved_game &state_of_game, mp_game_metadata *mp_info)
void play_slice(bool is_delay_enabled=true) override
int side_number
Definition: game_info.hpp:40