HOLY SHIT SKILLS WOWOWOWOWOWOW

This commit is contained in:
mallocnull 2017-11-14 16:59:51 -06:00
parent b0e6c58c14
commit f1b13b2a2f
27 changed files with 217 additions and 23 deletions

2
debug
View file

@ -1,2 +1,2 @@
gcc src/*.c src/server/*.c src/client/*.c -g -iquotesrc/ -lpthread -lncursesw -lm -o bin/mahou gcc src/*.c src/util/etc/*.c src/util/file/*.c src/util/net/*.c src/util/types/*.c src/server/*.c src/client/*.c -g -iquotesrc/ -iquotesrc/util/ -lpthread -lncursesw -lm -o bin/mahou
chmod +x bin/mahou chmod +x bin/mahou

View file

@ -1,2 +1,2 @@
gcc src/*.c src/server/*.c src/client/*.c -iquotesrc/ -lpthread -lncursesw -lm -o bin/mahou gcc src/*.c src/util/etc/*.c src/util/file/*.c src/util/net/*.c src/util/types/*.c src/server/*.c src/client/*.c -iquotesrc/ -iquotesrc/util/ -lpthread -lncursesw -lm -o bin/mahou
chmod +x bin/mahou chmod +x bin/mahou

View file

@ -38,7 +38,7 @@ static void client_loop();
void client() { void client() {
int selected, err; int selected, err;
BOOL running = TRUE; BOOL running = TRUE;
ctx.sock = sock_client_init("127.0.0.1", "6770"); ctx.sock = sock_client_init("127.0.0.1", MAHOU_PORT);
printf("Connecting to server...\n"); printf("Connecting to server...\n");
err = sock_start(ctx.sock); err = sock_start(ctx.sock);

View file

@ -5,8 +5,8 @@
#include <locale.h> #include <locale.h>
#include <ncurses.h> #include <ncurses.h>
#include "common.h" #include "common.h"
#include "sock.h" #include "net/sock.h"
#include "packet.h" #include "net/packet.h"
#include "screen.h" #include "screen.h"
#include "ui.h" #include "ui.h"

View file

@ -1,7 +1,7 @@
#include "common.h" #include "common.h"
#include "packet.h"
#include "client/client.h" #include "client/client.h"
#include "server/server.h" #include "server/server.h"
#include "net/packet.h"
int main(int argc, char **argv) { int main(int argc, char **argv) {
uint8_t spawn_type = uint8_t spawn_type =

View file

@ -6,8 +6,11 @@ struct {
} static ctx; } static ctx;
void* server_context(void *params) { void* server_context(void *params) {
flimit_t vsync;
while(ctx.running == TRUE) { while(ctx.running == TRUE) {
frame_limit_tick(&vsync);
frame_limit_wait(&vsync, 60);
} }
return NULL; return NULL;

View file

@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <pthread.h> #include <pthread.h>
#include "common.h" #include "common.h"
#include "etc/flimit.h"
void server_context_start(void); void server_context_start(void);
void server_context_stop(void); void server_context_stop(void);

View file

@ -7,7 +7,7 @@ void server() {
user_context_init(); user_context_init();
server_context_start(); server_context_start();
socket_t *sock = sock_server_init("6770"); socket_t *sock = sock_server_init(MAHOU_PORT);
sock_start(sock); sock_start(sock);
sock_set_nonblocking(sock); sock_set_nonblocking(sock);

View file

@ -2,12 +2,12 @@
#define SERVER_H #define SERVER_H
#include <stdio.h> #include <stdio.h>
#include "net/sock.h"
#include "net/packet.h"
#include "types/queue.h"
#include "etc/flimit.h"
#include "context.h" #include "context.h"
#include "user.h" #include "user.h"
#include "sock.h"
#include "packet.h"
#include "queue.h"
#include "flimit.h"
void server(void); void server(void);

View file

@ -1,12 +1,21 @@
#include "user.h" #include "user.h"
const char* _SKILL_NAMES[] = {
"Bare-Handed",
"Melee",
"Ranged",
"White Magic",
"Black Magic",
"Firemaking"
};
struct { struct {
pthread_mutex_t mx_ctx; pthread_mutex_t mx_ctx;
list_t *active_users; list_t *active_users;
user_t **users; user_t **users;
} static ctx; } static ctx;
BOOL user_check_flag_nomx(user_t *user, uint64_t flag); static BOOL user_check_flag_nomx(user_t *user, uint64_t flag);
void user_context_init() { void user_context_init() {
pthread_mutex_init(&ctx.mx_ctx, NULL); pthread_mutex_init(&ctx.mx_ctx, NULL);
@ -37,10 +46,11 @@ BOOL user_context_add(socket_t *sock) {
} }
void user_context_remove(user_t *user) { void user_context_remove(user_t *user) {
pthread_mutex_lock(&ctx.mx_ctx); if(user_check_flag_nomx(user, USER_FLAG_DELETING))
if(user_check_flag(user, USER_FLAG_DELETING))
return; return;
pthread_mutex_lock(&ctx.mx_ctx);
pthread_mutex_lock(&user->mx_user); pthread_mutex_lock(&user->mx_user);
user->flags |= USER_FLAG_DELETING; user->flags |= USER_FLAG_DELETING;
list_remove_item(ctx.active_users, user); list_remove_item(ctx.active_users, user);
@ -80,9 +90,8 @@ BOOL user_check_flag_nomx(user_t *user, uint64_t flag) {
BOOL user_check_flag(user_t *user, uint64_t flag) { BOOL user_check_flag(user_t *user, uint64_t flag) {
BOOL retval;
pthread_mutex_lock(&user->mx_user); pthread_mutex_lock(&user->mx_user);
retval = user_check_flag_nomx(user, flag); BOOL retval = user_check_flag_nomx(user, flag);
pthread_mutex_unlock(&user->mx_user); pthread_mutex_unlock(&user->mx_user);
return retval; return retval;
} }

View file

@ -4,15 +4,26 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <pthread.h> #include <pthread.h>
#include "list.h" #include "types/list.h"
#include "queue.h" #include "types/queue.h"
#include "sock.h" #include "net/sock.h"
#include "packet.h" #include "net/packet.h"
#include "common.h" #include "common.h"
#define USER_FLAG_LOGGED 1 #define USER_FLAG_LOGGED 1
#define USER_FLAG_DELETING 2 #define USER_FLAG_DELETING 2
#define SKILL_COUNT 6
#define SKILL_BAREHANDS 0
#define SKILL_MELEE 1
#define SKILL_RANGED 2
#define SKILL_WHMAGIC 3
#define SKILL_BLMAGIC 4
#define SKILL_FIREMAKE 5
extern const char* _SKILL_NAMES[];
typedef struct user_t user_t; typedef struct user_t user_t;
struct user_t { struct user_t {
pthread_mutex_t mx_user; pthread_mutex_t mx_user;
@ -22,8 +33,15 @@ struct user_t {
socket_t *sock; socket_t *sock;
uint64_t flags; uint64_t flags;
uint16_t user_id, context_id; uint16_t user_id;
uint16_t x, y;
struct {
char name[9];
uint64_t flags;
uint16_t pin, x, y;
uint16_t context_id;
uint32_t skill_exp[SKILL_COUNT];
} data;
}; };
void user_context_init(void); void user_context_init(void);

116
src/util/file/bdat.c Normal file
View file

@ -0,0 +1,116 @@
#include "bdat.h"
bdat_t* bdat_open_read(char *file) {
bdat_t *bdat = (bdat_t*)malloc(sizeof(bdat_t));
bdat->fp = fopen(file, "rb");
bdat->mode = BDAT_MODE_READ;
return bdat;
}
bdat_t* bdat_open_write(char *file) {
bdat_t *bdat = (bdat_t*)malloc(sizeof(bdat_t));
bdat->fp = fopen(file, "wb+");
bdat->mode = BDAT_MODE_WRITE;
return bdat;
}
uint8_t bdat_get_mode(bdat_t *bdat) {
return bdat->mode;
}
void* bdat_get_raw(bdat_t *bdat, void *data, int length) {
if(bdat->mode != BDAT_MODE_READ)
return NULL;
fread(data, length, 1, bdat->fp);
}
uint8_t bdat_get_uint8(bdat_t *bdat) {
if(bdat->mode != BDAT_MODE_READ)
return 0;
uint8_t data;
fread(&data, 1, 1, bdat->fp);
return data;
}
uint16_t bdat_get_uint16(bdat_t *bdat) {
if(bdat->mode != BDAT_MODE_READ)
return 0;
uint16_t data;
fread(&data, sizeof(data), 1, bdat->fp);
return data;
}
uint32_t bdat_get_uint32(bdat_t *bdat) {
if(bdat->mode != BDAT_MODE_READ)
return 0;
uint32_t data;
fread(&data, sizeof(data), 1, bdat->fp);
return data;
}
uint64_t bdat_get_uint64(bdat_t *bdat) {
if(bdat->mode != BDAT_MODE_READ)
return 0;
uint64_t data;
fread(&data, sizeof(data), 1, bdat->fp);
return data;
}
float bdat_get_float(bdat_t *bdat) {
if(bdat->mode != BDAT_MODE_READ)
return 0;
float data;
fread(&data, sizeof(data), 1, bdat->fp);
return data;
}
double bdat_get_double(bdat_t *bdat) {
if(bdat->mode != BDAT_MODE_READ)
return 0;
double data;
fread(&data, sizeof(data), 1, bdat->fp);
return data;
}
void bdat_write_raw(bdat_t *bdat, void *data, int length) {
if(bdat->mode != BDAT_MODE_WRITE)
return;
fwrite(data, length, 1, bdat->fp);
}
void bdat_write_uint8(bdat_t *bdat, uint8_t data) {
bdat_write_raw(bdat, (void*)(&data), 1);
}
void bdat_write_uint16(bdat_t *bdat, uint16_t data) {
bdat_write_raw(bdat, (void*)(&data), sizeof(data));
}
void bdat_write_uint32(bdat_t *bdat, uint32_t data) {
bdat_write_raw(bdat, (void*)(&data), sizeof(data));
}
void bdat_write_uint64(bdat_t *bdat, uint64_t data) {
bdat_write_raw(bdat, (void*)(&data), sizeof(data));
}
void bdat_write_float(bdat_t *bdat, float data) {
bdat_write_raw(bdat, (void*)(&data), sizeof(data));
}
void bdat_write_double(bdat_t *bdat, double data) {
bdat_write_raw(bdat, (void*)(&data), sizeof(data));
}
void bdat_close(bdat_t *bdat) {
fclose(bdat->fp);
free(bdat);
}

40
src/util/file/bdat.h Normal file
View file

@ -0,0 +1,40 @@
#ifndef BDAT_H
#define BDAT_H
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define BDAT_MODE_READ 0
#define BDAT_MODE_WRITE 1
typedef struct bdat_t bdat_t;
struct bdat_t {
FILE *fp;
uint8_t mode;
};
bdat_t* bdat_open_read(char*);
bdat_t* bdat_open_write(char*);
uint8_t bdat_get_mode(bdat_t*);
void* bdat_get_raw (bdat_t*, void*, int);
uint8_t bdat_get_uint8 (bdat_t*);
uint16_t bdat_get_uint16 (bdat_t*);
uint32_t bdat_get_uint32 (bdat_t*);
uint64_t bdat_get_uint64 (bdat_t*);
float bdat_get_float (bdat_t*);
double bdat_get_double (bdat_t*);
void bdat_write_raw (bdat_t*, void*, int);
void bdat_write_uint8 (bdat_t*, uint8_t);
void bdat_write_uint16 (bdat_t*, uint16_t);
void bdat_write_uint32 (bdat_t*, uint32_t);
void bdat_write_uint64 (bdat_t*, uint64_t);
void bdat_write_float (bdat_t*, float);
void bdat_write_double (bdat_t*, double);
void bdat_close(bdat_t*);
#endif

1
src/util/file/map.c Normal file
View file

@ -0,0 +1 @@
#include "map.h"

6
src/util/file/map.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef MAP_H
#define MAP_H
#include <stdio.h>
#endif

View file

@ -5,7 +5,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include "list.h" #include "types/list.h"
#include "common.h" #include "common.h"
#define PCK_CTX_C2S 0 #define PCK_CTX_C2S 0