1 /*****************************************************************************
2  * PokerTH - The open source texas holdem engine                             *
3  * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May          *
4  *                                                                           *
5  * This program is free software: you can redistribute it and/or modify      *
6  * it under the terms of the GNU Affero General Public License as            *
7  * published by the Free Software Foundation, either version 3 of the        *
8  * License, or (at your option) any later version.                           *
9  *                                                                           *
10  * This program is distributed in the hope that it will be useful,           *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
13  * GNU Affero General Public License for more details.                       *
14  *                                                                           *
15  * You should have received a copy of the GNU Affero General Public License  *
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.     *
17  *                                                                           *
18  *                                                                           *
19  * Additional permission under GNU AGPL version 3 section 7                  *
20  *                                                                           *
21  * If you modify this program, or any covered work, by linking or            *
22  * combining it with the OpenSSL project's OpenSSL library (or a             *
23  * modified version of that library), containing parts covered by the        *
24  * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH           *
25  * (Felix Hammer, Florian Thauer, Lothar May) grant you additional           *
26  * permission to convey the resulting work.                                  *
27  * Corresponding Source for a non-source form of such a combination          *
28  * shall include the source code for the parts of OpenSSL used as well       *
29  * as that of the covered work.                                              *
30  *****************************************************************************/
31 
32 #include <dbofficial/asyncdbadminplayers.h>
33 #include <dbofficial/dbidmanager.h>
34 
35 
36 using namespace std;
37 
38 
AsyncDBAdminPlayers(unsigned queryId,const string & preparedName)39 AsyncDBAdminPlayers::AsyncDBAdminPlayers(unsigned queryId, const string &preparedName)
40 	: SingleAsyncDBQuery(queryId, preparedName, list<string>())
41 {
42 }
43 
~AsyncDBAdminPlayers()44 AsyncDBAdminPlayers::~AsyncDBAdminPlayers()
45 {
46 }
47 
48 void
Init(DBIdManager &)49 AsyncDBAdminPlayers::Init(DBIdManager& /*idManager*/)
50 {
51 }
52 
53 void
HandleResult(mysqlpp::Query &,DBIdManager &,mysqlpp::StoreQueryResult & result,boost::asio::io_service & service,ServerDBCallback & cb)54 AsyncDBAdminPlayers::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb)
55 {
56 	list<DB_id> adminPlayers;
57 	for (size_t i = 0; i < result.num_rows(); ++i) {
58 		if (!result[i].empty()) {
59 			adminPlayers.push_back(result[i][0]);
60 		}
61 	}
62 	service.post(boost::bind(&ServerDBCallback::PlayerAdminList, &cb, GetId(), adminPlayers));
63 }
64 
65 void
HandleNoResult(mysqlpp::Query &,DBIdManager &,boost::asio::io_service & service,ServerDBCallback & cb)66 AsyncDBAdminPlayers::HandleNoResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, boost::asio::io_service &service, ServerDBCallback &cb)
67 {
68 	// This query should always produce a result.
69 	HandleError(service, cb);
70 }
71 
72 void
HandleError(boost::asio::io_service & service,ServerDBCallback & cb)73 AsyncDBAdminPlayers::HandleError(boost::asio::io_service &service, ServerDBCallback &cb)
74 {
75 	service.post(boost::bind(&ServerDBCallback::QueryError, &cb, "AsyncDBAdminPlayers: Failure."));
76 }
77