[mw-devel] MW3 r1119 - branches/nomud/src

welshbyte at sucs.org welshbyte at sucs.org
Mon Dec 7 17:58:17 GMT 2009


Author: welshbyte
Date: 2009-12-07 17:58:16 +0000 (Mon, 07 Dec 2009)
New Revision: 1119

Modified:
   branches/nomud/src/bb.h
   branches/nomud/src/init.c
   branches/nomud/src/log.c
   branches/nomud/src/main.c
   branches/nomud/src/rooms.c
   branches/nomud/src/rooms.h
   branches/nomud/src/script_inst.c
   branches/nomud/src/talker.c
Log:
- Rip out the rooms stuff specific to mudmode
- Use the new sqlite functions in LoadRoom()


Modified: branches/nomud/src/bb.h
===================================================================
--- branches/nomud/src/bb.h	2009-12-07 17:56:29 UTC (rev 1118)
+++ branches/nomud/src/bb.h	2009-12-07 17:58:16 UTC (rev 1119)
@@ -31,8 +31,6 @@
 #define EDITOR		"/usr/bin/vim"
 #define SECUREEDITOR	"/bin/rnano"
 
-#define ROOMPATH	"rooms"
-
 #define HELPDIR		"help"
 #define WIZHELP		"wizhelp"
 #define SCRIPTHELP	"scripthelp"
@@ -41,6 +39,7 @@
 #define USERSQL		"users.db"
 #define USERDB_PRIVATE	"private"
 #define USERDB_PUBLIC	"public"
+#define USERDB_ROOMS	"rooms"
 
 #define TEXT_END	".t"
 #define INDEX_END	".i"
@@ -195,15 +194,6 @@
 	int32_t posn;
 };
 
-typedef struct __dirinfo
-{
-	char *link;	/* direction command (eg, 'jump') */
-	char *from;     /* leave message (eg, 'jumped up') */
-	char *to;	/* entering message (eg, 'fallen from') */
-	char *leaving;	/* leaving message (eg, 'leaving main hall, falling down to') */
-	struct __dirinfo *next;
-} DirInfo;
-
 struct room_vis_info
 {
 	char *name;
@@ -220,15 +210,6 @@
 	int32_t hidden;				/* cant find room using 'room' command */
 	int32_t sproof;				/* soundproof? */
 	int32_t locked;				/* locked even if mudmode off? */
-	int32_t *dir;				/* room numbers can find from here */
-	int32_t *hidedir;				/* room is hidden */
-	char **link;				/* link text for directions off here */
-	char **dirdef;				/* direction name redefs */
-	char **fromdef;				/* direction leave redefs */
-	char **todef;				/* direction arrive redefs */
-	char **leavedef;			/* direction leaving redefs */
-
-	struct room_vis_info *vnames;		/* externally visible names */
 };
 
 typedef struct gag_info

Modified: branches/nomud/src/init.c
===================================================================
--- branches/nomud/src/init.c	2009-12-07 17:56:29 UTC (rev 1118)
+++ branches/nomud/src/init.c	2009-12-07 17:58:16 UTC (rev 1119)
@@ -136,7 +136,7 @@
 	}
 
 	if ((a=strrchr(filename, '.'))!=NULL && strncasecmp(a, ".js", 3)==0) {
-		int ret = load_jsfile(file, filename);
+		load_jsfile(file, filename);
 		fclose(file);
 		return 0; // changed because if an error occured after this point the file exists, the js code has reported the error to the user and returning 1 will report to them that it doesn't exist
 	}

Modified: branches/nomud/src/log.c
===================================================================
--- branches/nomud/src/log.c	2009-12-07 17:56:29 UTC (rev 1118)
+++ branches/nomud/src/log.c	2009-12-07 17:58:16 UTC (rev 1119)
@@ -42,7 +42,6 @@
 extern int runautoexec;
 
 extern struct room myroom;
-extern DirInfo *roomlink;
 
 extern GagInfo gaglist[];
 

Modified: branches/nomud/src/main.c
===================================================================
--- branches/nomud/src/main.c	2009-12-07 17:56:29 UTC (rev 1118)
+++ branches/nomud/src/main.c	2009-12-07 17:58:16 UTC (rev 1119)
@@ -664,10 +664,7 @@
 
 	init_colour();
 	
