From 98bed89d6f2cd0582bd82e51f7e708214a663502 Mon Sep 17 00:00:00 2001
From: Cthulhu-throwaway <96153783+Cthulhu-throwaway@users.noreply.github.com>
Date: Fri, 24 Dec 2021 22:30:33 -0300
Subject: [PATCH] Netplay custom relay server to use default port (#13411)

Allow the custom server to use the default port if a port was not provided.
---
 network/netplay/netplay_frontend.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c
index 326bdd7424..40cefe1ffb 100644
--- a/network/netplay/netplay_frontend.c
+++ b/network/netplay/netplay_frontend.c
@@ -7202,21 +7202,24 @@ void netplay_toggle_play_spectate(netplay_t *netplay)
       case NETPLAY_CONNECTION_PLAYING:
       case NETPLAY_CONNECTION_SLAVE:
          {
-            uint32_t device;
-
-            /* Switch to spectator mode immediately */
-            netplay->self_mode    = NETPLAY_CONNECTION_SPECTATING;
-            netplay->self_devices = 0;
-
-            netplay->connected_players &= ~(1<<netplay->self_client_num);
-            netplay->client_devices[netplay->self_client_num] = 0;
-            for (device = 0; device < MAX_INPUT_DEVICES; device++)
-               netplay->device_clients[device] &= ~(1<<netplay->self_client_num);
-
-            /* Announce it */
+            /* Switch to spectator mode immediately.
+               Host switches to spectator on netplay_cmd_mode. */
             if (!netplay->is_server)
+            {
+               uint32_t device;
+
+               netplay->self_mode    = NETPLAY_CONNECTION_SPECTATING;
+               netplay->self_devices = 0;
+
+               netplay->connected_players &= ~(1<<netplay->self_client_num);
+               netplay->client_devices[netplay->self_client_num] = 0;
+               for (device = 0; device < MAX_INPUT_DEVICES; device++)
+                  netplay->device_clients[device] &= ~(1<<netplay->self_client_num);
+
+               /* Announce it */
                announce_play_spectate(netplay,
                   NULL, NETPLAY_CONNECTION_SPECTATING, 0, -1);
+            }
 
             netplay_cmd_mode(netplay, NETPLAY_CONNECTION_SPECTATING);
          }
@@ -8128,6 +8131,9 @@ static bool netplay_mitm_query(const char *mitm_name)
       netplay_decode_hostname(custom_server,
          addr, &port, sess, sizeof(addr));
 
+      if (!port)
+         port = RARCH_DEFAULT_PORT;
+
       strlcpy(host_room->mitm_address, addr,
          sizeof(host_room->mitm_address));
       host_room->mitm_port = port;