-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
382 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
[ | ||
{ | ||
"directory": "/home/pass_is_1/Car-Application/backend", | ||
"arguments": ["/usr/bin/gcc", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++17", "-Iinclude", "-I", "/home/pass_is_1/.xmake/packages/f/fmt/10.1.1/f6aacaa0e06a42ca8786f360cc1d31c5/include", "-I", "/home/pass_is_1/.xmake/packages/s/spdlog/v1.12.0/e24126f106564f7c97234caa2b9c81c5/include", "-I", "/home/pass_is_1/.xmake/packages/o/oatpp/1.3.0/0f4509c6b55d49128c21c834ef94e6a0/include/oatpp-1.3.0/oatpp", "-I", "/home/pass_is_1/.xmake/packages/t/tl_expected/v1.1.0/57774aec28a24eb8b84e9c45d2905d73/include", "-DNDEBUG", "-o", "build/.objs/backend/linux/x86_64/release/src/websocket/WSListener.cpp.o", "src/websocket/WSListener.cpp"], | ||
"file": "src/websocket/WSListener.cpp" | ||
"arguments": ["/usr/bin/gcc", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++17", "-Iinclude", "-I", "/home/pass_is_1/.xmake/packages/f/fmt/10.1.1/f6aacaa0e06a42ca8786f360cc1d31c5/include", "-I", "/home/pass_is_1/.xmake/packages/s/spdlog/v1.12.0/e24126f106564f7c97234caa2b9c81c5/include", "-I", "/home/pass_is_1/.xmake/packages/o/oatpp-websocket/1.3.0/74ca6ba37ddc4ed596561e2625c0b306/include/oatpp-1.3.0/oatpp-websocket", "-I", "/home/pass_is_1/.xmake/packages/o/oatpp/1.3.0/0f4509c6b55d49128c21c834ef94e6a0/include/oatpp-1.3.0/oatpp", "-I", "/home/pass_is_1/.xmake/packages/t/tl_expected/v1.1.0/57774aec28a24eb8b84e9c45d2905d73/include", "-DNDEBUG", "-o", "build/.objs/backend/linux/x86_64/release/src/rooms/Peer.cpp.o", "src/rooms/Peer.cpp"], | ||
"file": "src/rooms/Peer.cpp" | ||
}, | ||
{ | ||
"directory": "/home/pass_is_1/Car-Application/backend", | ||
"arguments": ["/usr/bin/gcc", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++17", "-Iinclude", "-I", "/home/pass_is_1/.xmake/packages/f/fmt/10.1.1/f6aacaa0e06a42ca8786f360cc1d31c5/include", "-I", "/home/pass_is_1/.xmake/packages/s/spdlog/v1.12.0/e24126f106564f7c97234caa2b9c81c5/include", "-I", "/home/pass_is_1/.xmake/packages/o/oatpp/1.3.0/0f4509c6b55d49128c21c834ef94e6a0/include/oatpp-1.3.0/oatpp", "-I", "/home/pass_is_1/.xmake/packages/t/tl_expected/v1.1.0/57774aec28a24eb8b84e9c45d2905d73/include", "-DNDEBUG", "-o", "build/.objs/backend/linux/x86_64/release/src/App.cpp.o", "src/App.cpp"], | ||
"arguments": ["/usr/bin/gcc", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++17", "-Iinclude", "-I", "/home/pass_is_1/.xmake/packages/f/fmt/10.1.1/f6aacaa0e06a42ca8786f360cc1d31c5/include", "-I", "/home/pass_is_1/.xmake/packages/s/spdlog/v1.12.0/e24126f106564f7c97234caa2b9c81c5/include", "-I", "/home/pass_is_1/.xmake/packages/o/oatpp-websocket/1.3.0/74ca6ba37ddc4ed596561e2625c0b306/include/oatpp-1.3.0/oatpp-websocket", "-I", "/home/pass_is_1/.xmake/packages/o/oatpp/1.3.0/0f4509c6b55d49128c21c834ef94e6a0/include/oatpp-1.3.0/oatpp", "-I", "/home/pass_is_1/.xmake/packages/t/tl_expected/v1.1.0/57774aec28a24eb8b84e9c45d2905d73/include", "-DNDEBUG", "-o", "build/.objs/backend/linux/x86_64/release/src/rooms/Lobby.cpp.o", "src/rooms/Lobby.cpp"], | ||
"file": "src/rooms/Lobby.cpp" | ||
}, | ||
{ | ||
"directory": "/home/pass_is_1/Car-Application/backend", | ||
"arguments": ["/usr/bin/gcc", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++17", "-Iinclude", "-I", "/home/pass_is_1/.xmake/packages/f/fmt/10.1.1/f6aacaa0e06a42ca8786f360cc1d31c5/include", "-I", "/home/pass_is_1/.xmake/packages/s/spdlog/v1.12.0/e24126f106564f7c97234caa2b9c81c5/include", "-I", "/home/pass_is_1/.xmake/packages/o/oatpp-websocket/1.3.0/74ca6ba37ddc4ed596561e2625c0b306/include/oatpp-1.3.0/oatpp-websocket", "-I", "/home/pass_is_1/.xmake/packages/o/oatpp/1.3.0/0f4509c6b55d49128c21c834ef94e6a0/include/oatpp-1.3.0/oatpp", "-I", "/home/pass_is_1/.xmake/packages/t/tl_expected/v1.1.0/57774aec28a24eb8b84e9c45d2905d73/include", "-DNDEBUG", "-o", "build/.objs/backend/linux/x86_64/release/src/rooms/Room.cpp.o", "src/rooms/Room.cpp"], | ||
"file": "src/rooms/Room.cpp" | ||
}, | ||
{ | ||
"directory": "/home/pass_is_1/Car-Application/backend", | ||
"arguments": ["/usr/bin/gcc", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++17", "-Iinclude", "-I", "/home/pass_is_1/.xmake/packages/f/fmt/10.1.1/f6aacaa0e06a42ca8786f360cc1d31c5/include", "-I", "/home/pass_is_1/.xmake/packages/s/spdlog/v1.12.0/e24126f106564f7c97234caa2b9c81c5/include", "-I", "/home/pass_is_1/.xmake/packages/o/oatpp-websocket/1.3.0/74ca6ba37ddc4ed596561e2625c0b306/include/oatpp-1.3.0/oatpp-websocket", "-I", "/home/pass_is_1/.xmake/packages/o/oatpp/1.3.0/0f4509c6b55d49128c21c834ef94e6a0/include/oatpp-1.3.0/oatpp", "-I", "/home/pass_is_1/.xmake/packages/t/tl_expected/v1.1.0/57774aec28a24eb8b84e9c45d2905d73/include", "-DNDEBUG", "-o", "build/.objs/backend/linux/x86_64/release/src/App.cpp.o", "src/App.cpp"], | ||
"file": "src/App.cpp" | ||
}] |
18 changes: 18 additions & 0 deletions
18
backend/repository/packages/j/json-schema-validator-/port/xmake.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
add_rules("mode.debug", "mode.release") | ||
|
||
add_requires("nlohmann_json") | ||
|
||
target("json-schema-validator") | ||
set_kind("$(kind)") | ||
set_languages("cxx17") | ||
add_packages("nlohmann_json") | ||
|
||
add_headerfiles("src/(nlohmann/json-schema.hpp)") | ||
add_includedirs("src", { public = true }) | ||
|
||
add_files("src/**.cpp") | ||
add_headerfiles("src/*.hpp") | ||
|
||
if is_plat("windows") then | ||
add_defines("_WIN32") | ||
end |
33 changes: 33 additions & 0 deletions
33
backend/repository/packages/j/json-schema-validator-/xmake.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package("json-schema-validator-") | ||
set_homepage("https://github.com/pboettch/json-schema-validator") | ||
set_description("JSON schema validator for JSON for Modern C++") | ||
|
||
add_urls("https://github.com/pboettch/json-schema-validator/archive/refs/tags/$(version).tar.gz", | ||
"https://github.com/pboettch/json-schema-validator.git") | ||
add_versions("2.1.0", "83f61d8112f485e0d3f1e72d51610ba3924b179926a8376aef3c038770faf202") | ||
|
||
add_deps("nlohmann_json") | ||
|
||
on_install(function (package) | ||
os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua") | ||
local configs = {} | ||
if package:config("shared") then | ||
package:add("defines", "JSON_SCHEMA_VALIDATOR_EXPORTS") | ||
end | ||
import("package.tools.xmake").install(package, configs) | ||
end) | ||
|
||
on_test(function (package) | ||
assert(package:check_cxxsnippets({test = [[ | ||
#include <nlohmann/json-schema.hpp> | ||
using nlohmann::json; | ||
using nlohmann::json_schema::json_validator; | ||
static json person_schema = R"({})"_json; | ||
static void test() { | ||
json_validator validator; | ||
validator.set_root_schema(person_schema); | ||
} | ||
]]}, {configs = {languages = "c++17"}})) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
#include "Lobby.hpp" | ||
|
||
v_int32 Lobby::obtainNewUserId() { | ||
return m_userIdCounter ++; | ||
} | ||
|
||
std::shared_ptr<Room> Lobby::getOrCreateRoom(const oatpp::String& roomName) { | ||
std::lock_guard<std::mutex> lock(m_roomsMutex); | ||
std::shared_ptr<Room>& room = m_rooms[roomName]; | ||
if(!room) { | ||
room = std::make_shared<Room>(roomName); | ||
} | ||
return room; | ||
} | ||
|
||
void Lobby::onAfterCreate_NonBlocking(const std::shared_ptr<AsyncWebSocket>& socket, const std::shared_ptr<const ParameterMap>& params) { | ||
|
||
auto roomName = params->find("roomName")->second; | ||
auto nickname = params->find("nickname")->second; | ||
auto room = getOrCreateRoom(roomName); | ||
|
||
auto peer = std::make_shared<Peer>(socket, room, nickname, obtainNewUserId()); | ||
socket->setListener(peer); | ||
|
||
room->addPeer(peer); | ||
room->sendMessage(nickname + " joined " + roomName); | ||
|
||
} | ||
|
||
void Lobby::onBeforeDestroy_NonBlocking(const std::shared_ptr<AsyncWebSocket>& socket) { | ||
|
||
auto peer = std::static_pointer_cast<Peer>(socket->getListener()); | ||
auto nickname = peer->getNickname(); | ||
auto room = peer->getRoom(); | ||
|
||
room->removePeerByUserId(peer->getUserId()); | ||
|
||
room->sendMessage(nickname + " left the room"); | ||
|
||
/* Remove circle `std::shared_ptr` dependencies */ | ||
socket->setListener(nullptr); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
#ifndef ASYNC_SERVER_ROOMS_LOBBY_HPP | ||
#define ASYNC_SERVER_ROOMS_LOBBY_HPP | ||
|
||
#include "./Room.hpp" | ||
|
||
#include "oatpp-websocket/AsyncConnectionHandler.hpp" | ||
|
||
#include <unordered_map> | ||
#include <mutex> | ||
|
||
class Lobby : public oatpp::websocket::AsyncConnectionHandler::SocketInstanceListener { | ||
public: | ||
std::atomic<v_int32> m_userIdCounter; | ||
std::unordered_map<oatpp::String, std::shared_ptr<Room>> m_rooms; | ||
std::mutex m_roomsMutex; | ||
public: | ||
|
||
Lobby() | ||
: m_userIdCounter(0) | ||
{} | ||
|
||
/** | ||
* Generate id for new user | ||
* @return | ||
*/ | ||
v_int32 obtainNewUserId(); | ||
|
||
/** | ||
* Get room by name or create new one if not exists. | ||
* @param roomName | ||
* @return | ||
*/ | ||
std::shared_ptr<Room> getRoom(const oatpp::String& roomName); | ||
|
||
public: | ||
|
||
/** | ||
* Called when socket is created | ||
*/ | ||
void onAfterCreate_NonBlocking(const std::shared_ptr<AsyncWebSocket>& socket, const std::shared_ptr<const ParameterMap>& params) override; | ||
|
||
/** | ||
* Called before socket instance is destroyed. | ||
*/ | ||
void onBeforeDestroy_NonBlocking(const std::shared_ptr<AsyncWebSocket>& socket) override; | ||
|
||
}; | ||
|
||
|
||
#endif //ASYNC_SERVER_ROOMS_LOBBY_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
|
||
#include "Peer.hpp" | ||
#include "Room.hpp" | ||
|
||
void Peer::sendMessage(const oatpp::String& message) { | ||
|
||
class SendMessageCoroutine : public oatpp::async::Coroutine<SendMessageCoroutine> { | ||
private: | ||
oatpp::async::Lock* m_lock; | ||
std::shared_ptr<AsyncWebSocket> m_websocket; | ||
oatpp::String m_message; | ||
public: | ||
|
||
SendMessageCoroutine(oatpp::async::Lock* lock, | ||
const std::shared_ptr<AsyncWebSocket>& websocket, | ||
const oatpp::String& message) | ||
: m_lock(lock) | ||
, m_websocket(websocket) | ||
, m_message(message) | ||
{} | ||
|
||
Action act() override { | ||
return oatpp::async::synchronize(m_lock, m_websocket->sendOneFrameTextAsync(m_message)).next(finish()); | ||
} | ||
|
||
}; | ||
|
||
m_asyncExecutor->execute<SendMessageCoroutine>(&m_writeLock, m_socket, message); | ||
|
||
} | ||
|
||
std::shared_ptr<Room> Peer::getRoom() { | ||
return m_room; | ||
} | ||
|
||
oatpp::String Peer::getNickname() { | ||
return m_nickname; | ||
} | ||
|
||
v_int32 Peer::getUserId() { | ||
return m_userId; | ||
} | ||
|
||
oatpp::async::CoroutineStarter Peer::onPing(const std::shared_ptr<AsyncWebSocket>& socket, const oatpp::String& message) { | ||
return oatpp::async::synchronize(&m_writeLock, socket->sendPongAsync(message)); | ||
} | ||
|
||
oatpp::async::CoroutineStarter Peer::onPong(const std::shared_ptr<AsyncWebSocket>& socket, const oatpp::String& message) { | ||
return nullptr; // do nothing | ||
} | ||
|
||
oatpp::async::CoroutineStarter Peer::onClose(const std::shared_ptr<AsyncWebSocket>& socket, v_uint16 code, const oatpp::String& message) { | ||
return nullptr; // do nothing | ||
} | ||
|
||
oatpp::async::CoroutineStarter Peer::readMessage(const std::shared_ptr<AsyncWebSocket>& socket, v_uint8 opcode, p_char8 data, oatpp::v_io_size size) { | ||
|
||
if(size == 0) { // message transfer finished | ||
|
||
auto wholeMessage = m_messageBuffer.toString(); | ||
m_messageBuffer.setCurrentPosition(0); | ||
|
||
m_room->sendMessage(m_nickname + ": " + wholeMessage); | ||
|
||
} else if(size > 0) { // message frame received | ||
m_messageBuffer.writeSimple(data, size); | ||
} | ||
|
||
return nullptr; // do nothing | ||
|
||
} |
Oops, something went wrong.