31 #include "eng3d/log.hpp"
63 auto& province = client_data.
gs.
world->provinces.at(province_id);
67 unit.set_path(province);
73 auto& province = client_data.
gs.
world->provinces.at(province_id);
81 auto& building = province.get_buildings().at(building_type_id);
82 const auto& unit_type = gs.
world->unit_types.at(unit_type_id);
85 building.work_on_unit(unit_type);
91 auto& province = gs.
world->provinces.at(province_id);
94 auto& building = province.buildings.at(building_type_id);
95 building.budget += building.get_upgrade_cost();
104 auto& province = gs.
world->provinces.at(province_id);
122 auto& treaty = gs.
world->treaties.at(treaty_id);
138 if(treaty.clauses.empty())
141 std::vector<NationId> approver_nations;
142 for(
auto& clause : treaty.clauses) {
143 approver_nations.push_back(clause->receiver_id);
144 approver_nations.push_back(clause->sender_id);
146 std::sort(approver_nations.begin(), approver_nations.end());
147 auto last = std::unique(approver_nations.begin(), approver_nations.end());
148 approver_nations.erase(last, approver_nations.end());
152 for(
auto& nation_id : approver_nations) {
157 auto it = std::find_if(treaty.approval_status.end(), treaty.approval_status.end(), [&client_data](
const auto& e) {
158 return e.first == *client_data.selected_nation;
169 auto tmp_packet = packet;
170 tmp_packet.data(tmp_ar.get_buffer(), tmp_ar.size());
180 auto decision = std::find_if(event.decisions.begin(), event.decisions.end(), [&ref_name](
const auto& o) {
181 return o.ref_name.get_string() == ref_name.get_string();
183 if(decision == event.decisions.end())
191 auto& nation = gs.
world->nations.at(nation_id);
200 auto& nation = gs.
world->nations.at(nation_id);
209 auto& nation = gs.
world->nations.at(nation_id);
215 auto& technology = gs.
world->technologies.at(technology_id);
223 clients[i].is_connected =
false;
234 packet.
pred = [
this]() {
235 return this->
run ==
true;
240 ar.set_buffer(packet.
data(), packet.
size());
245 client_data.username = cl.username;
251 packet.
data(ar.get_buffer(), ar.size());
258 Eng3D::Deser::serialize<std::string>(ar,
"[" + cl.username +
"] has connected");
259 packet.
data(ar.get_buffer(), ar.size());
268 packet.data(ar.get_buffer(), ar.size());
284 it->second(client_data, packet, ar);
@ BUILDING_START_BUILDING_UNIT
std::function< bool()> pred
std::unique_ptr< std::thread > thread
void do_netloop(std::function< void(int i)> on_wake_thread, int id)
void broadcast(const Eng3D::Networking::Packet &packet)
This will broadcast the given packet to all clients currently on the server.
std::atomic< bool > update_tick
TechnologyId focus_tech_id
void set_policy(const Policies &policies)
Enacts a policy on a nation.
std::vector< float > commodity_production
bool can_research(const Technology &tech) const
void declare_war(Nation &nation, std::vector< TreatyClause::BaseClause * > clauses=std::vector< TreatyClause::BaseClause * >())
Declare war.
std::vector< ClientData > clients_data
void on_connect(int conn_fd, int id) override
void netloop(int id)
This is the handling thread-function for handling a connection to a single client Sending packets wil...
Server(GameState &gs, unsigned port=1825, unsigned max_conn=4)
std::unordered_map< ActionType, std::function< void(ClientData &client_data, const Eng3D::Networking::Packet &packet, Eng3D::Deser::Archive &ar)> > action_handlers
void on_disconnect() override
void handler(const Eng3D::Networking::Packet &packet, Eng3D::Deser::Archive &ar, int id) override
std::vector< Nation * > clients_extra_data
Eng3D::Freelist< Unit > units
void deserialize(Eng3D::Deser::Archive &ar, T &obj)
void serialize(Eng3D::Deser::Archive &ar, const T &obj)
void debug(const std::string_view category, const std::string_view msg)
std::string string_format(const std::string_view format, Args &&... args)
String formatter.
std::string translate_format(const std::string_view format, Args &&... args)
String formatter, with translation.
static Eng3D::Networking::Packet form_packet(const Province &province, const BuildingType &building_type)
Base class that serves as archiver, stores (in memory) the data required for serialization/deserializ...
const char * c_str() const
constexpr Id get_id() const
Eng3D::StringRef ref_name
#define CXX_THROW(class,...)