Exemplo n.º 1
0
int chat_kick( int unum, char *msg )
{
  char *twit = nextword(&msg);
  int rnum = users[unum].room;
  int recunum;
  if (!OPERATOR(unum) && !MANAGER(unum)) {
    send_to_unum(unum, "*** You're not operator\n", -1);
    return 0;
  }
  if ((recunum = chatid_to_indx(twit)) == -1) {
    /* no such user */
    sprintf(genbuf, "*** No such chatid '%s'\n", twit);
    send_to_unum(unum, genbuf, -1);
    return 0;
  }    
  if (rnum != users[recunum].room) {
    sprintf(genbuf, "*** '%s' is not in this room\n", users[recunum].chatid);
    send_to_unum(unum, genbuf, -1);
    return 0;
  }
  exit_room(recunum, EXIT_KICK, msg);

  if (rnum == 0) logout_user(recunum);        
  else enter_room(recunum, mainroom, (char *)NULL);    

  return 0;  
}  
Exemplo n.º 2
0
/*
 * sight:
 *	He gets his sight back
 */
sight()
{
    if (on(player, ISBLIND))
    {
	extinguish(sight);
	player.t_flags &= ~ISBLIND;
	if (!(proom->r_flags & ISGONE))
	    enter_room(&hero);
	if (on(player, ISTrip))
	    msg("far out!  Everything is all cosmic again");
	else
	    msg("the veil of darkness lifts");
    }
}
Exemplo n.º 3
0
int chat_join( int unum, char *msg )
{
  char *roomid = nextword(&msg);
  if (RESTRICTED(unum)) {
    send_to_unum(unum, 
		 "*** You do not have permission to join other rooms\n", -1);
    return 0;
  }
  if (*roomid == '\0') {
    send_to_unum(unum, "*** You must specify a room\n", -1);
    return 0;
  }
  if (!is_valid_roomname(roomid)) {
    send_to_unum(unum, "*** Invalid room name\n", -1);
    return 0;
  }
  enter_room(unum, roomid, msg);
  return 0;
}  
Exemplo n.º 4
0
bool Light::Zap(Coord dir)
{
    //Ready Kilowatt wand.  Light up the room
    if (game->hero().is_blind())
        msg("you feel a warm glow around you");
    else
    {
        discover(false);
        if (game->hero().room()->is_gone())
            msg("the corridor glows and then fades");
        else
            msg("the room is lit by a shimmering blue light");
    }

    if (!game->hero().room()->is_gone())
    {
        game->hero().room()->set_dark(false);
        //Light the room and put the player back up
        enter_room(game->hero().position());
    }

    return true;
}
// enter a directory room and scan for the resident sensory pattern.
SENSORIMOTOR_SECTION
DIR* scan_room(char *dir, char *cwd, int cwdsize)
{
    DIR *dirp = NULL;
    struct dirent *de;

    //printf("[sm] entering room %s\n", dir);
    if ((dirp = enter_room(dir, cwd, cwdsize)) == NULL)
        return NULL;

    health_status -= HEALTH_DECAY;

    while ((de = readdir(dirp)) != NULL) {
        if (de->d_type == DT_REG) {
            if (consume_pattern(cwd, de->d_name) == 0) {
                //printf("\tfound pattern %s\n", de->d_name);
                return 0;
            }
        }
    }

    rewinddir(dirp);
    return dirp;
}
Exemplo n.º 6
0
Arquivo: wiz.c Projeto: hyena/fuzzball
void
do_teleport(int descr, dbref player, const char *arg1, const char *arg2)
{
	dbref victim;
	dbref destination;
	const char *to;
	struct match_data md;

	/* get victim, destination */
	if (*arg2 == '\0') {
		victim = player;
		to = arg1;
	} else {
		init_match(descr, player, arg1, NOTYPE, &md);
		match_neighbor(&md);
		match_possession(&md);
		match_me(&md);
		match_here(&md);
		match_absolute(&md);
		match_registered(&md);
		match_player(&md);

		if ((victim = noisy_match_result(&md)) == NOTHING) {
			return;
		}
		to = arg2;
	}
#ifdef GOD_PRIV
	if(tp_strict_god_priv && !God(player) && God(OWNER(victim))) {
		notify(player, "God has already set that where He wants it to be.");
		return;
	}
#endif

	/* get destination */
	init_match(descr, player, to, TYPE_PLAYER, &md);
	match_possession(&md);
	match_me(&md);
	match_here(&md);
	match_home(&md);
	match_absolute(&md);
	match_registered(&md);
	if (Wizard(OWNER(player))) {
		match_neighbor(&md);
		match_player(&md);
	}
	switch (destination = match_result(&md)) {
	case NOTHING:
		notify(player, "Send it where?");
		break;
	case AMBIGUOUS:
		notify(player, "I don't know which destination you mean!");
		break;
	case HOME:
		switch (Typeof(victim)) {
		case TYPE_PLAYER:
			destination = PLAYER_HOME(victim);
			if (parent_loop_check(victim, destination))
				destination = PLAYER_HOME(OWNER(victim));
			break;
		case TYPE_THING:
			destination = THING_HOME(victim);
			if (parent_loop_check(victim, destination)) {
			  destination = PLAYER_HOME(OWNER(victim));
			  if (parent_loop_check(victim, destination)) {
			    destination = (dbref) 0;
			  }
			}
			break;
		case TYPE_ROOM:
			destination = GLOBAL_ENVIRONMENT;
			break;
		case TYPE_PROGRAM:
			destination = OWNER(victim);
			break;
		default:
			destination = tp_player_start;	/* caught in the next
											   * switch anyway */
			break;
		}
	default:
		switch (Typeof(victim)) {
		case TYPE_PLAYER:
			if (!controls(player, victim) ||
				!controls(player, destination) ||
				!controls(player, getloc(victim)) ||
				(Typeof(destination) == TYPE_THING && !controls(player, getloc(destination)))) {
				notify(player, "Permission denied. (must control victim, dest, victim's loc, and dest's loc)");
				break;
			}
			if (Typeof(destination) != TYPE_ROOM && Typeof(destination) != TYPE_THING) {
				notify(player, "Bad destination.");
				break;
			}
			if (!Wizard(victim) &&
				(Typeof(destination) == TYPE_THING && !(FLAGS(destination) & VEHICLE))) {
				notify(player, "Destination object is not a vehicle.");
				break;
			}
			if (parent_loop_check(victim, destination)) {
				notify(player, "Objects can't contain themselves.");
				break;
			}
			notify(victim, "You feel a wrenching sensation...");
			enter_room(descr, victim, destination, DBFETCH(victim)->location);
			notify(player, "Teleported.");
			break;
		case TYPE_THING:
			if (parent_loop_check(victim, destination)) {
				notify(player, "You can't make a container contain itself!");
				break;
			}
		case TYPE_PROGRAM:
			if (Typeof(destination) != TYPE_ROOM
				&& Typeof(destination) != TYPE_PLAYER && Typeof(destination) != TYPE_THING) {
				notify(player, "Bad destination.");
				break;
			}
			if (!((controls(player, destination) ||
				   can_link_to(player, NOTYPE, destination)) &&
				  (controls(player, victim) || controls(player, DBFETCH(victim)->location)))) {
				notify(player, "Permission denied. (must control dest and be able to link to it, or control dest's loc)");
				break;
			}
			/* check for non-sticky dropto */
			if (Typeof(destination) == TYPE_ROOM
				&& DBFETCH(destination)->sp.room.dropto != NOTHING
				&& !(FLAGS(destination) & STICKY))
						destination = DBFETCH(destination)->sp.room.dropto;
			if (tp_thing_movement && (Typeof(victim) == TYPE_THING)) {
				enter_room(descr, victim, destination, DBFETCH(victim)->location);
			} else {
				moveto(victim, destination);
			}
			notify(player, "Teleported.");
			break;
		case TYPE_ROOM:
			if (Typeof(destination) != TYPE_ROOM) {
				notify(player, "Bad destination.");
				break;
			}
			if (!controls(player, victim)
				|| !can_link_to(player, NOTYPE, destination)
				|| victim == GLOBAL_ENVIRONMENT) {
				notify(player, "Permission denied. (Can't move #0, dest must be linkable, and must control victim)");
				break;
			}
			if (parent_loop_check(victim, destination)) {
				notify(player, "Parent would create a loop.");
				break;
			}
			moveto(victim, destination);
			notify(player, "Parent set.");
			break;
		case TYPE_GARBAGE:
			notify(player, "That object is in a place where magic cannot reach it.");
			break;
		default:
			notify(player, "You can't teleport that.");
			break;
		}
		break;
	}
	return;
}
Exemplo n.º 7
0
int login_user( int unum, char *msg )
{
  int i, utent, fd = users[unum].sockfd;
  char accessbytes[MAX_CLNTCMDS];
  char *utentstr = nextword(&msg);
  char *chatid = nextword(&msg);
  USERDATA udata;
  PATH ignorefile;
      
  utent = atoi(utentstr);
  if (utable_get_record(utent, &udata) != S_OK || udata.u.mode != M_CHAT) {
    send_to_unum(unum, CHAT_LOGIN_BOGUS, -1);
    return -1;
  }
  for (i=0; i<bbs_max_users; i++) {
    if (users[i].sockfd != -1 && users[i].utent == utent) {
      /* Either a "ghost" or a hacker */
      if (kill(users[i].client_pid, 0) == 0) {
        send_to_unum(unum, CHAT_LOGIN_BOGUS, -1);
        return -1;
      }
      else {
        exit_room(i, EXIT_LOSTCONN, (char *)NULL);
        logout_user(i);
      }
    }
  }
  if (strlen(chatid) > CHATID_MAX) chatid[CHATID_MAX] = '\0';
  if (!is_valid_chatid(chatid)) {
    send_to_unum(unum, CHAT_LOGIN_INVALID, -1);
    return 0; /* TODO change to -1 when possible */
  }
  if (chatid_to_indx(chatid) != -1) {
    /* userid in use */
    send_to_unum(unum, CHAT_LOGIN_EXISTS, -1);
    return 0; /* TODO: change to -1 when possible */
  }    

  /* Login is ok. Set flags and fill in user record. */
  utable_get_record(utent, &udata);
  if (udata.u.flags & FLG_CLOAK) {
    udata.u.flags &= ~FLG_CLOAK;
    users[unum].flags |= FLG_RESTORECLOAK;
  }  
  utable_set_record(utent, &udata);

  if (is_in_namelist(manager_list, udata.u.userid))
    users[unum].flags |= FLG_CHATMGR;    
  else if (is_in_namelist(restricted_list, udata.u.userid))
    users[unum].flags |= FLG_CHATGUEST;

  users[unum].utent = utent;
  users[unum].client_pid = udata.u.pid;
  strncpy(users[unum].userid, udata.u.userid, NAMELEN);
  if (!RESTRICTED(unum)) {
    chat_get_ignore_file(users[unum].userid, ignorefile);  
    read_namelist(ignorefile, &users[unum].ignorelist);
  }
  users[unum].ignoring = NULL;
  for (i = 0; i < bbs_max_users; i++) {
    if (users[i].sockfd == -1) continue;
    if (is_in_namelist(users[i].ignorelist, udata.u.userid)) {
      if (users[unum].ignoring == NULL)
        users[unum].ignoring = (char *)calloc(bbs_max_users, sizeof(char));
      if (users[unum].ignoring != NULL)
        users[unum].ignoring[i] = 1;
    }
    if (is_in_namelist(users[unum].ignorelist, users[i].userid)) {
      if (users[i].ignoring == NULL)
        users[i].ignoring = (char *)calloc(bbs_max_users, sizeof(char));
      if (users[i].ignoring != NULL)
        users[i].ignoring[unum] = 1;
    }
  }
  strcpy(users[unum].chatid, chatid);
  send_to_unum(unum, CHAT_LOGIN_OK, -1);
  sprintf(genbuf, "*** Welcome to Chat, %s\n", users[unum].chatid);
  send_to_unum(unum, genbuf, -1);
  display_motd(unum);
  print_user_counts(unum);
  enter_room(unum, mainroom, (char *)NULL);
  return 0;  
}  
Exemplo n.º 8
0
int main(int argc, char **argv) {

    char line[MAX_MESSAGE_LEN+1];

    if (argc < 5) {
        printUsage();
    }

    host = argv[1];
    sport = argv[2];
    user = argv[3];
    password = argv[4];

    printf("\nStarting talk-client %s %s %s %s\n", host, sport, user, password);

    // Convert port to number
    sscanf(sport, "%d", &port);

    //create gui
    //
    //entry.c - text fields, messages, password
    //panned.c - split pane
    //radio.c - radio buttons
    //timer.c - time and countdown






    add_user();

    // Enter room
    enter_room();

    printf("\nEntered room and starting message thread\n");

    // Start message thread
    startGetMessageThread();

    while (1) {
        printPrompt();

        char * s = fgets(line,MAX_MESSAGE_LEN, stdin);
        if (s==NULL) {
            leave_room();
            printf("talk-client exiting...\n");
            exit(1);
        }

        if (!isatty(0)) {
            // If it is not a terminal, echo command as well
            printf("%s\n", line);
        }

        if (line[0]=='-') {
            // This is a command process it
            if (!strcmp(line,"-help")) {
                printHelp();
            }
            else if (!strcmp(line,"-quit")) {
                printf("talk-client exiting...\n");
                exit(1);
            }
            // Put other commands here
            else if (!strcmp(line,"-users")) {
                print_users();
            }
            else if (!strcmp(line,"-who")) {
                print_users_in_room();
            }
            else {
                printf("Wrong command\n");
            }
        }
        else if (line[0]==0) {
            // Empty line. Print help
            printf("Type -help to print the available commands\n");
        }
        else {
            // Send message
            char response[MAX_RESPONSE];
            sendCommand(host,port,"SEND-MESSAGE", user, password, line, response);
        }
    }

    printf("TEST ENDS\n");
    return 0;
}
Exemplo n.º 9
0
int main(int argc, char **argv) {

    char line[MAX_MESSAGE_LEN+1];

    if (argc < 5) {
        printUsage();
    }

    host = argv[1];
    sport = argv[2];
    user = argv[3];
    password = argv[4];

    printf("\nStarting talk-client %s %s %s %s\n", host, sport, user, password);

    int i;
    for (i = 0; i < 100; i++) {
        messages[i] = (char*) malloc(100*sizeof(char));
    }
    
    // Convert port to number
    sscanf(sport, "%d", &port);

    add_user();
    create_room();

    // Enter room
    enter_room();

    // Start message thread
    startGetMessageThread();

    //TODO

    GtkWidget *window;
    GtkWidget *table;

    GtkWidget *title;
    GtkWidget *title1;
    GtkWidget *title2;
    GtkWidget *title3;

    GtkWidget *activate;
    GtkWidget *halign;
    GtkWidget *halign1;
    GtkWidget *halign2;
    GtkWidget *halign3;
    GtkWidget *halign4;
    GtkWidget *halign5;

    GtkWidget *valign;
    GtkWidget *close;
    GtkWidget *wins;
    GtkWidget *list;
    GtkWidget *wins1;
    GtkWidget *messages;
    GtkWidget *type;

    GtkWidget *send;
    GtkWidget *createAccount;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_widget_set_size_request (window, 800, 700);
    gtk_window_set_resizable(GTK_WINDOW(window), TRUE);

    gtk_container_set_border_width(GTK_CONTAINER(window), 15);

    table = gtk_table_new(8, 8, FALSE);
    gtk_table_set_col_spacings(GTK_TABLE(table), 10);
    gtk_table_set_row_spacings(GTK_TABLE(table), 10);

    title = gtk_label_new("Rooms");
    halign = gtk_alignment_new(0, 0, 0, 0);
    gtk_container_add(GTK_CONTAINER(halign), title);
    gtk_table_attach(GTK_TABLE(table), halign, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);

    title1 = gtk_label_new("Users");
    halign1 = gtk_alignment_new(0, 0, 0, 0);
    gtk_container_add(GTK_CONTAINER(halign1), title1);
    gtk_table_attach(GTK_TABLE(table), halign1, 4, 5, 0, 1, GTK_FILL, GTK_FILL, 0, 0);

    //wins = gtk_text_view_new();
    //gtk_text_view_set_editable(GTK_TEXT_VIEW(wins), TRUE);
    //gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(wins), TRUE);
    wins = create_list("Rooms");
    gtk_table_attach(GTK_TABLE(table), wins, 0, 4, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    //wins1 = gtk_text_view_new();
    //gtk_text_view_set_editable(GTK_TEXT_VIEW(wins1), TRUE);
    //gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(wins1), TRUE);
    wins1 = create_list("Users");
    gtk_table_attach(GTK_TABLE(table), wins1, 4, 8, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    title2 = gtk_label_new("Messages");
    halign4 = gtk_alignment_new(0, 0, 0, 0);
    gtk_container_add(GTK_CONTAINER(halign4), title2);
    gtk_table_attach(GTK_TABLE(table), halign4, 0, 1, 2, 3, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    messages = gtk_text_view_new();
    gtk_text_view_set_editable(GTK_TEXT_VIEW(messages), FALSE);
    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(messages), FALSE);
    gtk_table_attach(GTK_TABLE(table), messages, 0, 8, 3, 5, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    title3 = gtk_label_new("Type a message:");
    halign5 = gtk_alignment_new(0, 0, 0, 0);
    gtk_container_add(GTK_CONTAINER(halign5), title3);
    gtk_table_attach(GTK_TABLE(table), halign5, 0, 1, 5, 6, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    type = gtk_text_view_new();
    gtk_text_view_set_editable(GTK_TEXT_VIEW(type), TRUE);
    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(type), TRUE);
    gtk_table_attach(GTK_TABLE(table), type, 0, 8, 6, 7, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    halign2 = gtk_alignment_new(0, 1, 0, 0);
    send = gtk_button_new_with_label("Send");
    g_signal_connect (send, "clicked", G_CALLBACK (send_message), NULL);
    gtk_container_add(GTK_CONTAINER(halign2), send);
    gtk_table_attach(GTK_TABLE(table), halign2, 0, 1, 7, 8, GTK_FILL, GTK_FILL, 0, 0);

    createAccount = gtk_button_new_with_label("Create Account");
    g_signal_connect (createAccount, "clicked", G_CALLBACK (add_user), NULL);
    gtk_table_attach(GTK_TABLE(table), createAccount, 5, 8, 7, 8, GTK_FILL, GTK_FILL, 0, 0);


    gtk_container_add(GTK_CONTAINER(window), table);

    g_signal_connect_swapped(G_OBJECT(window), "destroy",
            G_CALLBACK(gtk_main_quit), G_OBJECT(window));

    gtk_widget_show_all(window);
    gtk_main();
    //TODO
    while (1) {
        printPrompt();
        //gtk_main();
        //gtk_main_quit();
        char * s = fgets(line,MAX_MESSAGE_LEN, stdin);
        if (s==NULL) {
            leave_room();
            printf("talk-client exiting...\n");
            exit(1);
        }

        if (!isatty(0)) {
            // If it is not a terminal, echo command as well
            printf("%s\n", line);
        }

        if (line[0]=='-') {
            // This is a command process it
            if (!strcmp(line,"-help")) {
                printHelp();
            }
            else if (!strcmp(line,"-quit")) {
                printf("talk-client exiting...\n");
                exit(1);
            }
            // Put other commands here
        }
        else if (line[0]==0) {
            // Empty line. Print help
            printf("Type -help to print the available commands\n");
        }
        else {
            // Send message
        }
    }

    printf("TEST ENDS\n");
    return 0;

}