diff --git a/src/config.c b/src/config.c index f65f236..6054798 100644 --- a/src/config.c +++ b/src/config.c @@ -72,6 +72,7 @@ static struct option long_options[] = { {"verbose", no_argument, NULL, 'z'}, {"debug", no_argument, NULL, 'Z'}, {"nomouseemulation", no_argument, NULL, '4'}, + {"pin", required_argument, NULL, '5'}, {0, 0, 0, 0}, }; @@ -244,6 +245,9 @@ static void parse_argument(int c, char* value, PCONFIGURATION config) { case '4': config->mouse_emulation = false; break; + case '5': + config->pin = atoi(value); + break; case 1: if (config->action == NULL) config->action = value; @@ -364,6 +368,7 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) { config->mouse_emulation = true; config->rotate = 0; config->codec = CODEC_UNSPECIFIED; + config->pin = 0; config->inputsCount = 0; config->mapping = get_path("gamecontrollerdb.txt", getenv("XDG_DATA_DIRS")); @@ -381,7 +386,7 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) { } else { int option_index = 0; int c; - while ((c = getopt_long_only(argc, argv, "-abc:d:efg:h:i:j:k:lm:no:p:q:r:s:tu:v:w:xy4", long_options, &option_index)) != -1) { + while ((c = getopt_long_only(argc, argv, "-abc:d:efg:h:i:j:k:lm:no:p:q:r:s:tu:v:w:xy45:", long_options, &option_index)) != -1) { parse_argument(c, optarg, config); } } diff --git a/src/config.h b/src/config.h index ed236ce..eb49d4b 100644 --- a/src/config.h +++ b/src/config.h @@ -47,6 +47,7 @@ typedef struct _CONFIGURATION { char* inputs[MAX_INPUTS]; int inputsCount; enum codecs codec; + int pin; } CONFIGURATION, *PCONFIGURATION; extern bool inputAdded; diff --git a/src/main.c b/src/main.c index 996bc5b..7dc7408 100644 --- a/src/main.c +++ b/src/main.c @@ -373,7 +373,11 @@ int main(int argc, char* argv[]) { stream(&server, &config, system); } else if (strcmp("pair", config.action) == 0) { char pin[5]; - sprintf(pin, "%d%d%d%d", (int)random() % 10, (int)random() % 10, (int)random() % 10, (int)random() % 10); + if (config.pin > 0 && config.pin <= 9999) { + sprintf(pin, "%04d", config.pin); + } else { + sprintf(pin, "%d%d%d%d", (int)random() % 10, (int)random() % 10, (int)random() % 10, (int)random() % 10); + } printf("Please enter the following PIN on the target PC: %s\n", pin); fflush(stdout); if (gs_pair(&server, &pin[0]) != GS_OK) {