From 633faa793fadbc22f65d4913f3c6169b1b2c3316 Mon Sep 17 00:00:00 2001 From: MysterD Date: Sun, 16 Apr 2023 22:03:46 -0700 Subject: [PATCH] Only allow clients to send discord invites of public lobbies --- lib/coopnet/linux/libcoopnet.a | Bin 3789380 -> 3789380 bytes src/pc/discord/discord_activity.c | 10 +++++++--- src/pc/network/coopnet/coopnet.c | 7 ++++++- src/pc/network/network_player.c | 13 +++++++++---- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/coopnet/linux/libcoopnet.a b/lib/coopnet/linux/libcoopnet.a index b60075fbc7503c769c54065a1c2d702181a363ed..e9139df66258396600b9db0a703b4b0c9a3cd0ee 100644 GIT binary patch delta 10441 zcmb_idstNE*5B`j5fDZhL|_97qg%NSFe=_r$15sIqo$Ucp?NJ+%1)McltL{TWf2{TUt@U2^ zdiUNlaCpPl;xM*FrJ__W4Jr*TwUjm~4Ji#R4J&P08eSSvYAtQHtNGDsLRwlotvR+x zY&L9B*jiwV#?}&B47ONoao7}W@z@fuC1PuZtu?kJY{}T{*xG2d)7nlvBnLIq(lXTE zLLAa&WU4VjY||Dw)U83X2;G$FRE4+=jt=TskqW^b)sMvp__U*XR4jw_oz(7fVKCgE zqfQPE{_gf|ux6^Awb{99j799ymULGq$YQj1si(S27FF7s-s(hIxU}mob(<_+&^Gp0 zM+n(<0TxY?GvVrVH5|%6%TCY=2C6TK(2<|szMa2(aeifAwG(X3Q>|KdzIs@M4LnEw z0ng^c3d|4p3{mUk=AW2yeAHcy)8-FVcMB1wIftoF$YPcDMxi=SmSaBh(*f$jw5LX> z9fVk>?HsAL5%RQ?P&QhfruDd6Efiu0EFZ1@F28-8B9md~IJK+x}H=0-)Vx(_FET6|pFN9k5#!8z)lQ+alSHmpjankQ$mfvHgb4_JQS|4ut zI!^i^+;S*Rx)|KeoM?%IWR4k%->*M_Qx=I@2)x*?b z_DUMzWgIJj8-6^9f`@xWMnVn->hgDR;o6J4+h?bXeM^sg(H>ihcI1oHiND0m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09vF<>JPy1n{ zrMv%29JC4JtdmIYJ@q4WCn^hJHvLFQz}rg+Q`nkGHPV{TWR*?Qtsx9G2OS=5cFayz zy~C={m^{svhx~((A(g5nw5PCy-Zn`y2g&-N6O&kVwXM=;4dLy+onlgbh~X@Qm&yl& zY)2spITV#pV3Wq^p%<6Z-SXpEwSa1+7GyQ70afb4nKV`!-JzKZu$a{eHv?YOR9z@&&QnQI#4ucB<`sTRbI)mjA~?-dq?qhd7I+W zOfIJ1)*z{u{G+hImQ*33jKTnYW-+bp)HV(Oks(=Qb8+3(xKhcygQ{iFUXE=-F)2BubEL#Aptd=R*$eeBRQ=QBb;;kj4g6y;KJ9Kl5O@mXm%SH| z|CO-uy}&Hp^ibdy+-t;PkaK9n zVT2UYMrkdu;)erm1@1t;k0ISh+dmHM#z(ZBd%PD;GNJ6hK+nPpJl4qnGm=`t$_%Jc>(qy21Pn3GUY9uMc+{$6b}+ z9!Fv6{>9m@>k{18QH6ACy_w&W;BH9O(p}(ua(*|#tx-(6uW+JIC%6UqQsCa$SK;xe zyY5U1!JYBk0Cs0d9xvCuy)U&n+$haB>3m%2mf(Mmq6o*g*V|L_x{6z@uTt{r7vnm_ zF9VxJ4K4?}j|wC_M6)i>n}+{-c}-e{bWXw?${r6`Ns}bt!b{jp+a>Ixuf`*wDUFx_ z*h3p9fSgN*C*;ZPj1;>zj+U6rY0&J~d3cjv7;}Yp=@-)g;}5Elkya wGn&yqYMc7$cwW~+anlli*RE*Y(1K{)(R!fuM9W9(g?1@gZ_D4cp#A#)0B{B*CjbBd diff --git a/src/pc/discord/discord_activity.c b/src/pc/discord/discord_activity.c index be001501..794035c4 100644 --- a/src/pc/discord/discord_activity.c +++ b/src/pc/discord/discord_activity.c @@ -10,6 +10,8 @@ extern struct DiscordApplication app; struct DiscordActivity sCurActivity = { 0 }; static int sQueuedLobby = 0; +static uint64_t sQueuedLobbyId = 0; +static char sQueuedLobbyPassword[64] = ""; static void on_activity_update_callback(UNUSED void* data, enum EDiscordResult result) { LOG_INFO("> on_activity_update_callback returned %d", result); @@ -31,7 +33,7 @@ static void on_activity_join(UNUSED void* data, const char* secret) { // extract lobby ID token = strtok(NULL, ":"); char* end; - u64 lobbyId = strtoll(token, &end, 10); + u64 lobbyId = strtoull(token, &end, 10); // extract lobby password token = strtok(NULL, ":"); @@ -41,8 +43,8 @@ static void on_activity_join(UNUSED void* data, const char* secret) { if (gNetworkType != NT_NONE) { network_shutdown(true, false, false, false); } - gCoopNetDesiredLobby = lobbyId; - snprintf(gCoopNetPassword, 64, "%s", token); + sQueuedLobbyId = lobbyId; + snprintf(sQueuedLobbyPassword, 64, "%s", token); sQueuedLobby = 2; #endif } @@ -138,6 +140,8 @@ void discord_activity_update(void) { void discord_activity_update_check(void) { if (sQueuedLobby > 0) { if (--sQueuedLobby == 0) { + gCoopNetDesiredLobby = sQueuedLobbyId; + snprintf(gCoopNetPassword, 64, "%s", sQueuedLobbyPassword); network_reset_reconnect_and_rehost(); network_set_system(NS_COOPNET); network_init(NT_CLIENT, false); diff --git a/src/pc/network/coopnet/coopnet.c b/src/pc/network/coopnet/coopnet.c index 8c2928ed..92c3f2fd 100644 --- a/src/pc/network/coopnet/coopnet.c +++ b/src/pc/network/coopnet/coopnet.c @@ -173,6 +173,11 @@ static int ns_coopnet_network_send(u8 localIndex, void* address, u8* data, u16 d return 0; } +static bool coopnet_allow_invite(void) { + if (sLocalLobbyId == 0) { return false; } + return (sLocalLobbyOwnerId == coopnet_get_local_user_id()) || (strlen(gCoopNetPassword) == 0); +} + static void ns_coopnet_get_lobby_id(UNUSED char* destination, UNUSED u32 destLength) { if (sLocalLobbyId == 0) { snprintf(destination, destLength, "%s", ""); @@ -182,7 +187,7 @@ static void ns_coopnet_get_lobby_id(UNUSED char* destination, UNUSED u32 destLen } static void ns_coopnet_get_lobby_secret(UNUSED char* destination, UNUSED u32 destLength) { - if (sLocalLobbyId == 0) { + if (sLocalLobbyId == 0 || !coopnet_allow_invite()) { snprintf(destination, destLength, "%s", ""); } else { snprintf(destination, destLength, "coopnet:%" PRIu64":%s", sLocalLobbyId, gCoopNetPassword); diff --git a/src/pc/network/network_player.c b/src/pc/network/network_player.c index ac1b4ed3..70376c5a 100644 --- a/src/pc/network/network_player.c +++ b/src/pc/network/network_player.c @@ -10,6 +10,7 @@ #include "game/hardcoded.h" #include "game/object_helpers.h" #include "pc/lua/smlua_hooks.h" +#include "pc/network/socket/socket.h" #include "lag_compensation.h" #ifdef DISCORD_SDK #include "pc/discord/discord.h" @@ -179,13 +180,15 @@ void network_player_update(void) { if (!np->connected && i > 0) { continue; } float elapsed = (clock_elapsed() - np->lastReceived); -#ifndef DEVELOPMENT +#ifdef DEVELOPMENT + if (elapsed > NETWORK_PLAYER_TIMEOUT && (gNetworkSystem != &gNetworkSystemSocket)) { +#else if (elapsed > NETWORK_PLAYER_TIMEOUT) { +#endif LOG_INFO("dropping player %d", i); network_player_disconnected(i); continue; } -#endif elapsed = (clock_elapsed() - np->lastSent); if (elapsed > NETWORK_PLAYER_TIMEOUT / 3.0f) { network_send_keep_alive(np->localIndex); @@ -196,12 +199,14 @@ void network_player_update(void) { if (!np->connected) { return; } float elapsed = (clock_elapsed() - np->lastReceived); -#ifndef DEVELOPMENT +#ifdef DEVELOPMENT + if (elapsed > NETWORK_PLAYER_TIMEOUT * 1.5f && (gNetworkSystem != &gNetworkSystemSocket)) { +#else if (elapsed > NETWORK_PLAYER_TIMEOUT * 1.5f) { +#endif LOG_INFO("dropping due to no server connectivity"); network_shutdown(false, false, true, false); } -#endif elapsed = (clock_elapsed() - np->lastSent); if (elapsed > NETWORK_PLAYER_TIMEOUT / 3.0f) {