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)
|
LocalServer_DatabaseInterface::LocalServer_DatabaseInterface(LocalServer *_localServer)
|
||||||
: Server_DatabaseInterface(_localServer),
|
: Server_DatabaseInterface(_localServer), localServer(_localServer)
|
||||||
nextGameId(0),
|
|
||||||
nextReplayId(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,13 @@ class LocalServer_DatabaseInterface : public Server_DatabaseInterface {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
LocalServer *localServer;
|
LocalServer *localServer;
|
||||||
int nextGameId, nextReplayId;
|
|
||||||
protected:
|
protected:
|
||||||
ServerInfo_User getUserData(const QString &name, bool withId = false);
|
ServerInfo_User getUserData(const QString &name, bool withId = false);
|
||||||
public:
|
public:
|
||||||
LocalServer_DatabaseInterface(LocalServer *_localServer);
|
LocalServer_DatabaseInterface(LocalServer *_localServer);
|
||||||
AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft);
|
AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft);
|
||||||
int getNextGameId() { return ++nextGameId; }
|
int getNextGameId() { return localServer->getNextLocalGameId(); }
|
||||||
int getNextReplayId() { return ++nextReplayId; }
|
int getNextReplayId() { return -1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -819,17 +819,6 @@ AbstractClient *TabGame::getClientForPlayer(int playerId) const
|
||||||
return clients.first();
|
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)
|
void TabGame::sendGameCommand(PendingCommand *pend, int playerId)
|
||||||
{
|
{
|
||||||
AbstractClient *client = getClientForPlayer(playerId);
|
AbstractClient *client = getClientForPlayer(playerId);
|
||||||
|
|
|
@ -210,7 +210,6 @@ public:
|
||||||
bool getSpectatorsSeeEverything() const { return gameInfo.spectators_omniscient(); }
|
bool getSpectatorsSeeEverything() const { return gameInfo.spectators_omniscient(); }
|
||||||
Player *getActiveLocalPlayer() const;
|
Player *getActiveLocalPlayer() const;
|
||||||
AbstractClient *getClientForPlayer(int playerId) const;
|
AbstractClient *getClientForPlayer(int playerId) const;
|
||||||
int getPlayerIdByName(const QString &playerName) const;
|
|
||||||
|
|
||||||
void setActiveCard(CardItem *_card) { activeCard = _card; }
|
void setActiveCard(CardItem *_card) { activeCard = _card; }
|
||||||
CardItem *getActiveCard() const { return activeCard; }
|
CardItem *getActiveCard() const { return activeCard; }
|
||||||
|
|
|
@ -182,7 +182,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
||||||
client->sendCommand(client->prepareSessionCommand(cmd));
|
client->sendCommand(client->prepareSessionCommand(cmd));
|
||||||
} else if (actionClicked == aKick) {
|
} else if (actionClicked == aKick) {
|
||||||
Command_KickFromGame cmd;
|
Command_KickFromGame cmd;
|
||||||
cmd.set_player_id(game->getPlayerIdByName(userName));
|
cmd.set_player_id(playerId);
|
||||||
game->sendGameCommand(cmd);
|
game->sendGameCommand(cmd);
|
||||||
} else if (actionClicked == aBan) {
|
} else if (actionClicked == aBan) {
|
||||||
Command_GetUserInfo cmd;
|
Command_GetUserInfo cmd;
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
Server::Server(bool _threaded, QObject *parent)
|
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_Game>("ServerInfo_Game");
|
||||||
qRegisterMetaType<ServerInfo_Room>("ServerInfo_Room");
|
qRegisterMetaType<ServerInfo_Room>("ServerInfo_Room");
|
||||||
|
|
|
@ -61,6 +61,7 @@ public:
|
||||||
virtual bool getThreaded() const { return false; }
|
virtual bool getThreaded() const { return false; }
|
||||||
|
|
||||||
Server_DatabaseInterface *getDatabaseInterface() const;
|
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) { }
|
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);
|
void sendIsl_Response(const Response &item, int serverId = -1, qint64 sessionId = -1);
|
||||||
|
@ -81,6 +82,8 @@ private:
|
||||||
bool threaded;
|
bool threaded;
|
||||||
QMultiMap<QString, PlayerReference> persistentPlayers;
|
QMultiMap<QString, PlayerReference> persistentPlayers;
|
||||||
mutable QReadWriteLock persistentPlayersLock;
|
mutable QReadWriteLock persistentPlayersLock;
|
||||||
|
int nextLocalGameId;
|
||||||
|
QMutex nextLocalGameIdMutex;
|
||||||
protected slots:
|
protected slots:
|
||||||
void externalUserJoined(const ServerInfo_User &userInfo);
|
void externalUserJoined(const ServerInfo_User &userInfo);
|
||||||
void externalUserLeft(const QString &userName);
|
void externalUserLeft(const QString &userName);
|
||||||
|
|
|
@ -247,9 +247,11 @@ void Server_Player::getProperties(ServerInfo_PlayerProperties &result, bool with
|
||||||
if (withUserInfo)
|
if (withUserInfo)
|
||||||
result.mutable_user_info()->CopyFrom(*userInfo);
|
result.mutable_user_info()->CopyFrom(*userInfo);
|
||||||
result.set_spectator(spectator);
|
result.set_spectator(spectator);
|
||||||
|
if (!spectator) {
|
||||||
result.set_conceded(conceded);
|
result.set_conceded(conceded);
|
||||||
result.set_sideboard_locked(sideboardLocked);
|
result.set_sideboard_locked(sideboardLocked);
|
||||||
result.set_ready_start(readyStart);
|
result.set_ready_start(readyStart);
|
||||||
|
}
|
||||||
if (deck)
|
if (deck)
|
||||||
result.set_deck_hash(deck->getDeckHash().toStdString());
|
result.set_deck_hash(deck->getDeckHash().toStdString());
|
||||||
result.set_ping_seconds(pingTime);
|
result.set_ping_seconds(pingTime);
|
||||||
|
@ -773,12 +775,22 @@ Response::ResponseCode Server_Player::cmdShuffle(const Command_Shuffle & /*cmd*/
|
||||||
if (conceded)
|
if (conceded)
|
||||||
return Response::RespContextError;
|
return Response::RespContextError;
|
||||||
|
|
||||||
zones.value("deck")->shuffle();
|
Server_CardZone *deckZone = zones.value("deck");
|
||||||
|
deckZone->shuffle();
|
||||||
|
|
||||||
Event_Shuffle event;
|
Event_Shuffle event;
|
||||||
event.set_zone_name("deck");
|
event.set_zone_name("deck");
|
||||||
ges.enqueueGameEvent(event, playerId);
|
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;
|
return Response::RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_decklist_files` (
|
||||||
`content` text NOT NULL,
|
`content` text NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `FolderPlusUser` (`id_folder`,`user`)
|
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,
|
`name` varchar(30) NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `ParentPlusUser` (`id_parent`,`user`)
|
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` (
|
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,
|
`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_started` datetime default NULL,
|
||||||
`time_finished` datetime default NULL,
|
`time_finished` datetime default NULL,
|
||||||
PRIMARY KEY (`id`)
|
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` (
|
CREATE TABLE IF NOT EXISTS `cockatrice_games_players` (
|
||||||
`id_game` int(7) unsigned zerofill NOT NULL,
|
`id_game` int(7) unsigned zerofill NOT NULL,
|
||||||
`player` varchar(35) default NULL,
|
`player_name` varchar(255) NOT NULL,
|
||||||
KEY `id_game` (`id_game`)
|
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,
|
`subject` varchar(255) NOT NULL,
|
||||||
`content` text NOT NULL,
|
`content` text NOT NULL,
|
||||||
PRIMARY KEY (`id`)
|
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,
|
`token` char(32) NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `name` (`name`)
|
UNIQUE KEY `name` (`name`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=915 ;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
CREATE TABLE `cockatrice_uptime` (
|
CREATE TABLE `cockatrice_uptime` (
|
||||||
`id_server` tinyint(3) NOT NULL,
|
`id_server` tinyint(3) NOT NULL,
|
||||||
|
|
|
@ -22,9 +22,11 @@ Servatrice_DatabaseInterface::~Servatrice_DatabaseInterface()
|
||||||
|
|
||||||
void Servatrice_DatabaseInterface::initDatabase(const QSqlDatabase &_sqlDatabase)
|
void Servatrice_DatabaseInterface::initDatabase(const QSqlDatabase &_sqlDatabase)
|
||||||
{
|
{
|
||||||
|
if (_sqlDatabase.isValid()) {
|
||||||
sqlDatabase = QSqlDatabase::cloneDatabase(_sqlDatabase, "pool_" + QString::number(instanceId));
|
sqlDatabase = QSqlDatabase::cloneDatabase(_sqlDatabase, "pool_" + QString::number(instanceId));
|
||||||
openDatabase();
|
openDatabase();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Servatrice_DatabaseInterface::initDatabase(const QString &type, const QString &hostName, const QString &databaseName, const QString &userName, const QString &password)
|
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()
|
int Servatrice_DatabaseInterface::getNextGameId()
|
||||||
{
|
{
|
||||||
|
if (!sqlDatabase.isValid())
|
||||||
|
return server->getNextLocalGameId();
|
||||||
|
|
||||||
if (!checkSql())
|
if (!checkSql())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue