aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2016-04-28 20:39:37 -0400
committerFranklin Wei <git@fwei.tk>2016-04-28 20:39:37 -0400
commit7f3ba14388a586a946d721a71eb3a9862f7f6c02 (patch)
tree05c96d39815a3719131ad966a73d1ba40fd96d75
parent0db524c05e0e077c06c7d02eaa2921159df04313 (diff)
downloadnetcosm-7f3ba14388a586a946d721a71eb3a9862f7f6c02.zip
netcosm-7f3ba14388a586a946d721a71eb3a9862f7f6c02.tar.gz
netcosm-7f3ba14388a586a946d721a71eb3a9862f7f6c02.tar.bz2
netcosm-7f3ba14388a586a946d721a71eb3a9862f7f6c02.tar.xz
fix build dependency checking, cleanup, simulation callback
-rw-r--r--Makefile4
-rw-r--r--README.md6
-rw-r--r--src/client_reqs.h2
-rw-r--r--src/hash.c3
-rw-r--r--src/server.c55
-rw-r--r--src/world.c35
-rw-r--r--src/world.h7
-rw-r--r--stunnel/client.cfg5
-rw-r--r--stunnel/server.cfg7
-rw-r--r--tools/worldgen.c4
-rw-r--r--worlds/SOURCES2
-rw-r--r--worlds/dunnet.c (renamed from worlds/netcosm_default.c)16
12 files changed, 110 insertions, 36 deletions
diff --git a/Makefile b/Makefile
index 5214414..372247c 100644
--- a/Makefile
+++ b/Makefile
@@ -46,7 +46,7 @@ LDFLAGS = -lev -lcrypto -ldl
HEADERS = src/*.h export/include/*.h
-DEPS = $(patsubst %.c,$(BUILDDIR)/%.d,$(SRC))
+DEPS = $(patsubst %.c,$(BUILDDIR)/src/%.d,$(SRC)) $(patsubst %.c,$(BUILDDIR)/worlds/%.d,$(WORLD_SRC))
# Main targets
################################################################################
@@ -79,7 +79,7 @@ $(BUILDDIR)/%.so: %.c $(BUILDDIR)/%.d Makefile
.PRECIOUS: $(BUILDDIR)/%.d
$(BUILDDIR)/%.d: %.c
@mkdir -p `dirname $@`
- @$(CC) $(CCFLAGS) -MF"$@" -MG -MM -MP -MT"$@" -MT"$(<:.c=.o)" "$<"
+ @$(CC) $(CFLAGS) -MF"$@" -MG -MM -MP -MT"$@" -MT"$(BUILDDIR)/$(<:.c=.o)" "$<"
-include $(DEPS)
diff --git a/README.md b/README.md
index 21cbf0f..fbfb8d8 100644
--- a/README.md
+++ b/README.md
@@ -44,6 +44,12 @@ Then connect to the server and start playing:
telnet localhost
+#### Stunnel
+
+Sample stunnel configuration files for both clients and servers are
+provided. The server configuration tunnels from TCP port 992 to local
+port 1234, and the client vice-versa.
+
## Todo List
* Game scripting
diff --git a/src/client_reqs.h b/src/client_reqs.h
index 0d2a63c..a2146c4 100644
--- a/src/client_reqs.h
+++ b/src/client_reqs.h
@@ -26,7 +26,7 @@
enum room_id;
-enum reqdata_typespec { TYPE_NONE = 0, TYPE_USERDATA, TYPE_BOOLEAN } reqdata_type;
+enum reqdata_typespec { TYPE_NONE = 0, TYPE_USERDATA, TYPE_BOOLEAN };
union reqdata_t {
struct userdata_t userdata;
diff --git a/src/hash.c b/src/hash.c
index 1e7b732..a2938e1 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -200,6 +200,7 @@ static void hash_internal_insert_new(const void *key, const void *data, struct h
/* resize if load factor exceeds threshold */
if((map->used_buckets << 16) / (map->table_sz) >= RESIZE_THRESHOLD)
{
+ //printf("resizing map of %zu elements...\n", map->used_buckets);
hash_resize(map, map->table_sz * 2);
}
}
@@ -548,7 +549,7 @@ void hash_dump(void *ptr)
--used_buckets;
while(iter)
{
- printf(" --> `%s'", iter->key);
+ printf(" --> `%s'", (char*)iter->key);
++n_entries;
iter = iter->next;
}
diff --git a/src/server.c b/src/server.c
index 75c87f6..b736124 100644
--- a/src/server.c
+++ b/src/server.c
@@ -42,7 +42,7 @@ static uint16_t port = DEFAULT_PORT;
static int server_socket;
/* for debugging: */
-static char *world_module = "build/worlds/netcosm_default.so";
+static char *world_module = "build/worlds/dunnet.so";
static char *module_handle = NULL;
/* save after every X changes to the world state */
@@ -188,27 +188,48 @@ static void check_userfile(void)
static void load_worldfile(void)
{
/* load the world module */
+
module_handle = dlopen(world_module, RTLD_NOW);
if(!module_handle)
error("cannot load world module `%s' (%s)", world_module, dlerror());
/* load symbols */
- size_t *ptr;
-
- netcosm_verb_classes = dlsym(module_handle, "netcosm_verb_classes");
- ptr = dlsym(module_handle, "netcosm_verb_classes_sz");
- netcosm_verb_classes_sz = *ptr;
+ {
+ size_t *ptr;
- netcosm_obj_classes = dlsym(module_handle, "netcosm_obj_classes");
- ptr = dlsym(module_handle, "netcosm_obj_classes_sz");
- netcosm_obj_classes_sz = *ptr;
+ netcosm_verb_classes = dlsym(module_handle, "netcosm_verb_classes");
+ ptr = dlsym(module_handle, "netcosm_verb_classes_sz");
+ netcosm_verb_classes_sz = *ptr;
- netcosm_world = dlsym(module_handle, "netcosm_world");
- ptr = dlsym(module_handle, "netcosm_world_sz");
- netcosm_world_sz = *ptr;
+ netcosm_obj_classes = dlsym(module_handle, "netcosm_obj_classes");
+ ptr = dlsym(module_handle, "netcosm_obj_classes_sz");
+ netcosm_obj_classes_sz = *ptr;
- char **tmp = dlsym(module_handle, "netcosm_world_name");
- netcosm_world_name = *tmp;
+ netcosm_world = dlsym(module_handle, "netcosm_world");
+ ptr = dlsym(module_handle, "netcosm_world_sz");
+ netcosm_world_sz = *ptr;
+ }
+ {
+ char **ptr = dlsym(module_handle, "netcosm_world_name");
+ netcosm_world_name = *ptr;
+ }
+ {
+ void *ptr;
+ ptr = dlsym(module_handle, "netcosm_world_simulation_cb");
+ netcosm_world_simulation_cb = ptr;
+ }
+ {
+ unsigned *ptr;
+ ptr = dlsym(module_handle, "netcosm_world_simulation_interval");
+ if(ptr)
+ netcosm_world_simulation_interval = *ptr;
+ else
+ {
+ netcosm_world_simulation_interval = 0;
+ if(netcosm_world_simulation_cb)
+ error("have simulation callback, but no interval specified");
+ }
+ }
if(access(WORLDFILE, F_OK) < 0)
{
@@ -483,6 +504,12 @@ int server_main(int argc, char *argv[])
parse_args(argc, argv);
+ /* load default if none specified */
+ if(!world_module)
+ {
+ error("no world module specified");
+ }
+
/* this must be done before any world module data is used */
load_worldfile();
diff --git a/src/world.c b/src/world.c
index d7c3590..d0e1711 100644
--- a/src/world.c
+++ b/src/world.c
@@ -35,6 +35,10 @@ size_t netcosm_obj_classes_sz;
const struct roomdata_t *netcosm_world;
size_t netcosm_world_sz;
+/* simulation callback */
+void (*netcosm_world_simulation_cb)(void) = NULL;
+unsigned netcosm_world_simulation_interval = 0;
+
const char *netcosm_world_name;
/* processed world data */
@@ -157,6 +161,16 @@ void world_save(const char *fname)
close(fd);
}
+static ev_timer *sim_timer = NULL;
+
+static void sim_cb(EV_P_ ev_timer *w, int revents)
+{
+ (void) EV_A;
+ (void) w;
+ (void) revents;
+ netcosm_world_simulation_cb();
+}
+
void world_free(void)
{
if(world)
@@ -174,6 +188,20 @@ void world_free(void)
free(world);
world = NULL;
}
+ if(sim_timer)
+ free(sim_timer);
+}
+
+static void start_sim_callback(void)
+{
+ /* start callback */
+ if(netcosm_world_simulation_cb && netcosm_world_simulation_interval)
+ {
+ sim_timer = calloc(1, sizeof(ev_timer));
+ ev_timer_init(sim_timer, sim_cb, netcosm_world_simulation_interval/1000.0,
+ netcosm_world_simulation_interval/1000.0);
+ ev_timer_start(EV_DEFAULT_ sim_timer);
+ }
}
/**
@@ -208,8 +236,8 @@ bool world_load(const char *fname, const struct roomdata_t *data, size_t data_sz
world_name = read_string(fd);
if(strcmp(name, world_name))
{
- free(world_name);
debugf("Incompatible world state (%s %s).\n", name, world_name);
+ free(world_name);
return false;
}
@@ -277,6 +305,9 @@ bool world_load(const char *fname, const struct roomdata_t *data, size_t data_sz
}
close(fd);
+
+ start_sim_callback();
+
return true;
}
@@ -385,6 +416,8 @@ void world_init(const struct roomdata_t *data, size_t sz, const char *name)
}
hash_free(dir_map);
+
+ start_sim_callback();
}
static void *verb_map = NULL;
diff --git a/src/world.h b/src/world.h
index 5dcd85d..4ce253e 100644
--- a/src/world.h
+++ b/src/world.h
@@ -41,10 +41,15 @@ extern size_t netcosm_obj_classes_sz;
extern const struct roomdata_t *netcosm_world;
extern size_t netcosm_world_sz;
+/* simulation callback */
+extern void (*netcosm_world_simulation_cb)(void);
+extern unsigned netcosm_world_simulation_interval;
+
extern const char *netcosm_world_name;
#endif
-/*** loads the world into RAM for the first time, resets the game state ***/
+/* loads the world into RAM for the first time, resets the game
+ * state */
void world_init(const struct roomdata_t *data, size_t sz, const char *name);
void world_save(const char *fname);
diff --git a/stunnel/client.cfg b/stunnel/client.cfg
index fc39f15..98bce53 100644
--- a/stunnel/client.cfg
+++ b/stunnel/client.cfg
@@ -16,9 +16,8 @@ options = -NO_SSLv3
; * Service definitions (remove all services for inetd mode) *
; **************************************************************************
-; ***************************************** Example TLS client mode services
-
[telnet]
client = yes
accept = 127.0.0.1:23
-connect = REMOTE_HOST:992
+connect = localhost:992
+verify = 0
diff --git a/stunnel/server.cfg b/stunnel/server.cfg
index 7772d54..de3c596 100644
--- a/stunnel/server.cfg
+++ b/stunnel/server.cfg
@@ -3,8 +3,8 @@
; For more options and details: see the manual (stunnel.html)
; File with certificate and private key
-cert = YOUR_CERT_HERE.pem
-key = YOUR_KEY_HERE.pem
+cert = cert.pem
+key = key.pem
; Log (1= minimal, 5=recommended, 7=all) and log file)
; Preceed with a “;” to disable logging
@@ -15,9 +15,6 @@ output = stunnel.log
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
-; Data compression algorithm: zlib or rle
-compression = zlib
-
; SSL bug options / NO SSL:v2 (SSLv3 and TLSv1 is enabled)
options = ALL
options = NO_SSLv2
diff --git a/tools/worldgen.c b/tools/worldgen.c
index 2568e54..2c9a3bd 100644
--- a/tools/worldgen.c
+++ b/tools/worldgen.c
@@ -7,8 +7,8 @@
/* x and y are horizontal and forward-back axes, respectively */
/* z is the vertical axis */
-#define MAX_X 1000
-#define MAX_Y 1000
+#define MAX_X 100
+#define MAX_Y 100
#define MAX_Z 1
struct direction_info_t {
diff --git a/worlds/SOURCES b/worlds/SOURCES
index 1fcc434..3e0607e 100644
--- a/worlds/SOURCES
+++ b/worlds/SOURCES
@@ -1,2 +1,2 @@
-netcosm_default.c
+dunnet.c
template.c
diff --git a/worlds/netcosm_default.c b/worlds/dunnet.c
index 11096df..790d0bf 100644
--- a/worlds/netcosm_default.c
+++ b/worlds/dunnet.c
@@ -607,11 +607,6 @@ static void type_exec(struct verb_t *verb, char *args, user_t *user)
}
}
-static void climb_exec(struct verb_t *verb, char *args, user_t *user)
-{
-
-}
-
/* verb classes */
const struct verb_class_t netcosm_verb_classes[] = {
@@ -634,3 +629,14 @@ const struct verb_class_t netcosm_verb_classes[] = {
};
const size_t netcosm_verb_classes_sz = ARRAYLEN(netcosm_verb_classes);
+
+/* simulation callback */
+void netcosm_world_simulation_cb(void)
+{
+ /* do nothing */
+ //printf("callback\n");
+ return;
+}
+
+/* 100 ms */
+unsigned netcosm_world_simulation_interval = 100;