Пример #1
0
CAtomList *DecodeList( const string &x, unsigned long iStart )
{
	unsigned long i = iStart + 1;

	CAtomList *pList = new CAtomList( );

	while( i < x.size( ) && x[i] != 'e' )
	{
		CAtom *pAtom = Decode( x, i );

		if( pAtom )
		{
			i += pAtom->EncodedLength( );

			pList->addItem( pAtom );
		}
		else
		{
			UTIL_LogPrint( "error decoding list - error decoding list item, discarding list\n" );

			delete pList;

			return NULL;
		}
	}

	return pList;
}
Пример #2
0
static PyObject*
CAtom_new( PyTypeObject* type, PyObject* args, PyObject* kwargs )
{
    PyDictPtr membersptr( PyObject_GetAttr( pyobject_cast( type ), atom_members ) );
    if( !membersptr )
        return 0;
    if( !membersptr.check_exact() )
        return py_bad_internal_call( "atom members" );
    PyObjectPtr selfptr( PyType_GenericNew( type, args, kwargs ) );
    if( !selfptr )
        return 0;
    CAtom* atom = catom_cast( selfptr.get() );
    uint32_t count = static_cast<uint32_t>( membersptr.size() );
    if( count > 0 )
    {
        if( count > MAX_MEMBER_COUNT )
            return py_type_fail( "too many members" );
        size_t size = sizeof( PyObject* ) * count;
        void* slots = PyObject_MALLOC( size );
        if( !slots )
            return PyErr_NoMemory();
        memset( slots, 0, size );
        atom->slots = reinterpret_cast<PyObject**>( slots );
        atom->set_slot_count( count );
    }
    atom->set_notifications_enabled( true );
    return selfptr.release();
}
Пример #3
0
static PyObject*
Member_del_slot( Member* self, PyObject* object )
{
    if( !CAtom::TypeCheck( object ) )
        return py_expected_type_fail( object, "CAtom" );
    CAtom* atom = catom_cast( object );
    if( self->index >= atom->get_slot_count() )
        return py_no_attr_fail( object, PyString_AsString( self->name ) );
    atom->set_slot( self->index, 0 );
    Py_RETURN_NONE;
}
Пример #4
0
CAtomDicti *DecodeDicti( const string &x, unsigned long iStart )
{
	unsigned long i = iStart + 1;

	CAtomDicti *pDicti = new CAtomDicti( );

	while( i < x.size( ) && x[i] != 'e' )
	{
		CAtom *pKey = Decode( x, i );

		if( pKey && dynamic_cast<CAtomString *>( pKey ) )
		{
			i += pKey->EncodedLength( );

			string strKey = pKey->toString( );

			delete pKey;

			if( i < x.size( ) )
			{
				CAtom *pValue = Decode( x, i );

				if( pValue )
				{
					i += pValue->EncodedLength( );

					pDicti->setItem( strKey, pValue );
				}
				else
				{
					UTIL_LogPrint( "error decoding dictionary - error decoding value, discarding dictionary\n" );

					delete pDicti;

					return NULL;
				}
			}
		}
		else
		{
			UTIL_LogPrint( "error decoding dictionary - error decoding key, discarding dictionary\n" );

			delete pDicti;

			return NULL;
		}
	}

	return pDicti;
}
Пример #5
0
static PyObject*
Member_set_slot( Member* self, PyObject* args )
{
    if( PyTuple_GET_SIZE( args ) != 2 )
        return py_type_fail( "set_slot() takes exactly 2 arguments" );
    PyObject* object = PyTuple_GET_ITEM( args, 0 );
    PyObject* value = PyTuple_GET_ITEM( args, 1 );
    if( !CAtom::TypeCheck( object ) )
        return py_expected_type_fail( object, "CAtom" );
    CAtom* atom = catom_cast( object );
    if( self->index >= atom->get_slot_count() )
        return py_no_attr_fail( object, PyString_AsString( self->name ) );
    atom->set_slot( self->index, value );
    Py_RETURN_NONE;
}
Пример #6
0
void CState::fillBoxes()
{
    cout << "CState::fillBoxes()" << endl;

    vec3 atomPosition;
    ivec3 boxIndex;
    CAtom* atomptr;

    for (int i = 0; i < nAtoms; i++)
    {
        atomptr = atoms[i];
        atomPosition = atomptr->getPosition();
        for (int j = 0; j < 3; j++)
        {
            boxIndex(j) = int(floor(atomPosition(j)/boxDimensions(j)));
        }
        boxes[calculate_box_number(boxIndex, NBoxes)]->addAtom(atomptr);
    }

    cout << "Exiting CState::fillBoxes()" << endl << endl;
}
Пример #7
0
void CState::makeAtoms(ivec3 N, vec3 L, mat r, double sites_per_cell, string atomType)
{
    cout << "CState::makeAtoms" << endl;

    vec3 cellPos;

    atoms = vector<CAtom*>();
    atoms.reserve(nAtoms); // don't want resize, since we're using "push_back" to add item
    for (int ix = 0; ix < N(0); ix++)
    {
        for (int iy = 0; iy < N(1); iy++)
        {
            for (int iz = 0; iz < N(2); iz++)
            {
                for (int i = 0; i < sites_per_cell; i++)
                {
                    CAtom* atom = new CAtom;
                    cellPos << L(0)*ix << L(1)*iy << L(2)*iz;
                    atom->setPosition(cellPos + r.row(i).t());
                    atom->setAtomType(atomType);
                    if (atom->matrixAtom)
                    {
                        nMatrixAtoms++;
                        atoms.push_back(atom);
                    }
                    else
                    {
                        nMovingAtoms++;
                        movingAtoms.push_back(atom);
                        atoms.push_back(atom);
                    }
                }
            }
        }
    }

    cout << "Exiting CState::makeAtoms" << endl;
}
void CTracker :: serverResponseSignupLilyPOST( struct request_t *pRequest, struct response_t *pResponse, CAtomList *pPost )
{
    // Set the start time
    const struct bnbttv btv( UTIL_CurrentTime( ) );

    // Verify that the IP is permitted to access the tracker
    if( m_ucIPBanMode != 0 )
        if( IsIPBanned( pRequest, pResponse, btv, gmapLANG_CFG["signup_page"], string( CSS_SIGNUP ), NOT_INDEX ) )
            return;

    string cstrLogin = string( );
    string cstrLilyID = string( );

    if( pPost )
    {
        // Initialise segment dictionary
        CAtomDicti *pSegment = 0;
        CAtom *pDisposition = 0;
        CAtom *pData = 0;
        CAtom *pName = 0;
        CAtom *pFile = 0;
        // Get the segments from the post
        vector<CAtom *> vecSegments = pPost->getValue( );

        // Loop through the segments
        for( unsigned long ulCount = 0; ulCount < vecSegments.size( ); ulCount++ )
        {
            // Is the segment a dictionary?
            if( vecSegments[ulCount]->isDicti( ) )
            {
                // Get the segment dictionary
                pSegment = (CAtomDicti *)vecSegments[ulCount];
                // Get the disposition and the data from the segment dictionary
                pDisposition = pSegment->getItem( "disposition" );
                pData = pSegment->getItem( "data" );

                // Did we get a disposition that is a dictionary and has data?
                if( pDisposition && pDisposition->isDicti( ) && pData )
                {
                    // Get the content name from the disposition
                    pName = ( (CAtomDicti *)pDisposition )->getItem( "name" );

                    // Did we get a content name?
                    if( pName )
                    {
                        // What is the content name to be tested?
                        string strName = pName->toString( );

                        if( strName == "us_login")
                            cstrLogin = pData->toString( );
                        else if( strName == "us_lilyid")
                            cstrLilyID = UTIL_ToLower( pData->toString( ) );
                    }
                    else
                    {
                        // Output common HTML head
                        HTML_Common_Begin(  pRequest, pResponse, gmapLANG_CFG["signup_page"], string( CSS_SIGNUP ), string( ), NOT_INDEX, CODE_400 );

                        // failed
                        pResponse->strContent += "<p class=\"failed\">" + gmapLANG_CFG["failed"] + "</p>\n";
                        // Signal a bad request
                        pResponse->strContent += "<p class=\"body_upload\">400 " + gmapLANG_CFG["server_response_400"] + "</p>\n";

                        // Output common HTML tail
                        HTML_Common_End( pRequest, pResponse, btv, NOT_INDEX, string( CSS_SIGNUP ) );

                        if( gbDebug )
                            UTIL_LogPrint( "Login Warning - Bad request (no users name)\n" );

                        return;
                    }
                }
            }
        }
    }
    else
    {
        // Output common HTML head
        HTML_Common_Begin(  pRequest, pResponse, gmapLANG_CFG["signup_page"], string( CSS_SIGNUP ), string( ), NOT_INDEX, CODE_400 );

        // failed
        pResponse->strContent += "<p class=\"failed\">" + gmapLANG_CFG["failed"] + "</p>\n";
        // Signal a bad request
        pResponse->strContent += "<p class=\"body_upload\">400 " + gmapLANG_CFG["server_response_400"] + "</p>\n";

        // Output common HTML tail
        HTML_Common_End( pRequest, pResponse, btv, NOT_INDEX, string( CSS_SIGNUP ) );

        if( gbDebug )
            UTIL_LogPrint( "Upload Warning - Bad request (no post received)\n" );

        return;
    }

    if( pRequest->user.ucAccess & ACCESS_SIGNUP )
    {
        HTML_Common_Begin(  pRequest, pResponse, gmapLANG_CFG["signup_page"], string( CSS_SIGNUP ), string( ), NOT_INDEX, CODE_200 );

        if(  !cstrLogin.empty( ) && !cstrLilyID.empty( ) )
        {
// 			if( cstrLogin[0] == ' ' || cstrLogin[cstrLogin.size( ) - 1] == ' ' || cstrLogin.size( ) > m_uiNameLength )
            if( cstrLogin.find( ' ' ) != string :: npos || cstrLogin.find( '.' ) != string :: npos || cstrLogin.find( '%' ) != string :: npos || cstrLogin.find( '&' ) != string :: npos || cstrLilyID.find( ' ' ) != string :: npos || cstrLilyID.find( '.' ) != string :: npos || cstrLilyID.find( '%' ) != string :: npos || cstrLilyID.find( '&' ) != string :: npos || cstrLogin.size( ) > m_uiNameLength )
            {
                // Unable to signup. Your name must be less than " + CAtomInt( m_uiNameLength ).toString( ) + " characters long and it must not start or end with spaces.
                pResponse->strContent += "<p class=\"signup_failed\">" + UTIL_Xsprintf( gmapLANG_CFG["signup_name_error"].c_str( ), CAtomInt( m_uiNameLength ).toString( ).c_str( ), string( "<a title=\"" + gmapLANG_CFG["navbar_signup"] + "\" href=\"" + RESPONSE_STR_SIGNUP_LILY_HTML + "\">" ).c_str( ), "</a>" ) + "</p>\n\n";

                // Output common HTML tail
                HTML_Common_End( pRequest, pResponse, btv, NOT_INDEX, string( CSS_SIGNUP ) );

                return;
            }
            time_t tNow = time( 0 );
            char pTime[256];
            memset( pTime, 0, sizeof( pTime ) / sizeof( char ) );
            strftime( pTime, sizeof( pTime ) / sizeof( char ), "%Y %m/%d %H:%M:%S", localtime( &tNow ) );

            const string cstrA1( cstrLogin + ":" + gstrRealm + ":" + pTime );

            unsigned char szMD5[16];
            memset( szMD5, 0, sizeof( szMD5 ) / sizeof( unsigned char ) );

            MD5_CTX md5;

            MD5Init( &md5 );
            MD5Update( &md5, (const unsigned char *)cstrA1.c_str( ), (unsigned int)cstrA1.size( ) );
            MD5Final( szMD5, &md5 );

            const string cstrPass = UTIL_HashToString( string( (char *)szMD5, sizeof( szMD5 ) / sizeof( unsigned char ) ) ).substr( 0, 8 );
            const string cstrMail = cstrLilyID + "@bbs.nju.edu.cn";

            if( !getUser( cstrLogin, m_ucGuestAccess ).strLogin.empty( ) )
            {
                // Unable to signup. The user \"" + UTIL_RemoveHTML( cstrLogin ) + "\" already exists.
                pResponse->strContent += "<p class=\"signup_failed\">" + UTIL_Xsprintf( gmapLANG_CFG["signup_exists_error"].c_str( ), UTIL_RemoveHTML( cstrLogin ).c_str( ), string( "<a title=\"" + gmapLANG_CFG["navbar_signup"] + "\" href=\"" + RESPONSE_STR_SIGNUP_LILY_HTML + "\">" ).c_str( ), "</a>" ) + "</p>\n\n";
            }
            else
            {
                CMySQLQuery *pQuery = new CMySQLQuery( "SELECT blilyid FROM lily WHERE blilyid=\'" + UTIL_StringToMySQL( cstrLilyID ) + "\'" );

                if( pQuery->nextRow( ).size( ) == 1 )
                {
                    pResponse->strContent += "<p class=\"signup_failed\">" + UTIL_Xsprintf( gmapLANG_CFG["signup_exists_error_lily"].c_str( ), UTIL_RemoveHTML( cstrLogin ).c_str( ), UTIL_RemoveHTML( cstrLilyID ).c_str( ), string( "<a title=\"" + gmapLANG_CFG["navbar_signup"] + "\" href=\"" + RESPONSE_STR_SIGNUP_LILY_HTML + "\">" ).c_str( ), "</a>" ) + "</p>\n\n";
                }
                else
                {
                    if( addUser( cstrLogin, cstrPass, m_ucMemberAccess, cstrMail ) )
                    {
                        CMySQLQuery mq01( "INSERT INTO lily (blilyid,busername,bpassword) VALUES(\'" + UTIL_StringToMySQL( cstrLilyID ) + "\',\'" + UTIL_StringToMySQL( cstrLogin ) + "\',\'" + UTIL_StringToMySQL( cstrPass ) + "\')" );

                        system( string( "echo \"ID: " + cstrLogin + " Password: "******"\" | mutt -s \"ZiJingBT\" " + cstrMail ).c_str( ) );

                        // Thanks! You've successfully signed up!
                        pResponse->strContent += "<p class=\"signup_ok\">" + UTIL_Xsprintf( gmapLANG_CFG["signup_success_lily"].c_str( ), UTIL_RemoveHTML( cstrLilyID ).c_str( ), string( "<a title=\"" + gmapLANG_CFG["navbar_signup"] + "\" href=\"" + RESPONSE_STR_LOGIN_HTML + "\">" ).c_str( ), "</a>" ) + "</p>\n\n";
                    }
                    else
                        pResponse->strContent += "<p class=\"signup_failed\">" + UTIL_Xsprintf( gmapLANG_CFG["users_max_create_fail"].c_str( ), string( "<a title=\"" + gmapLANG_CFG["navbar_users"] + "\" href=\"" + RESPONSE_STR_USERS_HTML + "\">" ).c_str( ), "</a>" ) + "</p>\n";
                }
                delete pQuery;
            }

            HTML_Common_End( pRequest, pResponse, btv, NOT_INDEX, string( CSS_SIGNUP ) );
        }
    }
    else
    {
        //Unable to signup. You must fill in all the fields.
        pResponse->strContent += "<p class=\"signup_failed\">" + UTIL_Xsprintf( gmapLANG_CFG["signup_fields_error"].c_str( ), string( "<a title=\"" + gmapLANG_CFG["navbar_signup"] + "\" href=\"" + RESPONSE_STR_SIGNUP_LILY_HTML + "\">" ).c_str( ), "</a>" ) + "</p>\n\n";

        // Output common HTML tail
        HTML_Common_End( pRequest, pResponse, btv, NOT_INDEX, string( CSS_SIGNUP ) );

        return;
    }

}
Пример #9
0
static Residue::eAtomClassification ClassifyAtom(const Residue *residue, const CAtom& atom)
{
    if (!atom.IsSetIupac_code()) return Residue::eUnknownAtom;
    string code = atom.GetIupac_code().front();
    CAtom::EElement element = atom.GetElement();

    if (residue->IsAminoAcid()) {

        // amino acid C-alpha
        if (element==CAtom::eElement_c && code==" CA ")
            return Residue::eAlphaBackboneAtom;

        // amino acid partial backbone
        if (
            (element==CAtom::eElement_c && code==" C  ") ||
            (element==CAtom::eElement_n && code==" N  ")
           )
            return Residue::ePartialBackboneAtom;

        // amino acid complete backbone (all backbone that's not part of "partial")
        // including both GLY alpha hydrogens and terminal COOH and NH3+
        if (
            (element==CAtom::eElement_o &&
                (code==" O  " || code==" OXT")) ||
            (element==CAtom::eElement_h &&
                (code==" H  " || code==" HA " || code=="1HA " || code=="2HA " ||
                 code==" HXT" || code=="1H  " || code=="2H  " || code=="3H  "))
            )
            return Residue::eCompleteBackboneAtom;

        // anything else is side chain
        return Residue::eSideChainAtom;

    } else if (residue->IsNucleotide()) {

        // nucleic acid Phosphorus
        if (element==CAtom::eElement_p && code==" P  ")
            return Residue::eAlphaBackboneAtom;

        // nucleic acid partial backbone
        if (
            (element==CAtom::eElement_c && (code==" C5*" || code==" C4*" || code==" C3*")) ||
            (element==CAtom::eElement_o && (code==" O5*" || code==" O3*")) ||
            (element==CAtom::eElement_h && (code==" H3T" || code==" H5T"))
           )
            return Residue::ePartialBackboneAtom;

        // nucleic acid complete backbone (all backbone that's not part of "partial")
        if (
            (element==CAtom::eElement_o &&
                (code==" O1P" || code==" O2P" || code==" O4*" || code==" O2*")) ||
            (element==CAtom::eElement_c && (code==" C2*" || code==" C1*")) ||
            (element==CAtom::eElement_h &&
                (code=="1H5*" || code=="2H5*" || code==" H4*" || code==" H3*" ||
                 code==" H2*" || code==" H1*" || code==" H1P" || code==" H2P" ||
                 code==" HO2" || code=="1H2*" || code=="2H2*"))
           )
            return Residue::eCompleteBackboneAtom;

        // anything else is side chain
        return Residue::eSideChainAtom;
    }

    return Residue::eUnknownAtom;
}
Пример #10
0
void CInventory::Update()
{
	// add an atom to the beaker when selected from the inventory
	int touchX = 0;
	int touchY = 0;
	if (g_Game.getGameState() == GS_Playing && s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)
	{
		touchX = s3ePointerGetX();
		touchY = s3ePointerGetY();

		for (int i = 0; i < inventoryCount; i++)
		{
			if (atomObjs[i]->isTouched(touchX, touchY))
			{
				if (g_Beaker.getAtomSymbol() != NULL && !strcmp(atomObjs[i]->getSymbol(), g_Beaker.getAtomSymbol()))
				{
					// Early-terminate because the same inventory item was clicked more than once & can be ignored
					break;
				}

				if (atomCount[i] == 1)
				{
					// hide atom to indicate zero are left
					atomObjs[i]->setVisible(false);
					// HASAN - new to display the inventory count image
					atomCountImages[i]->setVisible(false);
				}

				// create new CAtom object to be held in the beaker, so inventory atom can remain unchanged
				CAtom* newAtom = new CAtom();
				newAtom->Init(atomObjs[i]->getSymbol());

				CAtom* prevAtom = g_Beaker.setAtom(newAtom);
				if (prevAtom != NULL)
				{
					// replacing previously selected atom in the beaker, so moving previous one back into this inventory
					// 1 - find previous atom slot in inventory
					// 2 - if previously zero count, then set back to visible
					// 3 - increment the atom counter
					for (int j = 0; j < inventoryCount; j++)
					{
						if (!strcmp(prevAtom->getSymbol(), atomObjs[j]->getSymbol()))
						{
							// match found
							if (atomCount[j] <= 0)
							{
								atomObjs[j]->setVisible(true);
								atomCountImages[j]->setVisible(true);
							}

							atomCount[j]++;

							// This was a clone of the object in the inventory, need to delete it (happens inside the sprite manager) when it's being replaced and not shot into the environment
							g_Game.getSpriteManager()->removeSprite(prevAtom);

							break;
						}
					}
				}

				atomCount[i]--;
			}
		}
	}
}
Пример #11
0
void CInventory::AddAtoms(char* i_strAtomSymbol, int i_nCount)
{
	bool bMatchFound = false;
	int matchIndex = -1;

	if (inventoryCount == 0)
	{
		// HASAN - debug
		//s3eDebugOutputString("Adding inventory sprite to sprite manager.");

		// add the inventory to the sprite manager when the first atom is added
		g_Game.getSpriteManager()->addSprite(inventory_sprite);
	}

	if (inventoryCount > 0)
	{
		for (int i = 0; i < MAX_COUNT; i++)
		{
			if (!strcmp(atoms[i], i_strAtomSymbol))
			{
				bMatchFound = true;
				matchIndex = i;
				break;
			}
		}
	}

	if (!bMatchFound)
	{
		// match
		strcpy(atoms[inventoryCount], i_strAtomSymbol);
		atomCount[inventoryCount] += i_nCount;

		CAtom* atom = new CAtom();
		atom->Init(i_strAtomSymbol);

		// horizontal center, same as inventory graphic
		int posX = (Iw2DGetSurfaceWidth() / 2) - (IMAGE_SIZE_WIDTH / 2);
		int posY = Iw2DGetSurfaceHeight() - (IMAGE_SIZE_HEIGHT / 2);


		// offset inventory horizontally to fit in the container
		posX = posX + (10 + (64 / 2));  // NOTE: 64 = atom size, 10 = border + spacing
		if (inventoryCount > 0)
		{
			posX = posX + (inventoryCount * (64 + 15));  // NOTE: 64 = atom size, 15 = spacing + border + spacing
		}

		atom->setPosAngScale(posX, posY, 0, IW_GEOM_ONE);
		atom->setVelocity(0,0);


		// HASAN - new to create/show the inventory count images
		CIw2DImage* inventoryCountImage = Iw2DCreateImageResource("inventory_number");
		CSprite* inventoryCountSprite = new CSprite();
		inventoryCountSprite->setImage(inventoryCountImage, "inventory_number");
		// NOTE: image width & height = 25 & font width & height = 30
		inventoryCountSprite->setPosition(posX + 13 + (30 / 2), posY + (30 / 2) + 3);
		inventoryCountSprite->setDestSize(30, 30);  // make larger than source to fit behind the text properly
		g_Game.getSpriteManager()->addSprite(inventoryCountSprite);
		atomCountImages[inventoryCount] = inventoryCountSprite;


		atomObjs[inventoryCount] = atom;

		inventoryCount++;
	}
	else
	{
		atomCount[matchIndex] += i_nCount;
	}
}