Anyone willing to PR this for me?

One of my prototype projects connect to RetroArch netplay rooms as to verify whether those rooms are reachable or not (so many people running netplay on badly configured networks without UPnP and port forwarding), time the estimated ping from the automatically sent header by the server, verify whether the header is from a RetroArch instance (‘RANP’) and whether it’s the currently netplay version (5).

Unfortunately, by just establishing a TCP connection, two notifications will be displayed to those in the room; “Failed to receive header from client.” followed by “A netplay client has disconnected”. Right now, I’ve my prototype send a fake header after receiving the one from the server to trigger a “A netplay connection attempt failed because the peer is not running RetroArch, or is running an old version of RetroArch.” notification instead of “Failed to receive header from client.”, but both can be quite annoying.

My proposal is to reserve a specific netplay magic for poking rooms without triggering any notifications or extra actions other than to close the connection after receiving the “poke” header.

The following code is 100% backwards compatible (all changes are to be made at network/netplay/netplay_frontend.c):

From: #define NETPLAY_MAGIC 0x52414E50 /* RANP / To: #define NETPLAY_MAGIC 0x52414E50 / RANP / #define POKE_MAGIC 0x504F4B45 / POKE */

Define the netplay_poke function: static bool netplay_poke(netplay_t *netplay, struct netplay_connection *connection, uint32_t netplay_magic) { if (!netplay || !netplay->is_server) return false;

   if (!connection || !connection->active)
      return false;

   if (netplay_magic != POKE_MAGIC)
      return false;

   socket_close(connection->fd);

   connection->active = false;

   netplay_deinit_socket_buffer(&connection->send_packet_buffer);
   netplay_deinit_socket_buffer(&connection->recv_packet_buffer);

   return true;
}

And finally at function netplay_handshake_init, change the following:

At the head of the function: uint32_t netplay_magic = 0;

From: if (ntohl(header[0]) != NETPLAY_MAGIC) { dmsg = msg_hash_to_str(MSG_NETPLAY_NOT_RETROARCH); goto error; } To: netplay_magic = ntohl(header[0]);

   if (netplay_poke(netplay, connection, netplay_magic))
      return true;

   if (netplay_magic != NETPLAY_MAGIC)
   {
      dmsg = msg_hash_to_str(MSG_NETPLAY_NOT_RETROARCH);
      goto error;
   }

I’ve had my GitHub account inactive/disabled after Microsoft acquired it, moving mainly to GitLab.

The formatting got all wrong despite ensuring it was correct before creating the topic.

Here is the source code file already ready for PR: https://mega.nz/file/0BkjFKQD#xOp8fk-3fwufdLou8fwPBk0aBvNMEH93FCXNdXUaqWA

I would really appreciate it if someone could do me this favor. I really hate that my lobby viewer can potentially annoy other people.

1 Like

How’s this? https://github.com/libretro/RetroArch/commit/8ff07916ecfa9b0b0b163448a47591539b753251

2 Likes

Thank you very much; I really appreciate it.