Example #1
0
File: rados.c Project: Nikolo/uwsgi
static int uwsgi_rados_read_async(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, const char *key, uint64_t off, uint64_t remains, size_t bufsize, int timeout) {
	int ret = -1;
	char *buf = uwsgi_malloc(UMIN(remains, bufsize));

	struct uwsgi_rados_io *urio = &urados.urio[wsgi_req->async_id];
	// increase request counter
	pthread_mutex_lock(&urio->mutex);
	urio->rid++;
	pthread_mutex_unlock(&urio->mutex);

	while(remains > 0) {
		struct uwsgi_rados_cb *urcb = uwsgi_malloc(sizeof(struct uwsgi_rados_cb));
		// map the current request id to the callback
		urcb->rid = urio->rid;
		// map urio to the callback
		urcb->urio = urio;


		rados_completion_t comp;
		if (rados_aio_create_completion(urcb, uwsgi_rados_read_async_cb, NULL, &comp) < 0) {
			free(urcb);
			break;
		}
		// trigger an async read
		if (rados_aio_read(ctx, key, comp, buf, UMIN(remains, bufsize), off) < 0) {
			free(urcb);
			rados_aio_release(comp);
			break;
		}
		// wait for the callback to be executed
		if (uwsgi.wait_read_hook(urio->fds[0], timeout) <= 0) {
			rados_aio_release(comp);
			break;
		}
		char ack = 1;
		if (read(urio->fds[0], &ack, 1) != 1) {
			rados_aio_release(comp);
			uwsgi_error("uwsgi_rados_read_async()/read()");
			break;
		}
		int rlen = -1;	
		if (rados_aio_is_complete_and_cb(comp)) {
			rlen = rados_aio_get_return_value(comp);
		}
		rados_aio_release(comp);
		if (rlen <= 0) break;
		if (uwsgi_response_write_body_do(wsgi_req, buf, rlen)) break;
		remains -= rlen;
		off += rlen;
	}

	free(buf);
	if (remains == 0) ret = 0;

	pthread_mutex_lock(&urio->mutex);
	// increase the counter again
	urio->rid++;
	pthread_mutex_unlock(&urio->mutex);
	return ret;	
}
Example #2
0
ssize_t uwsgi_proto_sctp_sendfile(struct wsgi_request * wsgi_req) {

        ssize_t len;
        char buf[65536];
        size_t remains = wsgi_req->sendfile_fd_size - wsgi_req->sendfile_fd_pos;

        wsgi_req->sendfile_fd_chunk = 65536;

        if (uwsgi.async > 1) {
                len = read(wsgi_req->sendfile_fd, buf, UMIN(remains, wsgi_req->sendfile_fd_chunk));
                if (len != (int) UMIN(remains, wsgi_req->sendfile_fd_chunk)) {
                        uwsgi_error("read()");
                        return -1;
                }
                wsgi_req->sendfile_fd_pos += len;
                return uwsgi_proto_sctp_write(wsgi_req, buf, len);
        }

        while (remains) {
                len = read(wsgi_req->sendfile_fd, buf, UMIN(remains, wsgi_req->sendfile_fd_chunk));
                if (len != (int) UMIN(remains, wsgi_req->sendfile_fd_chunk)) {
                        uwsgi_error("read()");
                        return -1;
                }
                wsgi_req->sendfile_fd_pos += len;
                len = uwsgi_proto_sctp_write(wsgi_req, buf, len);
                remains = wsgi_req->sendfile_fd_size - wsgi_req->sendfile_fd_pos;
        }

        return wsgi_req->sendfile_fd_pos;

}
Example #3
0
socklen_t socket_to_un_addr(char *socket_name, struct sockaddr_un * sun_addr) {

	size_t len = strlen(socket_name);

	if (len > 102) {
		uwsgi_log("invalid UNIX socket address: %s\n", socket_name);
		uwsgi_nuclear_blast();
	}

	memset(sun_addr, 0, sizeof(struct sockaddr_un));

	sun_addr->sun_family = AF_UNIX;

	// abstract socket
	if (socket_name[0] == '@') {
		memcpy(sun_addr->sun_path + 1, socket_name + 1, UMIN(len - 1, 101));
		len = strlen(socket_name) + 1;
	}
	else if (len > 1 && socket_name[0] == '\\' && socket_name[1] == '0') {
		memcpy(sun_addr->sun_path + 1, socket_name + 2, UMIN(len - 2, 101));
		len = strlen(socket_name + 1) + 1;
	}
	else {
		memcpy(sun_addr->sun_path, socket_name, UMIN(len, 102));
	}

	return sizeof(sun_addr->sun_family) + len;
}
Example #4
0
/*
 * Lets mob cause unconditional damage to someone. Nasty, use with caution.
 * Also, this is silent, you must show your own damage message...
 *
 * Syntax: mob damage [victim] [min] [max] {kill}
 */
