diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bb885d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# Don't incude these binary files +*.out +*.o +*.exe diff --git a/README.md b/README.md index 77b4bdd..82cdbe9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # online-game An online game created with C++ + +# Port +This game uses port 34698 diff --git a/client/Makefile b/client/Makefile new file mode 100644 index 0000000..3a90abb --- /dev/null +++ b/client/Makefile @@ -0,0 +1,17 @@ +all: connections.o main.o mainloop-api.o socket.o + g++ connections.o main.o mainloop-api.o socket.o + +connections.o: connections.cpp + g++ -c connections.cpp + +main.o: main.cpp + g++ -c main.cpp + +mainloop-api.o: lib/mainloop-api/mainloop-api.cpp + g++ -c lib/mainloop-api/mainloop-api.cpp -o mainloop-api.o + +socket.o: lib/socket/socket.cpp + g++ -c lib/socket/socket.cpp -o socket.o + +clean: + rm *.o diff --git a/client/connections.cpp b/client/connections.cpp index f6a6f78..fccd288 100644 --- a/client/connections.cpp +++ b/client/connections.cpp @@ -1,8 +1,20 @@ -#include "lib/socket.h" +#include "lib/socket/socket.h" +#include client_tcp *client; -int connections_init() +void connections_init(int argc, char const* argv[]) { - client = new client_tcp() + // Get the port + int port = PORT_DEFAULT; + + // Did the user specify a port + if(argc > 2) + { + // Set the port to the specified one + port = atoi(argv[2]); + } + + // Create a client + client = new client_tcp(argv[1], port); } diff --git a/client/connections.h b/client/connections.h index e69de29..160e9fd 100644 --- a/client/connections.h +++ b/client/connections.h @@ -0,0 +1 @@ +void connections_init(int argc, char const* argv[]); diff --git a/client/main.cpp b/client/main.cpp index 57efb02..6f400e2 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -2,6 +2,8 @@ int main(int argc, char const *argv[]) { + // Initialise the connections + connections_init(argc, argv); return 0; } diff --git a/lib/mainloop-api b/lib/mainloop-api new file mode 160000 index 0000000..c7924fc --- /dev/null +++ b/lib/mainloop-api @@ -0,0 +1 @@ +Subproject commit c7924fc3f4cef1e42b27c683d1413aed5d684374 diff --git a/lib/socket.cpp b/lib/socket/socket.cpp similarity index 100% rename from lib/socket.cpp rename to lib/socket/socket.cpp diff --git a/lib/socket.h b/lib/socket/socket.h similarity index 94% rename from lib/socket.h rename to lib/socket/socket.h index 693e0ae..9e81731 100644 --- a/lib/socket.h +++ b/lib/socket/socket.h @@ -2,6 +2,8 @@ #include #include +#define PORT_DEFAULT 34698; + class client_tcp { public: diff --git a/lib/socks_test_client b/lib/socks_test_client deleted file mode 100644 index 80dbc92..0000000 Binary files a/lib/socks_test_client and /dev/null differ diff --git a/lib/socks_test_client.cpp b/lib/socks_test_client.cpp deleted file mode 100644 index 78c3d8d..0000000 --- a/lib/socks_test_client.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -#include "socket.h" - -int main(int argc, char const *argv[]) -{ - client_tcp client("localhost", 12345); - std::cout << "Status: " << client.status << '\n'; - std::cout << client.recv(2) << '\n'; - - return 0; -} diff --git a/lib/socks_test_server b/lib/socks_test_server deleted file mode 100644 index ae44e07..0000000 Binary files a/lib/socks_test_server and /dev/null differ diff --git a/lib/socks_test_server.cpp b/lib/socks_test_server.cpp deleted file mode 100644 index d0a4156..0000000 --- a/lib/socks_test_server.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -#include "socket.h" - -int main(int argc, char const *argv[]) -{ - server_tcp server(12345); - - while(1) - { - client_tcp client = server.cliaccept(); - client.send("hi", 2); - } - - return 0; -} diff --git a/server/Makefile b/server/Makefile new file mode 100644 index 0000000..3a90abb --- /dev/null +++ b/server/Makefile @@ -0,0 +1,17 @@ +all: connections.o main.o mainloop-api.o socket.o + g++ connections.o main.o mainloop-api.o socket.o + +connections.o: connections.cpp + g++ -c connections.cpp + +main.o: main.cpp + g++ -c main.cpp + +mainloop-api.o: lib/mainloop-api/mainloop-api.cpp + g++ -c lib/mainloop-api/mainloop-api.cpp -o mainloop-api.o + +socket.o: lib/socket/socket.cpp + g++ -c lib/socket/socket.cpp -o socket.o + +clean: + rm *.o diff --git a/server/connections.cpp b/server/connections.cpp index 22d7477..dd59a39 100644 --- a/server/connections.cpp +++ b/server/connections.cpp @@ -1,3 +1,20 @@ -#include "lib/socket.h" +#include "lib/socket/socket.h" +#include -server_tcp server; +server_tcp *server; + +void connections_init(int argc, char const *argv[]) +{ + // Get the port + int port = PORT_DEFAULT; + + // Did the user specify a port + if(argc > 1) + { + // Set the port to the specified one + port = atoi(argv[1]); + } + + // Start the server + server = new server_tcp(port); +}