-	/* load in room directions */
-	LoadDirections();
 	RoomInit(&myroom);
-	LoadRoom(&myroom, user->room);
 
 /*	if (!(rights&65l))  a pleb - timeout of 10 mins 
 		user->timeout=600; */
@@ -941,7 +938,6 @@
 	ScriptCleanup();
 
 	RoomDestroy(&myroom);
-	DestroyDirections();
 	ClearStack();
 	stop_js();
 	alarm_cleanup();

Modified: branches/nomud/src/rooms.c
===================================================================
--- branches/nomud/src/rooms.c	2009-12-07 17:56:29 UTC (rev 1118)
+++ branches/nomud/src/rooms.c	2009-12-07 17:58:16 UTC (rev 1119)
@@ -16,6 +16,7 @@
 #include "frl.h"
 #include "strings.h"
 #include "ipc.h"
+#include "sqlite.h"
 
 extern unsigned long rights;
 #define MAX_ARGC 128
@@ -29,171 +30,21 @@
 
 struct room myroom;
 
-DirInfo *roomlink = NULL;
-
 int isanum(char *a, int *result, int onlydecimal);
 
-
-void LoadDirections(void)
-{
-	char fname[1024];
-	FILE *file;
-	char *buff;
-	DirInfo *temp, *tail;
-
-	while (roomlink != NULL)
-	{
-		free(roomlink->link);
-		free(roomlink->to);
-		free(roomlink->from);
-		free(roomlink->leaving);
-		temp = roomlink;
-		roomlink = roomlink->next;
-		free(temp);
-	}
-	roomlink = NULL;
-
-	snprintf(fname, 1023, "%s/%s/defaults", HOMEPATH, ROOMPATH);
-	if ((file=fopen(fname, "r"))==NULL) {
-		return;
-	}
-
-	tail=NULL;
-	while(!feof(file) && ((buff = frl_line_nspace(file, "#"))!=NULL))
-	{
-		temp = malloc(sizeof(DirInfo));
-		temp->link = buff;
-		temp->to = frl_line_nspace(file, "#");
-		temp->from = frl_line_nspace(file, "#");
-		temp->leaving = frl_line_nspace(file, "#");
-		temp->next = NULL;
-		if (tail == NULL)
-			roomlink = temp;
-		else
-			tail->next = temp;
-		tail = temp;
-	}
-	
-	fclose(file);
-	return;
-}
-
-void DestroyDirections(void)
-{
-	DirInfo *temp;
-
-	while (roomlink != NULL)
-	{
-		free(roomlink->link);
-		free(roomlink->to);
-		free(roomlink->from);
-		free(roomlink->leaving);
-		temp = roomlink;
-		roomlink = roomlink->next;
-		free(temp);
-	}
-	roomlink = NULL;
-}
-
 void RoomInit(struct room *room)
 {
-	int i;
-	DirInfo *temp;
-
-	room->name=NULL;
-	room->desc=NULL;
-	room->prompt=NULL;
-	room->sproof=0;
-	room->num=-1;
-	room->hidden=0;
-	room->locked=0;
-
-	i=0;
-	temp = roomlink;
-	while(temp!=NULL)
-	{
-		temp = temp->next;
-		i++;
-	};
-	if (!i) i = 1; /* Prevent efence error (refuses to do malloc(0)) */
-
-	room->vnames=malloc(sizeof(struct room_vis_info));
-	room->vnames[0].name = NULL;
-
-	room->dir=malloc(sizeof(int) * i);
-	room->hidedir=malloc(sizeof(int) * i);
-	room->link=malloc(sizeof(char*) * i);
-	room->dirdef=malloc(sizeof(char*) * i);
-	room->todef=malloc(sizeof(char*) * i);
-	room->fromdef=malloc(sizeof(char*) * i);
-	room->leavedef=malloc(sizeof(char*) * i);
-
-	i=0;
-	temp = roomlink;
-	while(temp!=NULL)
-	{
-		room->dir[i]=-1;
-		room->hidedir[i]=-1;
-		room->link[i]=NULL;
-		room->dirdef[i]=NULL;
-		room->todef[i]=NULL;
-		room->fromdef[i]=NULL;
-		room->leavedef[i]=NULL;
-		i++;
-		temp = temp->next;
-	}
+	memset(room, 0, sizeof(struct room));
+	room->num = -1;
 }
 
 void RoomDestroy(struct room *room)
 {
-	int i;
-	DirInfo *temp;
-
 	SAFE_FREE(room->name);
 	SAFE_FREE(room->desc);
 	SAFE_FREE(room->prompt);
-
-	i=0;
-	temp = roomlink;
-	while(temp!=NULL)
-	{
-		SAFE_FREE(room->link[i]);
-		SAFE_FREE(room->dirdef[i]);
-		SAFE_FREE(room->todef[i]);
-		SAFE_FREE(room->fromdef[i]);
-		SAFE_FREE(room->leavedef[i]);
-		i++;
-		temp=temp->next;
-	}
-	SAFE_FREE(room->dir);
-	SAFE_FREE(room->hidedir);
-	SAFE_FREE(room->link);
-	SAFE_FREE(room->dirdef);
-	SAFE_FREE(room->todef);
-	SAFE_FREE(room->fromdef);
-	SAFE_FREE(room->leavedef);
-
-	i=0;
-	while(room->vnames[i].name!=NULL)
-	{
-		free(room->vnames[i].name);
-		i++;
-	}
-	SAFE_FREE(room->vnames);
 }
 