void do_mpdamage(CHAR_DATA * ch, char *argument)
{
    CHAR_DATA *victim = NULL, *victim_next;
    char target[MAX_INPUT_LENGTH], min[MAX_INPUT_LENGTH], max[MAX_INPUT_LENGTH];
    int low, high;
    bool fAll = FALSE, fKill = FALSE;

    argument = one_argument(argument, target);
    argument = one_argument(argument, min);
    argument = one_argument(argument, max);

    if (target[0] == '\0') {
	bug("MpDamage - Bad syntax from vnum %d.",
	    IS_NPC(ch) ? ch->pIndexData->vnum : 0);
	return;
    }
    if (!str_cmp(target, "all"))
	fAll = TRUE;
    else if ((victim = get_char_room(ch, target)) == NULL)
	return;

    if (is_number(min))
	low = atoi(min);
    else {
	bug("MpDamage - Bad damage min vnum %d.",
	    IS_NPC(ch) ? ch->pIndexData->vnum : 0);
	return;
    }
    if (is_number(max))
	high = atoi(max);
    else {
	bug("MpDamage - Bad damage max vnum %d.",
	    IS_NPC(ch) ? ch->pIndexData->vnum : 0);
	return;
    }
    one_argument(argument, target);

    /*
     * If kill parameter is omitted, this command is "safe" and will not
     * kill the victim.
     */

    if (target[0] != '\0')
	fKill = TRUE;
    if (fAll) {
	for (victim = ch->in_room->people; victim; victim = victim_next) {
	    victim_next = victim->next_in_room;
	    if (victim != ch)
		damage(victim, victim,
		       fKill ?
		       number_range(low, high) : UMIN(victim->hit, number_range(low, high)),
		       TYPE_UNDEFINED, DAM_NONE, FALSE);
	}
    } else
	damage(victim, victim,
	       fKill ?
	       number_range(low, high) : UMIN(victim->hit, number_range(low, high)),
	       TYPE_UNDEFINED, DAM_NONE, FALSE);
    return;
}
Example #5
0
void fill_combat_roll(COMBAT_ROLL_BOX *crb, bool defense, int bonus_die_skill)
{
	int roller, roll, temp;

	memset(crb->rolls, 0, MAX_COMBAT_DICE_POOL * sizeof(int));

	temp = (int)(UMIN(MAX_LEVEL, crb->combatant_level) / 50) + 1;
	crb->significant_dice_count = UMIN(MAX_COMBAT_DICE_POOL, temp);

	temp = crb->significant_dice_count + (crb->significant_dice_count / 2) + (defense ? 2 : 0);
	crb->dice_pool = UMIN(MAX_COMBAT_DICE_POOL, temp);

	crb->die_type = defense ? 115 : 125;

	/* Roll the pool of dice.  Any roll over the weapon skill counts as a "botch". */
	crb->botch_count = 0;
	for (roller = 0; roller < crb->dice_pool; roller++) {
		roll = number_range(1, crb->die_type);
		crb->rolls[roller] = (roll <= crb->weapon_skill) ? roll : 0;
		if (roll >= 105 && roll > crb->weapon_skill)
			crb->botch_count++;
	}

	/* Don't count the botches in the insignificant group of dice. */
	/* Accept the possibility of negative count. */
	crb->botch_count -= (crb->dice_pool - crb->significant_dice_count);

	/* Bubble sort is ok here because we are talking about only a few rolls. */
	i_bubble_sort(crb->rolls, crb->dice_pool);

	/* If bonus skill, roll the dice pool (limited to significant count) and allow the
	 * first success greater than the least roll in the significant pool to replace
	 * the least roll.
	 */
	if (bonus_die_skill > 0) {
		for (roller = 0; roller < crb->significant_dice_count; roller++) {
			roll = number_range(1, crb->die_type);
			if (roll <= bonus_die_skill && roll > crb->rolls[crb->significant_dice_count - 1]) {
				crb->rolls[crb->significant_dice_count - 1] = roll;
				crb->bonus_die_success = true;
				break;
			}
		}
	}

	/* Sum up all the significant rolls. */
	crb->total_roll = 0;
	for (roller = 0; roller < crb->significant_dice_count; roller++)
		crb->total_roll += crb->rolls[roller];

	if (crb->combat_rating > 10000)
		crb->total_roll *= 10;
}
Example #6
0
File: rados.c Project: Nikolo/uwsgi
static int uwsgi_rados_read_sync(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, const char *key, uint64_t off, uint64_t remains, size_t bufsize) {
	char* buf = uwsgi_malloc(UMIN(remains, bufsize));
	while(remains > 0) {
		int rlen = rados_read(ctx, key, buf, UMIN(remains, bufsize), off);
		if (rlen <= 0) goto end;
		if (uwsgi_response_write_body_do(wsgi_req, buf, rlen)) goto end;
		remains -= rlen;
		off += rlen;
	}
        free(buf);
	return 0;
end:
        free(buf);
        return -1;
}
Example #7
0
// Modified by SinaC 2001
void do_wizhelp( CHAR_DATA *ch, const char *argument ) {
  char buf[MAX_STRING_LENGTH];
  int cmd;
  int col;

  if ( IS_NPC(ch) ) {
    send_to_char("Mobiles can't see immortal command.\n\r",ch);
    return;
  }

  // Added by SinaC 2001
  int lvl = get_trust(ch);
  if ( argument[0] != '\0' && is_number(argument)) {
    lvl = UMIN( atoi(argument), lvl );
  }

  col = 0;
  //for ( cmd = 0; cmd_table[cmd].name[0] != '\0'; cmd++ ) {
  for ( cmd = 0; cmd < MAX_COMMANDS; cmd++ ) {
    if ( cmd_table[cmd].level >= LEVEL_HERO
	 &&   cmd_table[cmd].level <= /*get_trust( ch )*/lvl // Modified by SinaC 2001
	 &&   cmd_table[cmd].show) {
      sprintf( buf, "%-12s", cmd_table[cmd].name );
      send_to_char( buf, ch );
      if ( ++col % 6 == 0 )
	send_to_char( "\n\r", ch );
    }
  }
 
  if ( col % 6 != 0 )
    send_to_char( "\n\r", ch );
  return;
}
Example #8
0
int spell_sonic_blast( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim       = (CHAR_DATA *) vo;
    static const int        dam_each [ ] =
    {
          0,
          0,   0,   0,   0,   0,          0,   0,   0,   0,   0,
          0,   0,   0,   0,  30,         35,  40,  45,  50,  55,
         60,  65,  70,  75,  80,         82,  84,  86,  88,  90,
         92,  94,  96,  98, 100,        102, 104, 106, 108, 110,
        112, 114, 116, 118, 120,        122, 124, 126, 128, 130,
        132, 134, 136, 138, 140,        142, 144, 146, 148, 150,
        152, 154, 156, 158, 160,        162, 164, 166, 168, 170,
        172, 174, 176, 178, 180,        182, 184, 186, 188, 190,
        192, 194, 196, 198, 200,        202, 204, 206, 208, 210,
        215, 220, 225, 230, 235,        240, 245, 250, 255, 260
    };
    int        dam;

    level    = UMIN( level, sizeof( dam_each ) / sizeof( dam_each[0] ) - 1 );
    level    = UMAX( 0, level );
    dam      = number_range( dam_each[level], dam_each[level] * 6 );

    if ( saves_spell( level, victim ) )
        dam /= 2;
    //damage( ch, victim, dam, sn );
    return dam;   
}
Example #9
0
void do_blackjack(CHAR_DATA *ch,char *argument)
{
    char arg1[MAX_INPUT_LENGTH],arg2[MAX_INPUT_LENGTH];                         
    char buf[MAX_STRING_LENGTH];

	argument = one_argument( argument, arg1 );
	argument = one_argument( argument, arg2 );   

    if( arg1[0] == '\0' )
    {
      send_to_char("You must bet, hit, stand or hand.\n\r",ch);
      return;
    }

    switch( LOWER(arg1[0]) )
    {
      case 'b': place_bet(ch,UMIN(30000,atoi(arg2))); break;
      case 'h': give_card(ch); show_bj_hand(ch,TRUE); check_bj_hand(ch); break;
      case 's': show_bj_hand(ch,TRUE); show_bj_hand(ch,FALSE); break;
      case 'h':
      default: show_bj_hand(ch,TRUE);
    }

    return;
}
Example #10
0
File: webdav.c Project: JuanS/uwsgi
static int uwsgi_wevdav_manage_put(struct wsgi_request *wsgi_req) {
	char filename[PATH_MAX];
        size_t filename_len = uwsgi_webdav_expand_path(wsgi_req, wsgi_req->path_info, wsgi_req->path_info_len, filename);
        // the collection does not exist, search for the last /
        if (!filename_len) {
		filename_len = uwsgi_webdav_expand_fake_path(wsgi_req, wsgi_req->path_info, wsgi_req->path_info_len, filename);
		if (!filename_len) {
                        uwsgi_response_prepare_headers(wsgi_req, "409 Conflict", 12);
                        return UWSGI_OK;
                }
        }

	int fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
	if (fd < 0) {
		uwsgi_403(wsgi_req);
                return UWSGI_OK;
	}

	if (uwsgi_response_prepare_headers(wsgi_req, "201 Created", 11)) goto end;
	
	size_t remains = wsgi_req->post_cl;
	while(remains > 0) {
		ssize_t body_len = 0;
		char *body =  uwsgi_request_body_read(wsgi_req, UMIN(remains, 32768) , &body_len);
		if (!body || body == uwsgi.empty) break;
		if (write(fd, body, body_len) != body_len) goto end;
	}

end:
	close(fd);
	return UWSGI_OK;
}
Example #11
0
int save_npc(Character *ch)
{
    int res = save_character(ch, npc_flags);
    field_map npc_values[] =
    {
        {"nonplayerId", &ch->id, SQL_INT},
        {"shortDescr", &ch->npc->shortDescr, SQL_TEXT},
        {"longDescr", &ch->npc->longDescr, SQL_TEXT},
        {"startPosition", &ch->npc->startPosition, SQL_INT},
        {"areaId", &ch->npc->area->id, SQL_INT},
        {0, 0, 0}
    };

    if (res == 1)
    {

        if (sql_insert_query(npc_values, "nonplayer") != SQL_OK)
        {
            log_data("could not insert player");
            return 0;
        }
    }

    else if (res == 2)
    {

        if (sql_update_query(npc_values, "nonplayer", ch->id) != SQL_OK)
        {
            log_data("could not update character");
            return 0;
        }
    }
    return UMIN(res, 1);
}
Example #12
0
/*
 * Mass refresh will refresh every visible character in the room for only
 * 3 more mana than a normal refresh.  It also has an additional 1 to 10
 * movement random bonus on top of the normal refresh.
 */
