static PyObject *wpCharIterator_getAttr( wpCharIterator *self, char *name ) { if( !strcmp( name, "first" ) ) return PyGetCharObject( self->iter->first() ); else if( !strcmp( name, "next" ) ) return PyGetCharObject( self->iter->next() ); return PyFalse; }
void cAllTerritories::check( P_CHAR pc ) { cUOSocket *socket = NULL; if( pc->objectType() == enPlayer ) socket = dynamic_cast<P_PLAYER>(pc)->socket(); cTerritory* currRegion = this->region( pc->pos().x, pc->pos().y, pc->pos().map ); cTerritory* lastRegion = pc->region(); if( !currRegion ) return; if (!lastRegion) { pc->setRegion(currRegion); return; } if (currRegion != lastRegion) { pc->setRegion(currRegion); if (socket) { // If the last region was a cave or if the new region is a cave, // update the lightlevel. if ((currRegion->isCave() && !lastRegion->isCave()) || (!currRegion->isCave() && lastRegion->isCave())) { socket->updateLightLevel(); } socket->playMusic(); } PyObject *args = Py_BuildValue("(NNN)", PyGetCharObject(pc), PyGetRegionObject(lastRegion), PyGetRegionObject(currRegion)); if (!cPythonScript::callChainedEventHandler(EVENT_CHANGEREGION, pc->getEvents(), args) && socket) { if (lastRegion && !lastRegion->name().isEmpty()) socket->sysMessage(tr("You have left %1.").arg(lastRegion->name())); if (currRegion && !currRegion->name().isEmpty()) socket->sysMessage(tr("You have entered %1.").arg(currRegion->name())); if( (currRegion->isGuarded() != lastRegion->isGuarded()) || (currRegion->isGuarded() && (currRegion->guardOwner() != lastRegion->guardOwner()))) { if (currRegion->isGuarded()) { if(currRegion->guardOwner().isEmpty()) socket->clilocMessage(500112); // You are now under the protection of the town guards else socket->sysMessage(currRegion->guardOwner()); } else { if(lastRegion->guardOwner().isEmpty()) socket->clilocMessage(500113); // You have left the protection of the town guards. else socket->sysMessage(lastRegion->guardOwner()); } } } Py_DECREF(args); } }
static PyObject *wpMulti_getAttr( wpMulti *self, char *name ) { if( !strcmp( "events", name ) ) { QStringList events = QStringList::split( ",", self->pMulti->eventList() ); PyObject *list = PyList_New( events.count() ); for( uint i = 0; i < events.count(); ++i ) PyList_SetItem( list, i, PyString_FromString( events[i].latin1() ) ); return list; } else { cVariant result; stError *error = self->pMulti->getProperty( name, result ); if( !error ) { PyObject *obj = 0; switch( result.type() ) { case cVariant::BaseChar: obj = PyGetCharObject( result.toChar() ); break; case cVariant::Item: obj = PyGetItemObject( result.toItem() ); break; case cVariant::Long: case cVariant::Int: obj = PyInt_FromLong( result.toInt() ); break; case cVariant::String: if( result.toString().isNull() ) obj = PyString_FromString( "" ); else obj = PyString_FromString( result.toString().latin1() ); break; case cVariant::Double: obj = PyFloat_FromDouble( result.toDouble() ); break; case cVariant::Coord: obj = PyGetCoordObject( result.toCoord() ); break; } if( !obj ) { PyErr_Format( PyExc_ValueError, "Unsupported Property Type: %s", result.typeName() ); return 0; } return obj; } else delete error; } return Py_FindMethod( wpMultiMethods, (PyObject*)self, name ); }
static PyObject* wpCharIterator_getAttr( wpCharIterator* self, char* name ) { /* \rproperty chariterator.first Accessing this property will reset the iterator to the first character and return it. If there are no characters to iterate over, None is returned. */ if ( !strcmp( name, "first" ) ) return PyGetCharObject( self->iter->first() ); /* \rproperty chariterator.next Accessing this property will advance the iterator to the next character and return it. At the end of the iteration, None is returned. */ else if ( !strcmp( name, "next" ) ) return PyGetCharObject( self->iter->next() ); Py_RETURN_FALSE; }
float ScriptAction::postCondition() { if ( !postcond.isNull() ) { // Try to call the python function // Get everything before the last dot if ( postcond.contains( "." ) ) { // Find the last dot int position = postcond.findRev( "." ); QString sModule = postcond.left( position ); QString sFunction = postcond.right( postcond.length() - ( position + 1 ) ); PyObject* pModule = PyImport_ImportModule( const_cast<char*>( sModule.latin1() ) ); if ( pModule ) { PyObject* pFunc = PyObject_GetAttrString( pModule, const_cast<char*>( sFunction.latin1() ) ); if ( pFunc && PyCallable_Check( pFunc ) ) { // Create our Argument list PyObject* p_args = PyTuple_New( 3 ); PyTuple_SetItem( p_args, 0, PyGetCharObject( m_npc ) ); Py_INCREF( Py_None ); PyTuple_SetItem( p_args, 1, Py_None ); Py_INCREF( Py_None ); PyTuple_SetItem( p_args, 2, Py_None ); PyObject* returnValue = PyObject_CallObject( pFunc, p_args ); Py_XDECREF( p_args ); reportPythonError( sModule ); if ( returnValue == NULL || !PyFloat_Check( returnValue ) ) { Py_XDECREF( returnValue ); return 1.0f; } else { double result = PyFloat_AsDouble( returnValue ); Py_XDECREF( returnValue ); return result; } } Py_XDECREF( pFunc ); } Py_XDECREF( pModule ); } } return 1.0f; }
void ScriptAI::onSpeechInput( P_PLAYER pTalker, const QString& comm ) { if ( !onspeech.isNull() ) { // Try to call the python function // Get everything before the last dot if ( onspeech.contains( "." ) ) { // Find the last dot int position = onspeech.findRev( "." ); QString sModule = onspeech.left( position ); QString sFunction = onspeech.right( onspeech.length() - ( position + 1 ) ); PyObject* pModule = PyImport_ImportModule( const_cast<char*>( sModule.latin1() ) ); if ( pModule ) { PyObject* pFunc = PyObject_GetAttrString( pModule, const_cast<char*>( sFunction.latin1() ) ); if ( pFunc && PyCallable_Check( pFunc ) ) { // Create our Argument list PyObject* p_args = PyTuple_New( 3 ); PyTuple_SetItem( p_args, 0, PyGetCharObject( m_npc ) ); PyTuple_SetItem( p_args, 1, PyGetCharObject( pTalker ) ); PyTuple_SetItem( p_args, 2, PyString_FromString( comm.latin1() ) ); Py_XDECREF( PyEval_CallObject( pFunc, p_args ) ); Py_XDECREF( p_args ); reportPythonError( sModule ); } Py_XDECREF( pFunc ); } Py_XDECREF( pModule ); } } }
/* * Returns the bans list of this multi */ static PyObject* wpMulti_bans( wpMulti* self, PyObject* args ) { Q_UNUSED(args); if( !self->pMulti || self->pMulti->free ) return PyFalse; std::vector< SERIAL > bans = self->pMulti->bans(); std::vector< SERIAL >::iterator it = bans.begin(); PyObject* list = PyList_New( bans.size() ); while( it != bans.end() ) { P_CHAR pChar = FindCharBySerial( *it ); if( pChar ) PyList_Append( list, PyGetCharObject( pChar ) ); it ++; } return list; }
// Getters & Setters static PyObject* wpSocket_getAttr( wpSocket* self, char* name ) { /* \rproperty socket.player The <object id="CHAR">char</object> object for the player played by this socket. May be None. */ if ( !strcmp( name, "player" ) ) return PyGetCharObject( self->pSock->player() ); /* \rproperty socket.screenwidth The width of the game window in pixels as sent by the client. */ else if ( !strcmp( name, "screenwidth" ) ) { return PyInt_FromLong( self->pSock->screenWidth() ); } /* \rproperty socket.screenheight The height of the game window in pixels as sent by the client. */ else if ( !strcmp( name, "screenheight" ) ) { return PyInt_FromLong( self->pSock->screenHeight() ); } else if ( !strcmp( name, "walksequence" ) ) { return PyInt_FromLong( self->pSock->walkSequence() ); } /* \rproperty socket.account An <object id="account">account</object> object for the account used by this socket. Should not be None. */ else if ( !strcmp( name, "account" ) ) { return PyGetAccountObject( self->pSock->account() ); } /* \rproperty socket.address A string containing the IP address this socket is connected to. */ else if ( !strcmp( name, "address" ) ) { return QString2Python( self->pSock->ip() ); } else { return Py_FindMethod( wpSocketMethods, ( PyObject * ) self, name ); } }
void ScriptAction::execute() { if ( !exec.isNull() ) { // Try to call the python function // Get everything before the last dot if ( exec.contains( "." ) ) { // Find the last dot int position = exec.findRev( "." ); QString sModule = exec.left( position ); QString sFunction = exec.right( exec.length() - ( position + 1 ) ); PyObject* pModule = PyImport_ImportModule( const_cast<char*>( sModule.latin1() ) ); if ( pModule ) { PyObject* pFunc = PyObject_GetAttrString( pModule, const_cast<char*>( sFunction.latin1() ) ); if ( pFunc && PyCallable_Check( pFunc ) ) { // Create our Argument list PyObject* p_args = PyTuple_New( 3 ); PyTuple_SetItem( p_args, 0, PyGetCharObject( m_npc ) ); Py_INCREF( Py_None ); PyTuple_SetItem( p_args, 1, Py_None ); Py_INCREF( Py_None ); PyTuple_SetItem( p_args, 2, Py_None ); Py_XDECREF( PyEval_CallObject( pFunc, p_args ) ); Py_XDECREF( p_args ); reportPythonError( sModule ); } Py_XDECREF( pFunc ); } Py_XDECREF( pModule ); } } }
// Getters & Setters static PyObject* wpSocket_getAttr( wpSocket* self, char* name ) { /* \rproperty socket.player The <object id="CHAR">char</object> object for the player played by this socket. May be None. */ if ( !strcmp( name, "player" ) ) return PyGetCharObject( self->pSock->player() ); /* \rproperty socket.screenwidth The width of the game window in pixels as sent by the client. */ else if ( !strcmp( name, "screenwidth" ) ) { return PyInt_FromLong( self->pSock->screenWidth() ); } /* \rproperty socket.screenheight The height of the game window in pixels as sent by the client. */ else if ( !strcmp( name, "screenheight" ) ) { return PyInt_FromLong( self->pSock->screenHeight() ); } else if ( !strcmp( name, "walksequence" ) ) { return PyInt_FromLong( self->pSock->walkSequence() ); } /* \rproperty socket.account An <object id="account">account</object> object for the account used by this socket. Should not be None. */ else if ( !strcmp( name, "account" ) ) { return PyGetAccountObject( self->pSock->account() ); } /* \rproperty socket.address A string containing the IP address this socket is connected to. */ else if ( !strcmp( name, "address" ) ) { return QString2Python( self->pSock->ip() ); } /* \rproperty socket.id The unique socket identifier for this socket. */ else if ( !strcmp( name, "id" ) ) { return PyInt_FromLong( self->pSock->uniqueId() ); } /* \rproperty socket.version The client version string sent by the client. */ else if ( !strcmp( name, "version" ) ) { return QString2Python( self->pSock->version() ); } /* \rproperty socket.3dclient indicates that this is a 3d client. */ else if ( !strcmp( name, "3dclient" ) ) { if (self->pSock->is3dClient()) { Py_RETURN_TRUE; } else { Py_RETURN_FALSE; } } /* \rproperty socket.flags This is the bitfield sent by the client on character selection. Propable flags: <code>0x100 - 3d Client 0x10 - Samurai Empire 0x08 - Age of Shadows 0x04 - Lord Blackthornes Revenge 0x02 - Third Dawn 0x01 - Renaissance 0x00 - The Second Age</code> */ else if ( !strcmp( name, "flags" ) ) { return PyInt_FromLong(self->pSock->flags()); } /* \rproperty socket.rxbytes The number of bytes received by this socket. */ else if ( !strcmp( name, "rxbytes" ) ) { return PyInt_FromLong( self->pSock->rxBytes() ); } /* \rproperty socket.txbytes The number of bytes sent by this socket. */ else if ( !strcmp( name, "txbytes" ) ) { return PyInt_FromLong( self->pSock->txBytes() ); } /* \rproperty socket.txbytesraw The number of bytes sent by this socket before compression. */ else if ( !strcmp( name, "txbytesraw" ) ) { return PyInt_FromLong( self->pSock->txBytesRaw() ); } else { return Py_FindMethod( wpSocketMethods, ( PyObject * ) self, name ); } }
void cTerritories::check( P_CHAR pc ) { cUOSocket* socket = NULL; if ( pc->objectType() == enPlayer ) socket = dynamic_cast<P_PLAYER>( pc )->socket(); cTerritory* currRegion = this->region( pc->pos().x, pc->pos().y, pc->pos().map ); cTerritory* lastRegion = pc->region(); if ( !currRegion ) return; if ( !lastRegion ) { pc->setRegion( currRegion ); return; } if ( currRegion != lastRegion ) { pc->setRegion( currRegion ); if ( socket ) { // If the last region was a cave or if the new region is a cave, // update the lightlevel. if ( ( currRegion->isCave() && !lastRegion->isCave() ) || ( !currRegion->isCave() && lastRegion->isCave() ) ) { socket->updateLightLevel(); } socket->playMusic(); } PyObject* args = Py_BuildValue( "(NNN)", PyGetCharObject( pc ), PyGetRegionObject( lastRegion ), PyGetRegionObject( currRegion ) ); if ( !pc->callEventHandler( EVENT_CHANGEREGION, args ) && socket ) { if ( lastRegion && !lastRegion->name().isEmpty() && !lastRegion->isNoEnterMessage() ) socket->sysMessage( tr( "You have left %1." ).arg( lastRegion->name() ) ); if ( currRegion && !currRegion->name().isEmpty() && !currRegion->isNoEnterMessage() ) socket->sysMessage( tr( "You have entered %1." ).arg( currRegion->name() ) ); if ( ( currRegion->isGuarded() != lastRegion->isGuarded() ) || ( currRegion->isGuarded() && ( currRegion->guardOwner() != lastRegion->guardOwner() ) ) ) { /* Guarded Setting Changes */ if ( currRegion->isGuarded() != lastRegion->isGuarded() ) { if ( lastRegion->isGuarded() && !lastRegion->isNoGuardMessage() ) { if ( lastRegion->guardOwner().isEmpty() ) socket->clilocMessage( 500113 ); // You have left the protection of the town guards. else socket->sysMessage( tr( "You have left the protection of %1 guards." ).arg( lastRegion->guardOwner() ) ); } if ( currRegion->isGuarded() && !currRegion->isNoGuardMessage() ) { if ( currRegion->guardOwner().isEmpty() ) socket->clilocMessage( 500112 ); // You are now under the protection of the town guards else socket->sysMessage( tr( "You are now under the protection of %1 guards." ).arg( currRegion->guardOwner() ) ); } } } /* Remain Guarded */ if ( currRegion->isGuarded() == lastRegion->isGuarded() ) { /* Only show if you haven't gotten a message before. Or, only show if the guard owner changes. */ if ( ( !currRegion->isNoGuardMessage() && !lastRegion->isNoGuardMessage() ) && ( currRegion->guardOwner() != lastRegion->guardOwner() ) ) { if ( currRegion->guardOwner().isEmpty() ) socket->clilocMessage( 500112 ); // You are now under the protection of the town guards else socket->sysMessage( tr( "You are now under the protection of %1 guards." ).arg( currRegion->guardOwner() ) ); } } } Py_DECREF( args ); } }