Ejemplo n.º 1
0
char *uwsgi_get_cookie(struct wsgi_request *wsgi_req, char *key, uint16_t keylen, uint16_t *vallen) {
	uint16_t i;

	char *cookie = wsgi_req->cookie;
	uint16_t cookie_len = 0;
	char *ptr = wsgi_req->cookie;
	//start splitting by ;
	for(i=0;i<wsgi_req->cookie_len;i++) {
		if (!cookie) {
			cookie = ptr + i;
		}
		if (ptr[i] == ';') {
			char *value = check_cookie(cookie, cookie_len, key, keylen, vallen);
			if (value) {
				return value;
			}
			cookie_len = 0;
			cookie = NULL;
		}
		else {
			cookie_len++;
		}
	}

	if (cookie_len > 0) {
		char *value = check_cookie(cookie, cookie_len, key, keylen, vallen);
		if (value) {
                	return value;
                }
	}

	return NULL;
}
Ejemplo n.º 2
0
int
do_safari_zone(void)
{
    char buf[40] = { 0 };
    unsigned int move, round, name;
    size_t num_monsters = sizeof(data) / sizeof(data[0]);
    size_t index = game_state.games.safari_zone.encounter_data + 1;
    struct monster *monster;
    unsigned char capture_chance, run_chance;

    printf("Welcome to the Safari Zone!\n");

    if (!check_cookie(game_state.games.gallon_challenge.cookie))
        return EXIT_FAILURE;

    if (index > num_monsters - 1) {
        printf("Nothing happened...\n");
        return EXIT_SUCCESS;
    }

    monster = &data[index];
    game_state.games.safari_zone.encounter_data = get_flag_byte(index) % (num_monsters - 2);
    capture_chance = monster->capture_chance;
    run_chance = monster->run_chance;
    round = 0;

    printf("A wild %s has appeared!\n", monster->name);
    while (1) {
        printf("What to do?\n"
                "1. Ball\n"
                "2. Rock\n"
                "3. Bait\n"
                "4. Run\n\n");

        if (fread_until(buf, '\n', sizeof(buf), stdin) == EXIT_FAILURE)
            return EXIT_FAILURE;
        if (cgc_strlen(buf) == 0 || strtou(buf, 16, &move) == EXIT_FAILURE)
            return EXIT_FAILURE;

        if (round > 10 || (round > 0 && run_chance >= get_flag_byte(round))) {
            printf("%s got away :(\n", monster->name);
            return EXIT_SUCCESS; 
        }
        round++;

        if (move == 1) {
            if (capture_chance >= get_flag_byte(round++))
                break;
            else
                printf("Darn! Almost had it!\n");
        } else if (move == 2) {
            capture_chance *= 2;
            run_chance *= 2;
        } else if (move == 3) {
            capture_chance /= 2;
            run_chance /= 2;
        } else if (move == 4) {
            printf("Got away safely!\n");
            return EXIT_SUCCESS;
        }
    }

    printf("Congratulations, you've caught %s!\n"
            "Please enter a nickname:\n", monster->name);

    do {
        if (fread_until(buf, '\n', sizeof(buf), stdin) == EXIT_FAILURE)
            continue;
        if (cgc_strlen(buf) == 0 || strtou(buf, 16, &name) == EXIT_FAILURE)
            continue;

        break;
    } while(1);

    monster->set_nickname(index, name);

    return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
int
do_hugman(void)
{
    size_t round = game_state.games.hugman.round % 4;
#ifdef PATCHED_1
    size_t index = round * 256 + get_flag_byte(game_state.games.hugman.round);
#else
    size_t index = round * 256 + get_flag_byte_unsafe(game_state.games.hugman.round);
#endif
    const char *word = dict[index];
    int i, j, c_, success, win;
    char c;

    char board[11][31];
    cgc_memcpy(board, new_board, sizeof(board));

    char graveyard[53] = { 0 };

    const char limbs[] = {
        'O', '|', '\\', '/', '|', '/', '\\'
    };

    struct {
        size_t x, y;
    } limb_coordinates[] = {
        { 2, 21 },
        { 3, 21 },
        { 3, 20 },
        { 3, 22 },
        { 4, 21 },
        { 5, 20 },
        { 5, 22 }
    }, letter_coordinates[] = {
        { 10, 8 },
        { 10, 10 },
        { 10, 12 },
        { 10, 14 },
        { 10, 16 },
        { 10, 18 },
        { 10, 20 },
        { 10, 22 }
    };

    if (!check_cookie(game_state.games.gallon_challenge.cookie))
        return EXIT_FAILURE;

    for (i = 0; i < sizeof(limbs) / sizeof(limbs[0]);) {
        success = 0;
        win = 1;

        for (j = 0; j < sizeof(board) / sizeof(board[0]); j++)
            printf("%s", board[j]);
        printf("Incorrect: %s\n", graveyard);

        do {
            if ((c_ = getc()) < 0)
                return EXIT_FAILURE;
            c = c_;
        } while (c == '\n');

        for (j = 0; j < 8; j++) {
            if (word[j] == c) {
                board[letter_coordinates[j].x][letter_coordinates[j].y] = c;
                success = 1;
            }

            if (board[letter_coordinates[j].x][letter_coordinates[j].y] == '_')
                win = 0;
        }

        if (win)
            break;

        if (!success) {
            board[limb_coordinates[i].x][limb_coordinates[i].y] = limbs[i];
            i++;

            if (strchr(graveyard, c) == NULL)
                strncat(graveyard, &c, 1);
        }
    }

    for (j = 0; j < sizeof(board) / sizeof(board[0]); j++)
        printf("%s", board[j]);

    game_state.games.hugman.round++;
    // Avoid giving away a free Missigno/Mewthree!
    if (game_state.games.hugman.round == 6 ||
            game_state.games.hugman.round == 0xffffffff)
        game_state.games.hugman.round++;

    if (win)
        printf("CONGRATULATIONS!\n");
    else
        printf("Sorry, the word was %s!\n", word);

    return EXIT_SUCCESS;
}