Example #1
0
void FriendsListDialog::slot_popupTalk(void)
{
	Talk * talk;
    talk = connection->getTalk(popup_playerlisting);
	if(talk)
		talk->updatePlayerListing();
}
Example #2
0
void FriendsListDialog::slot_playersDoubleClickedWatches(const QModelIndex & index)
{
    PlayerListing * opponent = watchesListModel->playerListingFromIndex(index);
    Talk * talk = room->getTalk(opponent);
    if(talk)
        talk->updatePlayerListing();
}
Example #3
0
void FriendsListDialog::slot_playersDoubleClickedWatches(const QModelIndex & index)
{
	//QModelIndex translated = playerSortProxy->mapToSource(index);
	PlayerListing * opponent = watchesListModel->playerListingFromIndex(index);
	Talk * talk;
    talk = connection->getTalk(opponent);
	if(talk)
		talk->updatePlayerListing();
}
Example #4
0
void Accountintegration::test_TalkOperation()
{
    Anonymous op_arg;
    op_arg->setParents(std::list<std::string>());
    op_arg->setLoc("1");

    Talk op;
    op->setSerialno(1);
    op->setArgs1(op_arg);

    OpVector res;
    m_ac->operation(op, res);

    // FIXME Sound op should have been sent to the lobby
}
Example #5
0
void Controller::initShared(verboseEnum verbosity, bool fullscreen)
  // initialisation that's the same for client and server
{
  out.setVerbosity(verbosity);
  out.init();

  out.setCursor(0);

  transfercontrol.init(out); // TODO remove?

  // network TODO tidy
  net.init(out);// flagsize, unitsize, MAX_CLIENTS);
  Talk talk; // just for getting chunk bytes
  net.setAudioDataSize(talk.getChunkBytes()); // TODO when use UDP remove this
}
Example #6
0
/* This isn't really just a "sendStats" function anymore, that's
 * done by the talk object I think and... well its ugly, responsibilities
 * are crossed, etc.. FIXME */
