clii/src/main.c
2023-12-17 08:30:44 -06:00

100 lines
1.8 KiB
C

#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "wsock.h"
/** CONSTS & UTILITIES **/
/**************************/
const char FII_ADDR[] = "chatsrv-neru.flashii.net";
const char USAGE[] =
"clii -- Command-Line Flashii Chat\n"
"USAGE: clii [session key]\n\n"
"Session key will be stored for future use until\n"
"a new session key is given to the program.\n\n"
"If you do not know your session key, visit\n"
" https://flashii.net/_sockchat/token\n"
"on any web browser that is logged in.";
const char* _home(const char*);
/** GLOBALS **/
/***************/
struct {
char session[256];
} _G;
/** MAIN **/
/************/
int main(int argc, char** argv) {
FILE* fp;
switch(argc) {
case 1:
printf("Loading session key ...\n");
if((fp = fopen(_home(".fiikey"), "r")) == NULL) {
printf("No previous session key found.\n");
printf("%s\n", USAGE);
return -1;
}
fgets(_G.session, sizeof(_G.session), fp);
fclose(fp);
break;
case 2:
if(strncmp(argv[1], "--h", 3) == 0) {
printf("%s\n", USAGE);
return 0;
}
printf("New session key provided. Storing ...\n");
strcpy(_G.session, argv[1]);
if((fp = fopen(_home(".fiikey"), "w")) != NULL) {
fputs(_G.session, fp);
fclose(fp);
} else
printf("Could not write to ~/.fiikey. Session key will not be stored.\n");
break;
default:
printf("%s\n", USAGE);
return -1;
}
printf("Connecting to Flashii ...\n");
wsock_t* sock = wsock_open(FII_ADDR, "/", 80);
for(;;);
initscr();
raw(); noecho();
keypad(stdscr, TRUE);
/*for(;;) {
}*/
printw("hi mom");
refresh();
halfdelay(1);
while(getch() == ERR);
//getch();
endwin();
return 0;
}
const char* _home(const char* path) {
static char full_path[4096];
strcpy(full_path, getenv("HOME"));
strcat(full_path, "/");
strcat(full_path, path);
return full_path;
}