File: Networking.h

package info (click to toggle)
freeorion 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 194,940 kB
  • sloc: cpp: 186,508; python: 40,969; ansic: 1,164; xml: 719; makefile: 32; sh: 7
file content (62 lines) | stat: -rw-r--r-- 2,063 bytes parent folder | download
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
#ifndef _Networking_h_
#define _Networking_h_

#include <string>
#include <bitset>
#include <cstdint>

#include "../util/Enum.h"
#include "../util/Export.h"

namespace Networking {
    FO_COMMON_API extern const std::string DISCOVERY_QUESTION;
    FO_COMMON_API extern const std::string DISCOVERY_ANSWER;
    FO_COMMON_API extern const int SOCKET_LINGER_TIME;
    inline constexpr int INVALID_PLAYER_ID = -1;
    inline constexpr int NO_TEAM_ID = -1;

    FO_COMMON_API int DiscoveryPort();
    FO_COMMON_API int MessagePort();

    FO_ENUM(
        (ClientType),
        ((INVALID_CLIENT_TYPE, -1))
        ((CLIENT_TYPE_AI_PLAYER))
        ((CLIENT_TYPE_HUMAN_PLAYER))
        ((CLIENT_TYPE_HUMAN_OBSERVER))
        ((CLIENT_TYPE_HUMAN_MODERATOR))
        ((NUM_CLIENT_TYPES))
    )

    enum class RoleType : uint8_t {
        ROLE_HOST = 0,              ///< allows save and load games, edit other player settings, stop server
        ROLE_CLIENT_TYPE_MODERATOR, ///< allows have a client type Moderator
        ROLE_CLIENT_TYPE_PLAYER,    ///< allows have a client type Player
        ROLE_CLIENT_TYPE_OBSERVER,  ///< allows have a client type Observer
        ROLE_GALAXY_SETUP,          ///< allows change galaxy and AI settings in lobby

        Roles_Count
    };

    class FO_COMMON_API AuthRoles {
    public:
        constexpr AuthRoles() = default;
        explicit AuthRoles(std::initializer_list<RoleType> roles) {
            for (RoleType r : roles)
                m_roles.set(std::size_t(r), true);
        }

        void SetRole(RoleType role, bool value = true) { m_roles.set(std::size_t(role), value); }
        void Clear() noexcept { m_roles.reset(); }

        [[nodiscard]] bool HasRole(RoleType role) const { return m_roles.test(std::size_t(role)); }
        [[nodiscard]] std::string Text() const { return m_roles.to_string(); }
        void SetText(const std::string& text) { m_roles = std::bitset<std::size_t(RoleType::Roles_Count)>(text); }

    private:
        std::bitset<int(RoleType::Roles_Count)> m_roles;
    };

}

#endif