#include "backend/command.hpp" #include "util/session.hpp" namespace big { class switch_session : command { std::unordered_map m_session_types = { {eSessionType::JOIN_PUBLIC, "PUB"}, {eSessionType::NEW_PUBLIC, "NEWPUB"}, {eSessionType::CLOSED_CREW, "CLOSEDCREW"}, {eSessionType::CREW, "NEWCREW"}, {eSessionType::CLOSED_FRIENDS, "CLOSEDFRIENDS"}, {eSessionType::FIND_FRIEND, "FRIENDS"}, {eSessionType::SOLO, "SOLO"}, {eSessionType::INVITE_ONLY, "INVITE"}, {eSessionType::JOIN_CREW, "CREW"}, {eSessionType::SC_TV, "SCTV"}, {eSessionType::LEAVE_ONLINE, "SINGLEPLAYER"}, }; using command::command; std::string valid_args(bool was_session_string = false) { std::string valid_args; if (was_session_string) { for (const auto& session_type_string : m_session_types | std::ranges::views::values) { if (!empty(valid_args)) { valid_args += ", "; } valid_args += session_type_string; } return valid_args; } for (const auto& session_type_id : m_session_types | std::ranges::views::keys) { if (!empty(valid_args)) { valid_args += ", "; } valid_args += std::to_string(static_cast(session_type_id)); } return valid_args; } virtual std::optional parse_args(const std::vector& args, const std::shared_ptr ctx) override { command_arguments result(1); auto sessionType = static_cast(std::atoi(args[0].c_str())); if (m_session_types.find(sessionType) == m_session_types.end()) { ctx->report_error(std::format("Invalid session type ID given \"{}\", valid inputs are [{}].", args[0], valid_args())); return std::nullopt; } if (sessionType == eSessionType::JOIN_PUBLIC && args[0] != "0") { const auto it = std::find_if(m_session_types.begin(), m_session_types.end(), [&args](const std::pair& t) -> bool { return t.second == args[0]; }); if (it == m_session_types.end()) { ctx->report_error(std::format("Unknown session type \"{}\", valid inputs are [{}].", args[0], valid_args(true))); return std::nullopt; } sessionType = it->first; } result.push(sessionType); return result; } virtual void execute(const command_arguments& args, const std::shared_ptr ctx) override { session::join_type(args.shift()); } }; switch_session g_switch_session("joinsession", "Join Session", "Join a specific session type.", 1); }