diff --git a/src/client/application.cpp b/src/client/application.cpp index bc83675..7490ec1 100644 --- a/src/client/application.cpp +++ b/src/client/application.cpp @@ -323,7 +323,8 @@ void Application::process_event(Event const &event) void Application::add_to_show(std::string message) { using namespace std::chrono_literals; - _messages.emplace(current_time() + 10s, std::move(message)); + constexpr auto lasting_time{10s}; + _messages.emplace(current_time() + lasting_time, std::move(message)); } void Application::async_request(Command const &command, @@ -394,12 +395,15 @@ void Application::render_unlogged_in() _state = State::logging; } catch (std::runtime_error const &e) { - if (e.what() == std::string_view{"Connection refused"}) { - add_to_show("Cannot connect to the server. Maybe server is down, or " - "your input is incorrect."); - return; + if (e.what() == "Connection refused"sv) { + add_to_show("Cannot connect to the server. Connection refused."); + } + else if (e.what() == "resolve: Host not found (authoritative)"sv) { + add_to_show( + "Cannot connect to the server. Host not found. Please check " + "whether the server is down, or you mistyped the host."); } - throw; + spdlog::error(e.what()); } } } diff --git a/src/client/little-sb-client.cpp b/src/client/little-sb-client.cpp index f53d085..07c51de 100644 --- a/src/client/little-sb-client.cpp +++ b/src/client/little-sb-client.cpp @@ -1,6 +1,6 @@ #include "application.h" +#include "log.h" #include "window.h" -#include auto main(int argc, char **argv) -> int { @@ -13,7 +13,7 @@ auto main(int argc, char **argv) -> int return 1; } - spdlog::set_level(spdlog::level::info); + log_to_console_and_file(); Window::initialize(); #ifdef NDEBUG diff --git a/src/client/window.cpp b/src/client/window.cpp index 6cada91..bcc0342 100644 --- a/src/client/window.cpp +++ b/src/client/window.cpp @@ -35,7 +35,7 @@ void Window::deinitialize() } Window::Window() - : _window{glfwCreateWindow(1440, 960, "Little sb", nullptr, nullptr)} + : _window{glfwCreateWindow(1600, 1200, "Little sb", nullptr, nullptr)} { if (_window == nullptr) { throw "Window or OpenGL context creation failed"; diff --git a/src/log.cpp b/src/log.cpp new file mode 100644 index 0000000..4e27759 --- /dev/null +++ b/src/log.cpp @@ -0,0 +1,21 @@ +#include "log.h" +#include +#include +#include +#include + +void log_to_console_and_file() +{ + auto console_sink{std::make_shared()}; + console_sink->set_level(spdlog::level::warn); + + auto file_sink{std::make_shared( + "logs/multisink.txt", true)}; + file_sink->set_level(spdlog::level::trace); + + auto logger{std::make_shared( + "", spdlog::sinks_init_list{console_sink, file_sink})}; + + spdlog::default_logger()->name(); + spdlog::set_default_logger(logger); +} diff --git a/src/log.h b/src/log.h new file mode 100644 index 0000000..c474374 --- /dev/null +++ b/src/log.h @@ -0,0 +1,3 @@ +#pragma once + +void log_to_console_and_file(); diff --git a/src/server/little-sb-server.cpp b/src/server/little-sb-server.cpp index 2dcc46b..ab747b5 100644 --- a/src/server/little-sb-server.cpp +++ b/src/server/little-sb-server.cpp @@ -1,6 +1,8 @@ +#include "log.h" #include "server.h" #include -#include +#include +#include void signal_handler(int /*signal*/) { @@ -8,11 +10,18 @@ void signal_handler(int /*signal*/) Server::instance().shutdown(); } -auto main(int /*argc*/, char * /*argv*/[]) -> int +auto main(int argc, char **argv) -> int { + if (argc == 0) { + std::abort(); + return -1; + } + + std::span args{argv, static_cast(argc - 1)}; + // Signal handler for SIGINT std::signal(SIGINT, signal_handler); - spdlog::set_level(spdlog::level::info); // Set for debugging + log_to_console_and_file(); #ifdef NDEBUG // Disable try-catch in DEBUG mode to allow the debugger to catch and display