void EntityEditor::operationGetGoalInfoResult(const Atlas::Objects::Operation::RootOperation& op) { //What we receive here has been relayed from the mind of the entity. That means that this op //is potentially unsafe, as it could be of any type (Set, Logout etc.), all depending on what the //mind client decided to send (i.e. someone might want to try to hack). We should therefore treat it //very carefully. if (op->getClassNo() == Atlas::Objects::Operation::ROOT_OPERATION_NO) { //An empty root operation signals a timeout; we never got any answer from the entity. return; } //Since we'll just be iterating over the args we only need to do an extra check that what we got is a //"info" operation. if (op->getClassNo() != Atlas::Objects::Operation::INFO_NO) { S_LOG_WARNING("Got goal info operation with wrong type."); return; } if (!op->getArgs().empty()) { auto goalInfos = op->getArgsAsList(); for (auto goalInfo : goalInfos) { EventGotGoalInfo(goalInfo); } } else { S_LOG_VERBOSE("Got goal info op without any goals."); } }
int main() { TestWorld world; CommServer server; { Peer * p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); delete p; } { Peer * p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::RootOperation op; OpVector res; p->operation(op, res); delete p; } { // Test the setting of authentiaction states Peer * p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); assert(p->getAuthState() == PEER_INIT); p->setAuthState(PEER_AUTHENTICATED); assert(p->getAuthState() == PEER_AUTHENTICATED); delete p; } { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Info op; OpVector res; p->operation(op, res); } // Authenticating (no args) { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATING); Atlas::Objects::Operation::Info op; OpVector res; p->operation(op, res); } // Authenticating (empty arg) { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATING); Atlas::Objects::Operation::Info op; Atlas::Objects::Root arg; op->setArgs1(arg); OpVector res; p->operation(op, res); } // Authenticating (full arg) { TestPeer *p = new TestPeer(*(CommSocket*)0, *(ServerRouting*)0, "addr", "1", 1); p->setAuthState(PEER_AUTHENTICATING); Atlas::Objects::Operation::Info op; Atlas::Objects::Root arg; arg->setId("2"); std::list<std::string> parents; parents.push_back("server"); arg->setParents(parents); op->setArgs1(arg); OpVector res; p->operation(op, res); assert(p->getAccountType() == "server"); } // Authenticated (no args) { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Atlas::Objects::Operation::Info op; OpVector res; p->operation(op, res); } { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Error op; OpVector res; p->operation(op, res); } // Not authenticated { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Entity e("3", 3); int ret = p->teleportEntity(&e); assert(ret == -1); } // Authenticated { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Entity e("3", 3); int ret = p->teleportEntity(&e); assert(ret == 0); assert(stub_CommClient_sent_op.isValid()); assert(stub_CommClient_sent_op->getArgs().size() == 1); } // Re-teleport same entity { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Entity e("3", 3); int ret = p->teleportEntity(&e); assert(ret == 0); assert(stub_CommClient_sent_op.isValid()); assert(stub_CommClient_sent_op->getArgs().size() == 1); ret = p->teleportEntity(&e); assert(ret != 0); } // Character (no mind) { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Character e("3", 3); int ret = p->teleportEntity(&e); assert(ret == 0); assert(stub_CommClient_sent_op.isValid()); assert(stub_CommClient_sent_op->getArgs().size() == 1); } // Character (externl mind, unconnected) { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Character e("3", 3); e.m_externalMind = new ExternalMind(e); int ret = p->teleportEntity(&e); assert(ret == 0); assert(stub_CommClient_sent_op.isValid()); assert(stub_CommClient_sent_op->getArgs().size() == 1); } // Character (externl mind, connected) { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Character e("3", 3); ExternalMind * mind = new ExternalMind(e); mind->linkUp((Link*)23); e.m_externalMind = mind; int ret = p->teleportEntity(&e); assert(ret == 0); assert(stub_CommClient_sent_op.isValid()); assert(stub_CommClient_sent_op->getArgs().size() == 2); } // No arg { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Info op; OpVector res; p->peerTeleportResponse(op, res); } // Empty arg, no refno { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); p->peerTeleportResponse(op, res); } // Empty arg, made up refno, not CommPeer { TestCommClient *peerConn = new TestCommClient(*(CommServer*)0, "name"); Peer *p = new Peer(*peerConn, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); op->setRefno(23); p->peerTeleportResponse(op, res); } // Empty arg, made up refno { CommPeer *peerConn = new CommPeer(*(CommServer*)0, "name"); Peer *p = new Peer(*peerConn, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); op->setRefno(23); p->peerTeleportResponse(op, res); } // Empty arg, refno that matches earlier teleport, not in world { CommPeer *peerConn = new CommPeer(server, "name"); Peer *p = new Peer(*peerConn, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Entity e("23", 23); int ret = p->teleportEntity(&e); assert(ret == 0); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); op->setRefno(23); p->peerTeleportResponse(op, res); } // Empty arg, refno that matches earlier teleport, in world { CommPeer *peerConn = new CommPeer(server, "name"); Peer *p = new Peer(*peerConn, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Entity e("23", 23); int ret = p->teleportEntity(&e); assert(ret == 0); world.test_addEntity(&e, 23); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); op->setRefno(23); p->peerTeleportResponse(op, res); world.test_delEntity(23); } // Empty arg, refno that matches earlier teleport, with mind { CommPeer *peerConn = new CommPeer(server, "name"); Peer *p = new Peer(*peerConn, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Character e("23", 23); ExternalMind * mind = new ExternalMind(e); mind->linkUp((Link*)23); e.m_externalMind = mind; int ret = p->teleportEntity(&e); assert(ret == 0); world.test_addEntity(&e, 23); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); op->setRefno(23); p->peerTeleportResponse(op, res); world.test_delEntity(23); } // No teleports to clear { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); p->cleanTeleports(); } // One teleport to clear { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Entity e("23", 23); int ret = p->teleportEntity(&e); assert(ret == 0); p->cleanTeleports(); } return 0; }