Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/application/StarP2PNetworkingService_pc.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-27 20:23:44 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-27 20:23:44 +1000
commit332983c97b7a729c4dc5f19aa9ee4a22c420f7d8 (patch)
treefd9c441b796b522bdd5c7f8fbd32f51b8eff2a28 /source/application/StarP2PNetworkingService_pc.cpp
parent14b9689b6d4f4ad5276c88130dc6e449bedc0709 (diff)
The Formatting String Catastrophe
Diffstat (limited to 'source/application/StarP2PNetworkingService_pc.cpp')
-rw-r--r--source/application/StarP2PNetworkingService_pc.cpp98
1 files changed, 49 insertions, 49 deletions
diff --git a/source/application/StarP2PNetworkingService_pc.cpp b/source/application/StarP2PNetworkingService_pc.cpp
index 2a0b876..74c48ac 100644
--- a/source/application/StarP2PNetworkingService_pc.cpp
+++ b/source/application/StarP2PNetworkingService_pc.cpp
@@ -32,13 +32,13 @@ PcP2PNetworkingService::PcP2PNetworkingService(PcPlatformServicesStatePtr state)
m_discordOnActivityJoinToken = m_state->discordCore->ActivityManager().OnActivityJoin.Connect([this](char const* peerId) {
MutexLocker serviceLocker(m_mutex);
- Logger::info("Joining discord peer at '%s'", peerId);
- addPendingJoin(strf("+platform:%s", peerId));
+ Logger::info("Joining discord peer at '{}'", peerId);
+ addPendingJoin(strf("+platform:{}", peerId));
});
m_discordOnActivityRequestToken = m_state->discordCore->ActivityManager().OnActivityJoinRequest.Connect([this](discord::User const& user) {
MutexLocker serviceLocker(m_mutex);
String userName = String(user.GetUsername());
- Logger::info("Received join request from user '%s'", userName);
+ Logger::info("Received join request from user '{}'", userName);
m_discordJoinRequests.emplace_back(make_pair(user.GetId(), userName));
});
m_discordOnReceiveMessage = m_state->discordCore->LobbyManager().OnNetworkMessage.Connect(bind(&PcP2PNetworkingService::discordOnReceiveMessage, this, _1, _2, _3, _4, _5));
@@ -54,9 +54,9 @@ PcP2PNetworkingService::~PcP2PNetworkingService() {
if (m_state->discordAvailable) {
MutexLocker discordLocker(m_state->discordMutex);
if (m_discordServerLobby) {
- Logger::info("Deleting discord server lobby %s", m_discordServerLobby->first);
+ Logger::info("Deleting discord server lobby {}", m_discordServerLobby->first);
m_state->discordCore->LobbyManager().DeleteLobby(m_discordServerLobby->first, [](discord::Result res) {
- Logger::error("Could not connect delete server lobby (err %s)", (int)res);
+ Logger::error("Could not connect delete server lobby (err {})", (int)res);
});
}
@@ -108,18 +108,18 @@ void Star::PcP2PNetworkingService::setActivityData(String const& title, Maybe<pa
}
if (auto lobby = m_discordServerLobby)
- activity.GetParty().SetId(strf("%s", lobby->first).c_str());
+ activity.GetParty().SetId(strf("{}", lobby->first).c_str());
if (m_joinLocation.is<JoinLocal>()) {
if (auto lobby = m_discordServerLobby) {
- String joinSecret = strf("connect:discord_%s_%s_%s", m_state->discordCurrentUser->GetId(), lobby->first, lobby->second);
- Logger::info("Setting discord join secret as %s", joinSecret);
+ String joinSecret = strf("connect:discord_{}_{}_{}", m_state->discordCurrentUser->GetId(), lobby->first, lobby->second);
+ Logger::info("Setting discord join secret as {}", joinSecret);
activity.GetSecrets().SetJoin(joinSecret.utf8Ptr());
}
} else if (m_joinLocation.is<JoinRemote>()) {
- String address = strf("%s", (HostAddressWithPort)m_joinLocation.get<JoinRemote>());
- String joinSecret = strf("connect:address_%s", address);
- Logger::info("Setting discord join secret as %s", joinSecret);
+ String address = strf("{}", (HostAddressWithPort)m_joinLocation.get<JoinRemote>());
+ String joinSecret = strf("connect:address_{}", address);
+ Logger::info("Setting discord join secret as {}", joinSecret);
activity.GetSecrets().SetJoin(joinSecret.utf8Ptr());
activity.GetParty().SetId(address.utf8Ptr());
@@ -128,7 +128,7 @@ void Star::PcP2PNetworkingService::setActivityData(String const& title, Maybe<pa
m_discordUpdatingActivity = true;
m_state->discordCore->ActivityManager().UpdateActivity(activity, [this](discord::Result res) {
if (res != discord::Result::Ok)
- Logger::error("failed to set discord activity (err %s)", (int)res);
+ Logger::error("failed to set discord activity (err {})", (int)res);
MutexLocker serviceLocker(m_mutex);
m_discordUpdatingActivity = false;
@@ -193,7 +193,7 @@ void Star::PcP2PNetworkingService::update() {
m_state->discordCore->ActivityManager().SendRequestReply(p.first, reply, [](discord::Result res) {
if (res != discord::Result::Ok)
- Logger::error("Could not send discord activity join response (err %s)", (int)res);
+ Logger::error("Could not send discord activity join response (err {})", (int)res);
});
}
}
@@ -230,17 +230,17 @@ Either<String, P2PSocketUPtr> PcP2PNetworkingService::connectToPeer(P2PNetworkin
}
#endif
- return makeLeft(strf("Unsupported peer type '%s'", type));
+ return makeLeft(strf("Unsupported peer type '{}'", type));
}
void PcP2PNetworkingService::addPendingJoin(String connectionString) {
MutexLocker serviceLocker(m_mutex);
if (connectionString.extract(":") != "+platform")
- throw ApplicationException::format("malformed connection string '%s'", connectionString);
+ throw ApplicationException::format("malformed connection string '{}'", connectionString);
if (connectionString.extract(":") != "connect")
- throw ApplicationException::format("malformed connection string '%s'", connectionString);
+ throw ApplicationException::format("malformed connection string '{}'", connectionString);
String target = move(connectionString);
String targetType = target.extract("_");
@@ -248,7 +248,7 @@ void PcP2PNetworkingService::addPendingJoin(String connectionString) {
if (targetType == "address")
m_pendingJoin = HostAddressWithPort(target);
else
- m_pendingJoin = P2PNetworkingPeerId(strf("%s_%s", targetType, target));
+ m_pendingJoin = P2PNetworkingPeerId(strf("{}_{}", targetType, target));
}
#ifdef STAR_ENABLE_STEAM_INTEGRATION
@@ -312,7 +312,7 @@ auto PcP2PNetworkingService::createSteamP2PSocket(CSteamID steamId) -> unique_pt
void PcP2PNetworkingService::steamOnConnectionFailure(P2PSessionConnectFail_t* callback) {
MutexLocker serviceLocker(m_mutex);
- Logger::warn("Connection with steam user %s failed", callback->m_steamIDRemote.ConvertToUint64());
+ Logger::warn("Connection with steam user {} failed", callback->m_steamIDRemote.ConvertToUint64());
if (auto socket = m_steamOpenSockets.value(callback->m_steamIDRemote.ConvertToUint64())) {
MutexLocker socketLocker(socket->mutex);
steamCloseSocket(socket);
@@ -320,7 +320,7 @@ void PcP2PNetworkingService::steamOnConnectionFailure(P2PSessionConnectFail_t* c
}
void PcP2PNetworkingService::steamOnJoinRequested(GameRichPresenceJoinRequested_t* callback) {
- Logger::info("Queueing join request with steam friend id %s to address %s", callback->m_steamIDFriend.ConvertToUint64(), callback->m_rgchConnect);
+ Logger::info("Queueing join request with steam friend id {} to address {}", callback->m_steamIDFriend.ConvertToUint64(), callback->m_rgchConnect);
addPendingJoin(callback->m_rgchConnect);
}
@@ -330,19 +330,19 @@ void PcP2PNetworkingService::steamOnSessionRequest(P2PSessionRequest_t* callback
// non-friends can even initiate P2P sessions.
if (m_acceptingP2PConnections && SteamFriends()->HasFriend(callback->m_steamIDRemote, k_EFriendFlagImmediate)) {
if (SteamNetworking()->AcceptP2PSessionWithUser(callback->m_steamIDRemote)) {
- Logger::info("Accepted steam p2p connection with user %s", callback->m_steamIDRemote.ConvertToUint64());
+ Logger::info("Accepted steam p2p connection with user {}", callback->m_steamIDRemote.ConvertToUint64());
m_pendingIncomingConnections.append(createSteamP2PSocket(callback->m_steamIDRemote));
} else {
- Logger::error("Accepting steam p2p connection from user %s failed!", callback->m_steamIDRemote.ConvertToUint64());
+ Logger::error("Accepting steam p2p connection from user {} failed!", callback->m_steamIDRemote.ConvertToUint64());
}
} else {
- Logger::error("Ignoring steam p2p connection from user %s", callback->m_steamIDRemote.ConvertToUint64());
+ Logger::error("Ignoring steam p2p connection from user {}", callback->m_steamIDRemote.ConvertToUint64());
}
}
void PcP2PNetworkingService::steamCloseSocket(SteamP2PSocket* socket) {
if (socket->connected) {
- Logger::info("Closing p2p connection with steam user %s", socket->steamId.ConvertToUint64());
+ Logger::info("Closing p2p connection with steam user {}", socket->steamId.ConvertToUint64());
m_steamOpenSockets.remove(socket->steamId.ConvertToUint64());
socket->connected = false;
}
@@ -386,7 +386,7 @@ bool PcP2PNetworkingService::DiscordP2PSocket::sendMessage(ByteArray const& mess
discord::Result res = parent->m_state->discordCore->LobbyManager().SendNetworkMessage(lobbyId, remoteUserId, DiscordMainNetworkChannel, (uint8_t*)message.ptr(), message.size());
if (res != discord::Result::Ok)
- throw ApplicationException::format("discord::Network::Send returned error (err %s)", (int)res);
+ throw ApplicationException::format("discord::Network::Send returned error (err {})", (int)res);
return true;
}
@@ -407,13 +407,13 @@ void PcP2PNetworkingService::discordCloseSocket(DiscordP2PSocket* socket) {
if (!m_joinLocation.is<JoinLocal>() && m_discordOpenSockets.empty()) {
auto res = m_state->discordCore->LobbyManager().DisconnectNetwork(socket->lobbyId);
if (res != discord::Result::Ok)
- Logger::error("failed to leave network for lobby %s (err %s)", socket->lobbyId, (int)res);
+ Logger::error("failed to leave network for lobby {} (err {})", socket->lobbyId, (int)res);
m_state->discordCore->LobbyManager().DisconnectLobby(socket->lobbyId, [this, lobbyId = socket->lobbyId](discord::Result res) {
if (res != discord::Result::Ok)
- Logger::error("failed to leave discord lobby %s", lobbyId);
+ Logger::error("failed to leave discord lobby {}", lobbyId);
- Logger::info("Left discord lobby %s", lobbyId);
+ Logger::info("Left discord lobby {}", lobbyId);
MutexLocker serviceLocker(m_mutex);
m_discordServerLobby = {};
m_discordForceUpdateActivity = true;
@@ -438,7 +438,7 @@ P2PSocketUPtr PcP2PNetworkingService::discordConnectRemote(discord::UserId remot
socket->lobbyId = lobbyId;
m_discordOpenSockets[remoteUserId] = socket.get();
- Logger::info("Connect to discord lobby %s", lobbyId);
+ Logger::info("Connect to discord lobby {}", lobbyId);
m_state->discordCore->LobbyManager().ConnectLobby(lobbyId, lobbySecret.utf8Ptr(), [this, remoteUserId, lobbyId](discord::Result res, discord::Lobby const& lobby) {
MutexLocker serviceLocker(m_mutex);
if (res == discord::Result::Ok) {
@@ -448,25 +448,25 @@ P2PSocketUPtr PcP2PNetworkingService::discordConnectRemote(discord::UserId remot
res = m_state->discordCore->LobbyManager().ConnectNetwork(lobbyId);
if (res != discord::Result::Ok) {
discordCloseSocket(socket);
- return Logger::error("Could not connect to discord lobby network (err %s)", (int)res);
+ return Logger::error("Could not connect to discord lobby network (err {})", (int)res);
}
res = m_state->discordCore->LobbyManager().OpenNetworkChannel(lobbyId, DiscordMainNetworkChannel, true);
if (res != discord::Result::Ok) {
discordCloseSocket(socket);
- return Logger::error("Could not open discord main network channel (err %s)", (int)res);
+ return Logger::error("Could not open discord main network channel (err {})", (int)res);
}
socket->mode = DiscordSocketMode::Connected;
- Logger::info("Discord p2p connection opened to remote user %s via lobby %s", remoteUserId, lobbyId);
+ Logger::info("Discord p2p connection opened to remote user {} via lobby {}", remoteUserId, lobbyId);
m_discordServerLobby = make_pair(lobbyId, String());
m_discordForceUpdateActivity = true;
} else {
- Logger::error("discord::Lobbies::Connect callback no matching remoteUserId %s found", remoteUserId);
+ Logger::error("discord::Lobbies::Connect callback no matching remoteUserId {} found", remoteUserId);
}
} else {
- Logger::error("failed to connect to remote lobby (err %s)", (int)res);
+ Logger::error("failed to connect to remote lobby (err {})", (int)res);
if (auto socket = m_discordOpenSockets.value(remoteUserId)) {
MutexLocker socketLocker(socket->mutex);
discordCloseSocket(socket);
@@ -481,17 +481,17 @@ void PcP2PNetworkingService::discordOnReceiveMessage(discord::LobbyId lobbyId, d
MutexLocker serviceLocker(m_mutex);
if (lobbyId != m_discordServerLobby->first)
- return Logger::error("Received message from unexpected lobby %s", lobbyId);
+ return Logger::error("Received message from unexpected lobby {}", lobbyId);
if (auto socket = m_discordOpenSockets.value(userId)) {
if (channel == DiscordMainNetworkChannel) {
MutexLocker socketLocker(socket->mutex);
socket->incoming.append(ByteArray((char const*)data, size));
} else {
- Logger::error("Received discord message on unexpected channel %s, ignoring", channel);
+ Logger::error("Received discord message on unexpected channel {}, ignoring", channel);
}
} else {
- Logger::error("Could not find associated discord socket for user id %s", userId);
+ Logger::error("Could not find associated discord socket for user id {}", userId);
}
}
@@ -508,7 +508,7 @@ void PcP2PNetworkingService::discordOnLobbyMemberConnect(discord::LobbyId lobbyI
m_discordOpenSockets[userId] = socket.get();
m_pendingIncomingConnections.append(move(socket));
- Logger::info("Accepted new discord connection from remote user %s", userId);
+ Logger::info("Accepted new discord connection from remote user {}", userId);
}
}
}
@@ -548,13 +548,13 @@ void PcP2PNetworkingService::setJoinLocation(JoinLocation location) {
} else if (m_joinLocation.is<JoinLocal>()) {
auto steamId = SteamUser()->GetSteamID().ConvertToUint64();
- Logger::info("Setting steam rich presence connection as steamid_%s", steamId);
- SteamFriends()->SetRichPresence("connect", strf("+platform:connect:steamid_%s", steamId).c_str());
+ Logger::info("Setting steam rich presence connection as steamid_{}", steamId);
+ SteamFriends()->SetRichPresence("connect", strf("+platform:connect:steamid_{}", steamId).c_str());
} else if (m_joinLocation.is<JoinRemote>()) {
auto address = (HostAddressWithPort)location.get<JoinRemote>();
- Logger::info("Setting steam rich presence connection as address_%s", address);
- SteamFriends()->SetRichPresence("connect", strf("+platform:connect:address_%s", address).c_str());
+ Logger::info("Setting steam rich presence connection as address_{}", address);
+ SteamFriends()->SetRichPresence("connect", strf("+platform:connect:address_{}", address).c_str());
}
}
#endif
@@ -562,9 +562,9 @@ void PcP2PNetworkingService::setJoinLocation(JoinLocation location) {
#ifdef STAR_ENABLE_DISCORD_INTEGRATION
if (m_state->discordAvailable && m_state->discordCurrentUser) {
if (m_discordServerLobby) {
- Logger::info("Deleting discord server lobby %s", m_discordServerLobby->first);
+ Logger::info("Deleting discord server lobby {}", m_discordServerLobby->first);
m_state->discordCore->LobbyManager().DeleteLobby(m_discordServerLobby->first, [](discord::Result res) {
- Logger::error("Could not connect delete server lobby (err %s)", (int)res);
+ Logger::error("Could not connect delete server lobby (err {})", (int)res);
});
}
@@ -591,21 +591,21 @@ void PcP2PNetworkingService::setJoinLocation(JoinLocation location) {
// successfully joined lobby network
return;
} else {
- Logger::error("Failed to open discord main network channel (err %s)", (int)res);
+ Logger::error("Failed to open discord main network channel (err {})", (int)res);
}
} else {
- Logger::error("Failed to join discord lobby network (err %s)", (int)res);
+ Logger::error("Failed to join discord lobby network (err {})", (int)res);
}
// Created lobby but failed to join the lobby network, delete lobby
- Logger::error("Failed to join discord lobby network (err %s)", (int)res);
+ Logger::error("Failed to join discord lobby network (err {})", (int)res);
- Logger::info("Deleting discord lobby %s", lobbyId);
+ Logger::info("Deleting discord lobby {}", lobbyId);
m_state->discordCore->LobbyManager().DeleteLobby(lobbyId, [lobbyId](discord::Result res) {
- Logger::error("failed to delete lobby %s (err %s)", lobbyId, (int)res);
+ Logger::error("failed to delete lobby {} (err {})", lobbyId, (int)res);
});
} else {
- Logger::error("failed to create discord lobby (err %s)", (int)res);
+ Logger::error("failed to create discord lobby (err {})", (int)res);
}
});
}