1 /* Copyright (C) 2015 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
17 #include "precompiled.h"
18 #include "StanzaExtensions.h"
20 /******************************************************
21 * GameReport, fairly generic custom stanza extension used
22 * to report game statistics.
24 GameReport::GameReport(const glooxwrapper::Tag
* tag
)
25 : StanzaExtension(EXTGAMEREPORT
)
27 if (!tag
|| tag
->name() != "report" || tag
->xmlns() != XMLNS_GAMEREPORT
)
29 // TODO if we want to handle receiving this stanza extension.
33 * Required by gloox, used to serialize the GameReport into XML for sending.
35 glooxwrapper::Tag
* GameReport::tag() const
37 glooxwrapper::Tag
* t
= glooxwrapper::Tag::allocate("report");
38 t
->setXmlns(XMLNS_GAMEREPORT
);
40 for (const glooxwrapper::Tag
* const& tag
: m_GameReport
)
41 t
->addChild(tag
->clone());
47 * Required by gloox, used to find the GameReport element in a recived IQ.
49 const glooxwrapper::string
& GameReport::filterString() const
51 static const glooxwrapper::string filter
= "/iq/report[@xmlns='" XMLNS_GAMEREPORT
"']";
55 glooxwrapper::StanzaExtension
* GameReport::clone() const
57 GameReport
* q
= new GameReport();
61 /******************************************************
62 * BoardListQuery, a flexible custom IQ Stanza useful for anything with ratings, used to
63 * request and receive leaderboard and rating data from server.
65 * <board player="foobar">1200</board>
67 BoardListQuery::BoardListQuery(const glooxwrapper::Tag
* tag
)
68 : StanzaExtension(EXTBOARDLISTQUERY
)
70 if (!tag
|| tag
->name() != "query" || tag
->xmlns() != XMLNS_BOARDLIST
)
73 const glooxwrapper::Tag
* c
= tag
->findTag_clone("query/command");
75 m_Command
= c
->cdata();
76 glooxwrapper::Tag::free(c
);
77 for (const glooxwrapper::Tag
* const& t
: tag
->findTagList_clone("query/board"))
78 m_StanzaBoardList
.emplace_back(t
);
82 * Required by gloox, used to find the BoardList element in a received IQ.
84 const glooxwrapper::string
& BoardListQuery::filterString() const
86 static const glooxwrapper::string filter
= "/iq/query[@xmlns='" XMLNS_BOARDLIST
"']";
91 * Required by gloox, used to serialize the BoardList request into XML for sending.
93 glooxwrapper::Tag
* BoardListQuery::tag() const
95 glooxwrapper::Tag
* t
= glooxwrapper::Tag::allocate("query");
96 t
->setXmlns(XMLNS_BOARDLIST
);
98 // Check for ratinglist or boardlist command
99 if (!m_Command
.empty())
100 t
->addChild(glooxwrapper::Tag::allocate("command", m_Command
));
102 for (const glooxwrapper::Tag
* const& tag
: m_StanzaBoardList
)
103 t
->addChild(tag
->clone());
108 glooxwrapper::StanzaExtension
* BoardListQuery::clone() const
110 BoardListQuery
* q
= new BoardListQuery();
114 BoardListQuery::~BoardListQuery()
116 for (const glooxwrapper::Tag
* const& t
: m_StanzaBoardList
)
117 glooxwrapper::Tag::free(t
);
118 m_StanzaBoardList
.clear();
121 /******************************************************
122 * GameListQuery, custom IQ Stanza, used to receive
123 * the listing of games from the server, and register/
124 * unregister/changestate games on the server.
126 GameListQuery::GameListQuery( const glooxwrapper::Tag
* tag
)
127 : StanzaExtension(EXTGAMELISTQUERY
)
129 if (!tag
|| tag
->name() != "query" || tag
->xmlns() != XMLNS_GAMELIST
)
132 const glooxwrapper::Tag
* c
= tag
->findTag_clone( "query/game" );
134 m_Command
= c
->cdata();
135 glooxwrapper::Tag::free(c
);
137 for (const glooxwrapper::Tag
* const& t
: tag
->findTagList_clone("query/game"))
138 m_GameList
.emplace_back(t
);
142 * Required by gloox, used to find the GameList element in a received IQ.
144 const glooxwrapper::string
& GameListQuery::filterString() const
146 static const glooxwrapper::string filter
= "/iq/query[@xmlns='" XMLNS_GAMELIST
"']";
151 * Required by gloox, used to serialize the game object into XML for sending.
153 glooxwrapper::Tag
* GameListQuery::tag() const
155 glooxwrapper::Tag
* t
= glooxwrapper::Tag::allocate("query");
156 t
->setXmlns(XMLNS_GAMELIST
);
158 // Check for register / unregister command
159 if (!m_Command
.empty())
160 t
->addChild(glooxwrapper::Tag::allocate("command", m_Command
));
162 for (const glooxwrapper::Tag
* const& tag
: m_GameList
)
163 t
->addChild(tag
->clone());
168 glooxwrapper::StanzaExtension
* GameListQuery::clone() const
170 GameListQuery
* q
= new GameListQuery();
174 GameListQuery::~GameListQuery()
176 for (const glooxwrapper::Tag
* const & t
: m_GameList
)
177 glooxwrapper::Tag::free(t
);
181 /******************************************************
182 * ProfileQuery, a custom IQ Stanza useful for fetching
185 * <profile player="foobar" highestRating="1500" rank="1895" totalGamesPlayed="50"
186 * wins="25" losses="25" /><command>foobar</command>
188 ProfileQuery::ProfileQuery(const glooxwrapper::Tag
* tag
)
189 : StanzaExtension(EXTPROFILEQUERY
)
191 if (!tag
|| tag
->name() != "query" || tag
->xmlns() != XMLNS_PROFILE
)
194 const glooxwrapper::Tag
* c
= tag
->findTag_clone("query/command");
196 m_Command
= c
->cdata();
197 glooxwrapper::Tag::free(c
);
199 for (const glooxwrapper::Tag
* const& t
: tag
->findTagList_clone("query/profile"))
200 m_StanzaProfile
.emplace_back(t
);
204 * Required by gloox, used to find the Profile element in a received IQ.
206 const glooxwrapper::string
& ProfileQuery::filterString() const
208 static const glooxwrapper::string filter
= "/iq/query[@xmlns='" XMLNS_PROFILE
"']";
213 * Required by gloox, used to serialize the Profile request into XML for sending.
215 glooxwrapper::Tag
* ProfileQuery::tag() const
217 glooxwrapper::Tag
* t
= glooxwrapper::Tag::allocate("query");
218 t
->setXmlns(XMLNS_PROFILE
);
220 if (!m_Command
.empty())
221 t
->addChild(glooxwrapper::Tag::allocate("command", m_Command
));
223 for (const glooxwrapper::Tag
* const& tag
: m_StanzaProfile
)
224 t
->addChild(tag
->clone());
229 glooxwrapper::StanzaExtension
* ProfileQuery::clone() const
231 ProfileQuery
* q
= new ProfileQuery();
235 ProfileQuery::~ProfileQuery()
237 for (const glooxwrapper::Tag
* const& t
: m_StanzaProfile
)
238 glooxwrapper::Tag::free(t
);
239 m_StanzaProfile
.clear();