123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #define _GNU_SOURCE
- #include <dlfcn.h>
- #include <errno.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <systemd/sd-bus.h>
- #include <unistd.h>
- static char error_string[512] = { 0 };
- static int gamemode_request(const char *function)
- {
- sd_bus_message *msg = NULL;
- sd_bus *bus = NULL;
- int result = -1;
-
- int ret = sd_bus_open_user(&bus);
- if (ret < 0) {
- snprintf(error_string,
- sizeof(error_string),
- "Could not connect to bus: %s",
- strerror(-ret));
- } else {
-
- ret = sd_bus_call_method(bus,
- "com.feralinteractive.GameMode",
- "/com/feralinteractive/GameMode",
- "com.feralinteractive.GameMode",
- function,
- NULL,
- &msg,
- "i",
- getpid());
- if (ret < 0) {
- snprintf(error_string,
- sizeof(error_string),
- "Could not call method on bus: %s",
- strerror(-ret));
- } else {
-
- ret = sd_bus_message_read(msg, "i", &result);
- if (ret < 0) {
- snprintf(error_string,
- sizeof(error_string),
- "Failure to parse response: %s",
- strerror(-ret));
- }
- }
- }
- return result;
- }
- extern const char *real_gamemode_error_string(void)
- {
- return error_string;
- }
- extern int real_gamemode_request_start(void)
- {
- return gamemode_request("RegisterGame");
- }
- extern int real_gamemode_request_end(void)
- {
- return gamemode_request("UnregisterGame");
- }
- extern int real_gamemode_query_status(void)
- {
- return gamemode_request("QueryStatus");
- }
|