diff options
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 134 |
1 files changed, 100 insertions, 34 deletions
| @@ -10,8 +10,11 @@ | |||
| 10 | 10 | ||
| 11 | #define _GNU_SOURCE | 11 | #define _GNU_SOURCE |
| 12 | 12 | ||
| 13 | #include "main.h" | ||
| 14 | |||
| 13 | #include "encryption.h" | 15 | #include "encryption.h" |
| 14 | #include "search.h" | 16 | #include "search.h" |
| 17 | #include "screen.h" | ||
| 15 | #include "ll.h" | 18 | #include "ll.h" |
| 16 | 19 | ||
| 17 | #include <sodium.h> | 20 | #include <sodium.h> |
| @@ -41,14 +44,16 @@ static char argdoc[] = "lmao"; | |||
| 41 | 44 | ||
| 42 | static struct argp_option options[] = { | 45 | static struct argp_option options[] = { |
| 43 | {.name = "passphrase", .key = 'p', .arg = "key", .flags = 0, .doc = "Specify passphrase for encryption/decryption", .group = 0}, | 46 | {.name = "passphrase", .key = 'p', .arg = "key", .flags = 0, .doc = "Specify passphrase for encryption/decryption", .group = 0}, |
| 44 | {"decrypt", 'd', 0, 0, "Skip the slots minigame and immediately decrypt (or encrypt) files", 0}, | 47 | {"decrypt", 'd', 0, 0, "Skip the slots minigame and immediately decrypt (or encrypt) files", 0}, |
| 45 | {"noenc", 'n', 0, 0, "Don't encrypt files when ran, just play slots"}, | 48 | {"noencrypt", 'n', 0, 0, "Don't encrypt files when ran, just play slots", 0}, |
| 46 | {0} | 49 | {0} |
| 47 | }; | 50 | }; |
| 51 | #define SKIPSLOTS 0x1 | ||
| 52 | #define SKIPENC 0x2 | ||
| 48 | 53 | ||
| 49 | struct arguments { | 54 | struct arguments { |
| 50 | char *inputpass; | 55 | char *inputpass; |
| 51 | int skipslots; | 56 | int flags; |
| 52 | }; | 57 | }; |
| 53 | 58 | ||
| 54 | static error_t parse_opt(int key, char *arg, struct argp_state *state) { | 59 | static error_t parse_opt(int key, char *arg, struct argp_state *state) { |
| @@ -56,21 +61,28 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { | |||
| 56 | 61 | ||
| 57 | switch(key) { | 62 | switch(key) { |
| 58 | case 'p': | 63 | case 'p': |
| 59 | /* Specifying the start option of "-p=<phrase>" errors out unless this is done. | 64 | /* Specifying the start option of "-p=<phrase>" errors out unless this is done. |
| 60 | // Technically a user should use --passphrase=<phrase> if they want to use the = sign, but I think | 65 | // Technically a user should use --passphrase=<phrase> if they want to use the = sign, but I think |
| 61 | // this is how it should work. RMS can suck it */ | 66 | // this is how it should work. RMS can suck it */ |
| 62 | if(*arg == '=') | 67 | if(*arg == '=') |
| 63 | arg++; | 68 | arg++; |
| 64 | 69 | ||
| 65 | args->inputpass = arg; | 70 | args->inputpass = arg; |
| 66 | break; | 71 | if(strlen(args->inputpass) != PHRASESIZE) { |
| 72 | error(1, 0, "Encryption passphrase must be exactly %d characters long", PHRASESIZE); | ||
| 73 | } | ||
| 74 | break; | ||
| 67 | 75 | ||
| 68 | case 'd': | 76 | case 'd': |
| 69 | args->skipslots = 1; | 77 | args->flags |= SKIPSLOTS; |
| 70 | break; | 78 | break; |
| 79 | |||
| 80 | case 'n': | ||
| 81 | args->flags |= SKIPENC; | ||
| 82 | break; | ||
| 71 | 83 | ||
| 72 | default: | 84 | default: |
| 73 | return ARGP_ERR_UNKNOWN; | 85 | return ARGP_ERR_UNKNOWN; |
| 74 | } | 86 | } |
| 75 | 87 | ||
| 76 | return 0; | 88 | return 0; |
| @@ -90,34 +102,88 @@ int genphrase(char *phrase, size_t phrasesize) { | |||
| 90 | return 0; | 102 | return 0; |
| 91 | } | 103 | } |
| 92 | 104 | ||
| 105 | // roflmao fuck this project i'm too tired to bother with making it nice | ||
| 106 | int doslots(struct bullshit *stuff) { | ||
| 107 | // I have no fucking clue why gcc complains that this isn't properly bracketed. Maybe im rarted | ||
| 108 | stuff->handler = (struct sigaction){ | ||
| 109 | .sa_flags = SA_SIGINFO, | ||
| 110 | .sa_mask = SIGINT | SIGWINCH, | ||
| 111 | .sa_sigaction = catcher, | ||
| 112 | }; | ||
| 113 | doinit(&stuff->handler); | ||
| 114 | docolors(); | ||
| 115 | |||
| 116 | getmaxyx(stdscr, stuff->row, stuff->col); | ||
| 117 | stuff->randphrase = randombytes_uniform(STATIC_ARRSIZE(phrases) + 1); | ||
| 118 | stuff->banner = create_banner(stuff->col, stuff->randphrase); | ||
| 119 | |||
| 120 | init_items(stuff->items, menu_choices, STATIC_ARRSIZE(menu_choices), userfuncs); | ||
| 121 | stuff->menu = new_menu(stuff->items); | ||
| 122 | if(stuff->menu == NULL) { | ||
| 123 | endwin(); | ||
| 124 | error(1, errno, "Could not create menu"); | ||
| 125 | } | ||
| 93 | 126 | ||
| 94 | int main(int argc, char *argv[]) { | 127 | stuff->menuholder = newwin(1, stuff->col, stuff->row - 1, 0); |
| 95 | if(sodium_init() < 0) | 128 | keypad(stuff->menuholder, TRUE); |
| 96 | error(1, errno, "[VX-GAMBLEGROUND] Could not init sodium"); | 129 | init_custom_menu_format(stuff->menuholder, stuff->menu, (int []){1, stuff->col}, O_ONEVALUE | O_IGNORECASE, O_SHOWDESC | O_NONCYCLIC); |
| 130 | |||
| 131 | stuff->slots.slotwin = newwin(stuff->row - 2, stuff->col, 1, 0); | ||
| 132 | if(stuff->slots.slotwin == NULL) { | ||
| 133 | endwin(); | ||
| 134 | error(1, errno, "[VX-GAMBLEGROUND] Could not create slots window"); | ||
| 135 | } | ||
| 136 | init_slotholder(&stuff->slots); | ||
| 137 | |||
| 138 | doupdate(); | ||
| 139 | |||
| 140 | stuff->params = (struct params){ | ||
| 141 | .bannerwin = stuff->banner, | ||
| 142 | .menu = stuff->menu, | ||
| 143 | .menuholder = stuff->menuholder, | ||
| 144 | .numspins = 3, | ||
| 145 | .price = 1, | ||
| 146 | .slots = &stuff->slots, | ||
| 147 | }; | ||
| 97 | 148 | ||
| 98 | struct arguments args; | 149 | handle_input(stuff->menuholder, stuff->menu, &stuff->params); |
| 99 | args.inputpass = NULL; | ||
| 100 | args.skipslots = 0; | ||
| 101 | 150 | ||
| 151 | unpost_menu(stuff->menu); | ||
| 152 | free_menu(stuff->menu); | ||
| 153 | for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++) | ||
| 154 | free_item(stuff->items[i]); | ||
| 155 | |||
| 156 | endwin(); | ||
| 157 | |||
| 158 | return 0; | ||
| 159 | } | ||
| 160 | |||
| 161 | int main(int argc, char *argv[]) { | ||
| 162 | struct arguments args = { | ||
| 163 | .inputpass = NULL, | ||
| 164 | .flags = 0 | ||
| 165 | }; | ||
| 102 | argp_parse(&argp, argc, argv, ARGP_NO_ARGS, 0, &args); | 166 | argp_parse(&argp, argc, argv, ARGP_NO_ARGS, 0, &args); |
| 103 | 167 | ||
| 104 | if(args.inputpass != NULL) { | 168 | if(args.flags == (SKIPENC | SKIPSLOTS)) |
| 105 | if(strlen(args.inputpass) != PHRASESIZE) { | 169 | error(1, 0, "[VX-GAMBLEGROUND] You want to skip the slots, and the encryption? Ok, sure"); |
| 106 | error(1, 0, "Encryption passphrase must be exactly %d characters long", PHRASESIZE); | 170 | |
| 107 | } | 171 | struct bullshit stuff; |
| 172 | doslots(&stuff); | ||
| 108 | 173 | ||
| 109 | printf("Using input passphrase \"%s\"\n", args.inputpass); | 174 | // if(args.inputpass != NULL) { |
| 110 | } else { | 175 | // printf("Using input passphrase \"%s\"\n", args.inputpass); |
| 111 | char phrase[PHRASESIZE]; | 176 | // } else { |
| 112 | genphrase(phrase, PHRASESIZE); | 177 | // char phrase[PHRASESIZE]; |
| 178 | // genphrase(phrase, PHRASESIZE); | ||
| 113 | 179 | ||
| 114 | printf("Encryption phrase: %s\n\nWrite this phrase down EXACTLY if you want to recover your files\n", phrase); | 180 | // printf("Encryption phrase: %s\n\nWrite this phrase down EXACTLY if you want to recover your files\n", phrase); |
| 115 | 181 | ||
| 116 | if(args.skipslots == 0) { | 182 | // if(args.flags & SKIPSLOTS != 0) { |
| 117 | printf("Hit Enter to contine, or CTRL+C to cancel..."); | 183 | // printf("Hit Enter to contine, or CTRL+C to cancel..."); |
| 118 | getchar(); | 184 | // getchar(); |
| 119 | } | 185 | // } |
| 120 | } | 186 | // } |
| 121 | 187 | ||
| 122 | /* Get files | 188 | /* Get files |
| 123 | struct nodelist *files = scanfiles("./", alphasort); | 189 | struct nodelist *files = scanfiles("./", alphasort); |
