From 6c099af4a16d783a06d5dffa21e5f63bbab43f3c Mon Sep 17 00:00:00 2001 From: reemo Date: Sat, 16 Dec 2023 12:59:22 -0600 Subject: [PATCH] initial kermit --- src/main.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/main.c diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..755648a --- /dev/null +++ b/src/main.c @@ -0,0 +1,123 @@ +#include +#include +#include +#include + +#include +#include +#include + +/************************/ +/* CONSTS & UTILITIES */ +/************************/ + +const char FII_ADDR[] = "chatsrv-neru.flashii.net"; +const char USAGE[] = + "flashii -- Terminal-Based Flashii Chat\n" + "USAGE: flashii [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*); + + +/*****************/ +/* DATA BUFFER */ +/*****************/ + +struct buffer_t { + char* data; + int length; + struct buffer_t* next; +}; +typedef struct buffer_t buffer_t; + + +/****************/ +/* WEB SOCKET */ +/****************/ + +typedef struct { + int sock; +} wsock_t; + +wsock_t* wsock_open(const char*, uint16_t); + +void wsock_close(wsock_t*); + + +/*************/ +/* GLOBALS */ +/*************/ + +struct { + char session[256]; +} _G; + + +int main(int argc, char** argv) { + FILE* fp; + printf("Loading session key ..."); + + switch(argc) { + case 1: + if((fp = fopen(_home(".fiikey"), "r")) == NULL) { + 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; + } + + strcpy(_G.session, argv[1]); + if((fp = fopen(_home(".fiikey"), "w")) != NULL) { + fputs(_G.session, fp); + fclose(fp); + } + break; + default: + printf("%s\n", USAGE); + return -1; + } + + printf("Session key loaded.\n"); + printf("Connecting to Flashii ...\n"); + + struct hostent* fiihost; + fiihost = gethostbyname(FII_ADDR); + + 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; +}