示例#1
0
void load_default_npc_lines(Vector **line_type, char *fname, int next_state, int next_state_index)
{
	FILE *f;
	char line[4096];
	f = fopen(fname, "r");
	if (f != NULL)
	{
		//load line by line
		while (fgets(line, 4096 -1, f) != NULL)
		{
			char *faction_name;
			char *tone_name;
			char *text;

			faction_name = strtok(line, "\t");
			int faction_id = FACTION_NONE;
			if (strcmp(faction_name, "FACTION_SNEEB") == 0)
			{
				faction_id = FACTION_SNEEB;
			}
			else if (strcmp(faction_name, "FACTION_KRULL") == 0)
			{
				faction_id = FACTION_KRULL;
			}
			else if (strcmp(faction_name, "FACTION_PLINK") == 0)
			{
				faction_id = FACTION_PLINK;
			}

			tone_name = strtok(NULL, "\t");
			int tone_id = COMMS_TONE_UNKNOWN;
			if (strcmp(tone_name, "TONE_NEUTRAL") == 0)
			{
				tone_id = COMMS_TONE_NEUTRAL;
			}
			else if (strcmp(tone_name, "TONE_AGGRESSIVE") == 0)
			{
				tone_id = COMMS_TONE_AGGRESSIVE;
			}
			else if (strcmp(tone_name, "TONE_HAPPY") == 0)
			{
				tone_id = COMMS_TONE_HAPPY;
			}
			text = strtok(NULL, "\t");

			//Create a new Comms_NPCDialogue to store all this data in and whack it in the library
			Comms_NPCDialogue *npcd;
			npcd = malloc(sizeof(Comms_NPCDialogue));
			npcd->text = wrap_text(text, 64);
			npcd->next_state = next_state;
			npcd->next_state_index = next_state_index;
			vector_add(&line_type[faction_id][tone_id], npcd);
		}
	}
	else
	{
		printf("Error loading %s\n", fname);
	}
}
示例#2
0
void comms_set_subject_name(char name[])
{
	if (comms_intro_text != NULL)
	{
		free(comms_intro_text);
	}
	comms_intro_text = (char *)malloc(sizeof(char) * (strlen(">incoming signal from ") + strlen(name) + 1));
	sprintf(comms_intro_text, ">incoming signal from %s", name);
	comms_intro_text = wrap_text(comms_intro_text, 64);
}
示例#3
0
BOOL CTextPlain::AppendPart(LPCTSTR szContent, 
							LPCTSTR szParameters, 
							int nEncoding, 
							BOOL bPath, 
							CString & sDestination)
{
	CString sSubHeader;
	CString sWrapped;
	sSubHeader = build_sub_header( szContent,
								   szParameters,
								   nEncoding,
								   bPath );
	sWrapped = wrap_text( szContent );
	sDestination += (sSubHeader + sWrapped);
	return TRUE;
}
示例#4
0
static void
layout_curses_msgwin(struct win_msgwin *wmw, int *linecount, char ***lines,
                     nh_bool recalc)
{
    int width = strlen(wmw->msg) + 4;
    if (width > COLNO - 1)
        width = COLNO - 1;
    if (width > getmaxx(stdscr) - 2)
        width = getmaxx(stdscr) - 2;

    if (!recalc)
        width = wmw->layout_width;

    wrap_text(width - 4, wmw->msg, linecount, lines);

    if (recalc) {
        wmw->layout_width = width;
        wmw->layout_height = *linecount + 2;
    }
}
示例#5
0
int
network_motd(void)
{
    char errmsg[256];
    char motdmsg[4096];
    int fd = -1;

    if (settings.show_motd == MOTD_TRUE) {

        fd = connect_server(MOTD_SERVER, MOTD_PORT, FALSE,
                            errmsg, sizeof errmsg);
        if (fd == -1)
            fd = connect_server(MOTD_SERVER, MOTD_PORT, TRUE,
                                errmsg, sizeof errmsg);
        
        errmsg[sizeof errmsg - 1] = '\0';

        if (fd == -1) {
            strcpy(motdmsg, "Could not connect to <" MOTD_SERVER "> to "
                   "receive a Message of the Day: ");
            strcat(motdmsg, errmsg);
        } else {
            /* We want to receive until the connection closes (which causes
               either EPIPE on abnormal shutdown, or 0 on normal shutdown). So
               continue until we get an error message other than EINTR or the
               buffer fills (indicating a malicious connection; I'm not planning
               on sending malicious packets from motd.nethack4.org, especially
               as I wrote this code and so know it wouldn't work, but it's worth
               allowing for the possibility that someone else intercepts the
               connection). */
            int recvlen = 0;
            int rv;
            while (recvlen < sizeof motdmsg &&
                   (((rv = recv(fd, motdmsg + recvlen,
                                (sizeof motdmsg) - recvlen, 0))) > 0 ||
                    errno == EINTR))
                recvlen += rv < 0 ? 0 : rv;
            if (recvlen >= sizeof motdmsg)
                recvlen = -1 + sizeof motdmsg;

            motdmsg[recvlen] = '\0';
        }

        close(fd);
    } else if (settings.show_motd == MOTD_FALSE) {
        return 1;
    } else {
        /* It's a bad idea to do network connections without asking the user for
           permission first. (Arguably we could make an exception for
           connection-only mode, but that connects to localhost, which is not
           quite the same thing as connecting to the Internet, so I'd rather
           make absolutely sure we aren't doing connections unsolicited.)

           Note that nothing is sent (other than the fact that the connection
           exists); the nethack4 binary just creates the connection, then reads
           from it. */
        strcpy(motdmsg, "The Message of the Day system connects to the "
               "Internet to receive gameplay tips and announcements (such "
               "as tournament information or release announcements). Do you "
               "want to turn it on? (You can change this later with the "
               "\x0enetwork_motd\x0f option.)");
    }

    /* SI/SO in the output indicate bold text. This isn't implemented yet.  Also
       strip out all other unprintable characters for security reasons. We just
       use the ASCII space-to-tilde range for printables; we're not expecting
       any control characters but SI/SO, not even newlines. */
    char *f, *t;
    f = t = motdmsg;
    while (*f) {
        if (*f >= ' ' && *f <= '~')
            *(t++) = *f;
        f++;
    }
    *t = '\0';

    int outcount;
    char **outlines;
    wrap_text(COLNO-6, motdmsg, &outcount, &outlines);

    struct nh_menulist menu;
    int i;

    init_menulist(&menu);

    for (i = 0; i < outcount; i++)
        add_menu_txt(&menu, outlines[i], MI_TEXT);

    free_wrap(outlines);

    if (settings.show_motd == MOTD_ASK) {
        add_menu_txt(&menu, "", MI_TEXT);
        add_menu_item(&menu, 1,
                      "Yes, I'd like announcements and gameplay tips",
                      'y', FALSE);
        add_menu_item(&menu, 2,
                      "No, please don't connect to the MotD server",
                      'n', FALSE);

        curses_display_menu(&menu, "Message of the Day", PICK_ONE,
                            PLHINT_ANYWHERE, &i, curses_menu_callback);

        if (i == 1) {
            curses_set_option("networkmotd",
                              (union nh_optvalue){.e = MOTD_TRUE});
示例#6
0
文件: mail_admin.c 项目: xxx/cdlib
/*
 * Function name: export_mail
 * Description  : With this function the mail-folder of a player can be
 *                exported to a file.
 * Arguments    : string name - the lower case name of the player whose
 *                              mailbox is to be exported.
 *                string path - the name of the output file.
 * Returns      : int 1/0 - success/failure.
 */
static int
export_mail(string name, string path)
{
    mapping mail;
    mixed   messages;
    int     index;
    int     size;
    string  text;

    /* Get the output path and test its valitity by writing the header. */
    path = FTPATH(this_player()->query_path(), path);
    if (file_size(path) != -1)
    {
	notify_fail("File " + path + " already exists.\n");
	return 0;
    }

    /* This may fail if there is no such directory, for instance. */
    if (!write_file(path, "Mailbox of: " + capitalize(name) +
	"\nPrinted at: " + ctime(time()) + "\n\n"))
    {
	notify_fail("Failed to write header of " + path + "\n");
	return 0;
    }

    /* Read the mail file. */
    mail = restore_mail(name);
    if (!mappingp(mail))
    {
	notify_fail("No correct mail folder for player " + name + ".\n");
	return 0;
    }

    /* Loop over all messages. */
    messages = mail[MAIL_MAIL];
    index = -1;
    size = sizeof(messages);
    while(++index < size)
    {
	mail = restore_message(messages[index][MAIL_DATE]);
	
	text = "Message: " + (index + 1) + "\nFrom   : " +
	      messages[index][MAIL_FROM] + "\n" +
	      (messages[index][MAIL_REPLY] ? "Reply  : " : "Subject: ") +
	      messages[index][MAIL_SUBJ] + "\n";
	
	if (mail[MSG_TO] != capitalize(name))
	{
	    text += HANGING_INDENT("To     : " +
		COMPOSITE_WORDS(explode(mail[MSG_TO], ",")), 9, 1);
	}
	
	if (mail[MSG_CC] != "")
	{
	    text += HANGING_INDENT("CC     : " +
		COMPOSITE_WORDS(explode(mail["cc"], ",")), 9, 1);
	}

	/* Write the message to file and print a sequence number to the
	 * wizard. Notice that the index of the loop is also increased in
	 * this write-statement.
	 */	
	write_file(path, text + "Date   : " +
            MAKE_DATE(messages[index][MAIL_DATE]) + " " +
            DATE_YEAR(messages[index][MAIL_DATE]) +
	    "\n\n" + wrap_text(mail[MSG_BODY]) + "\n\n");
    }

    write("Mail folder written for " + capitalize(name) + ".\nFilename: " +
	path + "\n");
    return 1;
}
示例#7
0
void comms_set_current_npc_lines()
{
	vector_free(&comms_current_npc_lines);
	vector_init(&comms_current_npc_lines, COMMS_NPC_COUNT);
	vector_fill(&comms_current_npc_lines, NULL);

	//todo: load possible npc text from file and select appropriate one based on disposition/bounty/resource need
	Comms_NPCDialogue *npcd;
	Vector ** line_type;
	int line_count = 0;

	line_type = (Vector **)vector_get(&comms_npc_lines, COMMS_NPC_GREETING);
	line_count = vector_get_size(&line_type[comms_faction][comms_tone]);
	npcd = vector_get(&line_type[comms_faction][comms_tone], rand() % line_count);
	vector_set(&comms_current_npc_lines, COMMS_NPC_GREETING, npcd);

	line_type = (Vector **)vector_get(&comms_npc_lines, COMMS_NPC_DEFEND);
	line_count = vector_get_size(&line_type[comms_faction][comms_tone]);
	npcd = vector_get(&line_type[comms_faction][comms_tone], rand() % line_count);
	vector_set(&comms_current_npc_lines, COMMS_NPC_DEFEND, npcd);

	npcd = malloc(sizeof(Comms_NPCDialogue));
	npcd->text = wrap_text("We are glad you embrace fight willingly", 64);
	npcd->next_state = COMMS_STATE_ENTER_COMBAT;
	npcd->next_state_index = -1;
	vector_set(&comms_current_npc_lines, COMMS_NPC_ATTACK_ACCEPT, npcd);

	npcd = malloc(sizeof(Comms_NPCDialogue));
	npcd->text = wrap_text("You get away.for today.", 64);
	npcd->next_state = COMMS_STATE_ENTER_TRAVEL;
	npcd->next_state_index = -1;
	vector_set(&comms_current_npc_lines, COMMS_NPC_ATTACK_FLEE, npcd);

	npcd = malloc(sizeof(Comms_NPCDialogue));
	npcd->text = wrap_text("You are too pitiful to fight", 64);
	npcd->next_state = COMMS_STATE_PLAYER_CHOICE;
	npcd->next_state_index = COMMS_PLAYER_CHOICE_MAIN;
	vector_set(&comms_current_npc_lines, COMMS_NPC_ATTACK_PLEAD, npcd);

	line_type = (Vector **)vector_get(&comms_npc_lines, COMMS_NPC_TRADE);
	line_count = vector_get_size(&line_type[comms_faction][comms_tone]);
	npcd = vector_get(&line_type[comms_faction][comms_tone], rand() % line_count);
	vector_set(&comms_current_npc_lines, COMMS_NPC_TRADE, npcd);

	npcd = malloc(sizeof(Comms_NPCDialogue));
	npcd->text = wrap_text("Good, let's trade", 64);
	npcd->next_state = COMMS_STATE_ENTER_TRADE_BUY;
	npcd->next_state_index = -1;
	vector_set(&comms_current_npc_lines, COMMS_NPC_TRADE_ACCEPT_BUY, npcd);

	npcd = malloc(sizeof(Comms_NPCDialogue));
	npcd->text = wrap_text("Good, let's trade", 64);
	npcd->next_state = COMMS_STATE_ENTER_TRADE_SELL;
	npcd->next_state_index = -1;
	vector_set(&comms_current_npc_lines, COMMS_NPC_TRADE_ACCEPT_SELL, npcd);

	npcd = malloc(sizeof(Comms_NPCDialogue));
	npcd->text = wrap_text("No trade? oh well", 64);
	npcd->next_state = COMMS_STATE_PLAYER_CHOICE;
	npcd->next_state_index = COMMS_PLAYER_CHOICE_MAIN;
	vector_set(&comms_current_npc_lines, COMMS_NPC_TRADE_DECLINE, npcd);

	line_type = (Vector **)vector_get(&comms_npc_lines, COMMS_NPC_INFO);
	line_count = vector_get_size(&line_type[comms_faction][comms_tone]);
	npcd = vector_get(&line_type[comms_faction][comms_tone], rand() % line_count);
	vector_set(&comms_current_npc_lines, COMMS_NPC_INFO, npcd);

	line_type = (Vector **)vector_get(&comms_npc_lines, COMMS_NPC_FAREWELL);
	line_count = vector_get_size(&line_type[comms_faction][comms_tone]);
	npcd = vector_get(&line_type[comms_faction][comms_tone], rand() % line_count);
	vector_set(&comms_current_npc_lines, COMMS_NPC_FAREWELL, npcd);
}
示例#8
0
static void
curses_print_message_core(int turn, const char *msg, nh_bool canblock)
{
    int hsize, vsize, maxlen;
    nh_bool died;

    if (!msghistory)
        alloc_hist_array();

    if (turn != prevturn)
        start_of_turn_curline = last_redraw_curline = curline;

    if (turn < prevturn)        /* going back in time can happen during replay */
        prune_messages(turn);

    if (!*msg)
        return; /* empty message. done. */

    if (action > prevaction) {
        /* re-enable output if it was stopped and start a new line */
        stopprint = FALSE;
        newline();
    }
    prevturn = turn;
    prevaction = action;

    store_message(turn, msg);

    if (stopprint)
        return;

    /* 
     * generally we want to put as many messages on one line as possible to
     * maximize space usage. A new line is begun after each player turn or if
     * more() is called via pause_messages(). "You die" also deserves its own line.
     * 
     * If the message area is only one line high, space for "--More--" must be
     * reserved at the end of the line, otherwise  --More-- is shown on a new line.
     */

    getmaxyx(msgwin, vsize, hsize);

    maxlen = hsize;
    if (maxlen >= COLNO)
        maxlen = COLNO - 1;
    if (vsize == 1)
        maxlen -= 8;    /* for "--More--" */

    died = !strncmp(msg, "You die", 7);
    if (strlen(msglines[curline]) + strlen(msg) + 1 < maxlen && !died) {
        if (msglines[curline][0])
            strcat(msglines[curline], "  ");
        strcat(msglines[curline], msg);
    } else {
        int idx, output_count;
        char **output;

        wrap_text(maxlen, msg, &output_count, &output);

        for (idx = 0; idx < output_count; idx++) {
            if (strlen(msglines[curline]) > 0)
                fresh_message_line(canblock);
            if (stopprint)
                break;  /* may get set in more() */
            strcpy(msglines[curline], output[idx]);
        }

        free_wrap(output);
    }

    draw_msgwin();
}