From 5aa689043680b0521a79a58cb2562f72bf228aca Mon Sep 17 00:00:00 2001 From: netbenix Date: Tue, 18 Aug 2020 12:58:01 +0200 Subject: [PATCH 1/3] Updated Manual - added version manual - added cd manual --- .gitignore | 3 +- etc/man.c | 92 +++++++++++++++++++------------------- etc/man.h | 12 ++--- etc/your-reality.c | 38 ++++++++++++++++ etc/your-reality.h | 6 +++ main.c | 21 +++++---- makefile | 4 +- utils/update_check.c | 104 +++++++++++++++++++++---------------------- utils/update_check.h | 10 ++--- 9 files changed, 168 insertions(+), 122 deletions(-) create mode 100644 etc/your-reality.c create mode 100644 etc/your-reality.h diff --git a/.gitignore b/.gitignore index d45456c..0bc6d3c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ sys_info.o show_dir.o change_dir.o update_check.o -man.o \ No newline at end of file +man.o +your-reality.o \ No newline at end of file diff --git a/etc/man.c b/etc/man.c index 4aba44c..d855f22 100644 --- a/etc/man.c +++ b/etc/man.c @@ -1,47 +1,47 @@ -#include -#include -#include - -// Color Codes: -// Reset: \033[0m -// Red: \033[0;31m -// Green: \033[0;32m -// Yellow: \033[0;33m -// Blue: \033[0;34m -// Magenta: \033[0;35m -// Cyan: \033[0;36m -// BoldRed: \033[1;31m -// BoldGreen: \033[1;32m -// BoldYellow: \033[1;33m -// BoldBlue: \033[1;34m -// BoldMagenta: \033[1;35m -// BoldCyan: \033[1;36m - -//Main function to start man is at the bottom - -//MAN ENTRIES -//LS -void manEntry_ls(){ - printf("\033[0;33m##################\033[0m\n"); - printf("\033[0;33m# Manual of \033[0;36m'ls' \033[0;33m#\033[0m\n"); - printf("\033[0;33m##################\033[0m\n\n"); - printf("\033[0;33mNAME\033[0m\n"); - printf("\t\033[0;36mls - list directory contents\033[0m\n\n"); - printf("\033[0;33mUSAGE\033[0m\n"); - printf("\t\033[0;36mls \033[0;35m[DIRECTORY]\033[0m\n\n"); - printf("\033[0;33mDESCRIPTION\033[0m\n"); - printf("\t\033[0;36mList files and directorys in the given directory. Sorts entries alphabetically.\033[0m\n\n"); -} - - - -//MAIN FUNCTION -void showManEntry(char *arg[]){ - if(!strcmp(arg[1], "man")){ - printf("Coming soon.\n"); - } else if(!strcmp(arg[1], "ls")){ - manEntry_ls(); - } else { - printf("Entry not found.\n"); - } +#include +#include +#include + +// Color Codes: +// Reset: \033[0m +// Red: \033[0;31m +// Green: \033[0;32m +// Yellow: \033[0;33m +// Blue: \033[0;34m +// Magenta: \033[0;35m +// Cyan: \033[0;36m +// BoldRed: \033[1;31m +// BoldGreen: \033[1;32m +// BoldYellow: \033[1;33m +// BoldBlue: \033[1;34m +// BoldMagenta: \033[1;35m +// BoldCyan: \033[1;36m + +//Main function to start man is at the bottom + +//MAN ENTRIES +//LS +void manEntry_ls(){ + printf("\033[0;33m##################\033[0m\n"); + printf("\033[0;33m# Manual of \033[0;36m'ls' \033[0;33m#\033[0m\n"); + printf("\033[0;33m##################\033[0m\n\n"); + printf("\033[0;33mNAME\033[0m\n"); + printf("\t\033[0;36mls - list directory contents\033[0m\n\n"); + printf("\033[0;33mUSAGE\033[0m\n"); + printf("\t\033[0;36mls \033[0;35m[DIRECTORY]\033[0m\n\n"); + printf("\033[0;33mDESCRIPTION\033[0m\n"); + printf("\t\033[0;36mList files and directorys in the given directory. Sorts entries alphabetically.\033[0m\n\n"); +} + + + +//MAIN FUNCTION +void showManEntry(char *arg[]){ + if(!strcmp(arg[1], "man")){ + printf("Coming soon.\n"); + } else if(!strcmp(arg[1], "ls")){ + manEntry_ls(); + } else { + printf("Entry not found.\n"); + } } \ No newline at end of file diff --git a/etc/man.h b/etc/man.h index 9a5d76a..08bcf7c 100644 --- a/etc/man.h +++ b/etc/man.h @@ -1,7 +1,7 @@ -#ifndef _MAN_H_ -#define _MAN_H_ - -void manEntry_ls(); -void showManEntry(char *arg[]); - +#ifndef _MAN_H_ +#define _MAN_H_ + +void manEntry_ls(); +void showManEntry(char *arg[]); + #endif \ No newline at end of file diff --git a/etc/your-reality.c b/etc/your-reality.c new file mode 100644 index 0000000..127046f --- /dev/null +++ b/etc/your-reality.c @@ -0,0 +1,38 @@ +#include +#include + +#include "your-reality.h" + +//Lyrics from "Your Reality" by Dan Salvato + +//fs -> flush & sleep +void fs(int milliseconds){ + fflush(stdout); + usleep(milliseconds*1000); +} + +//p -> printf +void p(char* txt){ + printf(txt); +} + +void yourReality(){ + + printf("\e[?25l"); + p("Loading "); + for(int i = 0; i < 2; i++){ + //\033[XC => X columns right + //\033[XD => X columns left + printf("\033[3D "); printf("\033[3D"); + fs(500); printf("."); fs(500); printf("."); fs(500); printf("."); fs(500); + + } + printf("\n"); + printf("\033[0;33mEvery "); fs(350); printf("day, "); + fs(700); + p("I "); fs(450); p("imagine "); fs(350); p("a "); fs(350); p("future "); fs(350); p("where "); fs(750); + p("i "); fs(300); p("can "); fs(300); p("be "); fs(300); p("with "); fs(300); p("you."); + + p("\033[0m"); + printf("\e[?25h"); +} diff --git a/etc/your-reality.h b/etc/your-reality.h new file mode 100644 index 0000000..7dae4ca --- /dev/null +++ b/etc/your-reality.h @@ -0,0 +1,6 @@ +#ifndef _YOUR_REALITY_H +#define _YOUR_REALITY_H + +void yourReality(); + +#endif \ No newline at end of file diff --git a/main.c b/main.c index b15a390..1c94ad1 100644 --- a/main.c +++ b/main.c @@ -15,6 +15,7 @@ #include "utils/sql_test.h" #include "etc/logo.h" #include "etc/man.h" +#include "etc/your-reality.h" #include "utils/logger.h" #include "utils/sys_info.h" #include "utils/update_check.h" @@ -88,18 +89,16 @@ int commandHandler(char *cmd){ } else if(!strcmp(arg[0], "man")){ showManEntry(arg); return 0; - } else if(!strcmp(arg[0], "rainbow")){ - if(FUN_CONTENT){ - while(1){ - printf("\033[0;31m#####"); - printf("\033[0;32m#####"); - printf("\033[0;33m#####"); - printf("\033[0;34m#####"); - printf("\033[0;35m#####"); - } - } else { - return 0; + } else if(!strcmp(arg[0], "rainbow") && FUN_CONTENT){ + while(1){ + printf("\033[0;31m#####"); + printf("\033[0;32m#####"); + printf("\033[0;33m#####"); + printf("\033[0;34m#####"); + printf("\033[0;35m#####"); } + } else if(!strcmp(arg[0], "your-reality") && FUN_CONTENT){ + yourReality(); } else { printf("Unknown command. Please use 'help' for more information.\n"); logger("User entered unknown command."); diff --git a/makefile b/makefile index 7063ab6..407fe6f 100644 --- a/makefile +++ b/makefile @@ -2,7 +2,7 @@ CC= gcc ARGS= -export-dynamic -ansi -std=gnu99 CFLAGS= $(shell pkg-config --cflags gtk+-3.0) -I/usr/include/mysql LDLIBS= $(shell pkg-config --libs gtk+-3.0) -L/usr/lib/mysql -lmysqlclient -OBJ= main.o logo.o logger.o help.o sys_info.o gtk_test.o sql_test.o show_dir.o change_dir.o update_check.o man.o +OBJ= main.o logo.o logger.o help.o sys_info.o gtk_test.o sql_test.o show_dir.o change_dir.o update_check.o man.o your-reality.o netbenixCMD: $(OBJ) $(CC) $(CFLAGS) $(ARGS) -o netbenixCMD $(OBJ) $(LDLIBS) @@ -28,3 +28,5 @@ update_check.o: utils/update_check.c $(CC) $(CFLAGS) -c utils/update_check.c man.o: etc/man.c $(CC) $(CFLAGS) -c etc/man.c +your-reality.o: etc/your-reality.c + $(CC) $(CFLAGS) -c etc/your-reality.c \ No newline at end of file diff --git a/utils/update_check.c b/utils/update_check.c index 328ec98..8ca0442 100644 --- a/utils/update_check.c +++ b/utils/update_check.c @@ -1,53 +1,53 @@ -#include -#include -#include -#include -#include "update_check.h" -#include "logger.h" - -#define SERVER_IP "127.0.0.1" - -int checkForUpdate(char ver[10]){ - int sock; - struct sockaddr_in server; - char server_reply[2000]; - - //Create socket - sock = socket(AF_INET, SOCK_STREAM, 0); - if( sock == -1){ - printf("Error while creating socket."); - logger("Error while creating socket"); - } - - server.sin_addr.s_addr = inet_addr(SERVER_IP); //Set the IP address of the server - server.sin_family = AF_INET; - server.sin_port = htons( 34000 ); //Set the server port - - //Connect to server - if(connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0){ - perror("Error. Connnection to update server failed."); - logger("[ERROR] Connection to update server failed."); - return 1; - } - //Send message - if( send(sock, ver, strlen(ver), 0) < 0){ - puts("Error while communicating with server."); - logger("[ERROR] Send to server failed."); - } - //Receive response - if( recv(sock, server_reply, 2000, 0) < 0){ - puts("Error while communicating with server."); - logger("[ERROR] Receive from server failed."); - } - //Say that client outdated - if(!strcmp(server_reply, "VERSION_OUTDATED")){ - printf("\033[0;31mYour client is outdated. Please update your client.\033[0m\n"); - logger("[WARNING] Client is outdated."); - } - //Say that client is up-to-date - if(!strcmp(server_reply, "VERSION_OK")){ - logger("[INFO] Client is up-to-date."); - } - close(sock); //Close the socket - return 0; +#include +#include +#include +#include +#include "update_check.h" +#include "logger.h" + +#define SERVER_IP "127.0.0.1" + +int checkForUpdate(char ver[10]){ + int sock; + struct sockaddr_in server; + char server_reply[2000]; + + //Create socket + sock = socket(AF_INET, SOCK_STREAM, 0); + if( sock == -1){ + printf("Error while creating socket."); + logger("Error while creating socket"); + } + + server.sin_addr.s_addr = inet_addr(SERVER_IP); //Set the IP address of the server + server.sin_family = AF_INET; + server.sin_port = htons( 34000 ); //Set the server port + + //Connect to server + if(connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0){ + perror("Error. Connnection to update server failed."); + logger("[ERROR] Connection to update server failed."); + return 1; + } + //Send message + if( send(sock, ver, strlen(ver), 0) < 0){ + puts("Error while communicating with server."); + logger("[ERROR] Send to server failed."); + } + //Receive response + if( recv(sock, server_reply, 2000, 0) < 0){ + puts("Error while communicating with server."); + logger("[ERROR] Receive from server failed."); + } + //Say that client outdated + if(!strcmp(server_reply, "VERSION_OUTDATED")){ + printf("\033[0;31mYour client is outdated. Please update your client.\033[0m\n"); + logger("[WARNING] Client is outdated."); + } + //Say that client is up-to-date + if(!strcmp(server_reply, "VERSION_OK")){ + logger("[INFO] Client is up-to-date."); + } + close(sock); //Close the socket + return 0; } \ No newline at end of file diff --git a/utils/update_check.h b/utils/update_check.h index 55d7232..2b4a08d 100644 --- a/utils/update_check.h +++ b/utils/update_check.h @@ -1,6 +1,6 @@ -#ifndef _UPDATE_CHECK_H_ -#define _UPDATE_CHECK_H_ - -int checkForUpdate(char ver[10]); - +#ifndef _UPDATE_CHECK_H_ +#define _UPDATE_CHECK_H_ + +int checkForUpdate(char ver[10]); + #endif \ No newline at end of file From 552da1a4593295989a507cf2d9b57a46a53d0525 Mon Sep 17 00:00:00 2001 From: netbenix Date: Tue, 18 Aug 2020 13:13:23 +0200 Subject: [PATCH 2/3] Renamed fun arg --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 1c94ad1..8099c9d 100644 --- a/main.c +++ b/main.c @@ -148,7 +148,7 @@ int main(int argc, char *argv[]){ VER_CHECK_ON_START = false; DEV_MODE = true; logger("[INFO] Starting in developer mode."); - } else if (!strcmp(argv[1], "--time-to-have-fun")){ + } else if (!strcmp(argv[1], "--time-for-fun")){ FUN_CONTENT = true; logger("[WARNING] It's time... TO PARTYY."); } else { From f1cf6269f94065bfb8498dd7ef06bfbb61442b80 Mon Sep 17 00:00:00 2001 From: netbenix Date: Tue, 18 Aug 2020 13:16:33 +0200 Subject: [PATCH 3/3] Update to 0.2.5 --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 8099c9d..c55caaa 100644 --- a/main.c +++ b/main.c @@ -21,7 +21,7 @@ #include "utils/update_check.h" -#define VERSION "0.2.4" +#define VERSION "0.2.5" bool VER_CHECK_ON_START = true; bool DEV_MODE = false;