Merge branch 'master' of git://github.com/mbruker/Cockatrice
This commit is contained in:
commit
1409c50fbe
10 changed files with 46 additions and 37 deletions
|
@ -22,9 +22,7 @@ LocalServerInterface *LocalServer::newConnection()
|
|||
}
|
||||
|
||||
LocalServer_DatabaseInterface::LocalServer_DatabaseInterface(LocalServer *_localServer)
|
||||
: Server_DatabaseInterface(_localServer),
|
||||
nextGameId(0),
|
||||
nextReplayId(0)
|
||||
: Server_DatabaseInterface(_localServer), localServer(_localServer)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -20,14 +20,13 @@ class LocalServer_DatabaseInterface : public Server_DatabaseInterface {
|
|||
Q_OBJECT
|
||||
private:
|
||||
LocalServer *localServer;
|
||||
int nextGameId, nextReplayId;
|
||||
protected:
|
||||
ServerInfo_User getUserData(const QString &name, bool withId = false);
|
||||
public:
|
||||
LocalServer_DatabaseInterface(LocalServer *_localServer);
|
||||
AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft);
|
||||
int getNextGameId() { return ++nextGameId; }
|
||||
int getNextReplayId() { return ++nextReplayId; }
|
||||
int getNextGameId() { return localServer->getNextLocalGameId(); }
|
||||
int getNextReplayId() { return -1; }
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -819,17 +819,6 @@ AbstractClient *TabGame::getClientForPlayer(int playerId) const
|
|||
return clients.first();
|
||||
}
|
||||
|
||||
int TabGame::getPlayerIdByName(const QString &playerName) const
|
||||
{
|
||||
QMapIterator<int, Player *> playerIterator(players);
|
||||
while (playerIterator.hasNext()) {
|
||||
const Player *const p = playerIterator.next().value();
|
||||
if (p->getName() == playerName)
|
||||
return p->getId();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void TabGame::sendGameCommand(PendingCommand *pend, int playerId)
|
||||
{
|
||||
AbstractClient *client = getClientForPlayer(playerId);
|
||||
|
|
|
@ -210,7 +210,6 @@ public:
|
|||
bool getSpectatorsSeeEverything() const { return gameInfo.spectators_omniscient(); }
|
||||
Player *getActiveLocalPlayer() const;
|
||||
AbstractClient *getClientForPlayer(int playerId) const;
|
||||
int getPlayerIdByName(const QString &playerName) const;
|
||||
|
||||
void setActiveCard(CardItem *_card) { activeCard = _card; }
|
||||
CardItem *getActiveCard() const { return activeCard; }
|
||||
|
|
|
@ -182,7 +182,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
|||
client->sendCommand(client->prepareSessionCommand(cmd));
|
||||
} else if (actionClicked == aKick) {
|
||||
Command_KickFromGame cmd;
|
||||
cmd.set_player_id(game->getPlayerIdByName(userName));
|
||||
cmd.set_player_id(playerId);
|
||||
game->sendGameCommand(cmd);
|
||||
} else if (actionClicked == aBan) {
|
||||
Command_GetUserInfo cmd;
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include <QDebug>
|
||||
|
||||
Server::Server(bool _threaded, QObject *parent)
|
||||
: QObject(parent), threaded(_threaded), clientsLock(QReadWriteLock::Recursive)
|
||||
: QObject(parent), threaded(_threaded), clientsLock(QReadWriteLock::Recursive), nextLocalGameId(0)
|
||||
{
|
||||
qRegisterMetaType<ServerInfo_Game>("ServerInfo_Game");
|
||||
qRegisterMetaType<ServerInfo_Room>("ServerInfo_Room");
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
virtual bool getThreaded() const { return false; }
|
||||
|
||||
Server_DatabaseInterface *getDatabaseInterface() const;
|
||||
int getNextLocalGameId() { QMutexLocker locker(&nextLocalGameIdMutex); return ++nextLocalGameId; }
|
||||
virtual void storeGameInformation(int secondsElapsed, const QSet<QString> &allPlayersEver, const QSet<QString> &allSpectatorsEver, const QList<GameReplay *> &replays) { }
|
||||
|
||||
void sendIsl_Response(const Response &item, int serverId = -1, qint64 sessionId = -1);
|
||||
|
@ -81,6 +82,8 @@ private:
|
|||
bool threaded;
|
||||
QMultiMap<QString, PlayerReference> persistentPlayers;
|
||||
mutable QReadWriteLock persistentPlayersLock;
|
||||
int nextLocalGameId;
|
||||
QMutex nextLocalGameIdMutex;
|
||||
protected slots:
|
||||
void externalUserJoined(const ServerInfo_User &userInfo);
|
||||
void externalUserLeft(const QString &userName);
|
||||
|
|
|
@ -247,9 +247,11 @@ void Server_Player::getProperties(ServerInfo_PlayerProperties &result, bool with
|
|||
if (withUserInfo)
|
||||
result.mutable_user_info()->CopyFrom(*userInfo);
|
||||
result.set_spectator(spectator);
|
||||
result.set_conceded(conceded);
|
||||
result.set_sideboard_locked(sideboardLocked);
|
||||
result.set_ready_start(readyStart);
|
||||
if (!spectator) {
|
||||
result.set_conceded(conceded);
|
||||
result.set_sideboard_locked(sideboardLocked);
|
||||
result.set_ready_start(readyStart);
|
||||
}
|
||||
if (deck)
|
||||
result.set_deck_hash(deck->getDeckHash().toStdString());
|
||||
result.set_ping_seconds(pingTime);
|
||||
|
@ -772,13 +774,23 @@ Response::ResponseCode Server_Player::cmdShuffle(const Command_Shuffle & /*cmd*/
|
|||
return Response::RespGameNotStarted;
|
||||
if (conceded)
|
||||
return Response::RespContextError;
|
||||
|
||||
zones.value("deck")->shuffle();
|
||||
|
||||
Server_CardZone *deckZone = zones.value("deck");
|
||||
deckZone->shuffle();
|
||||
|
||||
Event_Shuffle event;
|
||||
event.set_zone_name("deck");
|
||||
ges.enqueueGameEvent(event, playerId);
|
||||
|
||||
if (deckZone->getAlwaysRevealTopCard() && !deckZone->cards.isEmpty()) {
|
||||
Event_RevealCards revealEvent;
|
||||
revealEvent.set_zone_name(deckZone->getName().toStdString());
|
||||
revealEvent.set_card_id(0);
|
||||
deckZone->cards.first()->getInfo(revealEvent.add_cards());
|
||||
|
||||
ges.enqueueGameEvent(revealEvent, playerId);
|
||||
}
|
||||
|
||||
return Response::RespOk;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_decklist_files` (
|
|||
`content` text NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FolderPlusUser` (`id_folder`,`user`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=550 ;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -49,7 +49,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_decklist_folders` (
|
|||
`name` varchar(30) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `ParentPlusUser` (`id_parent`,`user`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=80 ;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -58,13 +58,17 @@ CREATE TABLE IF NOT EXISTS `cockatrice_decklist_folders` (
|
|||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `cockatrice_games` (
|
||||
`id` int(7) unsigned zerofill NOT NULL,
|
||||
`room_name` varchar(255) NOT NULL,
|
||||
`id` int(7) unsigned NOT NULL auto_increment,
|
||||
`descr` varchar(50) default NULL,
|
||||
`password` tinyint(1) default NULL,
|
||||
`creator_name` varchar(255) NOT NULL,
|
||||
`password` tinyint(1) NOT NULL,
|
||||
`game_types` varchar(255) NOT NULL,
|
||||
`player_count` tinyint(3) NOT NULL,
|
||||
`time_started` datetime default NULL,
|
||||
`time_finished` datetime default NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -74,9 +78,9 @@ CREATE TABLE IF NOT EXISTS `cockatrice_games` (
|
|||
|
||||
CREATE TABLE IF NOT EXISTS `cockatrice_games_players` (
|
||||
`id_game` int(7) unsigned zerofill NOT NULL,
|
||||
`player` varchar(35) default NULL,
|
||||
`player_name` varchar(255) NOT NULL,
|
||||
KEY `id_game` (`id_game`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -91,7 +95,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_news` (
|
|||
`subject` varchar(255) NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -114,7 +118,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_users` (
|
|||
`token` char(32) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name` (`name`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=915 ;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `cockatrice_uptime` (
|
||||
`id_server` tinyint(3) NOT NULL,
|
||||
|
|
|
@ -22,8 +22,10 @@ Servatrice_DatabaseInterface::~Servatrice_DatabaseInterface()
|
|||
|
||||
void Servatrice_DatabaseInterface::initDatabase(const QSqlDatabase &_sqlDatabase)
|
||||
{
|
||||
sqlDatabase = QSqlDatabase::cloneDatabase(_sqlDatabase, "pool_" + QString::number(instanceId));
|
||||
openDatabase();
|
||||
if (_sqlDatabase.isValid()) {
|
||||
sqlDatabase = QSqlDatabase::cloneDatabase(_sqlDatabase, "pool_" + QString::number(instanceId));
|
||||
openDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
void Servatrice_DatabaseInterface::initDatabase(const QString &type, const QString &hostName, const QString &databaseName, const QString &userName, const QString &password)
|
||||
|
@ -387,6 +389,9 @@ QMap<QString, ServerInfo_User> Servatrice_DatabaseInterface::getIgnoreList(const
|
|||
|
||||
int Servatrice_DatabaseInterface::getNextGameId()
|
||||
{
|
||||
if (!sqlDatabase.isValid())
|
||||
return server->getNextLocalGameId();
|
||||
|
||||
if (!checkSql())
|
||||
return -1;
|
||||
|
||||
|
|
Loading…
Reference in a new issue