From b11004f221f2d413c285426b10aa83eff8ef4678 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Wed, 6 Apr 2016 01:56:02 -0400 Subject: [PATCH] Implemented udsUpdateNetworkAttribute() and udsSetNewConnectionsBlocked(). --- libctru/include/3ds/services/uds.h | 17 ++++++++++++++++- libctru/source/services/uds.c | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/libctru/include/3ds/services/uds.h b/libctru/include/3ds/services/uds.h index 0e16f7d..7220ed6 100644 --- a/libctru/include/3ds/services/uds.h +++ b/libctru/include/3ds/services/uds.h @@ -103,7 +103,7 @@ typedef struct { } udsNetworkScanInfo; enum { - UDSNETATTR_DisableConnectClients = BIT(1), //When set new Clients are not allowed to connect. + UDSNETATTR_DisableConnectClients = BIT(1), //When set new Clients are (supposedly) not allowed to connect. UDSNETATTR_DisableConnectSpectators = BIT(2), //When set new Spectators are (probably) not allowed to connect. UDSNETATTR_Default = BIT(15), //Unknown what this bit is for. }; @@ -276,3 +276,18 @@ Result udsDisconnectNetwork(void); */ Result udsEjectClient(u16 NetworkNodeID); +/** + * @brief This can be used by the host to update the network attributes. If bitmask 0x4 is clear in the input bitmask, this clears that bit in the value before actually writing the value into state. + * @param bitmask Bitmask to clear/set in the attributes. See the UDSNETATTR enum values. + * @param flag When false, bit-clear, otherwise bit-set. + */ +Result udsUpdateNetworkAttribute(u16 bitmask, bool flag); + +/** + * @brief This uses udsUpdateNetworkAttribute() for (un)blocking new connections to this host with the specified type(s). This is what it was supposed to do, doesn't seem actually to affect new connections though. + * @param block When true, block the specified connection types. Otherwise allow them. + * @param clients When true, (un)block regular clients. + * @param clients When true, (un)block spectators(?). + */ +Result udsSetNewConnectionsBlocked(bool block, bool clients, bool spectators); + diff --git a/libctru/source/services/uds.c b/libctru/source/services/uds.c index 02c564c..81c2aaa 100644 --- a/libctru/source/services/uds.c +++ b/libctru/source/services/uds.c @@ -321,6 +321,32 @@ Result udsEjectClient(u16 NetworkNodeID) return cmdbuf[1]; } +Result udsUpdateNetworkAttribute(u16 bitmask, bool flag) +{ + u32* cmdbuf=getThreadCommandBuffer(); + + if(flag)flag = 1; + + cmdbuf[0]=IPC_MakeHeader(0x7,2,0); // 0x70080 + cmdbuf[1]=bitmask; + cmdbuf[2]=flag; + + Result ret=0; + if(R_FAILED(ret=svcSendSyncRequest(__uds_servhandle)))return ret; + + return cmdbuf[1]; +} + +Result udsSetNewConnectionsBlocked(bool block, bool clients, bool spectators) +{ + u16 bitmask = 0; + + if(clients)bitmask |= UDSNETATTR_DisableConnectClients; + if(spectators)bitmask |= UDSNETATTR_DisableConnectSpectators; + + return udsUpdateNetworkAttribute(bitmask, block); +} + Result udsDestroyNetwork(void) { u32* cmdbuf=getThreadCommandBuffer(); -- 2.39.5