void EntityEditor::getGoalInfo(const std::string& id) { Eris::Account* account = EmberServices::getSingleton().getServerService().getAccount(); Atlas::Objects::Operation::Generic get; std::list<std::string> parents; parents.emplace_back("commune"); get->setParents(parents); get->setTo(mEntity.getId()); //By setting it TO an entity and FROM our avatar we'll make the server deliver it as //if it came from the entity itself (the server rewrites the FROM to be of the entity). get->setFrom(mWorld.getAvatar()->getEmberEntity().getId()); //By setting a serial number we tell the server to "relay" the operation. This means that any //response operation from the target entity will be sent back to us. get->setSerialno(Eris::getNewSerialno()); Atlas::Message::MapType goalMap; goalMap["id"] = id; Atlas::Objects::Entity::Anonymous getArg; getArg->setAttr("goal_info", goalMap); get->setArgs1(getArg); Eris::Connection* connection = account->getConnection(); connection->getResponder()->await(get->getSerialno(), this, &EntityEditor::operationGetGoalInfoResult); connection->send(get); }
void EntityEditor::removeGoal(const std::string& id) { Eris::Account* account = EmberServices::getSingleton().getServerService().getAccount(); Atlas::Message::MapType goalElement; goalElement["id"] = id; //By not defining anything else than the id we're telling the server to remove it. Atlas::Objects::Entity::Anonymous thought; thought->setAttr("goal", goalElement); Atlas::Objects::Operation::RootOperation thinkOp; thinkOp->setArgs1(thought); std::list<std::string> parents; parents.emplace_back("think"); thinkOp->setParents(parents); thinkOp->setTo(mEntity.getId()); //By setting it TO an entity and FROM our avatar we'll make the server deliver it as //if it came from the entity itself (the server rewrites the FROM to be of the entity). thinkOp->setFrom(mWorld.getAvatar()->getEmberEntity().getId()); Eris::Connection* connection = account->getConnection(); connection->send(thinkOp); }
void ConnectedAdapter::actuate(Eris::Entity* entity, const std::string& action) { try { Atlas::Objects::Entity::Anonymous what; what->setId(entity->getId()); // what->setObjtype("obj"); Atlas::Objects::Operation::RootOperation actionOp; actionOp->setObjtype("op"); actionOp->setArgs1(what); std::list<std::string> actionParents; actionParents.push_back(action); actionOp->setParents(actionParents); Atlas::Objects::Operation::RootOperation actuateOp; actuateOp->setObjtype("op"); actuateOp->setArgs1(actionOp); std::list<std::string> actuateParents; actuateParents.push_back("actuate"); actuateOp->setParents(actuateParents); actuateOp->setFrom(mAvatar.getEntity()->getId()); S_LOG_INFO("Actuating entity with id " << entity->getId() << ", named " << entity->getName() << " with action '" << action << "'."); mConnection.send(actuateOp); } catch (const std::exception& ex) { S_LOG_WARNING("Got error on actuating." << ex); } }
void ConnectedAdapter::wield(Eris::Entity* entity, const std::string& outfitSlot) { try { if (entity->getLocation() != mAvatar.getEntity()) { S_LOG_WARNING("Can't wield an Entity which is not located in the avatar."); return; } Atlas::Objects::Entity::Anonymous arguments; arguments->setId(entity->getId()); if (outfitSlot != "") { arguments->setAttr("outfit", outfitSlot); } Atlas::Objects::Operation::Wield wield; wield->setFrom(mAvatar.getEntity()->getId()); wield->setArgs1(arguments); mConnection.send(wield); } catch (const std::exception& ex) { S_LOG_WARNING("Got error on wielding." << ex); } }
Root atlasClass(const std::string & name, const std::string & parent) { Atlas::Objects::Entity::Anonymous r; r->setParents(std::list<std::string>(1, parent)); r->setObjtype("class"); r->setId(name); return r; }
Root atlasOpDefinition(const std::string & name, const std::string & parent) { Atlas::Objects::Entity::Anonymous r; r->setParents(std::list<std::string>(1, parent)); r->setObjtype("op_definition"); r->setId(name); return r; }
Root atlasType(const std::string & name, const std::string & parent, bool abstract) { Atlas::Objects::Entity::Anonymous r; r->setParents(std::list<std::string>(1, parent)); r->setObjtype(abstract ? "data_type" : "type"); r->setId(name); return r; }
void BaseMindtest::test_unseenOperation() { OpVector res; Atlas::Objects::Operation::Unseen op; bm->operation(op, res); Atlas::Objects::Entity::Anonymous arg; op->setArgs1(arg); bm->operation(op, res); arg->setId("2"); bm->operation(op, res); }
void BaseMindtest::test_disappearanceOperation() { OpVector res; Atlas::Objects::Operation::Disappearance op; bm->operation(op, res); Atlas::Objects::Entity::Anonymous arg; op->setArgs1(arg); bm->operation(op, res); arg->setId("2"); bm->operation(op, res); }
Py::Object CyPy_Task::irrelevant(const Py::Tuple& args) { m_value->irrelevant(); if (args.size() > 0) { args.verify_length(1); Atlas::Objects::Operation::Error e; Atlas::Objects::Entity::Anonymous arg; arg->setAttr("message", verifyString(args.front())); e->modifyArgs().push_back(arg); e->setTo(m_value->m_usageInstance.actor->getId()); return CyPy_Operation::wrap(e); } return Py::None(); }
void ConnectedAdapter::eat(Eris::Entity* entity) { try { Atlas::Objects::Entity::Anonymous what; what->setId(entity->getId()); Atlas::Objects::Operation::Generic op; op->setType("eat", -1); op->setFrom(mAvatar.getEntity()->getId()); op->setArgs1(what); S_LOG_INFO("Eating entity with id " << entity->getId() << ", named " << entity->getName()); mConnection.send(op); } catch (const std::exception& ex) { S_LOG_WARNING("Got error on eating entity." << ex); } }
void ConnectedAdapter::deleteEntity(Eris::Entity* entity) { try { Atlas::Objects::Entity::Anonymous what; what->setId(entity->getId()); Atlas::Objects::Operation::Delete deleteOp; deleteOp->setFrom(mAvatar.getEntity()->getId()); deleteOp->setTo(entity->getId()); deleteOp->setArgs1(what); S_LOG_INFO("Deleting entity with id " << entity->getId() << ", named " << entity->getName()); mConnection.send(deleteOp); } catch (const std::exception& ex) { S_LOG_WARNING("Got error on deleting entity." << ex); } }
void BaseMindtest::test_sightSetOperation() { Atlas::Objects::Operation::Set sub_op; Atlas::Objects::Operation::Sight op; op->setArgs1(sub_op); OpVector res; bm->operation(op, res); sub_op->setArgs1(Atlas::Objects::Entity::Anonymous()); bm->operation(op, res); sub_op->setArgs1(Atlas::Objects::Entity::Anonymous(0)); bm->operation(op, res); Atlas::Objects::Entity::Anonymous arg; arg->setId("2"); sub_op->setArgs1(arg); bm->operation(op, res); }
void BaseMindMapEntityintegration::test_MemMap_updateAdd_location_properties_have_effect() { MemEntity * tlve = new MemEntity("0", 0); Location location(tlve); BBox bbox(WFMath::Point<3>(1,2,3), WFMath::Point<3>(4,5,6)); location.setBBox(bbox); { Atlas::Objects::Entity::Anonymous args; location.addToEntity(args); args->setAttr("id", "0"); m_mind->m_map.updateAdd(args, 1.0f); } MemEntity* ent = m_mind->m_map.get("0"); ASSERT_EQUAL("0", ent->getId()); ASSERT_EQUAL(bbox, ent->m_location.m_bBox); ASSERT_TRUE(ent->m_location.isSolid()); ASSERT_TRUE(ent->m_location.isSimple()); BBox bbox2(WFMath::Point<3>(10,20,30), WFMath::Point<3>(40,50,60)); location.setBBox(bbox2); { Atlas::Objects::Entity::Anonymous args; location.addToEntity(args); args->setAttr("id", "0"); args->setAttr("solid", 0); args->setAttr("simple", 0); m_mind->m_map.updateAdd(args, 2.0f); } ent = m_mind->m_map.get("0"); ASSERT_EQUAL(bbox2, ent->m_location.m_bBox); ASSERT_TRUE(!ent->m_location.isSolid()); ASSERT_TRUE(!ent->m_location.isSimple()); }
void ConnectedAdapter::adminTell(const std::string& entityId, const std::string& attribute, const std::string &value) { try { Atlas::Objects::Entity::Anonymous what; what->setAttr(attribute, value); Atlas::Objects::Operation::Talk talk; talk->setFrom(entityId); talk->setTo(entityId); talk->setArgs1(what); Atlas::Objects::Operation::Sound sound; sound->setFrom(mAvatar.getEntity()->getId()); sound->setTo(entityId); sound->setArgs1(talk); mConnection.send(sound); } catch (const std::exception& ex) { S_LOG_WARNING("Got error on admin_tell." << ex); } }
void EntityEditor::addKnowledge(const std::string& predicate, const std::string& subject, const std::string& knowledge) { Eris::Account* account = EmberServices::getSingleton().getServerService().getAccount(); Atlas::Objects::Entity::Anonymous thought; thought->setAttr("predicate", predicate); thought->setAttr("subject", subject); thought->setAttr("object", knowledge); Atlas::Objects::Operation::RootOperation thinkOp; thinkOp->setArgs1(thought); std::list<std::string> parents; parents.emplace_back("think"); thinkOp->setParents(parents); thinkOp->setTo(mEntity.getId()); //By setting it TO an entity and FROM our avatar we'll make the server deliver it as //if it came from the entity itself (the server rewrites the FROM to be of the entity). thinkOp->setFrom(mWorld.getAvatar()->getEmberEntity().getId()); Eris::Connection* connection = account->getConnection(); connection->send(thinkOp); }
int main() { { AtlasStreamClient * asc = new AtlasStreamClient; delete asc; } TestAtlasStreamClient * asc = new TestAtlasStreamClient; { Atlas::Objects::Root obj; asc->test_objectArrived(obj); obj->setParents(std::list<std::string>()); asc->test_objectArrived(obj); obj->setParents(std::list<std::string>(1, "foo")); asc->test_objectArrived(obj); obj->setObjtype("foo"); asc->test_objectArrived(obj); } Operation op; asc->test_objectArrived(op); asc->test_operation(op); TestClientTask * tct = new TestClientTask(); // Test starting a task asc->runTask(tct, "foo"); assert(asc->test_currentTask() == tct); // Try and start it again will busy, as one is running asc->runTask(new TestClientTask(), "foo"); assert(asc->test_currentTask() == tct); asc->endTask(); assert(asc->test_currentTask() == 0); asc->endTask(); assert(asc->test_currentTask() == 0); tct = new TestClientTask(); asc->runTask(tct, "foo"); // Pass in an operation while a task is running. asc->test_operation(op); assert(asc->test_currentTask() == tct); tct->make_complete(); asc->test_operation(op); assert(asc->test_currentTask() == 0); tct = new TestClientTask(); asc->runTask(tct, "foo"); assert(asc->test_currentTask() == tct); // Pass in an operation while a task is running. asc->test_operation(op); assert(asc->test_currentTask() == tct); { Atlas::Objects::Operation::Info op; asc->test_operation(op); Atlas::Objects::Entity::Anonymous arg; op->setArgs1(arg); asc->test_operation(op); op->setRefno(23); asc->test_operation(op); op->setRefno(asc->newSerialNo()); asc->test_operation(op); op->setFrom("1"); asc->test_operation(op); } { Atlas::Objects::Operation::Error op; asc->test_operation(op); Atlas::Objects::Entity::Anonymous arg; op->setArgs1(arg); asc->test_operation(op); arg->setAttr("message", 1); asc->test_operation(op); arg->setAttr("message", "Real message"); asc->test_operation(op); } { Atlas::Objects::Operation::Appearance op; asc->test_operation(op); } { Atlas::Objects::Operation::Disappearance op; asc->test_operation(op); } { Atlas::Objects::Operation::Sight op; asc->test_operation(op); } { Atlas::Objects::Operation::Sound op; asc->test_operation(op); } assert(asc->test_currentTask() == tct); // Verify these bale out cleanly when unconnected asc->poll(); asc->login("foo", "bar"); asc->create("player", "foo", "bar"); int ret = asc->connect("localhost", 2323); assert(ret != 0); ret = asc->connectLocal("/sys/thereisnofilehere"); assert(ret != 0); }
int main(int argc, char** argv) { std::string atlas_xml_path; char * srcdir_env = getenv("srcdir"); if (srcdir_env != 0) { atlas_xml_path = srcdir_env; atlas_xml_path += "/"; } atlas_xml_path += "../../protocol/spec/atlas.xml"; try { Atlas::Objects::loadDefaults(atlas_xml_path); } catch(Atlas::Objects::DefaultLoadingException e) { std::cout << "DefaultLoadingException: " << e.getDescription() << std::endl; } Root root = Atlas::Objects::objectDefinitions.find("root")->second; Root root_inst; root_inst->setAttr("id", std::string("root_instantiation")); assert(root->getAttr("id").asString() == "root"); assert(root_inst->getAttr("id").asString() == "root_instantiation"); assert(root->getAttr("parents").asList().size() == 0); assert(root_inst->getAttr("parents").asList().size() == 1); assert((*root_inst->getAttr("parents").asList().begin()).asString() == "root"); Look look = smart_dynamic_cast<Look>(objectDefinitions.find("look")->second); Look look_inst; look_inst->setAttr("id", std::string("look_instantiation")); assert(look->getAttr("id").asString() == "look"); assert(look_inst->getAttr("id").asString() == "look_instantiation"); assert(look->getAttr("parents").asList().size() == 1); assert((*look->getAttr("parents").asList().begin()).asString() == "perceive"); assert(look_inst->getAttr("parents").asList().size() == 1); assert((*look_inst->getAttr("parents").asList().begin()).asString() == "look"); Account acct = smart_dynamic_cast<Account>(objectDefinitions.find("account")->second); Account acct_inst; acct_inst->setAttr("id", std::string("account_instantiation")); assert(acct->getAttr("id").asString() == "account"); assert(acct_inst->getAttr("id").asString() == "account_instantiation"); assert(acct->getAttr("parents").asList().size() == 1); assert((*acct->getAttr("parents").asList().begin()).asString() == "admin_entity"); assert(acct_inst->getAttr("parents").asList().size() == 1); assert((*acct_inst->getAttr("parents").asList().begin()).asString() == "account"); { Atlas::Objects::Entity::Anonymous anon; anon->setLoc("12345"); ListType velocity; velocity.push_back(1.4); velocity.push_back(2.4); velocity.push_back(3.4); anon->setVelocityAsList(velocity); ListType bbox; bbox.push_back(1.4); bbox.push_back(2.4); bbox.push_back(3.4); bbox.push_back(2.4); anon->setAttr("bbox", bbox); Atlas::Objects::Operation::Move move; move->setFrom("123456"); move->setTo("123456"); move->setSeconds(12345678); move->setId("123456"); move->setArgs1(anon); Atlas::Objects::Operation::Sight sight; sight->setFrom("123456"); sight->setTo("123456"); sight->setSeconds(12345678); sight->setId("123456"); sight->setArgs1(move); Atlas::Message::MapType map; sight->addToMessage(map); std::cout << map.size() << std::flush; assert(map.size() == 7); assert(map["objtype"].String() == "op"); assert(map["from"].String() == "123456"); assert(map["to"].String() == "123456"); assert(map["seconds"].Float() == 12345678); assert(map["id"].String() == "123456"); assert(map["args"].List().size() == 1); } }