From cfe28eb7eda17e4a604749fe2f027153a2ac5b6e Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Thu, 14 Apr 2016 20:21:02 -0400 Subject: things --- Makefile | 2 +- README.md | 18 +++++++++++++++++- src/main.c | 18 ++++++++++++++++++ src/server.c | 11 ++++++++--- src/world.c | 1 + worlds/test.c | 40 ++++++++++++++++++++++++++++++++++++++-- 6 files changed, 83 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index f9fc032..3b59ad4 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ INCLUDES = -I src/ -I export/include/ WARNFLAGS = -Wall -Wextra -Wshadow -fno-strict-aliasing OPTFLAGS = -O2 -DEBUGFLAGS = -g +DEBUGFLAGS = -g -fstack-protector -D_FORTIFY_SOURCE=2 CFLAGS = $(OPTFLAGS) $(DEBUGFLAGS) $(WARNFLAGS) -std=c99 $(INCLUDES) diff --git a/README.md b/README.md index f97f183..21cbf0f 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,22 @@ the CAP_NET_BIND_SERVICE capability on Linux: If running as root, you will need an unprivileged user called 'nobody' on your system in order for things to work. +After granting permissions, if necessary, start the server and run the +initial setup process. + + $ ./build/unix.bin 23 + *** NetCosm 0.5.2 (libev 4.20, OpenSSL 1.0.2g 1 Mar 2016) *** + Welcome to NetCosm! + Please set up the administrator account now. + Admin account name: blah + Admin password (_DO_NOT_ USE A VALUABLE PASSWORD): password here + Add user 'blah' + Listening on port 23. + +Then connect to the server and start playing: + + telnet localhost + ## Todo List * Game scripting @@ -88,7 +104,7 @@ latency. Versions are numbered using the MAJOR.MINOR.BUGFIX scheme. -The latest version is 0.5.1. +The latest version is 0.5.2. Major versions mark major milestones (see below), minor versions mark incremental milestones and compatibility of data files, and bugfix diff --git a/src/main.c b/src/main.c index b69ce76..31e6077 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,21 @@ +/* + * NetCosm - a MUD server + * Copyright (C) 2016 Franklin Wei + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "globals.h" #include "server.h" diff --git a/src/server.c b/src/server.c index a4280c2..a4558bc 100644 --- a/src/server.c +++ b/src/server.c @@ -277,7 +277,7 @@ static void new_connection_cb(EV_P_ ev_io *w, int revents) if(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, outpipe) < 0) { if(socketpair(AF_UNIX, SOCK_DGRAM, 0, outpipe) < 0) - error("error creating pipe, need linux kernel >= 3.4"); + error("error creating IPC pipe"); } } @@ -290,7 +290,7 @@ static void new_connection_cb(EV_P_ ev_io *w, int revents) /* child */ are_child = true; - /* close our file descriptors */ + /* close unused file descriptors */ close(readpipe[0]); close(outpipe[1]); close(server_socket); @@ -396,7 +396,12 @@ static void parse_args(int argc, char *argv[]) autopass = argv[++i]; break; case 'd': /* set data prefix */ - chdir(argv[++i]); + mkdir(argv[++i], 0700); + if(chdir(argv[i]) < 0) + { + debugf("Cannot access data prefix.\n"); + exit(0); + } break; default: c = 'h'; diff --git a/src/world.c b/src/world.c index 222155d..b3bb4b3 100644 --- a/src/world.c +++ b/src/world.c @@ -248,6 +248,7 @@ bool world_load(const char *fname, const struct roomdata_t *data, size_t data_sz /* read in the room name -> room map */ world_map = hash_init(world_sz * 2, hash_djb, compare_strings); + hash_setfreekey_cb(world_map, free); for(unsigned int i = 0; i < world_sz; ++i) { diff --git a/worlds/test.c b/worlds/test.c index 79b8429..11096df 100644 --- a/worlds/test.c +++ b/worlds/test.c @@ -38,6 +38,10 @@ static void deadend_init(room_id id) verb = verb_new("shake"); verb->name = strdup("shake"); world_verb_add(verb); + + verb = verb_new("type"); + verb->name = strdup("type"); + world_verb_add(verb); } static void ew_road_init(room_id id) @@ -138,6 +142,7 @@ static void computer_room_init(room_id id) room_obj_add(id, new); room_obj_add_alias(id, new, "vax"); + room_obj_add_alias(id, new, "pokey"); /* flag for whether computer is active */ room_get(id)->userdata = malloc(sizeof(bool)); @@ -485,6 +490,7 @@ static void put_exec(struct verb_t *verb, char *args, user_t *user) bool *b = room_get(user->room)->userdata; *b = true; + free(room_get(user->room)->data.desc); room_get(user->room)->data.desc = strdup("You are in a computer room. It seems like most of the equipment has been removed. There is a VAX 11/780 in front of you, however, with one of the cabinets wide open. A sign on the front of the machine says: This VAX is named 'pokey'. To type on the console, use the 'type' command. The exit is to the east.\nThe panel lights are flashing in a seemingly organized pattern."); } else @@ -571,11 +577,41 @@ static void shake_exec(struct verb_t *verb, char *args, user_t *user) char buf[MSG_MAX]; send_msg(user, "Shaking %s seems to have no effect.\n", format_noun(buf, sizeof(buf), obj->name, - n_objs_room, obj->default_article, + n_objs_inv, obj->default_article, false)); } } +static void type_exec(struct verb_t *verb, char *args, user_t *user) +{ + (void) verb; + (void) args; + + struct room_t *room = room_get(user->room); + if(strcmp(room->data.uniq_id, "computer_room")) + send_msg(user, "There is nothing here on which you could type.\n"); + else + { + bool *b = room->userdata; + + /* computer is not active */ + if(!*b) + { + send_msg(user, "You type on the keyboard, but your characters do not even echo.\n"); + return; + } + else + { + send_msg(user, "FIXME\n"); + } + } +} + +static void climb_exec(struct verb_t *verb, char *args, user_t *user) +{ + +} + /* verb classes */ const struct verb_class_t netcosm_verb_classes[] = { @@ -587,9 +623,9 @@ const struct verb_class_t netcosm_verb_classes[] = { eat_exec }, { "shake", shake_exec }, - /* { "type", type_exec }, + /* { "climb", climb_exec }, { "feed", -- cgit v1.1