aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cli/commands.c44
-rw-r--r--src/steam.c70
-rw-r--r--src/steam.h12
3 files changed, 93 insertions, 33 deletions
diff --git a/src/cli/commands.c b/src/cli/commands.c
index 9ff4791..08b7ed4 100644
--- a/src/cli/commands.c
+++ b/src/cli/commands.c
@@ -200,6 +200,48 @@ static int run(int c, char** v)
int exit_val = EXIT_SUCCESS;
char* of_dir = getOpenFortressDir();
+ int (*launch_func)(char**, size_t) = runOpenFortress;
+
+ int arg_index;
+ for (arg_index = 1; arg_index < c; ++arg_index)
+ {
+ if (v[arg_index][0] != '-' && v[arg_index][1] != '-')
+ break;
+
+ if (!strcmp(v[arg_index]+2, "direct"))
+ {
+
+ launch_func = runOpenFortressDirect;
+ }
+ else if (!strcmp(v[arg_index]+2, "naive"))
+ {
+
+ launch_func = runOpenFortressNaive;
+ }
+ else if (!strcmp(v[arg_index]+2, "steam"))
+ {
+
+ launch_func = runOpenFortressSteam;
+ }
+ else
+ {
+ fprintf(stderr,
+ "OFCL run [flags] [options]\n"
+ "\n"
+ " flags:\n"
+ " --direct launch OpenFortress directly\n"
+ " --naive tell steam to launch the game\n"
+ " --steam launch game via Steam\n"
+ );
+ return 0;
+ }
+ }
+
+
+ if (launch_func == runOpenFortressDirect) { fprintf(stderr, "Launching directly\n"); }
+ else if (launch_func == runOpenFortressNaive) { fprintf(stderr, "Launching naively\n"); }
+ else if (launch_func == runOpenFortressSteam) { fprintf(stderr, "Launching via Steam\n"); }
+
int local_rev = getLocalRevision(of_dir);
if (0 > local_rev)
{
@@ -215,7 +257,7 @@ static int run(int c, char** v)
goto run_cleanup;
}
- runOpenFortress(v+1, (size_t)(c-1));
+ launch_func(v+1, (size_t)(c-1));
run_cleanup:
free(of_dir);
diff --git a/src/steam.c b/src/steam.c
index de22787..77542e4 100644
--- a/src/steam.c
+++ b/src/steam.c
@@ -239,13 +239,13 @@ long getSteamPID(void)
return -1;
}
-int runOpenFortress(char** args, size_t arg_count)
+int runOpenFortressDirect(char** args, size_t arg_count)
{
-#ifdef STEAM_DIRECT_LAUNCH
int in_fork = 0;
#if defined(__linux__) || defined(__FreeBSD__)
// fork so we don't have to stay alive for the game
if (fork()) return 0;
+ in_fork = 1;
#endif
char* game = getSourceSDK2013MpDir();
if (!game)
@@ -297,23 +297,26 @@ int runOpenFortress(char** args, size_t arg_count)
free(of_dir);
exit(0);
+}
-#else
- #ifdef STEAM_NAIVE_LAUNCH
- #ifdef _WIN32
- return system("start steam://rungameid/11677091221058336806");
- #else
- return system("xdg-open steam://rungameid/11677091221058336806");
- #endif
-
+int runOpenFortressNaive(char** args, size_t arg_count)
+{
+ #ifdef _WIN32
+ return system("start steam://rungameid/11677091221058336806");
#else
- char* of_dir = getOpenFortressDir();
- char* steam = getSteamDir();
- steam = realloc(steam, strlen(steam) + strlen(OS_PATH_SEP) + strlen(STEAM_BIN) + 1);
- strcat(steam, OS_PATH_SEP);
- strcat(steam, STEAM_BIN);
+ return system("xdg-open steam://rungameid/11677091221058336806");
+ #endif
+}
+
+int runOpenFortressSteam(char** args, size_t arg_count)
+{
+ char* of_dir = getOpenFortressDir();
+ char* steam = getSteamDir();
+ steam = realloc(steam, strlen(steam) + strlen(OS_PATH_SEP) + strlen(STEAM_BIN) + 1);
+ strcat(steam, OS_PATH_SEP);
+ strcat(steam, STEAM_BIN);
- char** argv = malloc(sizeof(char*) * (arg_count + 8));
+ char** argv = malloc(sizeof(char*) * (arg_count + 8));
#ifdef _WIN32
size_t of_dir_len = strlen(of_dir);
@@ -324,18 +327,29 @@ int runOpenFortress(char** args, size_t arg_count)
of_dir[of_dir_len+2] = '\0';
#endif
- argv[0] = steam;
- argv[1] = "-applaunch";
- argv[2] = "243750";
- argv[3] = "-game";
- argv[4] = of_dir;
- argv[5] = "-secure";
- argv[6] = "-steam";
- for (size_t i = 0; i < arg_count; ++i)
- argv[7+i] = args[i];
- argv[7+arg_count] = NULL;
-
- return execv(steam, argv);
+ argv[0] = steam;
+ argv[1] = "-applaunch";
+ argv[2] = "243750";
+ argv[3] = "-game";
+ argv[4] = of_dir;
+ argv[5] = "-secure";
+ argv[6] = "-steam";
+ for (size_t i = 0; i < arg_count; ++i)
+ argv[7+i] = args[i];
+ argv[7+arg_count] = NULL;
+
+ return execv(steam, argv);
+}
+
+int runOpenFortress(char** args, size_t arg_count)
+{
+#ifdef STEAM_DIRECT_LAUNCH
+ return runOpenFortressDirect(args, arg_count);
+#else
+ #ifdef STEAM_NAIVE_LAUNCH
+ return runOpenFortressNaive(args, arg_count);
+ #else
+ return runOpenFortressSteam(args, arg_count);
#endif
#endif
}
diff --git a/src/steam.h b/src/steam.h
index c586137..27345a9 100644
--- a/src/steam.h
+++ b/src/steam.h
@@ -38,6 +38,10 @@ extern "C" {
#elif defined(__FreeBSD__)
#define HL2_EXE "hl2.sh"
#define STEAM_DIR "/.steam/steam"
+// No flatpak :(
+
+#else
+#error Unsupported Operating System
#endif
@@ -46,16 +50,16 @@ extern "C" {
#define SOURCEMOD_DIR STEAMAPPS OS_PATH_SEP "sourcemods"
#define OPEN_FORTRESS_DIR "open_fortress"
-#if defined(_WIN32)
-#else
-#endif
-
char* getSteamDir(void);
char* getSourcemodDir(void);
char* getOpenFortressDir(void);
char* getAppInstallDir(const char* appid);
char* getSourceSDK2013MpDir(void);
long getSteamPID(void);
+
+int runOpenFortressDirect(char**, size_t);
+int runOpenFortressNaive(char**, size_t);
+int runOpenFortressSteam(char**, size_t);
int runOpenFortress(char**, size_t);
#ifdef __cplusplus