THE ORIGINAL TOP THE TATER SOUR CREAM DIP

This commit is contained in:
mallocnull 2017-11-10 16:07:14 -06:00
parent e3171c9494
commit 5e3fb97a12
10 changed files with 104 additions and 23 deletions

BIN
core

Binary file not shown.

View file

@ -167,8 +167,8 @@ void create_account() {
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(40, "test of a prompt box of a prompt box of a prompt box of a prompt\n \nbox of a prompt box of a prompt box\n \nthis is a test of a prompt box", 3,
"testtesttesttesttesttesttest a", "test b", "test c");
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");
/*int a = 0;
while(a != KEY_LF)

View file

@ -4,6 +4,7 @@
#include <stdio.h>
#include <locale.h>
#include <ncurses.h>
#include "common.h"
#include "sock.h"
#include "packet.h"
#include "screen.h"

View file

@ -7,6 +7,8 @@
#define WORK
#define MAHOU_PORT "6770"
#define FALSE 0
#define TRUE 1
#define BOOL char

View file

@ -149,6 +149,12 @@ void* list_remove_back(list_t *list) {
return list_remove(list, list->size - 1);
}
void list_remove_item(list_t *list, void *item) {
int pos;
if((pos = list_find(list, item)) != -1)
list_remove(list, pos);
}
void list_iter_reset(list_t *list) {
list->iterator = NULL;
list->iter_prev = NULL;

View file

@ -40,6 +40,7 @@ int list_func_find(list_t*, listfindfptr);
void* list_remove(list_t*, int);
void* list_remove_front(list_t*);
void* list_remove_back(list_t*);
void* list_remove_item(list_t*, void*);
void list_iter_reset(list_t*);
void* list_iter_next(list_t*);

View file

@ -4,6 +4,12 @@
#include "server/server.h"
int main(int argc, char **argv) {
uint8_t spawn_type =
argc == 2 && strcmp(argv[1], "server") == 0
? SPAWN_SERVER
: SPAWN_CLIENT;
register_spawn_type(spawn_type);
packet_context_init(5);
packet_context_register(PCK_CTX_C2S, PCK_ID_CLERIC_REQ, 0, 1, 1);
@ -17,14 +23,13 @@ int main(int argc, char **argv) {
packet_context_register(PCK_CTX_S2C, PCK_ID_ALERT, 0, 4, 1, 1, 2, 512);
packet_context_register(PCK_CTX_S2C, PCK_ID_PROMPT_BOOL, 0, 4, 1, 1, 2, 512);
packet_context_register(PCK_CTX_S2C, PCK_ID_PROMPT_STR, 0, 5, 1, 1, 2, 512, 1);
packet_context_register(PCK_CTX_S2C, PCK_ID_PROMPT_LIST, 0, 6, 1, 1, 2, 512, 1, 256);
packet_context_register(PCK_CTX_S2C, PCK_ID_PROMPT_LIST, 5, 6, 1, 1, 2, 512, 2, 256);
packet_context_register(PCK_CTX_S2C, PCK_ID_CHANGE_CTX, 0, 1, 2);
if(argc == 2 && strcmp(argv[1], "server") == 0) {
register_spawn_type(SPAWN_SERVER);
if(spawn_type == SPAWN_SERVER)
server();
} else {
register_spawn_type(SPAWN_CLIENT);
else
client();
}
return 0;
}

View file

@ -1,6 +1,9 @@
#include "server.h"
void server() {
BOOL running = TRUE;
socket_t *conn;
user_context_init();
server_context_start();
@ -9,15 +12,33 @@ void server() {
sock_set_nonblocking(sock);
flimit_t vsync;
for(;;) {
while(running) {
frame_limit_tick(&vsync);
for(;;) {
conn = sock_accept(sock);
if(conn == NULL)
break;
else if(conn == -1) {
running = FALSE;
break;
} else {
}
}
frame_limit_wait(&vsync, 1000);
}
server_context_stop();
user_context_free();
printf("awaiting connection...\r\n");
sock_stop(sock);
sock_free(sock);
/*printf("awaiting connection...\r\n");
socket_t *conn = sock_accept(sock);
printf("connected\r\n");
@ -26,11 +47,5 @@ void server() {
char in[10];
sock_recv(conn, in, 10);
printf("got %s\r\n", in);
server_context_stop();
user_context_free();
sock_stop(sock);
sock_free(sock);
printf("got %s\r\n", in);*/
}

View file

@ -1,11 +1,13 @@
#include "user.h"
struct {
pthread_mutex_t mx_ctx;
list_t *active_users;
user_t **users;
} static ctx;
void user_context_init() {
ctx.mx_ctx = PTHREAD_MUTEX_INITIALIZER;
ctx.active_users = list_init();
ctx.users = (user_t**)malloc(MAX_CONNS * sizeof(user_t*));
@ -14,6 +16,26 @@ void user_context_init() {
ctx.users[i] = NULL;
}
BOOL user_context_add(socket_t *sock) {
int i;
for(i = 0; i < MAX_CONNS && ctx.users[i] != NULL; ++i);
if(i >= MAX_CONNS)
return FALSE;
}
void user_context_remove(user_t *user) {
if(user_check_flag(user, USER_FLAG_DELETING))
return;
pthread_mutex_lock(&user->mx_user);
user->flags |= USER_FLAG_DELETING;
list_remove_item(ctx.active_users, user);
users[user->user_id] = NULL;
}
void user_context_free() {
list_free(ctx.active_users);
@ -22,4 +44,26 @@ void user_context_free() {
free(ctx.users[i]);
free(ctx.users);
}
user_t* user_init(socket_t *sock) {
user_t *user = (user_t*)malloc(sizeof(user_t));
user->mx_user = PTHREAD_MUTEX_INITIALIZER;
return user;
}
void user_free(user_t *user) {
packet_t *pck = NULL;
while((pck = (packet_t*)queue_pop(user->in_packets) != NULL)
packet_free(pck);
queue_free(user->in_packets);
while((pck = (packet_t*)queue_pop(user->out_packets) != NULL)
packet_free(pck);
queue_free(user->out_packets);
free(user);
}

View file

@ -3,28 +3,35 @@
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>
#include "list.h"
#include "queue.h"
#include "sock.h"
#include "common.h"
#define USER_FLAG_LOGGED 1
#define USER_FLAG_DELETING 2
typedef struct user_t user_t;
struct user_t {
queue_t *in_packets;
pthread_mutex_t mx_in_packets;
pthread_mutex_t mx_user;
queue_t *in_packets;
queue_t *out_packets;
pthread_mutex_t mx_out_packets;
socket_t *sock;
uint64_t flags;
uint16_t user_id, context_id;
uint16_t x, y;
};
void user_context_init();
void user_context_add(user_t*);
void user_context_remove(user_t*);
void user_context_free();
user_t* user_init(socket_t*);
BOOL user_check_flag(user_t*, uint64_t);
void user_free(user_t*);
#endif