initial kermit

This commit is contained in:
reemo 2023-12-16 12:59:22 -06:00
parent 31a1b503a9
commit 6c099af4a1

123
src/main.c Normal file
View file

@ -0,0 +1,123 @@
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
/************************/
/* 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;
}