summaryrefslogtreecommitdiff
path: root/core/multiplayer/multiplayer.h
blob: 5eb968171aad4abf37984a8b740c9e2eef1f762d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*************************************************************************/
/*  multiplayer.h                                                        */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                      https://godotengine.org                          */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/

#ifndef MULTIPLAYER_H
#define MULTIPLAYER_H

#include "core/variant/binder_common.h"

#include "core/string/string_name.h"

namespace Multiplayer {

enum TransferMode {
	TRANSFER_MODE_UNRELIABLE,
	TRANSFER_MODE_UNRELIABLE_ORDERED,
	TRANSFER_MODE_RELIABLE
};

enum RPCMode {
	RPC_MODE_DISABLED, // No rpc for this method, calls to this will be blocked (default)
	RPC_MODE_ANY_PEER, // Any peer can call this RPC
	RPC_MODE_AUTHORITY, // / Only the node's multiplayer authority (server by default) can call this RPC
};

struct RPCConfig {
	StringName name;
	RPCMode rpc_mode = RPC_MODE_DISABLED;
	bool call_local = false;
	TransferMode transfer_mode = TRANSFER_MODE_RELIABLE;
	int channel = 0;

	bool operator==(RPCConfig const &p_other) const {
		return name == p_other.name;
	}
};

struct SortRPCConfig {
	StringName::AlphCompare compare;
	bool operator()(const RPCConfig &p_a, const RPCConfig &p_b) const {
		return compare(p_a.name, p_b.name);
	}
};

}; // namespace Multiplayer

// This is needed for proper docs generation (i.e. not "Multiplayer."-prefixed).
typedef Multiplayer::RPCMode RPCMode;
typedef Multiplayer::TransferMode TransferMode;

VARIANT_ENUM_CAST(RPCMode);
VARIANT_ENUM_CAST(TransferMode);

#endif // MULTIPLAYER_H