Files
MoHadiShibli 546e04e066 Plugin: fix lag, crashes and user handling; add settings and security
RemotePad NG 1.0.0, a maintained fork of remotePad 1.2.0 by xfangfang.

Fixes:
- Input lag that grew to seconds in games that read one sample per frame:
  stick-only updates now replace the newest unread sample, presses and
  releases still get their own (xfangfang/remotePad#7).
- Crashes: the notify RPC used client text as a format string, a heap
  overflow in the ini parser, a too small server thread stack, unload
  crashes and leaks, a startup race, unchecked buffers from games
  (xfangfang/remotePad#9).
- Hex user ids were read as decimal, so several pads got the wrong users
  (xfangfang/remotePad#2).
- scePadRead returned shifted data with more than one queued sample; held
  buttons looked released between updates; buttons stayed pressed when a
  client went away.
- Lowercase "connection: upgrade" headers were refused; TCP_NODELAY.
- ini parsing: section order, UTF-8 BOM, "]" in values.

New:
- Settings module: everything the page can change is applied live and
  saved to remote_pad.ini, for all games or one game; lock_settings=1.
- Guests join when a device picks their pad, and pads look connected only
  while a device drives them (join_on_start / always_connected restore the
  old behavior).
- Configured PS4 users who aren't signed in play as guests.
- Share mode (userN_share): add a pad to a user's own DualShock.
- WebSocket protocol 2: claim, leave, status, settings, settings.set and
  live status notifications; protocol 1 clients keep working.
- Network security: pages from other sites are refused, settings and
  notifications need the console's own page opened by IP address (or a
  non-browser client), at most 16 connections and 64 KB buffered per
  connection, and the page is served with a content security policy.
- Clearer start notification with the address to open; logs go to the
  kernel log; guests are named after their pad (Remote1..4).
2026-10-02 23:38:32 +03:00

61 lines
2.2 KiB
C

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "user.h"
#ifndef REMOTE_PAD_SETTINGS_H
#define REMOTE_PAD_SETTINGS_H
#define SETTINGS_PATH_DEFAULT "/data/GoldHEN/remote_pad.ini"
#define SETTINGS_MAX_CONSOLE_USERS 16
// Everything the controller page can change. Stored in remote_pad.ini: [default] for all games, or a
// section named after the running game's title id for that game only.
typedef struct PadSettings {
bool enabled;
// A PS4 user this pad plays as while that user is signed in; 0 = always a guest
int32_t realId;
// With realId: that user's own controller keeps working and this pad's input is added to it
bool share;
// Name shown in games; "" = the default (the console name of the real user, or "RemoteN")
char name[ORBIS_USER_SERVICE_MAX_USER_NAME_LENGTH + 1];
} PadSettings;
typedef struct Settings {
bool joinOnStart;
bool alwaysConnected;
PadSettings pads[REMOTE_PAD_MAX_USERS];
} Settings;
typedef struct ConsoleUser {
int32_t id;
char name[ORBIS_USER_SERVICE_MAX_USER_NAME_LENGTH + 1];
bool signedIn;
} ConsoleUser;
// Remember the running game and the file to use (NULL: SETTINGS_PATH_DEFAULT)
void settingsInit(const char *titleId, const char *path);
// Read the file: [default] first, then the game's own section. Applies the result to the services.
void settingsLoad(void);
// The settings in effect, and whether they come from the game's own section
void settingsGet(Settings *settings, bool *gameOnly);
// Check, apply right away and save. gameOnly: store them for this game only (otherwise for all games, which
// also drops this game's own section). Returns false with a message when the settings are not valid;
// *saved tells whether the file could be written.
bool settingsSet(const Settings *settings, bool gameOnly, bool *saved, char *error, size_t errorSize);
// remote_pad.ini lock_settings=1: settingsSet refuses every change
bool settingsLocked(void);
// Users of this console for the "PS4 user" choice: the registered ones if the system lets a game see them,
// at least the signed-in ones. Returns the count.
int settingsListConsoleUsers(ConsoleUser *users, int max);
const char *settingsTitleId(void);
#endif //REMOTE_PAD_SETTINGS_H