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/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; 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/common/server_player.cpp b/common/server_player.cpp index b29da05a..bfa53805 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); @@ -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; } diff --git a/servatrice/servatrice.sql b/servatrice/servatrice.sql index d985325b..7646158d 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, diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index c0fc6b0b..15e7084f 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) @@ -387,6 +389,9 @@ QMap Servatrice_DatabaseInterface::getIgnoreList(const int Servatrice_DatabaseInterface::getNextGameId() { + if (!sqlDatabase.isValid()) + return server->getNextLocalGameId(); + if (!checkSql()) return -1;