void Room::sendStatsRequest(PlayerListing & opponent)
{
	Talk * talk;
	/* Whenever a talk window is opened, we want stats.  This
	 * means its easier to create the talk window and let it
	 * always create stats, then send out stats messages
	 * that generate talk windows */
	/* This is a little weird now...almost like we're just asking
	 * for an update on the references */
    talk = connection->getTalk(&opponent);
	//connection->sendStatsRequest(opponent);
	/* This is really only for ORO, and let's see if it works but... */
	if(talk)
		talk->updatePlayerListing();
}
void AccountServerLobbyintegration::test_talk()
{
    test_send_count = 0;

    Anonymous talk_arg;
    talk_arg->setAttr("say", "bb6a71d1-3ee9-43ac-8750-cd9d8f7921f6");

    Talk op;
    op->setArgs1(talk_arg);
    op->setFrom(m_account->getId());

    OpVector res;
    m_account->operation(op, res);
    ASSERT_TRUE(res.empty());

    // Ensure the resulting broadcast sound was sent to all three accounts
    ASSERT_EQUAL(test_send_count, 3);
}
Example #8
0
void Interactive::exec(const std::string & cmd, const std::string & arg)
{
    bool reply_expected = true;
    reply_flag = false;
    error_flag = false;

    boost::shared_ptr<ObjectContext> command_context = m_currentContext.lock();
    if (!command_context) {
        std::cout << "ERROR: Context free" << std::endl << std::flush;
        return;
    }

    if (cmd == "stat") {
        Get g;
        send(g);
    } else if (cmd == "install") {
        size_t space = arg.find(' ');
        if (space == std::string::npos || space >= (arg.size() - 1)) {
            std::cout << "usage: install <type id> <parent id>"
                      << std::endl << std::flush;
        } else {
            Create c;
            c->setFrom(m_accountId);
            Anonymous ent;
            ent->setId(std::string(arg, 0, space));
            ent->setObjtype("class");
            ent->setParents(std::list<std::string>(1, std::string(arg, space + 1)));
            c->setArgs1(ent);
            send(c);
        }
        reply_expected = false;
    } else if (cmd == "look") {
        Look l;
        if (!arg.empty()) {
            Anonymous cmap;
            cmap->setId(arg);
            l->setArgs1(cmap);
        }
        l->setSerialno(newSerialNo());
        command_context->setFromContext(l);
        send(l);
        reply_expected = false;
    } else if (cmd == "logout") {
        Logout l;
        l->setFrom(m_accountId);
        if (!arg.empty()) {
            Anonymous lmap;
            lmap->setId(arg);
            l->setArgs1(lmap);
            reply_expected = false;
        }
        send(l);
    } else if (cmd == "say") {
        Talk t;
        Anonymous ent;
        ent->setAttr("say", arg);
        t->setArgs1(ent);
        t->setFrom(m_accountId);
        send(t);
    } else if (cmd == "help" || cmd == "?") {
        reply_expected = false;
        help();
    } else if (cmd == "query") {
        Get g;

        if (!arg.empty()) {
            Anonymous cmap;
            if (::isdigit(arg[0])) {
                cmap->setObjtype("obj");
            } else {
                cmap->setObjtype("meta");
            }
            cmap->setId(arg);
            g->setArgs1(cmap);
        }
        g->setFrom(m_accountId);

        send(g);
    } else if (cmd == "reload") {
        if (arg.empty()) {
            reply_expected = false;
            std::cout << "reload: Argument required" << std::endl << std::flush;
        } else {
            Set s;

            Anonymous tmap;
            tmap->setObjtype("class");
            tmap->setId(arg);
            s->setArgs1(tmap);
            s->setFrom(m_accountId);

            send(s);
        }
    } else if (cmd == "get") {
        Get g;

        if (!arg.empty()) {
            Anonymous cmap;
            if (::isdigit(arg[0])) {
                cmap->setObjtype("obj");
            } else {
                cmap->setObjtype("meta");
            }
            cmap->setId(arg);
            g->setArgs1(cmap);
        }
        g->setFrom(m_accountId);

        send(g);
    } else if (cmd == "monitor") {
        ClientTask * task = new OperationMonitor;
        if (runTask(task, arg) == 0) {
            Monitor m;

            m->setArgs1(Anonymous());
            m->setFrom(m_accountId);

            send(m);
        }

        reply_expected = false;
    } else if (cmd == "unmonitor") {
        OperationMonitor * om = dynamic_cast<OperationMonitor *>(m_currentTask);

        if (om != 0) {
            Monitor m;

            m->setFrom(m_accountId);

            send(m);

            reply_expected = false;

            SystemTime now;
            now.update();

            time_t monitor_time = now.seconds() - om->startTime();

            std::cout << om->count() << " operations monitored in "
                      << monitor_time << " seconds = "
                      << om->count() / monitor_time
                      << " operations per second"
                      << std::endl << std::flush;

            endTask();
        }
    } else if (cmd == "connect") {
        std::vector<std::string> args;
        tokenize(arg, args);

        if (args.size() != 2) {
            std::cout << "usage: connect <hostname> <port>"
                      << std::endl << std::flush;

            reply_expected = false;
        } else {
            Anonymous cmap;
            cmap->setAttr("hostname", args[0]);
            cmap->setAttr("port", strtol(args[1].c_str(), 0, 10));

            Connect m;
            m->setArgs1(cmap);
            // No serialno yet
            // FIXME add serialno once Juncture context can handle this

            command_context->setFromContext(m);

            send(m);
        }
    } else if (cmd == "add_agent") {
        std::string agent_type("creator");

        if (!arg.empty()) {
            agent_type = arg;
        }
        
        Create c;

        Anonymous cmap;
        cmap->setParents(std::list<std::string>(1, agent_type));
        cmap->setName("cycmd agent");
        cmap->setObjtype("obj");
        c->setArgs1(cmap);
        c->setSerialno(newSerialNo());

        command_context->setFromContext(c);

        send(c);
    } else if (cmd == "delete") {
        if (arg.empty()) {
            std::cout << "Please specify the entity to delete" << std::endl << std::flush;
            reply_expected = false;
        } else {
            Delete del;

            Anonymous del_arg;
            del_arg->setId(arg);
            del->setArgs1(del_arg);

            command_context->setFromContext(del);

            send(del);

            reply_expected = false;
        }
    } else if (cmd == "find_by_name") {
        if (arg.empty()) {
            std::cout << "Please specify the name to search for" << std::endl << std::flush;
            reply_expected = false;
        } else {
            Look l;

            Anonymous lmap;
            lmap->setName(arg);
            l->setArgs1(lmap);
            l->setSerialno(newSerialNo());

            command_context->setFromContext(l);

            send(l);

            reply_expected = false;
        }
    } else if (cmd == "find_by_type") {
        if (arg.empty()) {
            std::cout << "Please specify the type to search for" << std::endl << std::flush;
            reply_expected = false;
        } else {
            Look l;

            Anonymous lmap;
            lmap->setParents(std::list<std::string>(1, arg));
            l->setArgs1(lmap);
            l->setSerialno(newSerialNo());

            command_context->setFromContext(l);

            send(l);

            reply_expected = false;
        }
    } else if (cmd == "flush") {
        if (arg.empty()) {
            // FIXME usage
            std::cout << "Please specify the type to flush" << std::endl << std::flush;
            reply_expected = false;
        } else {
            ClientTask * task = new Flusher(command_context);
            runTask(task, arg);
            reply_expected = false;
        }
    } else if (cmd == "cancel") {
        if (endTask() != 0) {
            std::cout << "No task currently running" << std::endl << std::flush;
        }
    } else if (cmd == "dump") {
        if (command_context->repr() != "avatar") {
            std::cout << "You must have an agent in the world in order to dump the world." << std::endl << std::flush;
        } else {
            //Extract the avatar id by "misusing" the setFromContext method
            Operation op;
            command_context->setFromContext(op);
            ClientTask * task = new EntityExporter(m_accountId, op->getFrom());
            runTask(task, "world.xml");
            reply_expected = false;
        }
    } else if (cmd == "restore") {
        if (command_context->repr() != "avatar") {
            std::cout << "You must have an agent in the world in order to dump the world." << std::endl << std::flush;
        } else {
            //Extract the avatar id by "misusing" the setFromContext method
            Operation op;
            command_context->setFromContext(op);
            ClientTask * task = new EntityImporter(m_accountId, op->getFrom());
            runTask(task, "world.xml");
            reply_expected = false;
        }
    } else if (cmd == "create") {
        std::vector<std::string> args;
        tokenize(arg, args);

        if (args.size() < 1) {
            std::cout << "usage: create <type> <params> ... "
                      << std::endl << std::flush;
        } else {
            Anonymous cmap;
            cmap->setParents(std::list<std::string>(1, args[0]));
            cmap->setObjtype("obj");

            Create c;
            c->setArgs1(cmap);
            c->setSerialno(newSerialNo());
            command_context->setFromContext(c);

            send(c);
        }
        reply_expected = false;
    } else if (cmd == "login") {
        std::vector<std::string> args;
        tokenize(arg, args);

        if (args.size() != 2) {
            std::cout << "usage: login <username> <password>"
                      << std::endl << std::flush;
            reply_expected = false;
        } else {
            Anonymous cmap;
            cmap->setAttr("username", args[0]);
            cmap->setAttr("password", args[1]);

            Login m;
            m->setArgs1(cmap);
            m->setSerialno(newSerialNo());

            command_context->setFromContext(m);

            send(m);
        }
    } else {
        reply_expected = false;
        std::cout << cmd << ": Command not known" << std::endl << std::flush;
    }

    if (!reply_expected) {
        updatePrompt();
        return;
    }
    // Wait for reply
    time_t wait_start_time = time(NULL);
    while (!reply_flag) {
       if (time(NULL) - wait_start_time > 5) {
           std::cout << cmd << ": No reply from server" << std::endl << std::flush;
           return;
       }
       if (select(false) != 0) {
           return;
       }
    }
}
Example #9
0
void Room::recvPlayerListing(PlayerListing * player)
{
	if(!player->online)
	{
#ifdef VIEWTESTDEBUG
		if(player->name == "REMOVEMENOTAPLAYER")
		{
			int i;
			delete player;
			player = 0;
			do
			{
				i = rand() % players;
			}
			while(!(player = playerListingIDRegistry->getIfEntry(i)));
			player->online = false;
		}
#endif  //VIEWTESTDEBUG
		removed_player[player] = player->playing;
#ifdef PLAYERLISTING_ISSUES
		qDebug("Removing player %s %p on attached game %d", player->name.toLatin1().constData(), player, player->playing);
#endif //PLAYERLISTING_ISSUES
		/* To prevent crashes due to GameListing link to PlayerListing
		 * FIXME */
		if(player->playing)
		{
			/* FIXME, something should clear this when games end */
			GameListing * g = getGameListing(player->playing);
			if(g)
			{
				if(g->black == player)
				{
					g->black = 0;
					g->_black_name = player->name;
					g->_black_rank = player->rank;
				}
				else if(g->white == player)
				{
					g->white = 0;
					g->_white_name = player->name;
					g->_white_rank = player->rank;
				}
			}
		}
		if(player->observing)
		{
			/* FIXME remove this check, room_list should be sufficient */
			/* FIXME, something should clear this when games end */
			BoardDispatch * b = connection->getIfBoardDispatch(player->observing);
			if(b)
			{
#ifdef PLAYERLISTING_ISSUES
				qDebug("Removing player %s on observing game %d", player->name.toLatin1().constData(), player->observing);
#endif //PLAYERLISTING_ISSUES
				b->recvObserver(player, false);
			}
			if(player->dialog_opened)
                connection->closeTalk(player);
		}
		std::vector<unsigned short>::iterator room_listit = player->room_list.begin();
		while(room_listit != player->room_list.end())
		{
			BoardDispatch * boarddispatch = connection->getIfBoardDispatch(*room_listit);
			if(boarddispatch)
				boarddispatch->recvObserver(player, false);
			else
				player->room_list.erase(room_listit);
			room_listit = player->room_list.begin();
		}
		if(player->friendWatchType != PlayerListing::none)
			connection->getAndSetFriendWatchType(*player);  //removes
	}
	PlayerListing * registered_player = 0;
	if(player->online)
		connection->getAndSetFriendWatchType(*player);
    if(connection->playerTrackingByID())
	{
		if(player->online)
            registered_player = playerListModel->getEntry(player->id, player);
		else
            playerListModel->deleteEntry(player->id);
	}
	else
	{
		if(player->online)
            registered_player = playerListModel->getEntry(player->name, player);
		else
            playerListModel->deleteEntry(player->name);
	}
	
	if(registered_player && player->online)
	{
		/* FIXME consider changing name of getEntry with the object?
		 * so that its more clear that it returns a new stored object
		 * based on the one passed. (i.e., looking it up if
		 * alread there)*/
		if(player->dialog_opened)
		{
            Talk * t = connection->getIfTalk(player);
			if(t)
				t->updatePlayerListing();
			else
				qDebug("dialog_opened flag set but no talk dialog");
		}
	}
	
	/* This is just for those listing bugs... its weird...remove it
	 * soon */
	if(registered_player && player->online)
	{
		std::map<PlayerListing *, unsigned short>::iterator it;
		it = removed_player.find(registered_player);
		if(it != removed_player.end())
			removed_player.erase(it);
	}
}
Example #10
0
int main()
{
    database_flag = false;

    (void)new Domain;

    WorldRouter world;
    Entity & e = world.m_gameWorld;

    ServerRouting server(world, "noruleset", "unittesting",
                         "1", 1, "2", 2);

    CommServer commServer(server);

    TestCommClient * tc = new TestCommClient(commServer);
    Connection * c = new Connection(*tc, server, "addr", "3", 3);
    TestAccount * ac = new TestAccount(c, "user", "password", "4", 4);
    Entity * chr;

    {
        chr = new Entity("5", 5);
        chr->m_location.m_loc = &e;
        chr->m_location.m_loc->makeContainer();
        assert(chr->m_location.m_loc->m_contains != 0);
        chr->m_location.m_loc->m_contains->insert(chr);

        ac->addCharacter(chr);

        chr->destroy();

    }

    {
        chr = new Character("6", 6);
        chr->m_location.m_loc = &e;
        chr->m_location.m_loc->makeContainer();
        assert(chr->m_location.m_loc->m_contains != 0);
        chr->m_location.m_loc->m_contains->insert(chr);

        ac->addCharacter(chr);

        chr->destroy();

    }

    {
        chr = new Character("7", 7);
        chr->m_location.m_loc = &e;
        chr->m_location.m_loc->makeContainer();
        assert(chr->m_location.m_loc->m_contains != 0);
        chr->m_location.m_loc->m_contains->insert(chr);

        ac->addCharacter(chr);
    }

    {
        Anonymous new_char;
        Entity * chr = ac->testAddNewCharacter("thing", new_char,
                                               RootEntity());
        assert(chr != 0);
    }

    ac->getType();

    {
        MapType emap;
        ac->addToMessage(emap);
    }

    {
        RootEntity ent;
        ac->addToEntity(ent);
    }

    {
        Create op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>());
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>(1, "game_entity"));
        ac->operation(op, res);
        op_arg->setName("Bob");
        ac->operation(op, res);
    }

    {
        Get op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>());
        ac->operation(op, res);
    }

    {
        Imaginary op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        op->setSerialno(1);
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setLoc("2");
        ac->operation(op, res);
    }

    {
        Look op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setId("1");
        ac->operation(op, res);
        op_arg->setId(chr->getId());
        ac->operation(op, res);
    }

    {
        Set op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setId("1");
        ac->operation(op, res);
        op_arg->setId(chr->getId());
        ac->operation(op, res);
        op_arg->setAttr("guise", "foo");
        ac->operation(op, res);
        op_arg->setAttr("height", 3.0);
        ac->operation(op, res);
        BBox newBox(WFMath::Point<3>(-0.5, -0.5, 0.0),
                    WFMath::Point<3>(-0.5, -0.5, 2.0));
        chr->m_location.setBBox(newBox);
        op_arg->setAttr("height", 3.0);
        ac->operation(op, res);
        op_arg->setAttr("tasks", ListType());
        ac->operation(op, res);
    }

    {
        Talk op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>());
        ac->operation(op, res);
        op->setSerialno(1);
        ac->operation(op, res);
        op_arg->setLoc("1");
        ac->operation(op, res);
    }

    {
        Logout op;
        OpVector res;
        ac->operation(op, res);
        op->setSerialno(1);
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>());
        ac->operation(op, res);
    }

    {
        // Move has no meaning
        Move op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>());
        ac->operation(op, res);
    }

    {
        Entity e("7", 7);

        int ret = ac->connectCharacter(&e);
        assert(ret == -1);
    }

    {
        Character e("8", 8);

        int ret = ac->connectCharacter(&e);
        assert(ret == 0);
    }

    delete ac;

    return 0;
}