Skip to content

Commit

Permalink
More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dchansen06 committed Dec 19, 2024
1 parent 3b340a7 commit 866b856
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CXXFLAGS = -Wall -Wextra
LDLIBS = $(shell sdl2-config --libs) $(shell sdl2-config --libs)_mixer

SRC_DIR = src
CLIENT_SRC := $(wildcard $(SRC_DIR)/client.cpp)
CLIENT_SRC := $(wildcard $(SRC_DIR)/client*.cpp)
SERVER_SRC := $(wildcard $(SRC_DIR)/server*.cpp)

# Heavily inspired by https://stackoverflow.com/a/30602701
Expand All @@ -18,7 +18,7 @@ OBJ_DIR = $(BUILD_DIR)/obj
CLIENT_OBJ := $(CLIENT_SRC:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
SERVER_OBJ := $(SERVER_SRC:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)

PROGRAM = $(BIN_DIR)/client $(BIN_DIR)/server $(BIN_DIR)/client2
PROGRAM = $(BIN_DIR)/client $(BIN_DIR)/server

.DELETE_ON_ERROR:
.PHONY: all clean
Expand Down
43 changes: 9 additions & 34 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,29 @@ You should have received a copy of the GNU General Public License along with thi
*/

#include <iostream>
#include <csignal>
#include <cstdlib>
#include <string>
#include <unistd.h>

#include "client_functions.h"
#include "signals.h"

using namespace std;

int main(int argc, char* argv[])
{
if (argc != 3) {
cerr << "Invalid options\n";
string path, directory;

if (!getInformation(path, directory, argc, argv)) {
cerr << "Failed to get information\n";
exit(-1);
}

int server = fork();

if (server == 0) {
execl(argv[1], argv[1], argv[2], nullptr);
} else {
char input;
cout << "Gained control of server " << server << "\nEnter instructions: [R]esume, [P]ause, re[W]ind, [S]kip, [E]xit (or Ctrl+C to close)\n";
cin >> input;

while (tolower(input) != 'e') {
switch(tolower(input)) {
case 'w':
kill(server, REWIND);
break;
case 'p':
kill(server, PAUSE);
break;
case 'r':
kill(server, RESUME);
break;
case 's':
kill(server, SKIP);
break;
default:
cout << "Misunderstood input, enter R, P, S, or E only:\n";
}

cin >> input;
}

kill(server, EXIT);
}
if (server == 0)
execl(path.c_str(), path.c_str(), directory.c_str(), nullptr);

controlServer(server);

return 0;
}

0 comments on commit 866b856

Please # to comment.