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
byte the one: 0xAD
byte the two: packet id
byte the 3-6: total body length - uint
b. 0: 0xDE
b. 1: 0xAD
b. 2: packet id
b.3-6: total body length - uint
byte the bytes after the header octet bytes bytes:
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
id 0: clerical request
r.0 - clerical id - byte
r.1 - action - byte
| start - 0
| stop - 1
id 1: alert prompt response
r.0 - clerical id - byte

View file

@ -92,7 +92,7 @@ static int main_menu() {
erase();
noecho();
cbreak();
raw();
#ifdef WORK
attron(SCR_PAIR(SCR_WHITE, SCR_BLACK) | A_BOLD);
@ -165,10 +165,11 @@ void create_account() {
packet_free(pck);
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);
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,
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,
"Now turn to the left!", "Now turn to the right!", "Uh oh");
for(;;);
/*int a = 0;
while(a != KEY_LF)

View file

@ -1,5 +1,9 @@
#include "screen.h"
struct {
uint8_t loading_progress;
} static ctx;
void scr_ctx_init() {
short i, j, val;
short colors[] = {COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
@ -110,10 +114,45 @@ static int calculate_height(int width, char *text) {
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) {
erase();
noecho();
cbreak();
raw();
short pair;
WINDOW *win;
@ -147,14 +186,14 @@ void scr_alert(int width, char *text) {
delwin(win);
}
BOOL scr_prompt(int width, char *text) {
BOOL scr_prompt(BOOL cancelable, int width, char *text) {
erase();
noecho();
cbreak();
raw();
int ch;
short pair;
BOOL retval = TRUE, loop = TRUE;
BOOL retval = TRUE, loop = TRUE, canceled = FALSE;
char check[] = "[ \u2714 ]";
char cross[] = "[ \u2718 ]";
WINDOW *win;
@ -171,7 +210,7 @@ BOOL scr_prompt(int width, char *text) {
attron(pair);
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));
wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
@ -179,6 +218,18 @@ BOOL scr_prompt(int width, char *text) {
wrefresh(win);
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) {
wmove(win, text_height + 1, (width - 12) / 2);
@ -204,6 +255,7 @@ BOOL scr_prompt(int width, char *text) {
scr_hide_cursor();
ch = getch();
printw("%i", ch);
switch(ch) {
case KEY_LEFT:
retval = TRUE;
@ -215,19 +267,24 @@ BOOL scr_prompt(int width, char *text) {
case KEY_ENTER:
loop = FALSE;
break;
case KEY_CC:
if(cancelable)
loop = !(canceled = TRUE);
break;
}
}
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();
noecho();
cbreak();
raw();
int ch, curlen = 0, i, origin;
BOOL canceled = FALSE;
short pair;
WINDOW *win;
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(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));
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);
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';
for(;;) {
origin = (width - (outlen + 3)) / 2;
@ -284,19 +347,24 @@ void scr_prompt_string(int width, char *text, char *out, int outlen) {
out[curlen] = '\0';
} else if(ch == KEY_LF || ch == KEY_ENTER)
break;
else if(ch == KEY_CC && cancelable) {
canceled = TRUE;
break;
}
}
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();
noecho();
cbreak();
raw();
int ch, selected = 0, i, origin, maxlen = 0;
short pair;
BOOL loop = TRUE;
BOOL loop = TRUE, canceled = FALSE;
WINDOW *win;
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(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));
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));
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) {
for(i = 0; i < optcount; ++i) {
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:
loop = FALSE;
break;
case KEY_CC:
if(cancelable)
loop = !(canceled = TRUE);
break;
}
}
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;
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*);
va_end(args);
retval = scr_prompt_options(width, text, options, optcount);
retval = scr_prompt_options(cancelable, width, text, options, optcount);
free(options);
return retval;
}

View file

@ -33,10 +33,15 @@ void scr_center_write(char*, int, int);
void scr_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*);
BOOL scr_prompt(int, char*);
void scr_prompt_string(int, char*, char*, int);
int scr_prompt_options(int, char*, char**, int);
int scr_prompt_voptions(int, char*, int, ...);
BOOL scr_prompt(BOOL, int, char*);
int scr_prompt_string(BOOL, int, char*, char*, int);
int scr_prompt_options(BOOL, int, char*, char**, int);
int scr_prompt_voptions(BOOL, int, char*, int, ...);
#endif

View file

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

View file

@ -26,7 +26,29 @@ const char* _SKILL_NAMES_SHORT[] = {
"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 {
pthread_mutex_t mx_ctx;
@ -88,9 +110,9 @@ void user_context_purge() {
user_t *ptr;
list_iter_reset(ctx.pending_removals);
while((ptr = list_iter_next(ctx.pending_removals)) != NULL) {
list_remove_item(ctx.active_users, user);
ctx.users[user->user_id] = NULL;
user_free(user);
list_remove_item(ctx.active_users, ptr);
ctx.users[ptr->user_id] = NULL;
user_free(ptr);
list_iter_remove(ctx.pending_removals);
}
@ -132,12 +154,32 @@ BOOL user_check_flag(user_t *user, uint64_t flag) {
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);
queue_push(user->in_packets, packet);
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) {
if(user == NULL)
return;

View file

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