BUILD_SERVER cleanup
This commit is contained in:
parent
bc0717b189
commit
0cb42976d8
@ -26,6 +26,7 @@ endif()
|
||||
|
||||
if(BUILD_CLIENT)
|
||||
file(GLOB_RECURSE CLIENT_SOURCES "src/game/**.cpp")
|
||||
file(GLOB_RECURSE VENDOR_SOURCES "src/vendor/**.cpp")
|
||||
endif()
|
||||
if(BUILD_SERVER)
|
||||
file(GLOB_RECURSE SERVER_SOURCES "src/server/**.cpp")
|
||||
@ -34,8 +35,10 @@ if(RENDERER_GL)
|
||||
file(GLOB_RECURSE RENDERER_GL_SOURCES "src/game/renderer/gl/**.cpp")
|
||||
endif()
|
||||
file(GLOB_RECURSE COMMON_SOURCES "src/common/**.cpp")
|
||||
file(GLOB_RECURSE VENDOR_SOURCES "src/vendor/**.cpp")
|
||||
|
||||
if(BUILD_SERVER AND NOT BUILD_CLIENT)
|
||||
set(PROJECT_NAME "polygun_server")
|
||||
endif()
|
||||
add_executable(${PROJECT_NAME}
|
||||
${CLIENT_SOURCES}
|
||||
${SERVER_SOURCES}
|
||||
@ -45,45 +48,48 @@ add_executable(${PROJECT_NAME}
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
if(NOT OPENGL_INCLUDE_DIR OR NOT OPENGL_LIBRARIES)
|
||||
find_package(OpenGL REQUIRED)
|
||||
endif()
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} "${OPENGL_LIBRARIES}")
|
||||
if(BUILD_CLIENT)
|
||||
if(NOT OPENGL_INCLUDE_DIR OR NOT OPENGL_LIBRARIES)
|
||||
find_package(OpenGL REQUIRED)
|
||||
endif()
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} "${OPENGL_LIBRARIES}")
|
||||
|
||||
if(NOT GLEW_INCLUDE_DIRS OR NOT GLEW_LIBRARIES)
|
||||
find_package(GLEW REQUIRED)
|
||||
endif()
|
||||
include_directories("${GLEW_INCLUDE_DIRS}")
|
||||
target_link_libraries(${PROJECT_NAME} "${GLEW_LIBRARIES}")
|
||||
if(NOT GLEW_INCLUDE_DIRS OR NOT GLEW_LIBRARIES)
|
||||
find_package(GLEW REQUIRED)
|
||||
endif()
|
||||
include_directories("${GLEW_INCLUDE_DIRS}")
|
||||
target_link_libraries(${PROJECT_NAME} "${GLEW_LIBRARIES}")
|
||||
|
||||
if(NOT GLFW3_INCLUDE_DIR OR NOT GLFW3_LIBRARY)
|
||||
find_package(GLFW3 REQUIRED)
|
||||
endif()
|
||||
include_directories("${GLFW3_INCLUDE_DIR}")
|
||||
target_link_libraries(${PROJECT_NAME} "${GLFW3_LIBRARY}")
|
||||
if(NOT GLFW3_INCLUDE_DIR OR NOT GLFW3_LIBRARY)
|
||||
find_package(GLFW3 REQUIRED)
|
||||
endif()
|
||||
include_directories("${GLFW3_INCLUDE_DIR}")
|
||||
target_link_libraries(${PROJECT_NAME} "${GLFW3_LIBRARY}")
|
||||
|
||||
if(NOT OPENAL_INCLUDE_DIR OR NOT OPENAL_LIBRARY)
|
||||
find_package(OpenAL REQUIRED)
|
||||
endif()
|
||||
include_directories("${OPENAL_INCLUDE_DIR}")
|
||||
target_link_libraries(${PROJECT_NAME} "${OPENAL_LIBRARY}")
|
||||
if(NOT OPENAL_INCLUDE_DIR OR NOT OPENAL_LIBRARY)
|
||||
find_package(OpenAL REQUIRED)
|
||||
endif()
|
||||
include_directories("${OPENAL_INCLUDE_DIR}")
|
||||
target_link_libraries(${PROJECT_NAME} "${OPENAL_LIBRARY}")
|
||||
|
||||
if(NOT OGG_INCLUDE_DIR OR NOT OGG_LIBRARY OR NOT VORBIS_INCLUDE_DIR OR NOT VORBIS_LIBRARY)
|
||||
find_package(OggVorbis REQUIRED)
|
||||
if(NOT OGG_INCLUDE_DIR OR NOT OGG_LIBRARY OR NOT VORBIS_INCLUDE_DIR OR NOT VORBIS_LIBRARY)
|
||||
find_package(OggVorbis REQUIRED)
|
||||
endif()
|
||||
include_directories("${OGG_INCLUDE_DIR}")
|
||||
include_directories("${VORBIS_INCLUDE_DIR}")
|
||||
target_link_libraries(${PROJECT_NAME} "${VORBIS_LIBRARY}")
|
||||
target_link_libraries(${PROJECT_NAME} "${OGG_LIBRARY}")
|
||||
|
||||
if(UNIX)
|
||||
target_link_libraries(${PROJECT_NAME} "dl")
|
||||
endif()
|
||||
endif()
|
||||
include_directories("${OGG_INCLUDE_DIR}")
|
||||
include_directories("${VORBIS_INCLUDE_DIR}")
|
||||
target_link_libraries(${PROJECT_NAME} "${VORBIS_LIBRARY}")
|
||||
target_link_libraries(${PROJECT_NAME} "${OGG_LIBRARY}")
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(${PROJECT_NAME} "ws2_32")
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
target_link_libraries(${PROJECT_NAME} "dl")
|
||||
endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} "${CMAKE_THREAD_LIBS_INIT}")
|
||||
|
@ -25,7 +25,6 @@ SOFTWARE.
|
||||
#include "common/network/network_manager.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "common/logger.hpp"
|
||||
|
||||
@ -92,7 +91,7 @@ void NetworkManager::push_packet(const NetworkPacket& packet) {
|
||||
}
|
||||
|
||||
if(m_incoming_packet_counter<=packet.get_num()) {
|
||||
m_incoming_packets.push_back(QueuedPacket{packet, glfwGetTime(), 0});
|
||||
m_incoming_packets.push_back(QueuedPacket{packet, time(0), 0});
|
||||
sort_packets(m_incoming_packets);
|
||||
}
|
||||
else { // send ACK just in case
|
||||
@ -116,11 +115,11 @@ void NetworkManager::update() {
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
if(glfwGetTime()-packet.m_last_retry>=NETWORK_MANAGER_PACKET_RETRY_INTERVAL) {
|
||||
if(time(0)-packet.m_last_retry>=NETWORK_MANAGER_PACKET_RETRY_INTERVAL) {
|
||||
if(packet.m_last_retry>0)
|
||||
LOG_VERBOSE("Resending reliable packet with num %d",packet.m_packet.get_num());
|
||||
m_socket->send(packet.m_packet, m_endpoint);
|
||||
packet.m_last_retry = glfwGetTime();
|
||||
packet.m_last_retry = time(0);
|
||||
packet.m_retries++;
|
||||
}
|
||||
}
|
||||
@ -132,8 +131,8 @@ void NetworkManager::update() {
|
||||
// TODO: Quit from game
|
||||
return;
|
||||
}
|
||||
if(glfwGetTime()-packet.m_last_retry>NETWORK_MANAGER_PACKET_RETRY_INTERVAL) {
|
||||
packet.m_last_retry = glfwGetTime();
|
||||
if(time(0)-packet.m_last_retry>NETWORK_MANAGER_PACKET_RETRY_INTERVAL) {
|
||||
packet.m_last_retry = time(0);
|
||||
packet.m_retries++;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ namespace polygun::network {
|
||||
public:
|
||||
struct QueuedPacket {
|
||||
NetworkPacket m_packet;
|
||||
double m_last_retry;
|
||||
time_t m_last_retry;
|
||||
uint8_t m_retries;
|
||||
};
|
||||
public:
|
||||
|
@ -24,8 +24,6 @@ SOFTWARE.
|
||||
|
||||
#include "server/client.hpp"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
using namespace polygun::server;
|
||||
|
||||
Client::Client(std::unique_ptr<polygun::network::NetworkManager> network_manager) :
|
||||
@ -34,11 +32,11 @@ Client::Client(std::unique_ptr<polygun::network::NetworkManager> network_manager
|
||||
m_uuid(0),
|
||||
m_pos(),
|
||||
m_join_completed(false),
|
||||
m_last_activity(glfwGetTime())
|
||||
m_last_activity(time(0))
|
||||
{
|
||||
m_network_manager = std::move(network_manager);
|
||||
}
|
||||
|
||||
void Client::update_activity() {
|
||||
m_last_activity = glfwGetTime();
|
||||
m_last_activity = time(0);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ namespace polygun::server {
|
||||
const std::string& get_nick() const { return m_nick; }
|
||||
uint32_t get_uuid() const { return m_uuid; }
|
||||
bool get_join_completed() const { return m_join_completed; }
|
||||
double get_last_activity() const { return m_last_activity; }
|
||||
time_t get_last_activity() const { return m_last_activity; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<polygun::network::NetworkManager> m_network_manager;
|
||||
@ -54,7 +54,7 @@ namespace polygun::server {
|
||||
uint32_t m_uuid;
|
||||
glm::vec3 m_pos;
|
||||
bool m_join_completed;
|
||||
double m_last_activity;
|
||||
time_t m_last_activity;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ SOFTWARE.
|
||||
#include "server/server.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
#if defined(__unix__)
|
||||
@ -50,7 +49,6 @@ Server::Server(std::atomic<bool>* running_atomic) :
|
||||
LOG_INFO("Starting server");
|
||||
m_server_socket->bind(1337);
|
||||
if(m_running_atomic_created) {
|
||||
glfwInit();
|
||||
srand(time(nullptr));
|
||||
m_running->store(true);
|
||||
g_current_server = this;
|
||||
@ -68,7 +66,6 @@ Server::~Server() {
|
||||
LOG_VERBOSE("Waiting for command thread to finish");
|
||||
if(m_command_thread->joinable())
|
||||
m_command_thread->join();
|
||||
glfwTerminate();
|
||||
delete m_running;
|
||||
}
|
||||
}
|
||||
@ -82,7 +79,7 @@ void Server::run() {
|
||||
sender.sin_family = AF_INET;
|
||||
sender.sin_addr.s_addr = INADDR_ANY;
|
||||
for(size_t i = 0; i<m_clients.size(); i++) {
|
||||
if(glfwGetTime()-m_clients[i]->get_last_activity()>=10) {
|
||||
if(time(0)-m_clients[i]->get_last_activity()>=10) {
|
||||
handle_player_timeout(m_clients[i].get());
|
||||
m_clients.erase(m_clients.begin()+i);
|
||||
i--;
|
||||
|
Loading…
x
Reference in New Issue
Block a user