// Add New RankStats Entry Routine
RankSystem::RankStats* RankSystem::newEntryInRank(const char* unique, const char* name)
{
	// Enter Critical Section
	EnterCriticalSection(MUTEX);

	// Create New RankStats Entry
	RankStats* a = new RankStats(unique, name, this);
	if(a == NULL)
	{
		MF_SyncLog("newEntryInRank: Could not allocate new \"RankStats\" entry");
		// Leave Critical Section
		LeaveCriticalSection(MUTEX);

		return NULL;
	}

	if(tail != NULL)
		put_after(a, tail);
	else
		head = tail = a;	// First Entry

	// Leave Critical Section
	LeaveCriticalSection(MUTEX);

	return a;
}
Beispiel #2
0
void RankSystem::updatePos(  RankStats* rr ,  Stats* s )
{
	rr->addStats( s );

	if ( calc.code ) {
		calc.physAddr1[0] = rr->kills;
		calc.physAddr1[1] = rr->deaths;
		calc.physAddr1[2] = rr->hs;
		calc.physAddr1[3] = rr->tks;
		calc.physAddr1[4] = rr->shots;
		calc.physAddr1[5] = rr->hits;
		calc.physAddr1[6] = rr->damage;
		calc.physAddr1[7] = rr->points;
		for(int i = 1; i < 8; ++i)
			calc.physAddr2[i] = rr->bodyHits[i];
		cell result = 0;
		int err;
		MF_AmxPush(&calc.amx, calc.amxAddr2);
		MF_AmxPush(&calc.amx, calc.amxAddr1);
		if ((err = MF_AmxExec(&calc.amx,&result, calc.func)) != AMX_ERR_NONE)
			MF_LogError(&calc.amx, err, "Fatal error calculating stats");
		rr->score = result;
	}
	else rr->score = rr->kills - rr->deaths;

	RankStats* aa = rr->next;
	while ( aa && (aa->score <= rr->score) ) { // try to nominate
		rr->goUp();
		aa->goDown();
		aa = aa->next;		// go to next rank
	}
	if ( aa != rr->next )
	{
		unlink( rr );
		put_before( rr, aa );
	}
	else
	{
		aa = rr->prev;
		while ( aa && (aa->score > rr->score) ) { // go down
			rr->goDown();
			aa->goUp();
			aa = aa->prev;	// go to prev rank
		}
		if ( aa != rr->prev ){
			unlink( rr );
			put_after( rr, aa );
		}
	}

}
Beispiel #3
0
RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const char* name, bool isip)
{
	RankStats* a = head;
	
	if (isip) // IP lookups need to strip the port from already saved instances.
	{         // Otherwise the stats file would be essentially reset.
	
		// The IP passed does not contain the port any more for unique
		size_t iplen = strlen(unique);
		
		
		while ( a )
		{
			const char* targetUnique = a->getUnique();
			if ( strncmp( targetUnique, unique, iplen) == 0 )
			{
				// It mostly matches, make sure this isn't a false match
				// eg: checking 4.2.2.2 would match 4.2.2.24 here.
				
				// Get the next character stored in targetUnique
				char c = targetUnique[iplen];
				
				// If c is either a colon or end of line, then this
				// is a valid match.
				if (c == ':' ||
					c == '\0')
				{
					// Yes, this is a match.
					return a;
				}
				// Any other case was a false match.
				a = a->prev;
			}
		}
	}
	else // No special case
	{
		while ( a )
		{
			if (  strcmp( a->getUnique() ,unique ) == 0 )
				return a;

			a = a->prev;
		}
	}
	a = new RankStats( unique ,name,this );
	if ( a == 0 ) return 0;
	put_after( a  , 0 );
	return a;
}
Beispiel #4
0
t_bool		set_rdir_at_the_end(t_shell *shell)
{
  t_lexem	*lex;

  lex = shell->lexem;
  while (lex)
    {
      if ((lex->type >= RDIR) && (lex->type <= DRDIR_ERR))
	{
	  while ((lex->right) && !(IS_DEL(lex->right->type)))
	    {
	      if (put_after(shell, lex) == FALSE)
		return (FALSE);
	    }
	}
      lex = lex->right;
    }
  return (CONTINUE);
}
void RankSystem::updatePos_exec(RankStats* rr)
{
	// Enter Critical Section
	EnterCriticalSection(MUTEX);

	// Verify Pointer to RankStats
	if(rr == NULL)
	{
		MF_SyncLog("updatePos_exec: Pointer to RankStats has Expired!");

		// Leave Critical Section
		LeaveCriticalSection(MUTEX);
		return;
	}

	// Update Calc Buffer
	uint8_t i;
	calc.physAddr1[0] = rr->kills;
	calc.physAddr1[1] = rr->deaths;
	calc.physAddr1[2] = rr->hs;
	calc.physAddr1[3] = rr->tks;
	calc.physAddr1[4] = rr->shots;
	calc.physAddr1[5] = rr->hits;
	calc.physAddr1[6] = rr->damage;
	calc.physAddr1[7] = rr->bDefusions;
	calc.physAddr1[8] = rr->bDefused;
	calc.physAddr1[9] = rr->bPlants;
	calc.physAddr1[10] = rr->bExplosions;
	for(i = 1; i < 8; ++i)
		calc.physAddr2[i] = rr->bodyHits[i];

	// Result Calculation using Calc Buffer and Calc Function "get_score"
	cell result = 0;
	MF_AmxPush(&calc.amx, calc.amxAddr2);
	MF_AmxPush(&calc.amx, calc.amxAddr1);
	if((i = (uint8_t)MF_AmxExec(&calc.amx, &result, calc.func)) != AMX_ERR_NONE)
	{
		MF_SyncLog("updatePos_exec: Error in pawn function \"get_score\"");

		// Leave Critical Section
		LeaveCriticalSection(MUTEX);
		return;
	}

	rr->score = result;
	RankStats* itr = rr->prev;
	while(itr != NULL && rr->score >= itr->score)
	{
		rr->id--;
		itr->id++;
		itr = itr->prev;
	}
	if(itr != rr->prev)
	{
		unlink_ptr(rr);
		if(itr == NULL)
			put_before(rr, head);
		else
			put_after(rr, itr);	// since current "itr" has greater score
	}
	else
	{
		itr = rr->next;
		while(itr != NULL && rr->score < itr->score)
		{
			rr->id++;
			itr->id--;
			itr = itr->next;
		}
		if(itr != rr->next)
		{
			unlink_ptr(rr);
			if(itr == NULL)
				put_after(rr, tail);
			else
				put_before(rr, itr);	// since current "itr" has lower (or equal) score
		}
	}

	// Leave Critical Section
	LeaveCriticalSection(MUTEX);
}