DAYS WITHOUT JEWISH TRICKS: 0

This commit is contained in:
mallocnull 2017-11-22 16:25:51 -06:00
parent 1a3eaf7133
commit 8f394ab34b
8 changed files with 171 additions and 41 deletions

BIN
core

Binary file not shown.

View file

@ -12,10 +12,10 @@ region n is r.n
--- ---
byte the zero: 0xDE b. 0: 0xDE
byte the one: 0xAD b. 1: 0xAD
byte the two: packet id b. 2: packet id
byte the 3-6: total body length - uint b.3-6: total body length - uint
byte the bytes after the header octet bytes bytes: byte the bytes after the header octet bytes bytes:
raw body data shoved next to each other with no separation raw body data shoved next to each other with no separation
@ -25,6 +25,9 @@ byte the bytes after the header octet bytes bytes:
client -> server client -> server
id 0: clerical request id 0: clerical request
r.0 - clerical id - byte r.0 - clerical id - byte
r.1 - action - byte
| start - 0
| stop - 1
id 1: alert prompt response id 1: alert prompt response
r.0 - clerical id - byte r.0 - clerical id - byte

View file

@ -92,7 +92,7 @@ static int main_menu() {
erase(); erase();
noecho(); noecho();
cbreak(); raw();
#ifdef WORK #ifdef WORK
attron(SCR_PAIR(SCR_WHITE, SCR_BLACK) | A_BOLD); attron(SCR_PAIR(SCR_WHITE, SCR_BLACK) | A_BOLD);
@ -165,11 +165,12 @@ void create_account() {
packet_free(pck); packet_free(pck);
char input[9]; char input[9];
//scr_prompt_string(20, "this prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test", input, 8); int a = //scr_prompt_string(TRUE, 20, "this prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test", input, 8);
scr_prompt_voptions(TRUE, 30, "I'm glad you know which way to go, but that ain't gunna stop me, here we go!\n \nCheck and turn the signals to the left.\n \nNow turn to the left.", 3,
scr_prompt_voptions(30, "I'm glad you know which way to go, but that ain't gunna stop me, here we go!\n \nCheck and turn the signals to the left.\n \nNow turn to the left.", 3,
"Now turn to the left!", "Now turn to the right!", "Uh oh"); "Now turn to the left!", "Now turn to the right!", "Uh oh");
for(;;);
/*int a = 0; /*int a = 0;
while(a != KEY_LF) while(a != KEY_LF)
printw("%i ", (a = getch()));*/ printw("%i ", (a = getch()));*/

View file

@ -1,5 +1,9 @@
#include "screen.h" #include "screen.h"
struct {
uint8_t loading_progress;
} static ctx;
void scr_ctx_init() { void scr_ctx_init() {
short i, j, val; short i, j, val;
short colors[] = {COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN, short colors[] = {COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
@ -110,10 +114,45 @@ static int calculate_height(int width, char *text) {
return lines; return lines;
} }
void scr_loading(int width, char *text) {
erase();
WINDOW *win;
int text_height = calculate_height(width, text);
#ifdef WORK
pair = SCR_PAIR(SCR_WHITE, SCR_BLACK);
#else
pair = SCR_PAIR(SCR_WHITE, SCR_BLUE);
#endif
attron(pair);
scr_fill();
attron(pair);
attron(SCR_PAIR(SCR_WHITE, SCR_BLACK));
win = scr_win_box(1, (COLS - (width + 2)) / 2, width + 2, text_height + 2);
attron(SCR_PAIR(SCR_WHITE, SCR_BLACK));
wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
wprintw(win, text);
wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
delwin(win);
scr_hide_cursor();
}
void scr_loading_bar(int width, char *text) {
erase();
ctx.loading_progress = 0;
}
void scr_alert(int width, char *text) { void scr_alert(int width, char *text) {
erase(); erase();
noecho(); noecho();
cbreak(); raw();
short pair; short pair;
WINDOW *win; WINDOW *win;
@ -147,14 +186,14 @@ void scr_alert(int width, char *text) {
delwin(win); delwin(win);
} }
BOOL scr_prompt(int width, char *text) { BOOL scr_prompt(BOOL cancelable, int width, char *text) {
erase(); erase();
noecho(); noecho();
cbreak(); raw();
int ch; int ch;
short pair; short pair;
BOOL retval = TRUE, loop = TRUE; BOOL retval = TRUE, loop = TRUE, canceled = FALSE;
char check[] = "[ \u2714 ]"; char check[] = "[ \u2714 ]";
char cross[] = "[ \u2718 ]"; char cross[] = "[ \u2718 ]";
WINDOW *win; WINDOW *win;
@ -171,7 +210,7 @@ BOOL scr_prompt(int width, char *text) {
attron(pair); attron(pair);
attron(SCR_PAIR(SCR_WHITE, SCR_BLACK)); attron(SCR_PAIR(SCR_WHITE, SCR_BLACK));
win = scr_win_box(1, (COLS - (width + 2)) / 2, width + 2, text_height + 4); win = scr_win_box(1, (COLS - (width + 2)) / 2, width + 2, text_height + 5);
attron(SCR_PAIR(SCR_WHITE, SCR_BLACK)); attron(SCR_PAIR(SCR_WHITE, SCR_BLACK));
wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
@ -179,6 +218,18 @@ BOOL scr_prompt(int width, char *text) {
wrefresh(win); wrefresh(win);
wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
#ifdef WORK
pair = SCR_PAIR(SCR_WHITE, SCR_BLACK);
#else
pair = SCR_PAIR(SCR_WHITE, SCR_BLUE);
#endif
if(cancelable) {
attron(SCR_PAIR(SCR_BLACK, SCR_WHITE));
scr_center_write("PRESS ^C TO CANCEL", 0, text_height + 5);
attroff(SCR_PAIR(SCR_BLACK, SCR_WHITE));
}
while(loop) { while(loop) {
wmove(win, text_height + 1, (width - 12) / 2); wmove(win, text_height + 1, (width - 12) / 2);
@ -204,6 +255,7 @@ BOOL scr_prompt(int width, char *text) {
scr_hide_cursor(); scr_hide_cursor();
ch = getch(); ch = getch();
printw("%i", ch);
switch(ch) { switch(ch) {
case KEY_LEFT: case KEY_LEFT:
retval = TRUE; retval = TRUE;
@ -215,19 +267,24 @@ BOOL scr_prompt(int width, char *text) {
case KEY_ENTER: case KEY_ENTER:
loop = FALSE; loop = FALSE;
break; break;
case KEY_CC:
if(cancelable)
loop = !(canceled = TRUE);
break;
} }
} }
delwin(win); delwin(win);
return retval; return canceled ? -1 : retval;
} }
void scr_prompt_string(int width, char *text, char *out, int outlen) { int scr_prompt_string(BOOL cancelable, int width, char *text, char *out, int outlen) {
erase(); erase();
noecho(); noecho();
cbreak(); raw();
int ch, curlen = 0, i, origin; int ch, curlen = 0, i, origin;
BOOL canceled = FALSE;
short pair; short pair;
WINDOW *win; WINDOW *win;
int text_height = calculate_height(width, text); int text_height = calculate_height(width, text);
@ -243,7 +300,7 @@ void scr_prompt_string(int width, char *text, char *out, int outlen) {
attron(pair); attron(pair);
attron(SCR_PAIR(SCR_WHITE, SCR_BLACK)); attron(SCR_PAIR(SCR_WHITE, SCR_BLACK));
win = scr_win_box(1, (COLS - (width + 2)) / 2, width + 2, text_height + 4); win = scr_win_box(1, (COLS - (width + 2)) / 2, width + 2, text_height + 5);
attroff(SCR_PAIR(SCR_WHITE, SCR_BLACK)); attroff(SCR_PAIR(SCR_WHITE, SCR_BLACK));
wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
@ -251,6 +308,12 @@ void scr_prompt_string(int width, char *text, char *out, int outlen) {
wrefresh(win); wrefresh(win);
wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
if(cancelable) {
attron(SCR_PAIR(SCR_BLACK, SCR_WHITE));
scr_center_write("PRESS ^C TO CANCEL", 0, text_height + 5);
attroff(SCR_PAIR(SCR_BLACK, SCR_WHITE));
}
out[0] = '\0'; out[0] = '\0';
for(;;) { for(;;) {
origin = (width - (outlen + 3)) / 2; origin = (width - (outlen + 3)) / 2;
@ -284,19 +347,24 @@ void scr_prompt_string(int width, char *text, char *out, int outlen) {
out[curlen] = '\0'; out[curlen] = '\0';
} else if(ch == KEY_LF || ch == KEY_ENTER) } else if(ch == KEY_LF || ch == KEY_ENTER)
break; break;
else if(ch == KEY_CC && cancelable) {
canceled = TRUE;
break;
}
} }
delwin(win); delwin(win);
return canceled ? -1 : curlen;
} }
int scr_prompt_options(int width, char *text, char **options, int optcount) { int scr_prompt_options(BOOL cancelable, int width, char *text, char **options, int optcount) {
erase(); erase();
noecho(); noecho();
cbreak(); raw();
int ch, selected = 0, i, origin, maxlen = 0; int ch, selected = 0, i, origin, maxlen = 0;
short pair; short pair;
BOOL loop = TRUE; BOOL loop = TRUE, canceled = FALSE;
WINDOW *win; WINDOW *win;
int text_height = calculate_height(width, text); int text_height = calculate_height(width, text);
@ -311,7 +379,7 @@ int scr_prompt_options(int width, char *text, char **options, int optcount) {
attron(pair); attron(pair);
attron(SCR_PAIR(SCR_WHITE, SCR_BLACK)); attron(SCR_PAIR(SCR_WHITE, SCR_BLACK));
win = scr_win_box(1, (COLS - (width + 2)) / 2, width + 2, text_height + 3 + optcount); win = scr_win_box(1, (COLS - (width + 2)) / 2, width + 2, text_height + 4 + optcount);
attroff(SCR_PAIR(SCR_WHITE, SCR_BLACK)); attroff(SCR_PAIR(SCR_WHITE, SCR_BLACK));
wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
@ -323,6 +391,12 @@ int scr_prompt_options(int width, char *text, char **options, int optcount) {
maxlen = MIN(width, MAX(maxlen, strlen(options[i]) + 3)); maxlen = MIN(width, MAX(maxlen, strlen(options[i]) + 3));
origin = (width - maxlen) / 2; origin = (width - maxlen) / 2;
if(cancelable) {
attron(SCR_PAIR(SCR_BLACK, SCR_WHITE));
scr_center_write("PRESS ^C TO CANCEL", 0, text_height + 4 + optcount);
attroff(SCR_PAIR(SCR_BLACK, SCR_WHITE));
}
while(loop) { while(loop) {
for(i = 0; i < optcount; ++i) { for(i = 0; i < optcount; ++i) {
pair = i == selected ? SCR_PAIR(SCR_BLACK, SCR_CYAN) pair = i == selected ? SCR_PAIR(SCR_BLACK, SCR_CYAN)
@ -350,14 +424,18 @@ int scr_prompt_options(int width, char *text, char **options, int optcount) {
case KEY_ENTER: case KEY_ENTER:
loop = FALSE; loop = FALSE;
break; break;
case KEY_CC:
if(cancelable)
loop = !(canceled = TRUE);
break;
} }
} }
delwin(win); delwin(win);
return selected; return canceled ? -1 : selected;
} }
int scr_prompt_voptions(int width, char *text, int optcount, ...) { int scr_prompt_voptions(BOOL cancelable, int width, char *text, int optcount, ...) {
int retval, i; int retval, i;
char **options = (char**)malloc(optcount * sizeof(char*)); char **options = (char**)malloc(optcount * sizeof(char*));
@ -367,7 +445,7 @@ int scr_prompt_voptions(int width, char *text, int optcount, ...) {
options[i] = va_arg(args, char*); options[i] = va_arg(args, char*);
va_end(args); va_end(args);
retval = scr_prompt_options(width, text, options, optcount); retval = scr_prompt_options(cancelable, width, text, options, optcount);
free(options); free(options);
return retval; return retval;
} }

View file

@ -33,10 +33,15 @@ void scr_center_write(char*, int, int);
void scr_box(int, int, int, int); void scr_box(int, int, int, int);
WINDOW* scr_win_box(int, int, int, int); WINDOW* scr_win_box(int, int, int, int);
void scr_loading(int, char*);
void scr_loading_bar(int, char*);
void scr_loading_bar_set(uint8_t);
void scr_loading_bar_close();
void scr_alert(int, char*); void scr_alert(int, char*);
BOOL scr_prompt(int, char*); BOOL scr_prompt(BOOL, int, char*);
void scr_prompt_string(int, char*, char*, int); int scr_prompt_string(BOOL, int, char*, char*, int);
int scr_prompt_options(int, char*, char**, int); int scr_prompt_options(BOOL, int, char*, char**, int);
int scr_prompt_voptions(int, char*, int, ...); int scr_prompt_voptions(BOOL, int, char*, int, ...);
#endif #endif

View file

@ -16,6 +16,7 @@
#define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
#define KEY_CC 3
#define KEY_BS 8 #define KEY_BS 8
#define KEY_TAB 9 #define KEY_TAB 9
#define KEY_LF 10 #define KEY_LF 10

View file

@ -26,7 +26,29 @@ const char* _SKILL_NAMES_SHORT[] = {
"COOK" "COOK"
}; };
const char * OFINISH THESE GI const char* _STAT_NAMES[] = {
"Strength",
"Health",
"Defense",
"Agility",
"Intellect",
"Wisdom",
"Charisma",
"Perception",
"Luck"
};
const char* _STAT_NAMES_SHORT[] = {
"STR",
"HP",
"DEF",
"AGIL",
"INT",
"WIS",
"CHAR",
"PCPT",
"LUCK"
};
struct { struct {
pthread_mutex_t mx_ctx; pthread_mutex_t mx_ctx;
@ -88,9 +110,9 @@ void user_context_purge() {
user_t *ptr; user_t *ptr;
list_iter_reset(ctx.pending_removals); list_iter_reset(ctx.pending_removals);
while((ptr = list_iter_next(ctx.pending_removals)) != NULL) { while((ptr = list_iter_next(ctx.pending_removals)) != NULL) {
list_remove_item(ctx.active_users, user); list_remove_item(ctx.active_users, ptr);
ctx.users[user->user_id] = NULL; ctx.users[ptr->user_id] = NULL;
user_free(user); user_free(ptr);
list_iter_remove(ctx.pending_removals); list_iter_remove(ctx.pending_removals);
} }
@ -132,12 +154,32 @@ BOOL user_check_flag(user_t *user, uint64_t flag) {
return retval; return retval;
} }
void user_push_in_packet(user_t *user) { void user_push_in_packet(user_t *user, packet_t *packet) {
pthread_mutex_lock(&user->mx_user); pthread_mutex_lock(&user->mx_user);
queue_push(user->in_packets, packet);
pthread_mutex_unlock(&user->mx_user); pthread_mutex_unlock(&user->mx_user);
} }
void user_push_out_packet(user_t *user, packet_t *packet) {
pthread_mutex_lock(&user->mx_user);
queue_push(user->out_packets, packet);
pthread_mutex_unlock(&user->mx_user);
}
packet_t* user_pop_in_packet(user_t *user) {
pthread_mutex_lock(&user->mx_user);
packet_t *packet = queue_pop(user->in_packets);
pthread_mutex_unlock(&user->mx_user);
return packet;
}
packet_t* user_pop_out_packet(user_t *user) {
pthread_mutex_lock(&user->mx_user);
packet_t *packet = queue_pop(user->out_packets);
pthread_mutex_unlock(&user->mx_user);
return packet;
}
static void user_free(user_t *user) { static void user_free(user_t *user) {
if(user == NULL) if(user == NULL)
return; return;

View file

@ -15,7 +15,7 @@
#define USER_GENDER_FEMALE 1 #define USER_GENDER_FEMALE 1
#define USER_FLAG_POISONED 2 #define USER_FLAG_POISONED 2
#define SKILLS_COUNT 5 #define SKILLS_COUNT 10
#define SKILL_MELEE 0 #define SKILL_MELEE 0
#define SKILL_RANGED 1 #define SKILL_RANGED 1
#define SKILL_WHMAGIC 2 #define SKILL_WHMAGIC 2
@ -35,7 +35,7 @@
#define STAT_INTELLECT 4 #define STAT_INTELLECT 4
#define STAT_WISDOM 5 #define STAT_WISDOM 5
#define STAT_CHARISMA 6 #define STAT_CHARISMA 6
#define STAT_ #define STAT_PERCEPT 7
#define STAT_LUCK 8 #define STAT_LUCK 8
extern const char* _SKILL_NAMES[]; extern const char* _SKILL_NAMES[];
@ -73,8 +73,8 @@ void user_context_purge(void);
void user_context_free(void); void user_context_free(void);
BOOL user_check_flag(user_t*, uint64_t); BOOL user_check_flag(user_t*, uint64_t);
void user_push_in_packet(user_t*); void user_push_in_packet(user_t*, packet_t*);
void user_push_out_packet(user_t*); void user_push_out_packet(user_t*, packet_t*);
packet_t* user_pop_in_packet(user_t*); packet_t* user_pop_in_packet(user_t*);
packet_t* user_pop_out_packet(user_t*); packet_t* user_pop_out_packet(user_t*);