Saving changes #1

This commit is contained in:
mrkubax10 2023-05-25 10:23:19 +03:00
parent 23b3700a42
commit 42145215dd
5 changed files with 17 additions and 5 deletions

View File

@ -57,14 +57,14 @@ std::string polygun::utils::get_user_dir() {
#elif defined(_WIN32)
char* c_appdata = getenv("appdata");
std::string appdata;
if(!appdata)
if(!c_appdata)
LOG_FATAL("Failed to determine folder for writing user data (appdata not set)");
appdata = std::string(c_appdata)+"/polygun";
std::ofstream temp(appdata+"/a");
if(temp.good())
temp.close();
else
std::filesystem::create_directories(data_home);
std::filesystem::create_directories(appdata);
return appdata;
#else
LOG_FATAL("polygun::utils::get_user_dir is not implemented for your platform");

View File

@ -79,7 +79,9 @@ GameSessionScreen::GameSessionScreen(const std::string& ip, unsigned short port,
#if defined(BUILD_SERVER)
m_local_server_thread(),
#endif
m_game_state(GameState::GAME_STATE_JOINING)
m_game_state(GameState::GAME_STATE_JOINING),
m_player_uuid(0),
m_max_node_id(0)
{}
void GameSessionScreen::begin() {
@ -356,8 +358,13 @@ void GameSessionScreen::connection_thread_func() {
case network::NetworkPacketID::PACKET_HANDSHAKE:
if(m_game_state==GameState::GAME_STATE_RUNNING)
LOG_WARNING("Received another handshake packet from server!!");
else
else {
m_game_state = GameState::GAME_STATE_RUNNING;
packet.read(m_player_uuid);
LOG_INFO("Your UUID: %d", m_player_uuid);
packet.read(m_max_node_id);
LOG_VERBOSE("%d registered nodes on server", m_max_node_id);
}
break;
}
}

View File

@ -79,6 +79,8 @@ namespace polygun::screens {
std::unique_ptr<std::thread> m_local_server_thread;
#endif
std::atomic<GameState> m_game_state;
unsigned m_player_uuid;
uint16_t m_max_node_id;
private:
void connection_thread_func();

View File

@ -43,6 +43,7 @@ namespace polygun::server {
void set_current_module(Mod* module) { m_current_module = module; }
Mod* get_current_module() { return m_current_module; }
uint16_t get_next_node_id() { return m_current_node_id++; }
uint16_t get_current_node_id() const { return m_current_node_id; }
private:
Server& m_server;

View File

@ -227,7 +227,9 @@ bool Server::handle_new_player(polygun::network::NetworkPacket& packet) {
m_latest_client->get_connection().send_ack(packet.get_num());
polygun::network::NetworkPacket out_packet = m_latest_client->get_connection().create_packet(polygun::network::NetworkPacketFlag::FLAG_RELIABLE, polygun::network::NetworkPacketID::PACKET_HANDSHAKE);
out_packet.write(uuid);
out_packet.write(uuid); // player UUID
LOG_VERBOSE("Current node ID: %d", m_mod_manager.get_current_node_id());
out_packet.write(m_mod_manager.get_current_node_id()); // max node ID
m_latest_client->get_connection().send_packet(out_packet);
m_latest_client->get_connection().update();
m_latest_client->set_uuid(uuid);