static void User_command() { char command[130]; char client_group[13]; char mess[SPREAD_MESS_LEN]; char group[MAX_ROOM_LEN - strlen("CR#_")]; char groups[10][MAX_GROUP_NAME]; int num_groups; unsigned int mess_len; int ret; int srv; int i; for( i=0; i < sizeof(command); i++ ) command[i] = 0; if( fgets( command, 130, stdin ) == NULL ) Bye(); switch( command[0] ) { case 'u': ret = sscanf( &command[2], "%s", u_id); if (ret < 1 ) printf("invalid username\n"); break; case 'c': ret = sscanf( &command[2], "%d", &srv); if ( ret < 1 || isValidServer(srv) != 1) { //isValid sets server_num printf("invalid server index\n"); break; } ret = sprintf( client_group, "client_group%d",server_num); if (ret < 1) { printf("Error connecting to server-client group\n"); break; } ret = SP_join(Mbox, client_group); if (ret < 0) SP_error( ret ); sprintf( server_priv_group, "server%d", server_num); break; case 'j': //check if already in room if (strlen(chatroom) > 0) { clear_room(chatroom); } else { ret = sscanf( &command[2], "%s", chatroom ); if( ret < 1 ) { printf(" invalid chatroom name \n"); break;} add_room(chatroom); } if (strlen(u_id) > 0 && isValidServer(server_num)) { //need valid username + server for chatroom ret = sprintf ( group, "%s%d_%s","CR",server_num,chatroom); if (ret < 1) { printf("Error creating chatroom name <%s> from group <%s>\n",chatroom,group); break; } ret = SP_join( Mbox, group ); //join CR#_<group> spread group if( ret < 0 ) SP_error( ret ); } else { printf("Invalid username or server number, cannot join chatroom\n"); break;} join_chatroom* send = (join_chatroom*)mess; send->type = TYPE_JOIN_CHATROOM; send->source = SOURCE_CLIENT; strncpy(send->u_id,u_id,MAX_NAME_LEN); strncpy(send->chatroom,chatroom,MAX_ROOM_LEN); //send <group> as chatroom spread name ret = SP_multicast( Mbox, AGREED_MESS, server_priv_group, 1, sizeof(join_chatroom), mess ); if( ret < 0 ) { SP_error( ret ); Bye(); } break; /* case 'x':{ char ms[6]; add_room(chatroom); set_max_msgs(25); int maxi = 40; for (int i = 1; i <= maxi;i++) { struct lamport* ts = malloc(sizeof(lamport)); ts->server_id = 1; ts->index = i; sprintf(ms,"%s%d","asdfd",i); add_message(ts,u_id,chatroom,ms); if (i % 3 == 0 || i % 4 == 1 || i % 6 == 2) { i++; maxi++; struct lamport* ls = malloc(sizeof(lamport)); ls->server_id = 1; ls->index = i; add_like(LIKE,ls,u_id,chatroom,ts); if (i % 6 == 2){ i++;maxi++; char newu[MAX_NAME_LEN]; sprintf(newu,"%sx",u_id); struct lamport* qs = malloc(sizeof(lamport)); qs->server_id = 1; qs->index = i; add_like(LIKE,qs,newu,chatroom,ts); } } if (i % 4 == 1) { i++; maxi++; struct lamport* ls = malloc(sizeof(lamport)); ls->server_id = 1; ls->index = i; add_like(UNLIKE,ls,u_id,chatroom,ts); } } printf("== %s ==\n",chatroom); print_room(chatroom); break;} */ case 'a': { char text[MAX_MESS_LEN]; printf("enter message: "); if (fgets(text, MAX_MESS_LEN, stdin) == NULL) Bye(); if (strlen(chatroom) < 1){ printf("Please join a chatroom\n"); break; } message* dat = (message*)mess; dat->type = TYPE_SEND_MSG; dat->source = SOURCE_CLIENT; strncpy(dat->u_id,u_id,MAX_NAME_LEN); strncpy(dat->chatroom,chatroom,MAX_ROOM_LEN); strncpy(dat->mess,text,MAX_MESS_LEN); ret= SP_multicast( Mbox, AGREED_MESS, server_priv_group, 1, sizeof(message), mess ); if( ret < 0 ) { SP_error( ret ); Bye(); } break; } case 'l': { if (strlen(chatroom) < 1){ printf("Please join a chatroom\n"); break;} int linenum; ret = sscanf( &command[2], "%d", &linenum ); printf("Liking line %d.....\n",linenum); if( ret < 1 ) { printf(" invalid linenum \n"); break;} lamport* stamp = get_msg_stamp(linenum); printf("%d. index %d?\n",linenum,stamp->index); like* dat = (like*)mess; dat->type = TYPE_LIKE_MSG; dat->source = SOURCE_CLIENT; dat->msg_timestamp.server_id = stamp->server_id; dat->msg_timestamp.index = stamp->index; strncpy(dat->u_id,u_id,MAX_NAME_LEN); strncpy(dat->chatroom,chatroom,MAX_ROOM_LEN); dat->like_state = LIKE; ret = SP_multicast( Mbox, AGREED_MESS, server_priv_group, 1, sizeof(like), mess); if (ret < 0) { SP_error(ret); Bye; } break; } case 'r': { if (strlen(chatroom) < 1){ printf("Please join a chatroom\n"); break;} int linenum; ret = sscanf( &command[2], "%d", linenum ); if( ret < 1 ) { printf(" invalid linenum \n"); break;} lamport* stamp = get_msg_stamp(linenum); printf("%d. index %d?\n",linenum,stamp->index); like* dat = (like*)mess; dat->type = TYPE_LIKE_MSG; dat->source = SOURCE_CLIENT; dat->msg_timestamp.server_id = stamp->server_id; dat->msg_timestamp.index = stamp->index; strncpy(dat->u_id,u_id,MAX_NAME_LEN); strncpy(dat->chatroom,chatroom,MAX_ROOM_LEN); dat->like_state = UNLIKE; ret = SP_multicast( Mbox, AGREED_MESS, server_priv_group, 1, sizeof(like), mess); if (ret < 0) { SP_error(ret); Bye; } break; } case 'h': printf("history not implemented\n"); break; case 'v': printf("network view not implemented\n"); break; case 'q': Bye(); break; default: printf("\nUnknown commnad\n"); Print_menu(); break; } printf(" \n > "); fflush(stdout); }
/* This function is recursive, ie it calls itself */ void map_exits( CHAR_DATA * ch, ROOM_INDEX_DATA * pRoom, int x, int y, int depth ) { static char map_chars[11] = "|-|-UD/\\\\/"; int door; int exitx = 0, exity = 0; int roomx = 0, roomy = 0; EXIT_DATA *pExit; /* * Setup this coord as a room - Change any symbols that can't be displayed here */ dmap[x][y].sector = pRoom->sector_type; switch ( pRoom->sector_type ) { case SECT_INSIDE: dmap[x][y].tegn = 'O'; dmap[x][y].sector = -1; break; case SECT_CITY: dmap[x][y].tegn = ':'; break; case SECT_FIELD: case SECT_FOREST: case SECT_HILLS: dmap[x][y].tegn = '*'; break; case SECT_MOUNTAIN: dmap[x][y].tegn = '@'; break; case SECT_WATER_SWIM: case SECT_WATER_NOSWIM: dmap[x][y].tegn = '='; break; case SECT_AIR: dmap[x][y].tegn = '~'; break; case SECT_DESERT: dmap[x][y].tegn = '+'; break; default: dmap[x][y].tegn = 'O'; dmap[x][y].sector = -1; bug( "%s: Bad sector type (%d) in room %d.", __FUNCTION__, pRoom->sector_type, pRoom->vnum ); break; } dmap[x][y].vnum = pRoom->vnum; dmap[x][y].depth = depth; // dmap[x][y].info = pRoom->room_flags; dmap[x][y].can_see = room_is_dark( pRoom ); /* * Limit recursion */ if ( depth > MAXDEPTH ) return; /* * This room is done, deal with it's exits */ for ( door = 0; door < 10; ++door ) { /* * Skip if there is no exit in this direction */ if ( !( pExit = get_exit( pRoom, door ) ) ) continue; /* * Skip up and down until I can figure out a good way to display it */ if ( door == 4 || door == 5 ) continue; /* * Get the coords for the next exit and room in this direction */ get_exit_dir( door, &exitx, &exity, x, y ); get_exit_dir( door, &roomx, &roomy, exitx, exity ); /* * Skip if coords fall outside map */ if ( BOUNDARY( exitx, exity ) || BOUNDARY( roomx, roomy ) ) continue; /* * Skip if there is no room beyond this exit */ if ( !pExit->to_room ) continue; /* * Ensure there are no clashes with previously defined rooms */ if ( ( dmap[roomx][roomy].vnum != 0 ) && ( dmap[roomx][roomy].vnum != pExit->to_room->vnum ) ) { /* * Use the new room if the depth is higher */ if ( dmap[roomx][roomy].depth <= depth ) continue; /* * It is so clear the old room */ clear_room( roomx, roomy ); } /* * No exits at MAXDEPTH */ if ( depth == MAXDEPTH ) continue; /* * No need for exits that are already mapped */ if ( dmap[exitx][exity].depth > 0 ) continue; /* * Fill in exit */ dmap[exitx][exity].depth = depth; dmap[exitx][exity].vnum = pExit->to_room->vnum; // dmap[exitx][exity].info = pExit->exit_info; dmap[exitx][exity].tegn = map_chars[door]; dmap[exitx][exity].sector = -1; /* * More to do? If so we recurse */ if ( depth < MAXDEPTH && ( ( dmap[roomx][roomy].vnum == pExit->to_room->vnum ) || ( dmap[roomx][roomy].vnum == 0 ) ) ) { /* * Depth increases by one each time */ map_exits( ch, pExit->to_room, roomx, roomy, depth + 1 ); } } }
/* This function is recursive, ie it calls itself */ void map_exits(CHAR_DATA *ch, ROOM_INDEX_DATA *pRoom, int x, int y, int depth) { static char map_chars [4] = "|-|-"; int door; int exitx = 0, exity = 0; int roomx = 0, roomy = 0; char buf[200]; // bugs EXIT_DATA *pExit; /* Setup this coord as a room */ switch(pRoom->sector_type) { case SECT_CITY: case SECT_INSIDE: case SECT_UNUSED: map[x][y].tegn = 'O'; break; case SECT_FIELD: case SECT_FOREST: case SECT_HILLS: map[x][y].tegn = '*'; break; case SECT_MOUNTAIN: map[x][y].tegn = '@'; break; case SECT_WATER_SWIM: case SECT_WATER_NOSWIM: map[x][y].tegn = '='; break; case SECT_AIR: map[x][y].tegn = '~'; break; case SECT_DESERT: map[x][y].tegn = '+'; break; default: map[x][y].tegn = 'O'; xprintf(buf, "Map_exits: Bad sector type (%d) in room %d.", pRoom->sector_type, pRoom->vnum); bug(buf, 0); break; } map[x][y].vnum = pRoom->vnum; map[x][y].depth = depth; map[x][y].info = pRoom->room_flags; map[x][y].can_see = room_is_dark( pRoom ); /* Limit recursion */ if ( depth > MAXDEPTH ) return; /* This room is done, deal with it's exits */ for( door = 0; door < 4; door++ ) { /* Skip if there is no exit in this direction */ if ( ( pExit = pRoom->exit[door] ) == NULL ) continue; /* Get the coords for the next exit and room in this direction */ get_exit_dir( door, &exitx, &exity, x, y ); get_exit_dir( door, &roomx, &roomy, exitx, exity ); /* Skip if coords fall outside map */ if ( BOUNDARY( exitx, exity ) || BOUNDARY( roomx, roomy )) continue; /* Skip if there is no room beyond this exit */ if ( pExit->to_room == NULL ) continue; /* Ensure there are no clashes with previously defined rooms */ if ( ( map[roomx][roomy].vnum != 0 ) && ( map[roomx][roomy].vnum != pExit->to_room->vnum )) { /* Use the new room if the depth is higher */ if ( map[roomx][roomy].depth <= depth ) continue; /* It is so clear the old room */ clear_room( roomx, roomy ); } /* No exits at MAXDEPTH */ if ( depth == MAXDEPTH ) continue; /* No need for exits that are already mapped */ if ( map[exitx][exity].depth > 0 ) continue; /* Fill in exit */ map[exitx][exity].depth = depth; map[exitx][exity].vnum = pExit->to_room->vnum; map[exitx][exity].info = pExit->exit_info; map[exitx][exity].tegn = map_chars[door]; /* More to do? If so we recurse */ if ( ( depth < MAXDEPTH ) && ( ( map[roomx][roomy].vnum == pExit->to_room->vnum ) || ( map[roomx][roomy].vnum == 0 ) ) ) { /* Depth increases by one each time */ map_exits( ch, pExit->to_room, roomx, roomy, depth + 1 ); } } }