diff --git a/debug b/debug index 304cfc6..27cd1d0 100755 --- a/debug +++ b/debug @@ -1,2 +1,2 @@ -gcc src/*.c -g -lncurses -o bin/mahou +gcc src/*.c src/server/*.c src/client/*.c -g -iquotesrc/ -lpthread -lncurses -o bin/mahou chmod +x bin/mahou diff --git a/release b/release index 8b6387d..7438405 100755 --- a/release +++ b/release @@ -1,2 +1,2 @@ -gcc src/*.c -lncurses -o bin/mahou +gcc src/*.c src/server/*.c src/client/*.c -iquotesrc/ -lpthread -lncurses -o bin/mahou chmod +x bin/mahou diff --git a/src/client.c b/src/client/client.c similarity index 77% rename from src/client.c rename to src/client/client.c index 5718148..bee33ab 100644 --- a/src/client.c +++ b/src/client/client.c @@ -11,28 +11,40 @@ char BANNER[BANNER_HEIGHT][BANNER_WIDTH + 1] = { "MMM M' \"MMMYMM \"\"` MMM YMM \"YMMMMMP\" \"YmmMMMM\"\"" }; -#define MM_OPT_COUNT 3 -#define MM_MAX_OPT_LEN 11 +#define MM_OPT_COUNT 4 +#define MM_MAX_OPT_LEN 15 char MM_OPTIONS[MM_OPT_COUNT][MM_MAX_OPT_LEN + 1] = { "Join Game", + "Create Account", "How to Play", "Quit" }; #define MM_OPT_JOIN 0 -#define MM_OPT_HOW 1 -#define MM_OPT_QUIT 2 +#define MM_OPT_REG 1 +#define MM_OPT_HOW 2 +#define MM_OPT_QUIT 3 struct { socket_t *sock; } client_ctx; -static void hide_cursor(); static int main_menu(); static void how_to_play(); +static void create_account(); +static void client_loop(); void client() { - int selected; + int selected, err; BOOL running = TRUE; + client_ctx.sock = sock_client_init("127.0.0.1", "6770"); + + printf("Connecting to server...\n"); + err = sock_start(client_ctx.sock); + if(err != SOCK_SUCCESS) { + printf("Connection failed, error %d.", err); + getchar(); + return; + } initscr(); @@ -44,7 +56,10 @@ void client() { switch(selected) { case MM_OPT_JOIN: - + client_loop(); + break; + case MM_OPT_REG: + create_account(); break; case MM_OPT_HOW: how_to_play(); @@ -68,10 +83,6 @@ void client() { sock_free(sock);*/ } -static void hide_cursor() { - move(LINES - 1, COLS - 1); -} - static int main_menu() { BOOL polling = TRUE; int i, j, selected = 0, color, ch; @@ -85,11 +96,8 @@ static int main_menu() { init_pair(2, COLOR_BLACK, COLOR_CYAN); attron(COLOR_PAIR(1) | A_BOLD); - - for(i = 0; i < LINES; ++i) - for(j = 0; j < COLS; ++j) - addch(' '); - + + scr_fill(); for(i = 0; i < BANNER_HEIGHT; ++i) mvprintw(3 + i, (COLS - BANNER_WIDTH) / 2, BANNER[i]); @@ -107,7 +115,7 @@ static int main_menu() { refresh(); - hide_cursor(); + scr_hide_cursor(); ch = getch(); switch(ch) { case KEY_UP: @@ -130,10 +138,17 @@ void how_to_play() { WINDOW *win; win = newwin(10, 10, 4, 4); wborder(win, '|', '|', '-', '-', '+', '+', '+', '+'); - mvwprintw(win, 1, 1, "test"); + mvwprintw(win, 1, 1, "to do: write this garbage"); wrefresh(win); - hide_cursor(); + scr_hide_cursor(); getch(); + delwin(win); } +void create_account() { +} + +void client_loop() { + +} diff --git a/src/client.h b/src/client/client.h similarity index 76% rename from src/client.h rename to src/client/client.h index f7a97e4..d00253c 100644 --- a/src/client.h +++ b/src/client/client.h @@ -4,6 +4,8 @@ #include #include #include "sock.h" +#include "screen.h" +#include "ui.h" void client(); diff --git a/src/client/screen.c b/src/client/screen.c new file mode 100644 index 0000000..933e94f --- /dev/null +++ b/src/client/screen.c @@ -0,0 +1,16 @@ +#include "screen.h" + +void scr_char_fill(char c) { + int i, j; + for(i = 0; i < LINES; ++i) + for(j = 0; j < COLS; ++j) + addch(c); +} + +void scr_fill() { + scr_char_fill(' '); +} + +void scr_hide_cursor() { + move(LINES - 1, COLS - 1); +} diff --git a/src/client/screen.h b/src/client/screen.h new file mode 100644 index 0000000..8d2aacf --- /dev/null +++ b/src/client/screen.h @@ -0,0 +1,11 @@ +#ifndef SCREEN_H +#define SCREEN_H + +#include +#include + +void scr_fill(); +void scr_char_fill(char); +void scr_hide_cursor(); + +#endif diff --git a/src/client/ui.c b/src/client/ui.c new file mode 100644 index 0000000..287a7d8 --- /dev/null +++ b/src/client/ui.c @@ -0,0 +1,29 @@ +#include "ui.h" + +struct { + WINDOW *main_win; + WINDOW *chat_win; + WINDOW *info_win; +} ui_ctx; + +static void ui_draw_borders(); + +void ui_init() { + +} + +void ui_refresh() { + clear(); + + + + ui_draw_borders(); +} + +static void ui_draw_borders() { + +} + +void ui_free() { + +} diff --git a/src/client/ui.h b/src/client/ui.h new file mode 100644 index 0000000..94cbada --- /dev/null +++ b/src/client/ui.h @@ -0,0 +1,13 @@ +#ifndef UI_H +#define UI_H + +#include +#include +#include + +void ui_init(); + + +void ui_free(); + +#endif diff --git a/src/main.c b/src/main.c index 8f05909..907073e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,5 @@ -#include -#include "common.h" -#include "sock.h" -#include "client.h" -#include "server.h" +#include "client/client.h" +#include "server/server.h" int main(int argc, char **argv) { if(argc == 2 && strcmp(argv[1], "server") == 0) { diff --git a/src/server.c b/src/server/server.c similarity index 91% rename from src/server.c rename to src/server/server.c index 1287e00..e408606 100644 --- a/src/server.c +++ b/src/server/server.c @@ -4,6 +4,9 @@ void server() { socket_t *sock = sock_server_init("6770"); sock_start(sock); + sock_set_timeout(sock, 0, 1); + + printf("awaiting connection...\r\n"); socket_t *conn = sock_accept(sock); @@ -18,3 +21,4 @@ void server() { sock_stop(sock); sock_free(sock); } + diff --git a/src/server.h b/src/server/server.h similarity index 100% rename from src/server.h rename to src/server/server.h diff --git a/src/sock.h b/src/sock.h index 116b8b9..984a5c7 100644 --- a/src/sock.h +++ b/src/sock.h @@ -14,6 +14,7 @@ #include #include "common.h" +#define SOCK_SUCCESS 0 #define SOCK_ERR_GETADDRINFO -1 #define SOCK_ERR_SOCKET -2 #define SOCK_ERR_BIND -3 diff --git a/src/stack.h b/src/stack.h new file mode 100644 index 0000000..af4c5da --- /dev/null +++ b/src/stack.h @@ -0,0 +1,13 @@ +#ifndef STACK_H +#define STACK_H + +struct stack_node_t { + +}; + +typedef struct stack_t stack_t; +struct stack_t { + +}; + +#endif