stack more like attack the japs

This commit is contained in:
mallocnull 2017-10-04 21:01:23 +00:00
parent b6312df730
commit bc5aff1a56
13 changed files with 127 additions and 26 deletions

2
debug
View file

@ -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 chmod +x bin/mahou

View file

@ -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 chmod +x bin/mahou

View file

@ -11,28 +11,40 @@ char BANNER[BANNER_HEIGHT][BANNER_WIDTH + 1] = {
"MMM M' \"MMMYMM \"\"` MMM YMM \"YMMMMMP\" \"YmmMMMM\"\"" "MMM M' \"MMMYMM \"\"` MMM YMM \"YMMMMMP\" \"YmmMMMM\"\""
}; };
#define MM_OPT_COUNT 3 #define MM_OPT_COUNT 4
#define MM_MAX_OPT_LEN 11 #define MM_MAX_OPT_LEN 15
char MM_OPTIONS[MM_OPT_COUNT][MM_MAX_OPT_LEN + 1] = { char MM_OPTIONS[MM_OPT_COUNT][MM_MAX_OPT_LEN + 1] = {
"Join Game", "Join Game",
"Create Account",
"How to Play", "How to Play",
"Quit" "Quit"
}; };
#define MM_OPT_JOIN 0 #define MM_OPT_JOIN 0
#define MM_OPT_HOW 1 #define MM_OPT_REG 1
#define MM_OPT_QUIT 2 #define MM_OPT_HOW 2
#define MM_OPT_QUIT 3
struct { struct {
socket_t *sock; socket_t *sock;
} client_ctx; } client_ctx;
static void hide_cursor();
static int main_menu(); static int main_menu();
static void how_to_play(); static void how_to_play();
static void create_account();
static void client_loop();
void client() { void client() {
int selected; int selected, err;
BOOL running = TRUE; 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(); initscr();
@ -44,7 +56,10 @@ void client() {
switch(selected) { switch(selected) {
case MM_OPT_JOIN: case MM_OPT_JOIN:
client_loop();
break;
case MM_OPT_REG:
create_account();
break; break;
case MM_OPT_HOW: case MM_OPT_HOW:
how_to_play(); how_to_play();
@ -68,10 +83,6 @@ void client() {
sock_free(sock);*/ sock_free(sock);*/
} }
static void hide_cursor() {
move(LINES - 1, COLS - 1);
}
static int main_menu() { static int main_menu() {
BOOL polling = TRUE; BOOL polling = TRUE;
int i, j, selected = 0, color, ch; int i, j, selected = 0, color, ch;
@ -85,11 +96,8 @@ static int main_menu() {
init_pair(2, COLOR_BLACK, COLOR_CYAN); init_pair(2, COLOR_BLACK, COLOR_CYAN);
attron(COLOR_PAIR(1) | A_BOLD); attron(COLOR_PAIR(1) | A_BOLD);
for(i = 0; i < LINES; ++i) scr_fill();
for(j = 0; j < COLS; ++j)
addch(' ');
for(i = 0; i < BANNER_HEIGHT; ++i) for(i = 0; i < BANNER_HEIGHT; ++i)
mvprintw(3 + i, (COLS - BANNER_WIDTH) / 2, BANNER[i]); mvprintw(3 + i, (COLS - BANNER_WIDTH) / 2, BANNER[i]);
@ -107,7 +115,7 @@ static int main_menu() {
refresh(); refresh();
hide_cursor(); scr_hide_cursor();
ch = getch(); ch = getch();
switch(ch) { switch(ch) {
case KEY_UP: case KEY_UP:
@ -130,10 +138,17 @@ void how_to_play() {
WINDOW *win; WINDOW *win;
win = newwin(10, 10, 4, 4); win = newwin(10, 10, 4, 4);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+'); wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
mvwprintw(win, 1, 1, "test"); mvwprintw(win, 1, 1, "to do: write this garbage");
wrefresh(win); wrefresh(win);
hide_cursor(); scr_hide_cursor();
getch(); getch();
delwin(win);
} }
void create_account() {
}
void client_loop() {
}

View file

@ -4,6 +4,8 @@
#include <stdio.h> #include <stdio.h>
#include <ncurses.h> #include <ncurses.h>
#include "sock.h" #include "sock.h"
#include "screen.h"
#include "ui.h"
void client(); void client();

16
src/client/screen.c Normal file
View file

@ -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);
}

11
src/client/screen.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef SCREEN_H
#define SCREEN_H
#include <ncurses.h>
#include <stdlib.h>
void scr_fill();
void scr_char_fill(char);
void scr_hide_cursor();
#endif

29
src/client/ui.c Normal file
View file

@ -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() {
}

13
src/client/ui.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef UI_H
#define UI_H
#include <ncurses.h>
#include <stdlib.h>
#include <stdint.h>
void ui_init();
void ui_free();
#endif

View file

@ -1,8 +1,5 @@
#include <stdio.h> #include "client/client.h"
#include "common.h" #include "server/server.h"
#include "sock.h"
#include "client.h"
#include "server.h"
int main(int argc, char **argv) { int main(int argc, char **argv) {
if(argc == 2 && strcmp(argv[1], "server") == 0) { if(argc == 2 && strcmp(argv[1], "server") == 0) {

View file

@ -4,6 +4,9 @@ void server() {
socket_t *sock = sock_server_init("6770"); socket_t *sock = sock_server_init("6770");
sock_start(sock); sock_start(sock);
sock_set_timeout(sock, 0, 1);
printf("awaiting connection...\r\n"); printf("awaiting connection...\r\n");
socket_t *conn = sock_accept(sock); socket_t *conn = sock_accept(sock);
@ -18,3 +21,4 @@ void server() {
sock_stop(sock); sock_stop(sock);
sock_free(sock); sock_free(sock);
} }

View file

@ -14,6 +14,7 @@
#include <errno.h> #include <errno.h>
#include "common.h" #include "common.h"
#define SOCK_SUCCESS 0
#define SOCK_ERR_GETADDRINFO -1 #define SOCK_ERR_GETADDRINFO -1
#define SOCK_ERR_SOCKET -2 #define SOCK_ERR_SOCKET -2
#define SOCK_ERR_BIND -3 #define SOCK_ERR_BIND -3

13
src/stack.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef STACK_H
#define STACK_H
struct stack_node_t {
};
typedef struct stack_t stack_t;
struct stack_t {
};
#endif