/** * Send a request to register a game to the server. * * @param data A JS array of game attributes */ void XmppClient::SendIqRegisterGame(ScriptInterface& scriptInterface, CScriptVal data) { glooxwrapper::JID xpartamuppJid(m_xpartamuppId); jsval dataval = data.get(); // Setup some base stanza attributes GameListQuery* g = new GameListQuery(); g->m_Command = "register"; glooxwrapper::Tag* game = glooxwrapper::Tag::allocate("game"); // Add a fake ip which will be overwritten by the ip stamp XMPP module on the server. game->addAttribute("ip", "fake"); // Iterate through all the properties reported and add them to the stanza. std::vector<std::string> properties; scriptInterface.EnumeratePropertyNamesWithPrefix(dataval, "", properties); for (std::vector<int>::size_type i = 0; i != properties.size(); i++) { std::wstring value; scriptInterface.GetProperty(dataval, properties[i].c_str(), value); game->addAttribute(properties[i], utf8_from_wstring(value)); } // Push the stanza onto the IQ g->m_GameList.push_back(game); // Send IQ glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid); iq.addExtension(g); DbgXMPP("SendIqRegisterGame [" << tag_xml(iq) << "]"); m_client->send(iq); }
/** * Send game report containing numerous game properties to the server. * * @param data A JS array of game statistics */ void XmppClient::SendIqGameReport(ScriptInterface& scriptInterface, CScriptVal data) { glooxwrapper::JID xpartamuppJid(m_xpartamuppId); jsval dataval = data.get(); // Setup some base stanza attributes GameReport* game = new GameReport(); glooxwrapper::Tag* report = glooxwrapper::Tag::allocate("game"); // Iterate through all the properties reported and add them to the stanza. std::vector<std::string> properties; scriptInterface.EnumeratePropertyNamesWithPrefix(dataval, "", properties); for (std::vector<int>::size_type i = 0; i != properties.size(); i++) { std::wstring value; scriptInterface.GetProperty(dataval, properties[i].c_str(), value); report->addAttribute(properties[i], utf8_from_wstring(value)); } // Add stanza to IQ game->m_GameReport.push_back(report); // Send IQ glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid); iq.addExtension(game); DbgXMPP("SendGameReport [" << tag_xml(iq) << "]"); m_client->send(iq); };
/** * Request the leaderboard data from the server. */ void XmppClient::SendIqGetBoardList() { glooxwrapper::JID xpartamuppJid(m_xpartamuppId); // Send IQ glooxwrapper::IQ iq(gloox::IQ::Get, xpartamuppJid); iq.addExtension(new BoardListQuery()); DbgXMPP("SendIqGetBoardList [" << tag_xml(iq) << "]"); m_client->send(iq); }
/** * Request the rating data from the server. */ void XmppClient::SendIqGetRatingList() { glooxwrapper::JID xpartamuppJid(m_xpartamuppId); // Send IQ BoardListQuery* b = new BoardListQuery(); b->m_Command = "getratinglist"; glooxwrapper::IQ iq(gloox::IQ::Get, xpartamuppJid); iq.addExtension(b); DbgXMPP("SendIqGetRatingList [" << tag_xml(iq) << "]"); m_client->send(iq); }
/** * Send a request to unregister a game to the server. */ void XmppClient::SendIqUnregisterGame() { glooxwrapper::JID xpartamuppJid(m_xpartamuppId); // Send IQ GameListQuery* g = new GameListQuery(); g->m_Command = "unregister"; g->m_GameList.push_back(glooxwrapper::Tag::allocate( "game" )); glooxwrapper::IQ iq( gloox::IQ::Set, xpartamuppJid ); iq.addExtension( g ); DbgXMPP("SendIqUnregisterGame [" << tag_xml(iq) << "]"); m_client->send( iq ); }
/** * Send a request to change the state of a registered game on the server. * * A game can either be in the 'running' or 'waiting' state - the server * decides which - but we need to update the current players that are * in-game so the server can make the calculation. */ void XmppClient::SendIqChangeStateGame(const std::string& nbp, const std::string& players) { glooxwrapper::JID xpartamuppJid(m_xpartamuppId); // Send IQ GameListQuery* g = new GameListQuery(); g->m_Command = "changestate"; glooxwrapper::Tag* game = glooxwrapper::Tag::allocate("game"); game->addAttribute("nbp", nbp); game->addAttribute("players", players); g->m_GameList.push_back(game); glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid); iq.addExtension( g ); DbgXMPP("SendIqChangeStateGame [" << tag_xml(iq) << "]"); m_client->send(iq); }