network, yuzu: Improve variable naming and style consistency
This commit is contained in:
		| @@ -43,7 +43,7 @@ struct Room { | ||||
|     RoomInformation information; | ||||
|  | ||||
|     std::string id; | ||||
|     std::string verify_UID; ///< UID used for verification | ||||
|     std::string verify_uid; ///< UID used for verification | ||||
|     std::string ip; | ||||
|     u32 net_version; | ||||
|     bool has_password; | ||||
|   | ||||
| @@ -10,8 +10,8 @@ | ||||
| namespace Network { | ||||
|  | ||||
| RoomNetwork::RoomNetwork() { | ||||
|     g_room = std::make_shared<Room>(); | ||||
|     g_room_member = std::make_shared<RoomMember>(); | ||||
|     m_room = std::make_shared<Room>(); | ||||
|     m_room_member = std::make_shared<RoomMember>(); | ||||
| } | ||||
|  | ||||
| bool RoomNetwork::Init() { | ||||
| @@ -19,30 +19,30 @@ bool RoomNetwork::Init() { | ||||
|         LOG_ERROR(Network, "Error initalizing ENet"); | ||||
|         return false; | ||||
|     } | ||||
|     g_room = std::make_shared<Room>(); | ||||
|     g_room_member = std::make_shared<RoomMember>(); | ||||
|     m_room = std::make_shared<Room>(); | ||||
|     m_room_member = std::make_shared<RoomMember>(); | ||||
|     LOG_DEBUG(Network, "initialized OK"); | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| std::weak_ptr<Room> RoomNetwork::GetRoom() { | ||||
|     return g_room; | ||||
|     return m_room; | ||||
| } | ||||
|  | ||||
| std::weak_ptr<RoomMember> RoomNetwork::GetRoomMember() { | ||||
|     return g_room_member; | ||||
|     return m_room_member; | ||||
| } | ||||
|  | ||||
| void RoomNetwork::Shutdown() { | ||||
|     if (g_room_member) { | ||||
|         if (g_room_member->IsConnected()) | ||||
|             g_room_member->Leave(); | ||||
|         g_room_member.reset(); | ||||
|     if (m_room_member) { | ||||
|         if (m_room_member->IsConnected()) | ||||
|             m_room_member->Leave(); | ||||
|         m_room_member.reset(); | ||||
|     } | ||||
|     if (g_room) { | ||||
|         if (g_room->GetState() == Room::State::Open) | ||||
|             g_room->Destroy(); | ||||
|         g_room.reset(); | ||||
|     if (m_room) { | ||||
|         if (m_room->GetState() == Room::State::Open) | ||||
|             m_room->Destroy(); | ||||
|         m_room.reset(); | ||||
|     } | ||||
|     enet_deinitialize(); | ||||
|     LOG_DEBUG(Network, "shutdown OK"); | ||||
|   | ||||
| @@ -27,8 +27,8 @@ public: | ||||
|     void Shutdown(); | ||||
|  | ||||
| private: | ||||
|     std::shared_ptr<RoomMember> g_room_member; ///< RoomMember (Client) for network games | ||||
|     std::shared_ptr<Room> g_room;              ///< Room (Server) for network games | ||||
|     std::shared_ptr<RoomMember> m_room_member; ///< RoomMember (Client) for network games | ||||
|     std::shared_ptr<Room> m_room;              ///< Room (Server) for network games | ||||
| }; | ||||
|  | ||||
| } // namespace Network | ||||
|   | ||||
| @@ -29,8 +29,8 @@ public: | ||||
|     std::atomic<State> state{State::Closed}; ///< Current state of the room. | ||||
|     RoomInformation room_information;        ///< Information about this room. | ||||
|  | ||||
|     std::string verify_UID;              ///< A GUID which may be used for verfication. | ||||
|     mutable std::mutex verify_UID_mutex; ///< Mutex for verify_UID | ||||
|     std::string verify_uid;              ///< A GUID which may be used for verfication. | ||||
|     mutable std::mutex verify_uid_mutex; ///< Mutex for verify_uid | ||||
|  | ||||
|     std::string password; ///< The password required to connect to this room. | ||||
|  | ||||
| @@ -369,8 +369,8 @@ void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) { | ||||
|  | ||||
|     std::string uid; | ||||
|     { | ||||
|         std::lock_guard lock(verify_UID_mutex); | ||||
|         uid = verify_UID; | ||||
|         std::lock_guard lock(verify_uid_mutex); | ||||
|         uid = verify_uid; | ||||
|     } | ||||
|     member.user_data = verify_backend->LoadUserData(uid, token); | ||||
|  | ||||
| @@ -1056,8 +1056,8 @@ const RoomInformation& Room::GetRoomInformation() const { | ||||
| } | ||||
|  | ||||
| std::string Room::GetVerifyUID() const { | ||||
|     std::lock_guard lock(room_impl->verify_UID_mutex); | ||||
|     return room_impl->verify_UID; | ||||
|     std::lock_guard lock(room_impl->verify_uid_mutex); | ||||
|     return room_impl->verify_uid; | ||||
| } | ||||
|  | ||||
| Room::BanList Room::GetBanList() const { | ||||
| @@ -1086,8 +1086,8 @@ bool Room::HasPassword() const { | ||||
| } | ||||
|  | ||||
| void Room::SetVerifyUID(const std::string& uid) { | ||||
|     std::lock_guard lock(room_impl->verify_UID_mutex); | ||||
|     room_impl->verify_UID = uid; | ||||
|     std::lock_guard lock(room_impl->verify_uid_mutex); | ||||
|     room_impl->verify_uid = uid; | ||||
| } | ||||
|  | ||||
| void Room::Destroy() { | ||||
|   | ||||
| @@ -416,8 +416,9 @@ void RoomMember::RoomMemberImpl::Disconnect() { | ||||
|     room_information.member_slots = 0; | ||||
|     room_information.name.clear(); | ||||
|  | ||||
|     if (!server) | ||||
|     if (!server) { | ||||
|         return; | ||||
|     } | ||||
|     enet_peer_disconnect(server, 0); | ||||
|  | ||||
|     ENetEvent event; | ||||
| @@ -483,8 +484,9 @@ template <typename T> | ||||
| void RoomMember::RoomMemberImpl::Invoke(const T& data) { | ||||
|     std::lock_guard lock(callback_mutex); | ||||
|     CallbackSet<T> callback_set = callbacks.Get<T>(); | ||||
|     for (auto const& callback : callback_set) | ||||
|     for (auto const& callback : callback_set) { | ||||
|         (*callback)(data); | ||||
|     } | ||||
| } | ||||
|  | ||||
| template <typename T> | ||||
|   | ||||
| @@ -10,7 +10,7 @@ Backend::~Backend() = default; | ||||
|  | ||||
| NullBackend::~NullBackend() = default; | ||||
|  | ||||
| UserData NullBackend::LoadUserData([[maybe_unused]] const std::string& verify_UID, | ||||
| UserData NullBackend::LoadUserData([[maybe_unused]] const std::string& verify_uid, | ||||
|                                    [[maybe_unused]] const std::string& token) { | ||||
|     return {}; | ||||
| } | ||||
|   | ||||
| @@ -25,11 +25,11 @@ public: | ||||
|  | ||||
|     /** | ||||
|      * Verifies the given token and loads the information into a UserData struct. | ||||
|      * @param verify_UID A GUID that may be used for verification. | ||||
|      * @param verify_uid A GUID that may be used for verification. | ||||
|      * @param token A token that contains user data and verification data. The format and content is | ||||
|      * decided by backends. | ||||
|      */ | ||||
|     virtual UserData LoadUserData(const std::string& verify_UID, const std::string& token) = 0; | ||||
|     virtual UserData LoadUserData(const std::string& verify_uid, const std::string& token) = 0; | ||||
| }; | ||||
|  | ||||
| /** | ||||
| @@ -40,7 +40,7 @@ class NullBackend final : public Backend { | ||||
| public: | ||||
|     ~NullBackend(); | ||||
|  | ||||
|     UserData LoadUserData(const std::string& verify_UID, const std::string& token) override; | ||||
|     UserData LoadUserData(const std::string& verify_uid, const std::string& token) override; | ||||
| }; | ||||
|  | ||||
| } // namespace Network::VerifyUser | ||||
|   | ||||
| @@ -54,7 +54,7 @@ static void to_json(nlohmann::json& json, const Room& room) { | ||||
| } | ||||
|  | ||||
| static void from_json(const nlohmann::json& json, Room& room) { | ||||
|     room.verify_UID = json.at("externalGuid").get<std::string>(); | ||||
|     room.verify_uid = json.at("externalGuid").get<std::string>(); | ||||
|     room.ip = json.at("address").get<std::string>(); | ||||
|     room.information.name = json.at("name").get<std::string>(); | ||||
|     try { | ||||
| @@ -116,7 +116,7 @@ WebService::WebResult RoomJson::Register() { | ||||
|     auto reply_json = nlohmann::json::parse(result.returned_data); | ||||
|     room = reply_json.get<AnnounceMultiplayerRoom::Room>(); | ||||
|     room_id = reply_json.at("id").get<std::string>(); | ||||
|     return WebService::WebResult{WebService::WebResult::Code::Success, "", room.verify_UID}; | ||||
|     return WebService::WebResult{WebService::WebResult::Code::Success, "", room.verify_uid}; | ||||
| } | ||||
|  | ||||
| void RoomJson::ClearPlayers() { | ||||
|   | ||||
| @@ -35,9 +35,9 @@ std::string GetPublicKey(const std::string& host) { | ||||
|  | ||||
| VerifyUserJWT::VerifyUserJWT(const std::string& host) : pub_key(GetPublicKey(host)) {} | ||||
|  | ||||
| Network::VerifyUser::UserData VerifyUserJWT::LoadUserData(const std::string& verify_UID, | ||||
| Network::VerifyUser::UserData VerifyUserJWT::LoadUserData(const std::string& verify_uid, | ||||
|                                                           const std::string& token) { | ||||
|     const std::string audience = fmt::format("external-{}", verify_UID); | ||||
|     const std::string audience = fmt::format("external-{}", verify_uid); | ||||
|     using namespace jwt::params; | ||||
|     std::error_code error; | ||||
|     auto decoded = | ||||
|   | ||||
| @@ -17,7 +17,7 @@ public: | ||||
|     VerifyUserJWT(const std::string& host); | ||||
|     ~VerifyUserJWT() = default; | ||||
|  | ||||
|     Network::VerifyUser::UserData LoadUserData(const std::string& verify_UID, | ||||
|     Network::VerifyUser::UserData LoadUserData(const std::string& verify_uid, | ||||
|                                                const std::string& token) override; | ||||
|  | ||||
| private: | ||||
|   | ||||
| @@ -163,7 +163,7 @@ void HostRoomWindow::Host() { | ||||
|         // Start the announce session if they chose Public | ||||
|         if (is_public) { | ||||
|             if (auto session = announce_multiplayer_session.lock()) { | ||||
|                 // Register the room first to ensure verify_UID is present when we connect | ||||
|                 // Register the room first to ensure verify_uid is present when we connect | ||||
|                 WebService::WebResult result = session->Register(); | ||||
|                 if (result.result_code != WebService::WebResult::Code::Success) { | ||||
|                     QMessageBox::warning( | ||||
|   | ||||
| @@ -149,11 +149,11 @@ void Lobby::OnJoinRoom(const QModelIndex& source) { | ||||
|     const std::string ip = | ||||
|         proxy->data(connection_index, LobbyItemHost::HostIPRole).toString().toStdString(); | ||||
|     int port = proxy->data(connection_index, LobbyItemHost::HostPortRole).toInt(); | ||||
|     const std::string verify_UID = | ||||
|     const std::string verify_uid = | ||||
|         proxy->data(connection_index, LobbyItemHost::HostVerifyUIDRole).toString().toStdString(); | ||||
|  | ||||
|     // attempt to connect in a different thread | ||||
|     QFuture<void> f = QtConcurrent::run([nickname, ip, port, password, verify_UID, this] { | ||||
|     QFuture<void> f = QtConcurrent::run([nickname, ip, port, password, verify_uid, this] { | ||||
|         std::string token; | ||||
| #ifdef ENABLE_WEB_SERVICE | ||||
|         if (!Settings::values.yuzu_username.GetValue().empty() && | ||||
| @@ -161,7 +161,7 @@ void Lobby::OnJoinRoom(const QModelIndex& source) { | ||||
|             WebService::Client client(Settings::values.web_api_url.GetValue(), | ||||
|                                       Settings::values.yuzu_username.GetValue(), | ||||
|                                       Settings::values.yuzu_token.GetValue()); | ||||
|             token = client.GetExternalJWT(verify_UID).returned_data; | ||||
|             token = client.GetExternalJWT(verify_uid).returned_data; | ||||
|             if (token.empty()) { | ||||
|                 LOG_ERROR(WebService, "Could not get external JWT, verification may fail"); | ||||
|             } else { | ||||
| @@ -239,7 +239,7 @@ void Lobby::OnRefreshLobby() { | ||||
|                               smdh_icon), | ||||
|             new LobbyItemHost(QString::fromStdString(room.information.host_username), | ||||
|                               QString::fromStdString(room.ip), room.information.port, | ||||
|                               QString::fromStdString(room.verify_UID)), | ||||
|                               QString::fromStdString(room.verify_uid)), | ||||
|             new LobbyItemMemberList(members, room.information.member_slots), | ||||
|         }); | ||||
|         model->appendRow(row); | ||||
|   | ||||
| @@ -123,11 +123,11 @@ public: | ||||
|     static const int HostVerifyUIDRole = Qt::UserRole + 4; | ||||
|  | ||||
|     LobbyItemHost() = default; | ||||
|     explicit LobbyItemHost(QString username, QString ip, u16 port, QString verify_UID) { | ||||
|     explicit LobbyItemHost(QString username, QString ip, u16 port, QString verify_uid) { | ||||
|         setData(username, HostUsernameRole); | ||||
|         setData(ip, HostIPRole); | ||||
|         setData(port, HostPortRole); | ||||
|         setData(verify_UID, HostVerifyUIDRole); | ||||
|         setData(verify_uid, HostVerifyUIDRole); | ||||
|     } | ||||
|  | ||||
|     QVariant data(int role) const override { | ||||
|   | ||||
| @@ -98,14 +98,18 @@ void MultiplayerState::retranslateUi() { | ||||
|         status_text->setText(tr("Not Connected")); | ||||
|     } | ||||
|  | ||||
|     if (lobby) | ||||
|     if (lobby) { | ||||
|         lobby->RetranslateUi(); | ||||
|     if (host_room) | ||||
|     } | ||||
|     if (host_room) { | ||||
|         host_room->RetranslateUi(); | ||||
|     if (client_room) | ||||
|     } | ||||
|     if (client_room) { | ||||
|         client_room->RetranslateUi(); | ||||
|     if (direct_connect) | ||||
|     } | ||||
|     if (direct_connect) { | ||||
|         direct_connect->RetranslateUi(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| void MultiplayerState::OnNetworkStateChanged(const Network::RoomMember::State& state) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user