-char *room_name(struct room tmp, int roomnum)
-{
-	int i = 0;
-
-	while(tmp.vnames[i].name!=NULL)
-	{
-		if (tmp.vnames[i].rnum == roomnum) return(tmp.vnames[i].name);
-		i++;
-	}
-	return(tmp.name);
-}
-
 void string_lines(char *text)
 {
 	char *a;
@@ -221,183 +72,23 @@
 
 int LoadRoom(struct room *room, int num)
 {
-	char *buff;
-	char fname[1024];
-	FILE *file;
-	char *a, *b, *c, *d;
-	char *backup;
-	int i;
-	DirInfo *temp;
-	int loaded = 0;
-	StringList *inif = NULL;
+	char *tmp;
 
 	if (room==NULL) return(0);
 	if (num < 0 || num > 65535) return(0);
 
-	snprintf(fname, 1023, "%s/%s/%d", HOMEPATH, ROOMPATH, num);
-	if ((file=fopen(fname, "r"))==NULL) return(0);
+	room->num=num;
+	room->name = db_room_get(num, "name");
+	room->desc = db_room_get(num, "desc");
+	room->prompt = db_room_get(num, "prompt");
+	tmp = db_room_get(num, "hidden");
+	if (tmp) room->hidden = atoi(tmp);
+	tmp = db_room_get(num, "soundproof");
+	if (tmp) room->sproof = atoi(tmp);
+	tmp = db_room_get(num, "locked");
+	if (tmp) room->locked = atoi(tmp);
 
-	inif = frl_buffer_ini(file, "#");
-
-	/* if we can load the name in from an ini file, then assume new mode */
-	if ((buff = frl_buffer_ini_string(inif, "general", "name")) == NULL)
-	{
-		rewind(file);
-
-		room->num=num;
-		while(!feof(file) && ((buff = frl_line_nspace(file, "#"))!=NULL))
-		{
-			backup = buff;
-			if ((a=strtok(buff, ":"))==NULL) { free(backup); continue; }
-			b=strtok(NULL,"\n\r");
-			if (b==NULL) { free(backup); continue; }
-			while (*b==' ' || *b=='\t') b++;
-			if (*b==0) { free(backup); continue; }
-
-			c=strchr(b,':');
-			if (c!=NULL)
-			{
-				d = c;
-				c++;
-				*d = 0;
-				while (*c==' ' || *c=='\t') c++;
-			}
-
-			if (!strcasecmp(a, "name")) {
-				loaded = 1;
-				room->name=strdup(b);
-				if (c!=NULL) { string_add(&(room->name), ":"); string_add(&(room->name), c); }
-			}else
-			if (!strcasecmp(a, "vname"))
-			{
-				i = 0;
-				while(room->vnames[i].name!=NULL) { i++; }
-
-				room->vnames = realloc(room->vnames, sizeof(struct room_vis_info) * (i + 1));
-				room->vnames[i].rnum=atoi(b);
-				room->vnames[i].name=strdup(c);
-				room->vnames[i+1].name=NULL;
-			}else
-			if (!strcasecmp(a, "desc")) {
-				room->desc=strdup(b);
-				if (c!=NULL) { string_add(&(room->desc), ":"); string_add(&(room->desc), c); }
-				string_lines(room->desc);
-			}else
-			if (!strcasecmp(a, "prompt")) {
-				room->prompt=strdup(b);
-				if (c!=NULL) { string_add(&(room->prompt), ":"); string_add(&(room->prompt), c); }
-			} else
-			if (!strcasecmp(a, "hide")) {
-				room->hidden=atoi(b);
-			} else
-			if (!strcasecmp(a, "sproof")) {
-				room->sproof=atoi(b);
-			} else
-			if (!strcasecmp(a, "locked")) {
-				room->locked=atoi(b);
-			} else
-			if (!strcasecmp(a, "redef"))
-			{
-				i=0;
-				temp = roomlink;
-				while (temp!=NULL)
-				{
-					if (!strcasecmp(temp->link, b))
-					{
-						room->dirdef[i]=strdup(c);
-					}
-					i++;
-					temp=temp->next;
-				}
-			} else
-			{
-				i=0;
-				temp = roomlink;
-				while (temp!=NULL)
-				{
-					if (!strcasecmp(temp->link, a))
-					{
-						room->dir[i]=atoi(b);
-						if (c!=NULL) {
-							room->link[i]=strdup(c);
-							string_lines(room->link[i]);
-						}
-					}
-					i++;
-					temp=temp->next;
-				}
-			}
-			free(backup);
-		}
-	}
-	else
-	{
-		StringList *sl = NULL;
-
-		/* set room to loaded, and set room number */
-		loaded = 1;
-		room->num = num;
-
-		/* store name */
-		room->name = buff;
-
-		/* read alternate prompt */
-		room->prompt = frl_buffer_ini_string(inif, "general", "prompt");
-
-		/* read and format description */
-		room->desc = frl_buffer_ini_string(inif, "general", "desc");
-		string_lines(room->desc);
-
-		/* read switch details */
-		room->hidden = str2num(frl_buffer_ini_string(inif, "switch", "hide"));
-		room->sproof = str2num(frl_buffer_ini_string(inif, "switch", "sproof"));
-		room->locked = str2num(frl_buffer_ini_string(inif, "switch", "locked"));
-
-		/* load in directional details */
-		i=0;
-		temp = roomlink;
-		while (temp!=NULL)
-		{
-			room->dirdef[i] = frl_buffer_ini_string(inif, temp->link, "name");
-			room->todef[i] = frl_buffer_ini_string(inif, temp->link, "leave");
-			room->fromdef[i] = frl_buffer_ini_string(inif, temp->link, "arrive");
-			room->leavedef[i] = frl_buffer_ini_string(inif, temp->link, "leaving");
-			room->dir[i] = str2num(frl_buffer_ini_string(inif, temp->link, "room"));
-			room->link[i] = frl_buffer_ini_string(inif, temp->link, "link");
-			string_lines(room->link[i]);
-			room->hidedir[i] = str2num(frl_buffer_ini_string(inif, temp->link, "hidden"));
-			i++;
-			temp=temp->next;
-		}
-
-		/* load in any external room names */
-		if ((sl = frl_buffer_ini_string_list(inif, "misc", "extern")) != NULL)
-		{
-			StringList *t = sl;
-
-			i=0;
-			while(t!=NULL)
-			{
-				b = strdup(t->text);
-				c = b;
-				if ((a=strsep(&b, ":"))!=NULL)
-				{
-					room->vnames = realloc(room->vnames, sizeof(struct room_vis_info) * (i + 1));
-					room->vnames[i].rnum=atoi(a);
-					room->vnames[i].name=strdup(b);
-					room->vnames[i+1].name=NULL;
-					i++;
-				}
-				free(c);
-				t=t->next;
-			}
-			frl_free_buffer(&sl);
-		}
-	}
-	frl_free_buffer(&inif);
-	fclose(file);
-
-	return(loaded);
+	return 1;
 }
 
 void room_who_list(void)
@@ -476,94 +167,6 @@
 	free(str);
 }
 
