Welcome to mirror list, hosted at ThFree Co, Russian Federation.

online_client_connection_manager.cpp « Online « Source - github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ca3668365778728768a109e7b0a8f58566477b4b (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//-----------------------------------------------------------------------------
//           Name: online_client_connection_manager.cpp
//      Developer: Wolfire Games LLC
//    Description: 
//        License: Read below
//-----------------------------------------------------------------------------
//
//   Copyright 2022 Wolfire Games LLC
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//
//-----------------------------------------------------------------------------
#include "online_client_connection_manager.h"

#include <Online/online_datastructures.h>
#include <Online/online_connection_states.h>

#include <Online/Message/pcs_build_version_message.h>
#include <Online/Message/pcs_loading_completed_message.h>
#include <Online/Message/pcs_client_parameters_message.h>

#include <Online/online.h>

bool ClientConnectionManager::IsEveryClientLoaded() const {
    for (auto& it : connection_states) {
        if (!it.second.actor.finished_loading) {
            return false;
        }
    }
    return true;
}

bool ClientConnectionManager::HasClientGottenPersistentQueue(const PeerID peer_id) const {
    if (HasConnection(peer_id))
        return connection_states.at(peer_id).actor.finished_sending_persistent_queue;

    LOGW << "Attempted to query persistent queue state of a non-connected client. This will always return false!" << std::endl;
    return false;
}

bool ClientConnectionManager::IsClientLoaded(const PeerID peer_id) const {
    if (HasConnection(peer_id))
        return connection_states.at(peer_id).actor.finished_loading;

    LOGW << "Attempted to query loading state of a non-connected client. This will always return false!" << std::endl;
    return false;
}

bool ClientConnectionManager::HasConnection(const PeerID peer_id) const {
    return connection_states.find(peer_id) != connection_states.end();
}

void ClientConnectionManager::Update() {
    for (auto& it : connection_states) {
        it.second.Update();
    }
}

void ClientConnectionManager::RemoveConnection(const PeerID peer_id) {
    connection_states.erase(peer_id);
}

void ClientConnectionManager::AddConnection(const PeerID peer_id, const NetConnectionID net_connection_id) {
    connection_states.emplace(std::piecewise_construct, std::make_tuple(peer_id), std::make_tuple(new StateVersionCheck(), PendingConnection(net_connection_id)));
}

void ClientConnectionManager::ResetConnections() {
    connection_states.clear();
    for (auto& peer : Online::Instance()->GetPeers()) {
        connection_states.emplace(std::piecewise_construct, std::make_tuple(peer.peer_id), std::make_tuple(new StateVersionCheck(), PendingConnection(peer.conn_id)));
    }
}

void ClientConnectionManager::ApplyPackage(const PeerID peer_id, PCSBuildVersionMessage* build_version) {
    connection_states[peer_id].actor.received_version = true;
    connection_states[peer_id].actor.build_id = build_version->build_id;
}

void ClientConnectionManager::ApplyPackage(const PeerID peer_id, PCSLoadingCompletedMessage* loading_completed) {
    connection_states[peer_id].actor.finished_loading = true;
}

void ClientConnectionManager::ApplyPackage(const PeerID peer_id, PCSClientParametersMessage* client_parameters) {
    connection_states[peer_id].actor.player_name = client_parameters->player_name;
    connection_states[peer_id].actor.active_mods_string = client_parameters->enabled_mods_string;
    connection_states[peer_id].actor.received_client_params = true;
}

void ClientConnectionManager::SetClientGottenPersistentQueue(const PeerID peer_id) {
    connection_states[peer_id].actor.finished_sending_persistent_queue = true;
}