aboutsummaryrefslogtreecommitdiff
path: root/src/netcosm.h
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2015-12-24 14:57:16 -0500
committerFranklin Wei <git@fwei.tk>2015-12-24 14:57:16 -0500
commit460d13ccd6242da9d25558aac6ffb7c6e9df03a6 (patch)
treedc872bc1a5afb940ec9ca2e0ab706bee811ef7e1 /src/netcosm.h
parentf1e708a631d7d5fbe6fc2f74e5f681d6a6786b4e (diff)
downloadnetcosm-460d13ccd6242da9d25558aac6ffb7c6e9df03a6.zip
netcosm-460d13ccd6242da9d25558aac6ffb7c6e9df03a6.tar.gz
netcosm-460d13ccd6242da9d25558aac6ffb7c6e9df03a6.tar.bz2
netcosm-460d13ccd6242da9d25558aac6ffb7c6e9df03a6.tar.xz
stuff
Diffstat (limited to 'src/netcosm.h')
-rw-r--r--src/netcosm.h106
1 files changed, 88 insertions, 18 deletions
diff --git a/src/netcosm.h b/src/netcosm.h
index 16ace01..ac2c72c 100644
--- a/src/netcosm.h
+++ b/src/netcosm.h
@@ -30,21 +30,106 @@
#define PRIV_USER 0
#define PRIV_ADMIN 1337
+/* child<->master commands */
+/* children might not implement all of these */
+#define REQ_NOP 0
+#define REQ_BCASTMSG 1
+#define REQ_LISTCLIENTS 2
+#define REQ_CHANGESTATE 3
+#define REQ_CHANGEUSER 4
+#define REQ_HANG 5
+#define REQ_KICK 6
+#define REQ_WAIT 7
+
+/* child states */
+#define STATE_INIT 0
+#define STATE_AUTH 1
+#define STATE_CHECKING 2
+#define STATE_LOGGEDIN 3
+#define STATE_ADMIN 4
+#define STATE_FAILED 5
+
+/* for convenience when writing world specs */
+#define NONE_N NULL
+#define NONE_NE NULL
+#define NONE_E NULL
+#define NONE_SE NULL
+#define NONE_S NULL
+#define NONE_SW NULL
+#define NONE_W NULL
+#define NONE_NW NULL
+#define NONE_UP NULL
+#define NONE_DN NULL
+
struct authinfo_t {
bool success;
const char *user;
int authlevel;
};
+/* logged in users are identified by the PID of the process serving them */
+struct user_t {
+ pid_t pid;
+};
+
+enum direction_t { DIR_N = 0, DIR_NE, DIR_E, DIR_SE, DIR_S, DIR_SW, DIR_W, DIR_NW, DIR_UP, DIR_DOWN, NUM_DIRECTIONS };
+
+struct item_t {
+ const char *class;
+
+};
+
+struct verb_t {
+ const char *name;
+
+ /* toks is strtok_r's pointer */
+ void (*execute)(const char *toks);
+};
+
+typedef int room_id;
+
+/* the data we get from a world module */
+struct roomdata_t {
+ const char *uniq_id;
+ const char *name;
+ const char *desc;
+
+ const char *adjacent[NUM_DIRECTIONS];
+
+ void (*hook_init)(room_id id);
+ void (*hook_enter)(room_id room, pid_t player);
+ void (*hook_say)(room_id room, pid_t player, const char *msg);
+ void (*hook_leave)(room_id room, pid_t player);
+};
+
+struct room_t {
+ room_id id;
+ struct roomdata_t data;
+
+ room_id adjacent[NUM_DIRECTIONS];
+
+ /* arrays instead of linked lists because insertion should be rare for these */
+ struct item_t *items;
+ size_t items_sz;
+
+ struct verb_t *verbs;
+ size_t verbs_sz;
+};
+
+extern const struct roomdata_t netcosm_world[];
+extern const size_t netcosm_world_sz;
+
void client_main(int sock, struct sockaddr_in *addr, int, int to_parent, int from_parent);
void __attribute__((noreturn)) error(const char *fmt, ...);
void first_run_setup(void);
struct authinfo_t auth_check(const char*, const char*);
-/* add or change a user */
+/* add or change a user, NOT reentrant */
bool add_change_user(const char *user2, const char *pass2, int level);
bool auth_remove(const char*);
+
void telnet_handle_command(const unsigned char*);
+
#define ARRAYLEN(x) (sizeof(x)/sizeof(x[0]))
void out(const char *fmt, ...) __attribute__((format(printf,1,2)));
@@ -56,21 +141,6 @@ void telnet_echo_off(void);
void remove_cruft(char*);
-/* child<->master commands */
-/* children might not implement all of these */
-#define REQ_NOP 0
-#define REQ_BCASTMSG 1
-#define REQ_LISTCLIENTS 2
-#define REQ_CHANGESTATE 3
-#define REQ_CHANGEUSER 4
-#define REQ_HANG 5
-#define REQ_KICK 6
-
-#define STATE_INIT 0
-#define STATE_AUTH 1
-#define STATE_CHECKING 2
-#define STATE_LOGGEDIN 3
-#define STATE_ADMIN 4
-#define STATE_FAILED 5
-
void auth_list_users(void);
+void world_init(const struct roomdata_t *data, size_t sz);
+void sig_printf(const char *fmt, ...);