-
-void RoomExits(struct room *room)
-{
-	struct room tmp;
-	int count=0;
-	char *buff;
-	int i;
-	DirInfo *temp;
-
-	if (room==NULL) {
-		display_message("No room loaded.", 0, 1);
-		return;
-	}
-
-	i=0;
-	temp = roomlink;
-	while(temp!=NULL)
-	{
-		if (room->dir[i] >= 0 && room->hidedir[i] < 1)
-		{
-			buff = strdup("\03318 - ");
-			if (room->dirdef[i]!=NULL)
-				string_add(&buff, room->dirdef[i]);
-			else
-				string_add(&buff, temp->link);
-			string_add(&buff, " to ");
-
-			RoomInit(&tmp);
-			if (LoadRoom(&tmp, room->dir[i]))
-				string_add(&buff, room_name(tmp, user->room));
-			else
-				string_addnum(&buff, room->dir[i]);
-			if (count == 0)
-				display_message("\03318From this room, you can go:", 0, 1);
-			display_message(buff, 0, 1);
-			RoomDestroy(&tmp);
-
-			free(buff);
-			count++;
-		}
-		i++;
-		temp=temp->next;
-	}
-	if (!count) display_message("\03318There are no exits from this room", 0, 1);
-}
-
-void RoomLook(struct room *room, int full)
-{
-	char *text;
-
-	if (room==NULL)
-	{
-		text = strdup("\03317");
-		string_add(&text, "You are in an empty void.");
-		display_message(text, 0, 1);
-		free(text);
-	}
-	else
-	{
-		if (full) if (room->name!=NULL)
-		{
-			text = strdup("\03316");
-			string_add(&text, room->name);
-			display_message(text, 1, 1);
-			free(text);
-		}
-		if (room->desc!=NULL)
-		{
-			char *a;
-			char *buff;
-		
-			buff = strdup(room->desc);
-			a = strtok(buff, "\n");
-			while (a!=NULL)
-			{
-				text = strdup("\03317");
-				string_add(&text, a);
-				display_message(text, 0, 1);
-				free(text);
-				a = strtok(NULL, "\n");
-			}
-			free(buff);
-		}
-		RoomExits(room);
-	}
-	room_who_list();
-}
-
 void talker_who(int mode)
 {
 	struct person	u;

Modified: branches/nomud/src/rooms.h
===================================================================
--- branches/nomud/src/rooms.h	2009-12-07 17:56:29 UTC (rev 1118)
+++ branches/nomud/src/rooms.h	2009-12-07 17:58:16 UTC (rev 1119)
@@ -1,12 +1,7 @@
 /* rooms.c */
-void LoadDirections(void);
-void DestroyDirections(void);
 void RoomInit(struct room *room);
 void RoomDestroy(struct room *room);
 int LoadRoom(struct room *room, int num);
-void RoomLook(struct room *room, int full);
-void RoomExits(struct room *room);
 void talker_who(int mode);
 void room_who_list(void);
-char *room_name(struct room tmp, int roomnum);
 int ChangeRoom(char *room, int quiet);

Modified: branches/nomud/src/script_inst.c
===================================================================
--- branches/nomud/src/script_inst.c	2009-12-07 17:56:29 UTC (rev 1118)
+++ branches/nomud/src/script_inst.c	2009-12-07 17:58:16 UTC (rev 1119)
@@ -30,9 +30,7 @@
 extern Alias bind_list;
 
 extern struct room myroom;
-extern DirInfo *roomlink;
 
-
 /* current script runaway variable */
 extern long runaway;
 

Modified: branches/nomud/src/talker.c
===================================================================
--- branches/nomud/src/talker.c	2009-12-07 17:56:29 UTC (rev 1118)
+++ branches/nomud/src/talker.c	2009-12-07 17:58:16 UTC (rev 1119)
@@ -62,7 +62,6 @@
 extern int runautoexec;
 
 extern struct room myroom;
-extern DirInfo *roomlink;
 
 extern GagInfo gaglist[];
 
@@ -478,9 +477,7 @@
 	setup_js();
 	
 	RoomDestroy(&myroom);
-	DestroyDirections();
 
-	LoadDirections();
 	RoomInit(&myroom);
 	LoadRoom(&myroom, user->room);
 




More information about the mw-devel mailing list