void sus(char *roomname, user_data *ud) { list subs_rooms = ud->subscribed_rooms; if (get_room(rooms, roomname) == NULL) { write(get_socket(ud), "Sorry, this room does not exist", MAX_PACK_SIZE); return; } if (is_in(get_room(rooms, roomname), subs_rooms)) { write(get_socket(ud), "You are already subscribed to this room", MAX_PACK_SIZE); return; } add_user(rooms, roomname, ud); add(subs_rooms, get_room(rooms, roomname)); char *buffer; if ((buffer = malloc(sizeof(char)*256)) == NULL) { perror("Malloc failed"); write(get_socket(ud), "You are now subscribed to the room!", 256); return; } memset(buffer, 0, 256); strcat(buffer, "You are now subscribed to the room '"); strcat(buffer, roomname); strcat(buffer,"'!"); write(get_socket(ud), buffer, 256); free(buffer); }
/*** Read the message board ***/ void read_board(UR_OBJECT user) { RM_OBJECT rm=NULL; char fname[FNAME_LEN], *name, rmname[ROOM_NAME_LEN+1]; int ret; set_crash(); if (word_count<2) rm=user->room; else { if (word_count>=3) { if ((rm=get_room(word[1]))==NULL) { write_user(user,nosuchroom); return; } read_board_specific(user,rm,atoi(word[2])); return; } if (word_count==2) { if (atoi(word[1])) { read_board_specific(user,user->room,atoi(word[1])); return; } else { if ((rm=get_room(word[1]))==NULL) { write_user(user,nosuchroom); return; } } } if (!has_room_access(user,rm)) { write_user(user,"That room is currently private, you cannot read the board.\n"); return; } } vwrite_user(user, message_board_header, rm->name); if (rm->access==PERSONAL_LOCKED || rm->access==PERSONAL_UNLOCKED) { midcpy(rm->name,rmname,1,strlen(rm->name)-2); rmname[0]=toupper(rmname[0]); sprintf(fname,"%s/%s.B", USERROOMS, rmname); } else sprintf(fname,"%s/%s.B", ROOMFILES, rm->name); if (!(ret=more(user, user->socket, fname))) vwrite_user(user, read_no_messages, rm->name); else if (ret==1) user->misc_op=2; if (user->vis) name=user->recap; else name=invisname; if (rm==user->room) vwrite_room_except(user->room, user, user_read_board_prompt, name); }
void eli(char *roomname, int socket) { box *temp_room = get_room(rooms, roomname); if (temp_room == NULL) { write(socket, "You can't delete a room that doesn't exist", MAX_PACK_SIZE); return; } if (temp_room == rooms->first) { write(socket, "You just can't delete the default room", MAX_PACK_SIZE); return; } box *temp_cu = connected_users->first; //delete subscriptions to the rooms of every user while (temp_cu != NULL) { del(get_subscribed_rooms(temp_cu->elem), temp_room); temp_cu = temp_cu->next; } //destroy list of users in the room list userslist = get_userslist(temp_room->elem); destroy(userslist); //delete the room del(rooms, temp_room->elem); }
void extract_data(t_env *env, t_data **room) { char *line; int type; t_data *temp; get_ant_numbers(env); temp = *room; while (get_next_line(0, &line) && ft_printf("%s\n", line)) { type = what_type(line); if (type == 1) get_link(line, temp); else if (type == 2) get_room(line, &temp, env); else if (type == 3) ; else if (type == 4) env->type = check_special(line, env); else { ft_putstr("error: invalid line\n"); exit(0); } free(line); } *room = temp; }
int main() { struct hotel plaza; int ans,i; init_hotel(&plaza); // Asks the user to check out rooms. printf("Would you like check in(1), or check out(2) or quit(4)?"); scanf("%d", &ans); // Execute the user's choices until they quit. while (ans != 4) { if (ans == 1) get_room(&plaza); else if (ans == 2) check_out(&plaza); else if (ans == 3) print_all(&plaza); // Get the user's next choice. printf("Would you like check in(1), or check out(2) or quit(3)?"); scanf("%d", &ans); } return 0; }
/* * Wizard moves a user to another room */ void move(UR_OBJECT user) { UR_OBJECT u; RM_OBJECT rm; const char *name; if (word_count < 2) { write_user(user, "Usage: move <user> [<room>]\n"); return; } u = get_user_name(user, word[1]); if (!u) { write_user(user, notloggedon); return; } if (u->login) { write_user(user, "That user is not logged in.\n"); return; } if (word_count < 3) { rm = user->room; } else { rm = get_room(word[2]); if (!rm) { write_user(user, nosuchroom); return; } } if (user == u) { write_user(user, "Trying to move yourself this way is the fourth sign of madness.\n"); return; } if (u->level >= user->level) { write_user(user, "You cannot move a user of equal or higher level than yourself.\n"); return; } if (rm == u->room) { vwrite_user(user, "%s~RS is already in the %s.\n", u->recap, rm->name); return; }; if (!has_room_access(user, rm)) { vwrite_user(user, "The %s is currently private, %s~RS cannot be moved there.\n", rm->name, u->recap); return; } write_user(user, "~FC~OLYou chant an ancient spell...\n"); name = user->vis ? user->recap : invisname; if (!user->vis) { write_monitor(user, user->room, 0); } vwrite_room_except(user->room, user, "%s~RS ~FC~OLchants an ancient spell...\n", name); move_user(u, rm, 2); prompt(u); }
/* * Move to another room */ void go(UR_OBJECT user) { RM_OBJECT rm; int i; if (user->lroom == 2) { write_user(user, "You have been shackled and cannot move.\n"); return; } if (word_count < 2) { rm = get_room_full(amsys->default_warp); if (!rm) { write_user(user, "You cannot warp to the main room at this time.\n"); return; } if (user->room == rm) { vwrite_user(user, "You are already in the %s!\n", rm->name); return; } move_user(user, rm, 1); return; } #ifdef NETLINKS release_nl(user); if (transfer_nl(user)) { return; } #endif rm = get_room(word[1]); if (!rm) { write_user(user, nosuchroom); return; } if (rm == user->room) { vwrite_user(user, "You are already in the %s!\n", rm->name); return; } /* See if link from current room */ for (i = 0; i < MAX_LINKS; ++i) { if (user->room->link[i] == rm) { break; } } if (i < MAX_LINKS) { move_user(user, rm, 0); return; } if (is_personal_room(rm)) { write_user(user, "To go to another user's home you must \".visit\" them.\n"); return; } if (user->level < WIZ) { vwrite_user(user, "The %s is not adjoined to here.\n", rm->name); return; } move_user(user, rm, 1); }
void lobby_info::close_room(const std::string& name) { room_info* r = get_room(name); DBG_LB << "lobby info: closing room " << name << " " << static_cast<void*>(r) << "\n"; if(r) { rooms_.erase(rooms_.begin() + (r - &rooms_[0])); } }
void init() { int num=get_room("east"); if (num >= 2) set("exits/east","/d/mingjiao/didao/didao_e_2"); else delete("exits/east"); add_action("do_dig","wa"); add_action("do_dig","dig"); }
void init() { int num=get_room("north"); if (num >= 4) set("exits/north","/d/mingjiao/didao/didao_n_4"); else delete("exits/north"); add_action("do_dig","wa"); add_action("do_dig","dig"); }
void init() { int num=get_room("west"); if (num >= 4) set("exits/west",__DIR__"didao_w_4"); else delete("exits/west"); add_action("do_dig","wa"); add_action("do_dig","dig"); }
int ROOM::init(double p[], int n_args) { float outskip = p[0]; float inskip = p[1]; float dur = p[2]; amp = p[3]; inchan = n_args > 4 ? (int)p[4] : AVERAGE_CHANS; if (outputchans != 2) return die("ROOM", "Output must be stereo."); if (rtsetinput(inskip, this) == -1) return DONT_SCHEDULE; insamps = (int) (dur * SR + 0.5); if (inchan >= inputChannels()) return die("ROOM", "You asked for channel %d of a %d-channel input file.", inchan, inputChannels()); if (inputChannels() == 1) inchan = 0; nmax = get_room(ipoint, lamp, ramp, SR); if (nmax == 0) return die("ROOM", "You need to call roomset before ROOM."); echo = new float[nmax]; for (int i = 0; i < nmax; i++) echo[i] = 0.0; jpoint = 0; #ifdef DEBUG printf("maximum delay = %d samples.\n", nmax); #endif float ringdur = (float) nmax / SR; if (rtsetoutput(outskip, dur + ringdur, this) == -1) return DONT_SCHEDULE; amparray = floc(1); if (amparray) { int amplen = fsize(1); tableset(SR, dur + ringdur, amplen, amptabs); } else rtcmix_advise("ROOM", "Setting phrase curve to all 1's."); aamp = amp; /* in case amparray == NULL */ skip = (int)(SR / (float)resetval); return nSamps(); }
int consume_tube(char *line, struct s_lem_in *lemin, int *state) { struct s_room *s1; struct s_room *s2; char **split; (void)state; (void)lemin; split = ft_strsplit(line, '-'); if (arraylen(split) == 2) { s1 = get_room(lemin, split[0]); s2 = get_room(lemin, split[1]); if (s1 && s2 && ft_strcmp(split[0], split[1])) { room_push_room(s1, s2); room_push_room(s2, s1); } } free_array(split); return (0); }
/*** Show list of people board posts are from without seeing the whole lot ***/ void board_from(UR_OBJECT user) { FILE *fp; int cnt; char id[ARR_SIZE],line[ARR_SIZE],fname[FNAME_LEN],rmname[ROOM_NAME_LEN+1]; RM_OBJECT rm; set_crash(); if (word_count<2) rm=user->room; else { if ((rm=get_room(word[1]))==NULL) { write_user(user,nosuchroom); return; } if (!has_room_access(user,rm)) { write_user(user,"That room is currently private, you cannot read the board.\n"); return; } } if (!rm->mesg_cnt) { write_user(user,"That room has no messages on it's board.\n"); return; } if (rm->access==PERSONAL_LOCKED || rm->access==PERSONAL_UNLOCKED) { midcpy(rm->name,rmname,1,strlen(rm->name)-2); rmname[0]=toupper(rmname[0]); sprintf(fname,"%s/%s.B", USERROOMS, rmname); } else sprintf(fname,"%s/%s.B", ROOMFILES, rm->name); if (!(fp=fopen(fname,"r"))) { write_user(user,"There was an error trying to read message board.\n"); write_syslog(ERRLOG,1,"Unable to open message board for %s in board_from().\n",rm->name); return; } vwrite_user(user,"\n~FG~BB*** Posts on the %s message board from ***\n\n",rm->name); cnt=0; line[0]='\0'; fgets(line,ARR_SIZE-1,fp); while (!feof(fp)) { sscanf(line,"%s",id); if (!strcmp(id,"PT:")) { cnt++; vwrite_user(user,"~FT%2d)~RS %s", cnt, remove_first(remove_first(remove_first(line)))); } line[0]='\0'; fgets(line,ARR_SIZE-1,fp); } fclose(fp); vwrite_user(user,"\nTotal of ~OL%d~RS messages.\n\n", rm->mesg_cnt); }
/* * Change whether a rooms access is fixed or not */ void change_room_fix(UR_OBJECT user, int fix) { RM_OBJECT rm; const char *name; if (word_count < 2) { rm = user->room; } else { rm = get_room(word[1]); if (!rm) { write_user(user, nosuchroom); return; } } if (fix) { if (is_fixed_room(rm)) { if (rm == user->room) { write_user(user, "This room's access is already fixed.\n"); } else { write_user(user, "That room's access is already fixed.\n"); } return; } } else { if (!is_fixed_room(rm)) { if (rm == user->room) { write_user(user, "This room's access is already unfixed.\n"); } else { write_user(user, "That room's access is already unfixed.\n"); } return; } } rm->access ^= FIXED; reset_access(rm); write_syslog(SYSLOG, 1, "%s %s access to room %s.\n", user->name, is_fixed_room(rm) ? "FIXED" : "UNFIXED", rm->name); name = user->vis ? user->recap : invisname; if (user->room == rm) { vwrite_room_except(rm, user, "%s~RS has %s~RS access for this room.\n", name, is_fixed_room(rm) ? "~FRFIXED" : "~FGUNFIXED"); } else { vwrite_room(rm, "This room's access has been %s~RS.\n", is_fixed_room(rm) ? "~FRFIXED" : "~FGUNFIXED"); } vwrite_user(user, "Access for room %s is now %s~RS.\n", rm->name, is_fixed_room(rm) ? "~FRFIXED" : "~FGUNFIXED"); }
int merger_rooms_index( lua_State *L ) { int vnum; if ( lua_isnumber( L, 2 ) ) { vnum = (int) lua_tointeger( L, 2 ); merger_push_room( L, get_room( vnum ) ); return 1; } else { lua_pushstring( L, "Can only index rooms[] with a number." ); lua_error( L ); } return 0; }
void parse_data(char *buffer, int *step, t_map *map) { char **tab; tab = my_strd_to_wordtab(buffer, " \t"); if (tab == NULL) my_error("Invalid/Empty line : check how to build a map\n"); if (my_strlen_tabs(tab) == 1) parse_data2(tab[0], step, map); else if (my_strlen_tabs(tab) == 3) { get_room(tab, step, map); printf("%s\n", buffer); } else { fprintf(stderr, "Invalid line : %s\n", buffer); exit(EXIT_FAILURE); } free_tab(tab); }
void parser(t_lem *p) { char *str; static t_state state = ANT; while (get_next_line(0, &str) > 0) { if (state == END) list(p, str, 1); else list(p, str, 0); if (str[0] != '#' || (str[0] == '#' && str[1] == '#')) { if (state == ANT) state = get_ant(p, str); else if (state == ROOM) state = get_room(p, str); else if (state == LINK) state = get_link(p, str); free(str); } } }
/* * Ask to be let into a private room */ void letmein(UR_OBJECT user) { RM_OBJECT rm; int i; if (word_count < 2) { write_user(user, "Knock on what door?\n"); return; } rm = get_room(word[1]); if (!rm) { write_user(user, nosuchroom); return; } if (rm == user->room) { vwrite_user(user, "You are already in the %s!\n", rm->name); return; } for (i = 0; i < MAX_LINKS; ++i) if (user->room->link[i] == rm) { break; } if (i >= MAX_LINKS) { vwrite_user(user, "The %s is not adjoined to here.\n", rm->name); return; } if (!is_private_room(rm)) { vwrite_user(user, "The %s is currently public.\n", rm->name); return; } vwrite_user(user, "You knock asking to be let into the %s.\n", rm->name); vwrite_room_except(user->room, user, "%s~RS knocks asking to be let into the %s.\n", user->recap, rm->name); vwrite_room(rm, "%s~RS knocks asking to be let in.\n", user->recap); }
void cre(int socket, char *roomname) { char *name; if ((name = malloc(sizeof(char)*strlen(roomname))) == NULL) { perror("Malloc failed"); write(socket, "Server: there was an error. Please, resend your message.", MAX_PACK_SIZE); return; } memset(name, 0, strlen(name)); strcpy(name, roomname); box *temp; if ((temp = get_room(rooms, name)) != NULL) { write(socket, "Room already exists", MAX_PACK_SIZE); return; } temp = NULL; if ((temp = add_room(rooms, name)) == NULL) { write(socket, "Problem creating room", MAX_PACK_SIZE); return; } }
bool lobby_info::has_room(const std::string& name) const { return get_room(name) != nullptr; }
} else { detect_format_and_read(cfg, *file); } foreach (const config &c, cfg.child_range("room")) { room* r(new room(c)); if (room_exists(r->name())) { ERR_LOBBY << "Duplicate room ignored in stored rooms: " << r->name() << "\n"; delete r; } else { rooms_by_name_.insert(std::make_pair(r->name(), r)); } } } lobby_ = get_room(lobby_name_); if (lobby_ == NULL) { lobby_ = create_room(lobby_name_); lobby_->set_persistent(true); lobby_->set_logged(true); dirty_ = true; } } void room_manager::write_rooms() { if (filename_.empty()) return; LOG_LOBBY << "Writing rooms to " << filename_ << "\n"; config cfg; foreach (const t_rooms_by_name_::value_type& v, rooms_by_name_) { const room& r = *v.second;
/* * Set rooms to public or private */ void set_room_access(UR_OBJECT user, int priv) { UR_OBJECT u; RM_OBJECT rm; const char *name; if (word_count < 2) { rm = user->room; } else { if (user->level < amsys->gatecrash_level) { write_user(user, "You are not a high enough level to use the room option.\n"); return; } rm = get_room(word[1]); if (!rm) { write_user(user, nosuchroom); return; } } if (is_personal_room(rm)) { if (rm == user->room) { write_user(user, "This room's access is personal.\n"); } else { write_user(user, "That room's access is personal.\n"); } return; } if (is_fixed_room(rm)) { if (rm == user->room) { write_user(user, "This room's access is fixed.\n"); } else { write_user(user, "That room's access is fixed.\n"); } return; } if (priv) { if (is_private_room(rm)) { if (rm == user->room) { write_user(user, "This room is already private.\n"); } else { write_user(user, "That room is already private.\n"); } return; } if (room_visitor_count(rm) < amsys->min_private_users && user->level < amsys->ignore_mp_level) { vwrite_user(user, "You need at least %d users/clones in a room before it can be made private.\n", amsys->min_private_users); return; } } else { if (!is_private_room(rm)) { if (rm == user->room) { write_user(user, "This room is already public.\n"); } else { write_user(user, "That room is already public.\n"); } return; } /* Reset any invites into the room & clear review buffer */ for (u = user_first; u; u = u->next) { if (u->invite_room == rm) { u->invite_room = NULL; } } clear_revbuff(rm); } rm->access ^= PRIVATE; name = user->vis ? user->recap : invisname; if (rm == user->room) { vwrite_room_except(rm, user, "%s~RS has set the room to %s~RS.\n", name, is_private_room(rm) ? "~FRPRIVATE" : "~FGPUBLIC"); } else { vwrite_room(rm, "This room has been set to %s~RS.\n", is_private_room(rm) ? "~FRPRIVATE" : "~FGPUBLIC"); } vwrite_user(user, "Room set to %s~RS.\n", is_private_room(rm) ? "~FRPRIVATE" : "~FGPUBLIC"); }
/* * Reloads the description for one or all rooms--incase you have edited the * file and do not want to reboot the talker to to make the changes displayed */ void reload_room_description(UR_OBJECT user) { int c, i, error; RM_OBJECT rm; char filename[80]; FILE *fp; if (word_count < 2) { write_user(user, "Usage: rloadrm -a/<room name>\n"); return; } /* if reload all of the rooms */ if (!strcmp(word[1], "-a")) { error = 0; for (rm = room_first; rm; rm = rm->next) { if (is_personal_room(rm)) { continue; } sprintf(filename, "%s/%s.R", DATAFILES, rm->name); fp = fopen(filename, "r"); if (!fp) { vwrite_user(user, "Sorry, cannot reload the description file for the room \"%s\".\n", rm->name); write_syslog(SYSLOG | ERRLOG, 0, "ERROR: Cannot reload the description file for room %s.\n", rm->name); ++error; continue; } i = 0; for (c = getc(fp); c != EOF; c = getc(fp)) { if (i == ROOM_DESC_LEN) { break; } rm->desc[i++] = c; } if (c != EOF) { vwrite_user(user, "The description is too long for the room \"%s\".\n", rm->name); write_syslog(SYSLOG | ERRLOG, 0, "ERROR: Description too long when reloading for room %s.\n", rm->name); } rm->desc[i] = '\0'; fclose(fp); } if (!error) { write_user(user, "You have now reloaded all room descriptions.\n"); } else { write_user(user, "You have now reloaded all room descriptions that you can.\n"); } write_syslog(SYSLOG, 1, "%s reloaded all of the room descriptions.\n", user->name); return; } /* if it is just one room to reload */ rm = get_room(word[1]); if (!rm) { write_user(user, nosuchroom); return; } /* check first for personal room, and do not reload */ if (is_personal_room(rm)) { write_user(user, "Sorry, but you cannot reload personal room descriptions.\n"); return; } sprintf(filename, "%s/%s.R", DATAFILES, rm->name); fp = fopen(filename, "r"); if (!fp) { vwrite_user(user, "Sorry, cannot reload the description file for the room \"%s\".\n", rm->name); write_syslog(SYSLOG | ERRLOG, 0, "ERROR: Cannot reload the description file for room %s.\n", rm->name); return; } i = 0; for (c = getc(fp); c != EOF; c = getc(fp)) { if (i == ROOM_DESC_LEN) { break; } rm->desc[i++] = c; } if (c != EOF) { vwrite_user(user, "The description is too long for the room \"%s\".\n", rm->name); write_syslog(SYSLOG | ERRLOG, 0, "ERROR: Description too long when reloading for room %s.\n", rm->name); } rm->desc[i] = '\0'; fclose(fp); vwrite_user(user, "You have now reloaded the description for the room \"%s\".\n", rm->name); write_syslog(SYSLOG, 1, "%s reloaded the description for the room %s\n", user->name, rm->name); }