From a40ef602a3fc6a522813bb3e021ba9555ee61fa3 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Tue, 31 Oct 2017 10:13:21 +0100 Subject: [PATCH 1/4] Network: Added an executable to host an dedicated room for local wifi --- src/CMakeLists.txt | 1 + src/dedicated_room/CMakeLists.txt | 20 +++ src/dedicated_room/citra-room.cpp | 223 ++++++++++++++++++++++++++++++ src/dedicated_room/citra-room.rc | 17 +++ 4 files changed, 261 insertions(+) create mode 100644 src/dedicated_room/CMakeLists.txt create mode 100644 src/dedicated_room/citra-room.cpp create mode 100644 src/dedicated_room/citra-room.rc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e11940f59..38e2e8b6a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,3 +17,4 @@ endif() if (ENABLE_WEB_SERVICE) add_subdirectory(web_service) endif() +add_subdirectory(dedicated_room) diff --git a/src/dedicated_room/CMakeLists.txt b/src/dedicated_room/CMakeLists.txt new file mode 100644 index 000000000..60ae42f6e --- /dev/null +++ b/src/dedicated_room/CMakeLists.txt @@ -0,0 +1,20 @@ +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules) + +set(SRCS + citra-room.cpp + citra-room.rc + ) + +create_directory_groups(${SRCS}) + +add_executable(citra-room ${SRCS}) +target_link_libraries(citra-room PRIVATE common core network) +target_link_libraries(citra-room PRIVATE glad) +if (MSVC) + target_link_libraries(citra-room PRIVATE getopt) +endif() +target_link_libraries(citra-room PRIVATE ${PLATFORM_LIBRARIES} SDL2 Threads::Threads) + +if(UNIX AND NOT APPLE) + install(TARGETS citra-room RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") +endif() diff --git a/src/dedicated_room/citra-room.cpp b/src/dedicated_room/citra-room.cpp new file mode 100644 index 000000000..8769934cf --- /dev/null +++ b/src/dedicated_room/citra-room.cpp @@ -0,0 +1,223 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include +#include +#include +#include +#define SDL_MAIN_HANDLED +#include +#include + +#ifdef _MSC_VER +#include +#else +#include +#include +#endif + +#ifdef _WIN32 +// windows.h needs to be included before shellapi.h +#include + +#include +#endif + +#include "common/common_types.h" +#include "common/scm_rev.h" +#include "core/announce_multiplayer_session.h" +#include "core/core.h" +#include "core/settings.h" +#include "network/network.h" + +static void PrintHelp(const char* argv0) { + std::cout << "Usage: " << argv0 + << " [options] \n" + "--room-name The name of the room\n" + "--port The port used for the room\n" + "--max_members The maximum number of players for this room\n" + "--password The password for the room\n" + "--preferred-game The prefered game for this room\n" + "--preferred-game-id The prefered game-id for this room\n" + "--username The username used for announce\n" + "--token The token used for announce\n" + "--announce-url The url to the announce server" + "-h, --help Display this help and exit\n" + "-v, --version Output version information and exit\n"; +} + +static void PrintVersion() { + std::cout << "Citra dedicated room " << Common::g_scm_branch << " " << Common::g_scm_desc + << " Libnetwork: " << Network::network_version << std::endl; +} + +/// Application entry point +int main(int argc, char** argv) { + int option_index = 0; + char* endarg; +#ifdef _WIN32 + int argc_w; + auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w); + + if (argv_w == nullptr) { + LOG_CRITICAL(Frontend, "Failed to get command line arguments"); + return -1; + } +#endif + + // This is just to be able to link against core + gladLoadGLLoader(static_cast(SDL_GL_GetProcAddress)); + + std::string room_name; + std::string password; + std::string preferred_game; + std::string username; + std::string token; + std::string announce_url; + u64 preferred_game_id = 0; + u16 port = Network::DefaultRoomPort; + u32 max_members = 16; + + static struct option long_options[] = { + {"room-name", required_argument, 0, 'n'}, + {"port", required_argument, 0, 'p'}, + {"max_members", required_argument, 0, 'm'}, + {"password", required_argument, 0, 'w'}, + {"preferred-game", required_argument, 0, 'g'}, + {"preferred-game-id", required_argument, 0, 'i'}, + {"username", required_argument, 0, 'u'}, + {"token", required_argument, 0, 't'}, + {"announce-url", required_argument, 0, 'a'}, + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'v'}, + {0, 0, 0, 0}, + }; + + while (optind < argc) { + char arg = getopt_long(argc, argv, "n:p:m:w:g:u:t:a:i:hv", long_options, &option_index); + if (arg != -1) { + switch (arg) { + case 'n': + room_name.assign(optarg); + break; + case 'p': + port = strtoul(optarg, &endarg, 0); + break; + case 'm': + max_members = strtoul(optarg, &endarg, 0); + break; + case 'w': + password.assign(optarg); + break; + case 'g': + preferred_game.assign(optarg); + break; + case 'i': + preferred_game_id = strtoull(optarg, &endarg, 16); + break; + case 'u': + username.assign(optarg); + break; + case 't': + token.assign(optarg); + break; + case 'a': + announce_url.assign(optarg); + break; + case 'h': + PrintHelp(argv[0]); + return 0; + case 'v': + PrintVersion(); + return 0; + } + } + } + std::cout << port << std::endl; +#ifdef _WIN32 + LocalFree(argv_w); +#endif + + if (room_name.empty()) { + std::cout << "room name is empty!\n\n"; + PrintHelp(argv[0]); + return -1; + } + if (preferred_game.empty()) { + std::cout << "prefered game is empty!\n\n"; + PrintHelp(argv[0]); + return -1; + } + if (preferred_game_id == 0) { + std::cout << "prefered-game-id not set!\nThis should get set to allow users to find your " + "room.\nSet with --prefered-game-id id\n\n"; + } + if (max_members >= Network::MaxConcurrentConnections || max_members < 2) { + std::cout << "max_members needs to be in the range 2 - " + << Network::MaxConcurrentConnections << "!\n\n"; + PrintHelp(argv[0]); + return -1; + } + if (port > 65535) { + std::cout << "port needs to be in the range 0 - 65535!\n\n"; + PrintHelp(argv[0]); + return -1; + } + bool announce = true; + if (username.empty()) { + announce = false; + std::cout << "username is empty: Hosting a private room\n\n"; + } + if (token.empty() && announce) { + announce = false; + std::cout << "token is empty: Hosting a private room\n\n"; + } + if (announce_url.empty() && announce) { + announce = false; + std::cout << "announce url is empty: Hosting a private room\n\n"; + } + if (announce) { + std::cout << "Hosting a public room\n\n"; + Settings::values.announce_multiplayer_room_endpoint_url = announce_url; + Settings::values.citra_username = username; + Settings::values.citra_token = token; + } + + Network::Init(); + if (std::shared_ptr room = Network::GetRoom().lock()) { + if (!room->Create(room_name, "", port, password, max_members, preferred_game, + preferred_game_id)) { + std::cout << "Failed to create room: \n\n"; + return -1; + } + std::cout << "Room is open. Close with Q+Enter...\n\n"; + auto announce_session = std::make_unique(); + if (announce) { + announce_session->Start(); + } + while (room->GetState() == Network::Room::State::Open) { + std::string in; + std::cin >> in; + if (in.size() > 0) { + if (announce) { + announce_session->Stop(); + } + announce_session.reset(); + room->Destroy(); + Network::Shutdown(); + return 0; + } + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + if (announce) { + announce_session->Stop(); + } + announce_session.reset(); + room->Destroy(); + } + Network::Shutdown(); + return 0; +} diff --git a/src/dedicated_room/citra-room.rc b/src/dedicated_room/citra-room.rc new file mode 100644 index 000000000..c490ef302 --- /dev/null +++ b/src/dedicated_room/citra-room.rc @@ -0,0 +1,17 @@ +#include "winresrc.h" +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +CITRA_ICON ICON "../../dist/citra.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// RT_MANIFEST +// + +1 RT_MANIFEST "../../dist/citra.manifest" From b3cdf30c65c2b07a847dd884ac6a0ba1ac77dd03 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Sun, 5 Nov 2017 20:26:55 +0100 Subject: [PATCH 2/4] fixup! Network: Added an executable to host an dedicated room for local wifi --- .travis/linux/upload.sh | 1 + .travis/macos/upload.sh | 1 + src/dedicated_room/citra-room.cpp | 19 +++---------------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/.travis/linux/upload.sh b/.travis/linux/upload.sh index 7584bbd1f..e9150d7a0 100755 --- a/.travis/linux/upload.sh +++ b/.travis/linux/upload.sh @@ -9,6 +9,7 @@ COMPRESSION_FLAGS="-cJvf" mkdir "$REV_NAME" cp build/src/citra/citra "$REV_NAME" +cp build/src/citra/citra-room "$REV_NAME" cp build/src/citra_qt/citra-qt "$REV_NAME" # We need icons on Linux for .desktop entries diff --git a/.travis/macos/upload.sh b/.travis/macos/upload.sh index 19c80fdf0..fa2380fc2 100755 --- a/.travis/macos/upload.sh +++ b/.travis/macos/upload.sh @@ -10,6 +10,7 @@ mkdir "$REV_NAME" cp build/src/citra/citra "$REV_NAME" cp -r build/src/citra_qt/citra-qt.app "$REV_NAME" +cp build/src/citra/citra-room "$REV_NAME" # move qt libs into app bundle for deployment $(brew --prefix)/opt/qt5/bin/macdeployqt "${REV_NAME}/citra-qt.app" diff --git a/src/dedicated_room/citra-room.cpp b/src/dedicated_room/citra-room.cpp index 8769934cf..d834a7aa0 100644 --- a/src/dedicated_room/citra-room.cpp +++ b/src/dedicated_room/citra-room.cpp @@ -40,11 +40,11 @@ static void PrintHelp(const char* argv0) { "--port The port used for the room\n" "--max_members The maximum number of players for this room\n" "--password The password for the room\n" - "--preferred-game The prefered game for this room\n" - "--preferred-game-id The prefered game-id for this room\n" + "--preferred-game The preferred game for this room\n" + "--preferred-game-id The preferred game-id for this room\n" "--username The username used for announce\n" "--token The token used for announce\n" - "--announce-url The url to the announce server" + "--announce-url The url to the announce server\n" "-h, --help Display this help and exit\n" "-v, --version Output version information and exit\n"; } @@ -58,15 +58,6 @@ static void PrintVersion() { int main(int argc, char** argv) { int option_index = 0; char* endarg; -#ifdef _WIN32 - int argc_w; - auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w); - - if (argv_w == nullptr) { - LOG_CRITICAL(Frontend, "Failed to get command line arguments"); - return -1; - } -#endif // This is just to be able to link against core gladLoadGLLoader(static_cast(SDL_GL_GetProcAddress)); @@ -136,10 +127,6 @@ int main(int argc, char** argv) { } } } - std::cout << port << std::endl; -#ifdef _WIN32 - LocalFree(argv_w); -#endif if (room_name.empty()) { std::cout << "room name is empty!\n\n"; From d4cc0d814805c562480618d26feb12c9e4660d20 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Thu, 16 Nov 2017 19:28:15 +0100 Subject: [PATCH 3/4] Fix path for travis upload --- .travis/linux/upload.sh | 2 +- .travis/macos/upload.sh | 2 +- src/dedicated_room/CMakeLists.txt | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.travis/linux/upload.sh b/.travis/linux/upload.sh index e9150d7a0..058c41dff 100755 --- a/.travis/linux/upload.sh +++ b/.travis/linux/upload.sh @@ -9,7 +9,7 @@ COMPRESSION_FLAGS="-cJvf" mkdir "$REV_NAME" cp build/src/citra/citra "$REV_NAME" -cp build/src/citra/citra-room "$REV_NAME" +cp build/src/dedicated_room/citra-room "$REV_NAME" cp build/src/citra_qt/citra-qt "$REV_NAME" # We need icons on Linux for .desktop entries diff --git a/.travis/macos/upload.sh b/.travis/macos/upload.sh index fa2380fc2..1f928c03c 100755 --- a/.travis/macos/upload.sh +++ b/.travis/macos/upload.sh @@ -10,7 +10,7 @@ mkdir "$REV_NAME" cp build/src/citra/citra "$REV_NAME" cp -r build/src/citra_qt/citra-qt.app "$REV_NAME" -cp build/src/citra/citra-room "$REV_NAME" +cp build/src/dedicated_room/citra-room "$REV_NAME" # move qt libs into app bundle for deployment $(brew --prefix)/opt/qt5/bin/macdeployqt "${REV_NAME}/citra-qt.app" diff --git a/src/dedicated_room/CMakeLists.txt b/src/dedicated_room/CMakeLists.txt index 60ae42f6e..d956c20cc 100644 --- a/src/dedicated_room/CMakeLists.txt +++ b/src/dedicated_room/CMakeLists.txt @@ -1,13 +1,12 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules) -set(SRCS - citra-room.cpp - citra-room.rc - ) +add_executable(citra-room + citra-room.cpp + citra-room.rc +) -create_directory_groups(${SRCS}) +create_target_directory_groups(citra-room) -add_executable(citra-room ${SRCS}) target_link_libraries(citra-room PRIVATE common core network) target_link_libraries(citra-room PRIVATE glad) if (MSVC) From 2d464e79dc1870ed180cde4cb1936f1dee67bec7 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Sun, 11 Mar 2018 12:58:00 +0100 Subject: [PATCH 4/4] fixe typos --- src/dedicated_room/citra-room.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dedicated_room/citra-room.cpp b/src/dedicated_room/citra-room.cpp index d834a7aa0..5388b3782 100644 --- a/src/dedicated_room/citra-room.cpp +++ b/src/dedicated_room/citra-room.cpp @@ -134,13 +134,13 @@ int main(int argc, char** argv) { return -1; } if (preferred_game.empty()) { - std::cout << "prefered game is empty!\n\n"; + std::cout << "preferred game is empty!\n\n"; PrintHelp(argv[0]); return -1; } if (preferred_game_id == 0) { - std::cout << "prefered-game-id not set!\nThis should get set to allow users to find your " - "room.\nSet with --prefered-game-id id\n\n"; + std::cout << "preferred-game-id not set!\nThis should get set to allow users to find your " + "room.\nSet with --preferred-game-id id\n\n"; } if (max_members >= Network::MaxConcurrentConnections || max_members < 2) { std::cout << "max_members needs to be in the range 2 - "