void spell_mass_refresh(int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *gch;
    char buf[MAX_STRING_LENGTH];

    for (gch = ch->in_room->people; gch != NULL; gch = gch->next_in_room)
    {
        // If the character can't be seen they can't be refreshed, we don't
        // want this used to sniff out hidden characters.
        if (!can_see(ch, gch))
        {
            continue;
        }

        gch->move = UMIN(gch->move + level + number_range(1, 10), gch->max_move);

        if (gch->max_move == gch->move)
        {
            send_to_char("You feel fully refreshed!\r\n", gch);
        }
        else
        {
            send_to_char("You feel less tired.\r\n", gch);
        }

        if (gch != ch)
        {
            sprintf(buf, "%s has been refreshed.\r\n", gch->name);
            send_to_char(buf, ch);
        }

    }

} // end spell_mass_refresh
Example #13
0
bool check_vnums( CHAR_DATA * ch, AREA_DATA * tarea, RENUMBER_AREA * r_area )
{
   int high, low;
   AREA_DATA *area;
   bool proto;

   if( !r_area )
   {
      bug( "%s: NULL r_area!", __func__ );
      return TRUE;
   }

   /*
    * this function assumes all the lows are allways gonna be
    * lower or equal to all the highs .. 
    */
   high = UMAX( r_area->hi_room, UMAX( r_area->hi_obj, r_area->hi_mob ) );
   low = UMIN( r_area->low_room, UMIN( r_area->low_obj, r_area->low_mob ) );

   /*
    * in do_check_vnums they use first_bsort, first_asort but.. i dunno.. 
    */
   area = first_area;
   proto = FALSE;
   while( area )
   {
      if( tarea == area )
         ;
      else if( !( high < area->low_r_vnum || low > area->hi_r_vnum ) ||
               !( high < area->low_o_vnum || low > area->hi_o_vnum ) ||
               !( high < area->low_m_vnum || low > area->hi_m_vnum ) )
      {
         ch_printf( ch, "This operation would overwrite area %s! Use checkvnums first.\r\n", area->filename );
         return TRUE;
      }

      area = area->next;
      if( area == NULL && !proto )
      {
         area = first_build;
         proto = TRUE;
      }
   }
   return FALSE;
}
Example #14
0
void make_blood( CHAR_DATA * ch )
{
   OBJ_DATA *obj;

   obj = create_object( get_obj_index( OBJ_VNUM_BLOOD ), 0 );
   obj->timer = number_range( 2, 4 );
   obj->value[1] = number_range( 3, UMIN( 5, ch->level ) );
   obj_to_room( obj, ch->in_room );
}
Example #15
0
int connect_to_unix(char *socket_name, int timeout, int async) {

	struct pollfd uwsgi_poll;
	struct sockaddr_un uws_addr;
	socklen_t un_size = sizeof(struct sockaddr_un);

	memset(&uws_addr, 0, sizeof(struct sockaddr_un));

	uws_addr.sun_family = AF_UNIX;

	if (socket_name[0] == '@') {
		un_size = sizeof(uws_addr.sun_family) + strlen(socket_name) + 1;
		memcpy(uws_addr.sun_path + 1, socket_name + 1, UMIN(strlen(socket_name + 1), 101));
	}
	else if (strlen(socket_name) > 1 && socket_name[0] == '\\' && socket_name[1] == '0') {
		un_size = sizeof(uws_addr.sun_family) + strlen(socket_name + 1) + 1;
		memcpy(uws_addr.sun_path + 1, socket_name + 2, UMIN(strlen(socket_name + 2), 101));
	}
	else {
		memcpy(uws_addr.sun_path, socket_name, UMIN(strlen(socket_name), 102));
	}

#if defined(__linux__) && defined(SOCK_NONBLOCK) && !defined(OBSOLETE_LINUX_KERNEL)
	uwsgi_poll.fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
#else
	uwsgi_poll.fd = socket(AF_UNIX, SOCK_STREAM, 0);
#endif
	if (uwsgi_poll.fd < 0) {
		uwsgi_error("socket()");
		return -1;
	}

	uwsgi_poll.events = POLLIN;

	if (timed_connect(&uwsgi_poll, (const struct sockaddr *) &uws_addr, un_size, timeout, async)) {
		// avoid error storm
		//uwsgi_error("connect()");
		close(uwsgi_poll.fd);
		return -1;
	}

	return uwsgi_poll.fd;

}
Example #16
0
bool spec_thief( CHAR_DATA *ch )
{
	CHAR_DATA *victim;
	CHAR_DATA *v_next;
	long gold,silver;

	if ( ch->position != POS_STANDING )
	return FALSE;

	for ( victim = ch->in_room->people; victim != NULL; victim = v_next )
	{
	v_next = victim->next_in_room;

	if ( IS_NPC(victim)
	||   victim->level >= LEVEL_IMMORTAL
	||   number_bits( 5 ) != 0 
	||   !can_see(ch,victim))
		continue;

	if ( IS_AWAKE(victim) && number_range( 0, ch->level ) == 0 )
	{
		act( "You discover $n's hands in your wallet!",
		ch, NULL, victim, TO_VICT );
		act( "$N discovers $n's hands in $S wallet!",
		ch, NULL, victim, TO_NOTVICT );
		return TRUE;
	}
	else
	{
		gold = victim->gold * UMIN(number_range(1,20),ch->level / 2) / 100;
		gold = UMIN(gold, ch->level * ch->level * 10 );
		ch->gold     += gold;
		victim->gold -= gold;
		silver = victim->silver * UMIN(number_range(1,20),ch->level/2)/100;
		silver = UMIN(silver,ch->level*ch->level * 25);
		ch->silver	+= silver;
		victim->silver -= silver;
		return TRUE;
	}
	}

	return FALSE;
}
Example #17
0
// "Included is a more accurate hash function for the temp_hash{find,add}
// functions.  It is based off a hash function that supposedly comes from
// perl."
// "The hash function calculates the hash based on the first 32 characters; I
// found that setting that value to 8 characters causes a 50% increase in the
// number of strcmps in temp_hash_find; setting it beyond 32 did not decrease
// it."
// "The hash function takes the string plus its length as a parameter:
// fread_string can figure out the length of the string so there is no reason
// to recalculate it."
// -- Erwin
static unsigned get_string_hash( register const char *key, int len )
{
    register int      i		= UMIN( len, 32 );
    register unsigned hash	= 0;

    while( i-- )
	hash = hash * 33U + *key++;

    return hash % MAX_KEY_HASH;
}
Example #18
0
// like uwsgi_pipe but with fixed size
ssize_t uwsgi_pipe_sized(int src, int dst, size_t required, int timeout) {
	char buf[8192];
	size_t written = 0;
	ssize_t len;

	while (written < required) {
		int ret = uwsgi_waitfd(src, timeout);
		if (ret > 0) {
			len = read(src, buf, UMIN(8192, required - written));
			if (len == 0) {
				return written;
			}
			else if (len < 0) {
				uwsgi_error("read()");
				return -1;
			}

			size_t remains = len;
			while (remains > 0) {
				int ret = uwsgi_waitfd_write(dst, timeout);
				if (ret > 0) {
					len = write(dst, buf, remains);
					if (len > 0) {
						remains -= len;
						written += len;
					}
					else if (len == 0) {
						return written;
					}
					else {
						uwsgi_error("write()");
						return -1;
					}
				}
				else if (ret == 0) {
					goto timeout;
				}
				else {
					return -1;
				}
			}
		}
		else if (ret == 0) {
			goto timeout;
		}
		else {
			return -1;
		}
	}

	return written;
timeout:
	uwsgi_log("timeout while piping from %d to %d !!!\n", src, dst);
	return -1;
}
Example #19
0
/* checks for skill improvement */
void check_improve( CHAR_DATA *ch, int sn, bool success, int multiplier ) {
  int chance;
  char buf[100];

  if (IS_NPC(ch))
    return;

  // Modified by SinaC 2001
  if (ch->level < class_abilitylevel( /*ch->cstat(classes)*/ch, sn )
      // Modified by SinaC 2003
      ||  class_abilityrating( ch, sn, ch->pcdata->ability_info[sn].casting_level ) == 0
      ||  ch->pcdata->ability_info[sn].learned == 0
      ||  ch->pcdata->ability_info[sn].learned == 100)
    return;  /* skill is not known */

  /* check to see if the character has a chance to learn */
  chance = 10 * int_app[ch->cstat(INT)].learn;
  chance /= ( multiplier
	      *	class_abilityrating( ch, sn, ch->pcdata->ability_info[sn].casting_level )
	      *	4 );
  chance += ch->level;

  if (number_range(1,1000) > chance)
    return;

  /* now that the character has a CHANCE to learn, see if they really have */

  bool done = FALSE; // Added by SinaC 2003
  if (success) {
    chance = URANGE(5,100 - ch->pcdata->ability_info[sn].learned, 95);
    if (number_percent() < chance) {
      sprintf(buf,"You have become better at %s!\n\r",
	      ability_table[sn].name);
      send_to_char(buf,ch);
      ch->pcdata->ability_info[sn].learned++;
      gain_exp(ch,2 * class_abilityrating( ch, sn, ch->pcdata->ability_info[sn].casting_level), TRUE);
      done = TRUE;
    }
  }
  else {
    chance = URANGE(5,ch->pcdata->ability_info[sn].learned/2,30);
    if (number_percent() < chance) {
      sprintf(buf,
	      "You learn from your mistakes, and your %s skill improves.\n\r",
	      ability_table[sn].name);
      send_to_char(buf,ch);
      ch->pcdata->ability_info[sn].learned += number_range(1,3);
      ch->pcdata->ability_info[sn].learned = UMIN(ch->pcdata->ability_info[sn].learned,100);
      gain_exp(ch,2 * class_abilityrating( ch, sn, ch->pcdata->ability_info[sn].casting_level), TRUE);
      done = TRUE;
    }
  }
  if ( done && ch->pcdata->ability_info[sn].learned == 100 ) // Added by SinaC 2003
    send_to_charf(ch,"You are now master in '%s'.\n\r", ability_table[sn].name );
}
Example #20
0
int class_thac0_00(long c) {
  int res = 500;
  int i = 0;

  for (i=0;i<MAX_CLASS;i++) {
    if ((1LL<<i) & c) {
      res = UMIN(res,class_table[i].thac0_00);
    }
  }
  return res;
}
Example #21
0
void
objfun_regen(OBJ_DATA *obj, CHAR_DATA *keeper)
{
    if (keeper == NULL || keeper->in_room == NULL)
        return;

    if (obj->wear_loc < 0)
        return;
    keeper->hit = UMIN(keeper->max_hit, keeper->hit + (number_range(obj->level / 20, obj->level / 5)));
    return;
}
Example #22
0
int class_abilitylevel(CHAR_DATA *ch,int sn) {
  int res = 0;
  int i = 0;
  long c = ch->cstat(classes);

  for (i=0;i<MAX_CLASS;i++) {
    if ( ( (1<<i) & c) && (ability_table[sn].ability_level[i] > 0)) {
      res = res ? UMIN(res,ability_table[sn].ability_level[i]):
	ability_table[sn].ability_level[i] ;
    }
  }

  // Added by SinaC 2001, if the spell has been learned at a level > 0
  //  means not a creation
  if ( !IS_NPC(ch) && ch->pcdata->ability_info[sn].level > 0  ) {
    res = UMIN( ch->pcdata->ability_info[sn].level, res );
  }

  return res;
}
Example #23
0
static int uwsgi_rados_read_sync(struct wsgi_request *wsgi_req, rados_ioctx_t *ctx, const char *key, size_t remains) {
	uint64_t off = 0;
	while(remains > 0) {
		char buf[8192];
		int rlen = rados_read(ctx, key, buf, UMIN(remains, 8192), off);
		if (rlen <= 0) return -1;
		if (uwsgi_response_write_body_do(wsgi_req, buf, rlen)) return -1;
		remains -= rlen;
		off += rlen;
	}
	return 0;
}
Example #24
0
int class_grouprating( const long c, const int sn) {
  int res = 0;
  int i = 0;

  //long c = ch->cstat(classes);

  for (i=0;i<MAX_CLASS;i++) {
    if ( ((1LL<<i) & c) && (group_table[sn].rating[i] > 0)) {
      res = res ? UMIN(res,group_table[sn].rating[i]) : group_table[sn].rating[i];
    }
  }
  return res;
}
Example #25
0
int generate_itemlevel( AREA_DATA * pArea, OBJ_INDEX_DATA * pObjIndex )
{
	int olevel;
	int min = UMAX( pArea->low_soft_range, 1 );
	int max = UMIN( pArea->hi_soft_range, min + 15 );

	if ( pObjIndex->level > 0 )
		olevel = UMIN( pObjIndex->level, MAX_LEVEL );
	else
		switch ( pObjIndex->item_type )
		{
			default:
				olevel = 0;
				break;
			case ITEM_PILL:
				olevel = number_range( min, max );
				break;
			case ITEM_POTION:
				olevel = number_range( min, max );
				break;
			case ITEM_SCROLL:
				olevel = pObjIndex->value[0];
				break;
			case ITEM_WAND:
				olevel = number_range( min + 4, max + 1 );
				break;
			case ITEM_STAFF:
				olevel = number_range( min + 9, max + 5 );
				break;
			case ITEM_ARMOR:
				olevel = number_range( min + 4, max + 1 );
				break;
			case ITEM_WEAPON:
				olevel = number_range( min + 4, max + 1 );
				break;
		}
	return olevel;
}
bool spell_causticblast(int sn, int level, CHAR_DATA * ch, void * vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int dam(dice(level, 4));

    // Blast them
    act("$n unleashes a blast of hissing acid upon $N!", ch, NULL, victim, TO_NOTVICT);
    act("You unleash a blast of hissing acid upon $N!", ch, NULL, victim, TO_CHAR);
    act("$n unleashes a blast of hissing acid upon you!", ch, NULL, victim, TO_VICT);
    
    if (saves_spell(level, ch, victim, DAM_ACID))
    {
        damage_old(ch, victim, dam / 2, sn, DAM_ACID, true);
        return true;
    }

    damage_old(ch, victim, dam, sn, DAM_ACID, true);
    if (!IS_VALID(victim) || victim->in_room != ch->in_room)
        return true;

    act("The acid eats away at you, leaving painful, ugly scars!", victim, NULL, NULL, TO_CHAR);
    act("The acid eats away at $m, leaving painful, ugly scars!", victim, NULL, NULL, TO_ROOM);
    
    // Apply -charisma
    AFFECT_DATA af = {0};
    af.where    = TO_AFFECTS;
    af.type     = sn;
    af.level    = level;
    af.duration = level / 2;
    af.location = APPLY_CHR;
    af.modifier = -1;
    affect_to_char(victim, &af);

    // Apply burning
    for (AFFECT_DATA * paf(get_affect(victim, sn)); paf != NULL; paf = get_affect(victim, sn, paf))
    {
        if (paf->location == APPLY_NONE)
        {
            paf->duration = UMAX(2, paf->duration);
            paf->modifier = UMIN(100, paf->modifier + 1);
            return true;
        }
    }

    af.duration = 2;
    af.location = APPLY_NONE;
    af.modifier = 1;
    affect_to_char(victim, &af);
    return true;
}
Example #27
0
void gain_level( CHAR_DATA * ch )
{
    int cost;
    char buf[MAX_STRING_LENGTH];

    cost = 5 * exp_for_mobile( ch->level, ch );
    if ( ch->exp < cost )
        return;

    ch->exp -= cost;
    ch->level = UMIN( 140, ch->level++ );

    snprintf( buf, MSL, "%s gains a level!", ch->get_name() );
    info( buf, 1 );
    return;
}
Example #28
0
void reset_colors( CHAR_DATA * ch )
{
   int x;

   if( !IS_NPC( ch ) )
   {
      char filename[256];
      FILE *fp;
      int max_colors = 0;

      snprintf( filename, 256, "%s%s", COLOR_DIR, "default" );
      if( !( fp = fopen( filename, "r" ) ) )
      {
         memcpy( &ch->colors, &default_set, sizeof( default_set ) );
         return;
      }
      while( !feof( fp ) )
      {
         char *word = fread_word( fp );
         if( !str_cmp( word, "MaxColors" ) )
         {
            int temp = fread_number( fp );
            max_colors = UMIN( temp, MAX_COLORS );
            continue;
         }
         if( !str_cmp( word, "Colors" ) )
         {
            for( x = 0; x < max_colors; ++x )
               ch->colors[x] = fread_number( fp );
            fread_to_eol( fp );
            continue;
         }
         if( !str_cmp( word, "End" ) )
         {
            fclose( fp );
            fp = NULL;
            return;
         }
      }
      fclose( fp );
      fp = NULL;
      return;
   }
   else
      log_printf( "%s: Attempting to reset NPC colors: %s", __func__, ch->short_descr );
}
Example #29
0
/* checks for skill improvement */
void check_improve( CHAR_DATA *ch, int sn, bool success, int multiplier )
{
	int chance = 0;

	if (IS_NPC(ch))
		return;

	if (ch->level < skill_table[sn].skill_level[ch->iclass]
		||  skill_table[sn].rating[ch->iclass] == 0
		||  ch->pcdata->learned[sn] == 0
		||  ch->pcdata->learned[sn] == 100)
	return;  /* skill is not known */ 

	/* check to see if the character has a chance to learn */
	chance = 10 * int_app[get_curr_stat(ch,STAT_INT)].learn;
	chance /= (	multiplier * skill_table[sn].rating[ch->iclass] * 4);
	chance += ch->level;

	if (number_range(1,1000) > chance)
		return;

	/* now that the character has a CHANCE to learn, see if they really have */	

	if (success)
	{
		chance = URANGE(5,100 - ch->pcdata->learned[sn], 95);
		if (number_percent() < chance)
		{
			send_to_char(Format("You have become better at %s!\n\r", skill_table[sn].name),ch);
			ch->pcdata->learned[sn]++;
			gain_exp(ch,2 * skill_table[sn].rating[ch->iclass]);
		}
	}

	else
	{
		chance = URANGE(5,ch->pcdata->learned[sn]/2,30);
		if (number_percent() < chance)
		{
			send_to_char(Format("You learn from your mistakes, and your %s skill improves.\n\r", skill_table[sn].name),ch);
			ch->pcdata->learned[sn] += number_range(1,3);
			ch->pcdata->learned[sn] = UMIN(ch->pcdata->learned[sn],100);
			gain_exp(ch,2 * skill_table[sn].rating[ch->iclass]);
		}
	}
}
Example #30
0
static inline void *
mem_stack_pop(struct stack * x)
{
  if (unlikely( x->pos == 0 )){
    x->pos_min = 0;
    void * p = malloc(x->malloc_size);
    if ( p ){
      ++x->created;
    }
    return p;
  }
  else {
    --x->pos;
    x->pos_min = UMIN(x->pos,x->pos_min);
    return (x->s[x->pos]);
  }
}