std::shared_ptr<Ego::Particle> ParticleHandler::spawnParticle(const Vector3f& spawnPos, const Facing& spawnFacing, const PRO_REF spawnProfile, const PIP_REF particleProfile, const ObjectRef spawnAttach, Uint16 vrt_offset, const TEAM_REF spawnTeam, const ObjectRef spawnOrigin, const ParticleRef spawnParticleOrigin, const int multispawn, const ObjectRef spawnTarget, const bool onlyOverWater) { const std::shared_ptr<ParticleProfile> &ppip = ProfileSystem::get().ParticleProfileSystem.get_ptr(particleProfile); if (!ppip) { const std::string spawnOriginName = _currentModule->getObjectHandler().exists(spawnOrigin) ? _currentModule->getObjectHandler()[spawnOrigin]->getName() : "INVALID"; const std::string spawnProfileName = ProfileSystem::get().isValidProfileID(spawnProfile) ? ProfileSystem::get().getProfile(spawnProfile)->getPathname() : "INVALID"; Log::get().debug("spawn_one_particle() - cannot spawn particle with invalid particle profile == %d, spawn origin == %" PRIuZ " (\"%s\"), spawn profile == %d (\"%s\"))\n", REF_TO_INT(particleProfile), spawnOrigin.get(), spawnOriginName.c_str(), REF_TO_INT(spawnProfile), spawnProfileName.c_str()); return Ego::Particle::INVALID_PARTICLE; } // count all the requests for this particle type ppip->_spawnRequestCount++; //Try to get a free particle std::shared_ptr<Ego::Particle> particle = getFreeParticle(ppip->force); if(particle) { //Initialize particle and add it into the game if(particle->initialize(ParticleRef(_totalParticlesSpawned++), spawnPos, spawnFacing, spawnProfile, particleProfile, spawnAttach, vrt_offset, spawnTeam, spawnOrigin, ParticleRef(spawnParticleOrigin), multispawn, spawnTarget, onlyOverWater)) { _pendingParticles.push_back(particle); _particleMap[particle->getParticleID()] = particle; } else { //If we failed to spawn somehow, put it back to the unused pool _unusedPool.push_back(particle); } } if(!particle) { const std::string spawnOriginName = _currentModule->getObjectHandler().exists(spawnOrigin) ? _currentModule->getObjectHandler().get(spawnOrigin)->getName() : "INVALID"; const std::string particleProfileName = LOADED_PIP(particleProfile) ? ProfileSystem::get().ParticleProfileSystem.get_ptr(particleProfile)->_name : "INVALID"; const std::string spawnProfileName = ProfileSystem::get().isValidProfileID(spawnProfile) ? ProfileSystem::get().getProfile(spawnProfile)->getPathname().c_str() : "INVALID"; Log::get().debug("spawn_one_particle() - cannot allocate a particle! owner == %" PRIuZ "(\"%s\"), spawn profile == %d(\"%s\"), particle profile == %d(\"%s\")\n", spawnOrigin.get(), spawnOriginName.c_str(), REF_TO_INT(spawnProfile), spawnProfileName.c_str(), REF_TO_INT(particleProfile), particleProfileName.c_str()); } return particle; }
QString Stringify::JO(ObjectRef o) { if (stack.contains(o.getPointer())) { ctx->throwTypeError(); return QString(); } Scope scope(ctx); QString result; stack.push(o.getPointer()); QString stepback = indent; indent += gap; QStringList partial; if (propertyList.isEmpty()) { ObjectIterator it(scope, o, ObjectIterator::EnumerableOnly); ScopedValue name(scope); ScopedValue val(scope); while (1) { name = it.nextPropertyNameAsString(val); if (name->isNull()) break; QString key = name->toQString(); QString member = makeMember(key, val); if (!member.isEmpty()) partial += member; } } else { ScopedString s(scope); for (int i = 0; i < propertyList.size(); ++i) { bool exists; s = propertyList.at(i); ScopedValue v(scope, o->get(s, &exists)); if (!exists) continue; QString member = makeMember(s->toQString(), v); if (!member.isEmpty()) partial += member; } } if (partial.isEmpty()) { result = QStringLiteral("{}"); } else if (gap.isEmpty()) { result = QStringLiteral("{") + partial.join(QLatin1Char(',')) + QStringLiteral("}"); } else { QString separator = QStringLiteral(",\n") + indent; result = QStringLiteral("{\n") + indent + partial.join(separator) + QStringLiteral("\n") + stepback + QStringLiteral("}"); } indent = stepback; stack.pop(); return result; }
void testObjectBlock (void) { /*ObjectRef<int> obj; obj.allocate(); *obj.get() = 18;*/ ObjectRef<TestDummyClass> ptr; ptr.allocate(); ptr.get()->i = 19; ptr.get()->j = 20; ObjectRef<TestDummyClass> ptr1 = ptr; }
void DomSerializer::GetList(const char* key, std::list<ObjectRef>& value, Object& model, bool required) { // Find the node corresponding to the object list wanting to be populated DOMNode* listNode = FindElementByName(m_node, CStdString(key)); // Create a new serializer and affect it to this object if (listNode) { // Iterate over the nodes ##### DOMNode* node = listNode->getFirstChild(); while(node) { // Create a new object instance ObjectRef newObject = model.NewInstance(); try { DomSerializer serializer(newObject.get()); serializer.DeSerialize(node); value.push_back(newObject); } catch (CStdString& e) { // For now, do not interrupt the deserialization process. // in the future, we might let this exception go through if the node has been // recognized to bear the proper tag name ; } node = node->getNextSibling(); } } else if (required) { throw(CStdString("DomSerializer::GetList: required node missing:") + key); } }
int CommandLineServer::svc(void) { for (bool active = true;active == true;) { char buf[2048]; ACE_Time_Value timeout; timeout.sec(3600); int i = 0; // Display prompt char prompt[] = "\r\n>"; peer().send(prompt, 3, MSG_NOSIGNAL); // Get one command line bool foundCRLF = false; while(active && !foundCRLF && i<2040) { ssize_t size = peer().recv(buf+i, 2040-i, &timeout); if (size == 0 || size == -1) { active = false; } else { for(int j=0; j<size && !foundCRLF;j++) { if(buf[i+j] == '\r' || buf[i+j] == '\n') { foundCRLF = true; buf[i+j] = '\0'; CStdString command(buf); try { CStdString className = SingleLineSerializer::FindClass(command); ObjectRef objRef = ObjectFactory::GetSingleton()->NewInstance(className); if (objRef.get()) { objRef->DeSerializeSingleLine(command); ObjectRef response = objRef->Process(); CStdString responseString = response->SerializeSingleLine(); peer().send((PCSTR)responseString, responseString.GetLength(), MSG_NOSIGNAL); } else { CStdString error = "Unrecognized command"; peer().send(error, error.GetLength(), MSG_NOSIGNAL); ; } } catch (CStdString& e) { peer().send(e, e.GetLength(), MSG_NOSIGNAL); ; } } } i += size; } } } return 0; }
int HttpServer::svc(void) { char buf[2048]; buf[2047] = '\0'; // security ACE_Time_Value timeout; timeout.sec(5); ssize_t size = peer().recv(buf, 2040, &timeout); if (size > 5) { try { int startUrlOffset = 5; // get rid of "GET /" from Http request, so skip 5 chars char* stopUrl = ACE_OS::strstr(buf+startUrlOffset, " HTTP"); // detect location of post-URL trailing stuff if(!stopUrl) { throw (CStdString("Malformed http request")); ; } *stopUrl = '\0'; // Remove post-URL trailing stuff CStdString url(buf+startUrlOffset); int queryOffset = url.Find("?"); if (queryOffset > 0) { // Strip beginning of URL in case the command is received as an URL "query" of the form: // http://hostname/service/command?type=ping url = url.Right(url.size() - queryOffset - 1); } CStdString className = UrlSerializer::FindClass(url); ObjectRef objRef = ObjectFactory::GetSingleton()->NewInstance(className); if (objRef.get()) { objRef->DeSerializeUrl(url); ObjectRef response = objRef->Process(); if(response.get() == NULL) { throw (CStdString("Command does not return a response:") + className); } else { DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(XStr("Core").unicodeForm()); XERCES_CPP_NAMESPACE::DOMDocument* myDoc; myDoc = impl->createDocument( 0, // root element namespace URI. XStr("response").unicodeForm(), // root element name 0); // document type object (DTD). response->SerializeDom(myDoc); CStdString pingResponse = DomSerializer::DomNodeToString(myDoc); CStdString httpOk("HTTP/1.0 200 OK\r\nContent-type: text/xml\r\n\r\n"); peer().send(httpOk, httpOk.GetLength(), MSG_NOSIGNAL); peer().send(pingResponse, pingResponse.GetLength(), MSG_NOSIGNAL); myDoc->release(); } } else { throw (CStdString("Command not found:") + className); ; } } catch (CStdString &e) { CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nError\r\n"); error = error + e + "\r\n"; peer().send(error, error.GetLength(), MSG_NOSIGNAL); } catch(const XMLException& e) { CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nXML Error\r\n"); peer().send(error, error.GetLength(), MSG_NOSIGNAL); } } else { CStdString notFound("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nNot found\r\n"); peer().send(notFound, notFound.GetLength(), MSG_NOSIGNAL); } return 0; }