示例#1
0
int load_roominfo(Room *r, char *username) {
Room *tmp;

	if (r == NULL)
		return -1;

	if (r->number == MAIL_ROOM)				/* don't bother */
		return 0;

	if (r->info != NULL)					/* already resident */
		return 0;

	tmp = new_Room();

	if (r->number == MAIL_ROOM)
		tmp = load_Mail(username, LOAD_ROOM_INFO);
	else
		if (r->number == HOME_ROOM)
			tmp = load_Home(username, LOAD_ROOM_INFO);
		else
			tmp = load_Room(r->number, LOAD_ROOM_INFO);

	if (tmp == NULL)
		return -1;

	destroy_StringIO(r->info);
	r->info = tmp->info;
	tmp->info = NULL;

	destroy_Room(tmp);
	return 0;
}
示例#2
0
int main(void) {
    char* topic1 = "Hello";
    int time1 = 10;
    int room1 = 1001;
    
    struct Meeting* Meeting1 = create_Meeting(time1, topic1);
    struct Room* Room1 = create_Room(room1);
    
    printf("%d\n", add_Room_Meeting(Room1, Meeting1));  // 0
    printf("%d\n", add_Room_Meeting(Room1, Meeting1));  // -1
    
    print_Meeting(find_Room_Meeting(Room1, time1));
    
    printf("%d\n", remove_Room_Meeting(Room1, Meeting1));   // 0
    printf("%d\n", remove_Room_Meeting(Room1, Meeting1));   // -1
    
    printf("%d\n", add_Room_Meeting(Room1, Meeting1));  // 0
    clear_Room(Room1);
    
    print_Room(Room1);
    
    
    const char *topicA = "Whisky", *topicB = "Tango";
    const char *firstname1 = "Bo", *lastname1 = "Jackson", *phoneno1 = "123";
    const char *firstname2 = "Mike", *lastname2 = "David", *phoneno2 = "456";
    
    struct Person* person1 = create_Person(firstname1, lastname1, phoneno1);
    struct Person* person2 = create_Person(firstname2, lastname2, phoneno2);
    
    
    struct Meeting *new_Meeting1 = create_Meeting(10, topicA);
    struct Meeting *new_Meeting2 = create_Meeting(9, topicB);

    struct Ordered_container* people = OC_create_container((OC_comp_fp_t) compare_Person_lastname);
    OC_insert(people, person1);
    OC_insert(people, person2);
    struct Room* room2 = create_Room(1000);
    
    
    add_Meeting_participant(new_Meeting1, person1);
    add_Meeting_participant(new_Meeting1, person2);
    
    add_Room_Meeting(room2, new_Meeting1);
    add_Room_Meeting(room2, new_Meeting2);

    printf("\n...saveload/file...\n");
    FILE *fp = fopen("Room_savefile.txt", "w");
    save_Room(room2, fp);
    fclose(fp);
    
    fp = fopen("Room_savefile.txt", "r");
    struct Room *new_Room = load_Room(fp, people);
    print_Room(new_Room);
    
    fclose(fp);
    

}
示例#3
0
/*
	load all rooms definitions at startup
	Note that room #1 and room #2 are 'shadow' rooms for Mail> and Home>
	the BBS cannot work without room #0, #1, and #2
*/
int init_Room(void) {
char buf[MAX_PATHLEN], *bufp;
DIR *dirp;
struct dirent *direntp;
struct stat statbuf;
Room *newroom;
unsigned int u;
int load_room_flags, len;

	printf("\n");

	listdestroy_Room(AllRooms);
	AllRooms = Lobby_room = NULL;

	load_room_flags = LOAD_ROOM_ALL;
	if (!PARAM_HAVE_RESIDENT_INFO)
		load_room_flags &= ~LOAD_ROOM_INFO;

	bufprintf(buf, sizeof(buf), "%s/", PARAM_ROOMDIR);
	path_strip(buf);
	len = strlen(buf);
	bufp = buf+len;

	if ((dirp = opendir(buf)) == NULL)
		return -1;

	while((direntp = readdir(dirp)) != NULL) {
		if (is_numeric(direntp->d_name)) {		/* only do numeric directories */
			cstrcpy(bufp, direntp->d_name, MAX_PATHLEN - len);
			if (stat(buf, &statbuf))
				continue;

			if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
				u = (unsigned int)cstrtoul(bufp, 10);

				printf("loading room %3u ... ", u);
				fflush(stdout);

				if ((newroom = load_Room(u, load_room_flags)) != NULL) {
					(void)prepend_Room(&AllRooms, newroom);
					room_readdir(newroom);
					printf("%s>\n", newroom->name);
				} else {
					printf("FAILED!\n");
					closedir(dirp);

					listdestroy_Room(AllRooms);
					AllRooms = Lobby_room = NULL;
					return -1;
				}
			}
		}
	}
	closedir(dirp);

	if (PARAM_HAVE_CATEGORY)
		(void)sort_Room(&AllRooms, room_sort_by_category);
	else
		(void)sort_Room(&AllRooms, room_sort_by_number);

/*
	find the Lobby>
	It should be first, but you never know...
*/
	if (Lobby_room == NULL) {
		Room *rm;

		for(rm = AllRooms; rm != NULL; rm = rm->next) {
			if (!rm->number) {
				Lobby_room = rm;
				break;
			}
		}
	}
	if (Lobby_room == NULL) {
		printf("Failed to find the Lobby> (room 0)\n"
			"Please create room definition file '%s/0/RoomData'\n", PARAM_ROOMDIR);

		listdestroy_Room(AllRooms);
		AllRooms = NULL;
		return -1;
	}
	printf("\n");
	return 0;
}