From 2eb3df1cdeedfa49002d642c9f7c3fc3f66f74e1 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Fri, 29 Jun 2012 15:47:53 +0200 Subject: [PATCH 1/6] servatrice.sql fixes --- servatrice/servatrice.sql | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/servatrice/servatrice.sql b/servatrice/servatrice.sql index 29bcf9ae..757f6bdc 100644 --- a/servatrice/servatrice.sql +++ b/servatrice/servatrice.sql @@ -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, From c8852b450d1016c2b96d61a2358efe891e17ef3f Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 17 Jul 2012 18:15:10 +0200 Subject: [PATCH 2/6] don't open database in connection pools if main database connection is not valid --- servatrice/src/servatrice_database_interface.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index c0fc6b0b..e79ca79f 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -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) From a1e35ccda5cb0872a8ee34c418413000eccd4ecd Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 17 Jul 2012 18:47:00 +0200 Subject: [PATCH 3/6] servatrice: create correct game ids when not using a database --- cockatrice/src/localserver.cpp | 4 +--- cockatrice/src/localserver.h | 7 +++---- common/server.cpp | 2 +- common/server.h | 3 +++ servatrice/src/servatrice_database_interface.cpp | 3 +++ 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cockatrice/src/localserver.cpp b/cockatrice/src/localserver.cpp index 26c5427c..833b4446 100644 --- a/cockatrice/src/localserver.cpp +++ b/cockatrice/src/localserver.cpp @@ -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) { } diff --git a/cockatrice/src/localserver.h b/cockatrice/src/localserver.h index ac6a8475..c77e6e7c 100644 --- a/cockatrice/src/localserver.h +++ b/cockatrice/src/localserver.h @@ -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 \ No newline at end of file +#endif diff --git a/common/server.cpp b/common/server.cpp index e273bd40..32f3c878 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -36,7 +36,7 @@ #include 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"); qRegisterMetaType("ServerInfo_Room"); diff --git a/common/server.h b/common/server.h index 1d87dc9e..aeb11bad 100644 --- a/common/server.h +++ b/common/server.h @@ -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 &allPlayersEver, const QSet &allSpectatorsEver, const QList &replays) { } void sendIsl_Response(const Response &item, int serverId = -1, qint64 sessionId = -1); @@ -81,6 +82,8 @@ private: bool threaded; QMultiMap persistentPlayers; mutable QReadWriteLock persistentPlayersLock; + int nextLocalGameId; + QMutex nextLocalGameIdMutex; protected slots: void externalUserJoined(const ServerInfo_User &userInfo); void externalUserLeft(const QString &userName); diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index e79ca79f..15e7084f 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -389,6 +389,9 @@ QMap Servatrice_DatabaseInterface::getIgnoreList(const int Servatrice_DatabaseInterface::getNextGameId() { + if (!sqlDatabase.isValid()) + return server->getNextLocalGameId(); + if (!checkSql()) return -1; From 28b18575f2e0929b0a1a7319ae4830332b15391e Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 17 Jul 2012 19:06:12 +0200 Subject: [PATCH 4/6] fixed issue #66: game creators can't kick spectators; unfortunately, this fix is client-side --- cockatrice/src/tab_game.cpp | 11 ----------- cockatrice/src/tab_game.h | 1 - cockatrice/src/user_context_menu.cpp | 2 +- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 632d4ecd..f920b98e 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -819,17 +819,6 @@ AbstractClient *TabGame::getClientForPlayer(int playerId) const return clients.first(); } -int TabGame::getPlayerIdByName(const QString &playerName) const -{ - QMapIterator 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); diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index db82d06d..f511ef69 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -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; } diff --git a/cockatrice/src/user_context_menu.cpp b/cockatrice/src/user_context_menu.cpp index 8898e21f..657dc40b 100644 --- a/cockatrice/src/user_context_menu.cpp +++ b/cockatrice/src/user_context_menu.cpp @@ -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; From 886f12d116676ba2824f6b41318dce436141d5a2 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 17 Jul 2012 19:17:26 +0200 Subject: [PATCH 5/6] fixed #63: spectators have sideboard lock icons --- common/server_player.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common/server_player.cpp b/common/server_player.cpp index b29da05a..48abb14c 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -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); From 4c9165f0997a6ae7c97c2ba5d1574adf4229484f Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 17 Jul 2012 19:22:09 +0200 Subject: [PATCH 6/6] fixed #62: shuffling doesn't reveal the top card even if AlwaysRevealTopCard is set --- common/server_player.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/common/server_player.cpp b/common/server_player.cpp index 48abb14c..bfa53805 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -774,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; }