mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-04 12:33:55 -07:00
Merge branch 'master' into tooomm-qt5
This commit is contained in:
commit
ae9ce701f4
290 changed files with 10683 additions and 4451 deletions
|
|
@ -48,7 +48,7 @@
|
|||
#include <libcockatrice/protocol/pb/response.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_player.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||
#include <libcockatrice/utility/trice_limits.h>
|
||||
#include <libcockatrice/utility/string_limits.h>
|
||||
|
||||
Server_AbstractParticipant::Server_AbstractParticipant(Server_Game *_game,
|
||||
int _playerId,
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@
|
|||
#include <libcockatrice/protocol/pb/serverinfo_player.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||
#include <libcockatrice/rng/rng_abstract.h>
|
||||
#include <libcockatrice/utility/trice_limits.h>
|
||||
#include <libcockatrice/utility/dice_limits.h>
|
||||
#include <libcockatrice/utility/string_limits.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
#include <limits>
|
||||
#include <ranges>
|
||||
|
|
@ -81,17 +82,6 @@ int Server_AbstractPlayer::newCardId()
|
|||
return nextCardId++;
|
||||
}
|
||||
|
||||
int Server_AbstractPlayer::newArrowId() const
|
||||
{
|
||||
int id = 0;
|
||||
for (Server_Arrow *a : arrows) {
|
||||
if (a->getId() > id) {
|
||||
id = a->getId();
|
||||
}
|
||||
}
|
||||
return id + 1;
|
||||
}
|
||||
|
||||
void Server_AbstractPlayer::setupZones()
|
||||
{
|
||||
nextCardId = 0;
|
||||
|
|
@ -1144,7 +1134,7 @@ Server_AbstractPlayer::cmdCreateToken(const Command_CreateToken &cmd, ResponseCo
|
|||
|
||||
Event_CreateArrow createEvent;
|
||||
ServerInfo_Arrow *arrowInfo = createEvent.mutable_arrow_info();
|
||||
const int newId = player->newArrowId();
|
||||
const int newId = game->generateArrowId();
|
||||
arrow->setId(newId);
|
||||
arrowInfo->set_id(newId);
|
||||
arrowInfo->set_start_player_id(player->getPlayerId());
|
||||
|
|
@ -1267,7 +1257,8 @@ Server_AbstractPlayer::cmdCreateArrow(const Command_CreateArrow &cmd, ResponseCo
|
|||
|
||||
int currentPhase = game->getActivePhase();
|
||||
int deletionPhase = cmd.has_delete_in_phase() ? cmd.delete_in_phase() : currentPhase;
|
||||
auto arrow = new Server_Arrow(newArrowId(), startCard, targetItem, cmd.arrow_color(), currentPhase, deletionPhase);
|
||||
auto arrow = new Server_Arrow(game->generateArrowId(), startCard, targetItem, cmd.arrow_color(), currentPhase,
|
||||
deletionPhase);
|
||||
addArrow(arrow);
|
||||
|
||||
Event_CreateArrow event;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ public:
|
|||
}
|
||||
|
||||
int newCardId();
|
||||
int newArrowId() const;
|
||||
|
||||
void addZone(Server_CardZone *zone);
|
||||
void addArrow(Server_Arrow *arrow);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@
|
|||
#include <libcockatrice/protocol/pb/event_set_card_attr.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_set_card_counter.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_card.pb.h>
|
||||
#include <libcockatrice/utility/trice_limits.h>
|
||||
#include <libcockatrice/utility/clamped_arithmetic.h>
|
||||
#include <libcockatrice/utility/counter_limits.h>
|
||||
#include <limits>
|
||||
|
||||
Server_Card::Server_Card(const CardRef &cardRef, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone)
|
||||
|
|
@ -114,8 +115,8 @@ QString Server_Card::setAttribute(CardAttribute attribute, const QString &avalue
|
|||
|
||||
bool Server_Card::setCounter(int _id, int value, Event_SetCardCounter *event)
|
||||
{
|
||||
// Clamp to valid card counter range [0, MAX_COUNTERS_ON_CARD]
|
||||
value = qBound(0, value, MAX_COUNTERS_ON_CARD);
|
||||
// Clamp to valid card counter range [0, MAX_COUNTER_VALUE]
|
||||
value = qBound(0, value, MAX_COUNTER_VALUE);
|
||||
|
||||
const int oldValue = counters.value(_id, 0);
|
||||
if (value == oldValue) {
|
||||
|
|
@ -139,10 +140,8 @@ bool Server_Card::setCounter(int _id, int value, Event_SetCardCounter *event)
|
|||
bool Server_Card::incrementCounter(int counterId, int delta, Event_SetCardCounter *event)
|
||||
{
|
||||
const int oldValue = counters.value(counterId, 0);
|
||||
const auto result = static_cast<int64_t>(oldValue) + static_cast<int64_t>(delta);
|
||||
// Clamp to [0, MAX_COUNTERS_ON_CARD] for card counters
|
||||
const int newValue =
|
||||
static_cast<int>(qBound(static_cast<int64_t>(0), result, static_cast<int64_t>(MAX_COUNTERS_ON_CARD)));
|
||||
// Clamp to [0, MAX_COUNTER_VALUE] for card counters
|
||||
const int newValue = addClamped(oldValue, delta, 0, MAX_COUNTER_VALUE);
|
||||
|
||||
if (newValue == oldValue) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ public:
|
|||
/**
|
||||
* @brief Sets a card counter to an exact value with clamping.
|
||||
* @param _id The counter ID.
|
||||
* @param value The desired value (clamped to [0, MAX_COUNTERS_ON_CARD]; 0 removes the counter).
|
||||
* @param value The desired value (clamped to [0, MAX_COUNTER_VALUE]; 0 removes the counter).
|
||||
* @param event Optional event to populate with counter state.
|
||||
* @return true if the value changed, false otherwise.
|
||||
*/
|
||||
|
|
@ -168,7 +168,7 @@ public:
|
|||
* @param event Optional event to populate with counter state.
|
||||
* @return true if the value changed, false otherwise.
|
||||
* @note If counter does not exist, starts from 0. Counter is removed if result is 0.
|
||||
* @note Clamps result to [0, MAX_COUNTERS_ON_CARD].
|
||||
* @note Clamps result to [0, MAX_COUNTER_VALUE].
|
||||
*/
|
||||
[[nodiscard]] bool incrementCounter(int counterId, int delta, Event_SetCardCounter *event = nullptr);
|
||||
void setTapped(bool _tapped)
|
||||
|
|
|
|||
|
|
@ -1,24 +1,12 @@
|
|||
#include "server_counter.h"
|
||||
|
||||
#include <libcockatrice/protocol/pb/serverinfo_counter.pb.h>
|
||||
#include <limits>
|
||||
|
||||
Server_Counter::Server_Counter(int _id, const QString &_name, const color &_counterColor, int _radius, int _count)
|
||||
: id(_id), name(_name), counterColor(_counterColor), radius(_radius), count(_count)
|
||||
{
|
||||
}
|
||||
|
||||
//! \todo Extract overflow-safe arithmetic into shared helper.
|
||||
//! Duplicated in Server_Card::incrementCounter() - keep in sync if modified.
|
||||
bool Server_Counter::incrementCount(int delta)
|
||||
{
|
||||
const int oldCount = count;
|
||||
const auto result = static_cast<int64_t>(count) + static_cast<int64_t>(delta);
|
||||
count = static_cast<int>(qBound(static_cast<int64_t>(std::numeric_limits<int>::min()), result,
|
||||
static_cast<int64_t>(std::numeric_limits<int>::max())));
|
||||
return count != oldCount;
|
||||
}
|
||||
|
||||
void Server_Counter::getInfo(ServerInfo_Counter *info)
|
||||
{
|
||||
info->set_id(id);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include <QString>
|
||||
#include <libcockatrice/protocol/pb/color.pb.h>
|
||||
#include <libcockatrice/utility/clamped_arithmetic.h>
|
||||
#include <limits>
|
||||
|
||||
class ServerInfo_Counter;
|
||||
|
||||
|
|
@ -92,7 +94,12 @@ public:
|
|||
* @return true if the value changed, false otherwise.
|
||||
* @note Clamps result to [INT_MIN, INT_MAX] to prevent overflow.
|
||||
*/
|
||||
[[nodiscard]] bool incrementCount(int delta);
|
||||
[[nodiscard]] bool incrementCount(int delta)
|
||||
{
|
||||
const int oldCount = count;
|
||||
count = addClamped(count, delta, std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
|
||||
return count != oldCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Populates info with this counter's current state for network serialization.
|
||||
|
|
|
|||
|
|
@ -697,6 +697,11 @@ void Server_Game::setActivePhase(int newPhase)
|
|||
sendGameEventContainer(prepareGameEvent(event, -1));
|
||||
}
|
||||
|
||||
qint64 Server_Game::generateArrowId()
|
||||
{
|
||||
return nextArrowId++;
|
||||
}
|
||||
|
||||
void Server_Game::removeArrows(int newPhase, bool force)
|
||||
{
|
||||
QMutexLocker locker(&gameMutex);
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class Server_Game : public QObject
|
|||
private:
|
||||
Server_Room *room;
|
||||
int nextPlayerId;
|
||||
std::atomic<qint64> nextArrowId = 1;
|
||||
int hostId;
|
||||
ServerInfo_User *creatorInfo;
|
||||
QMap<int, Server_AbstractParticipant *> participants;
|
||||
|
|
@ -196,6 +197,7 @@ public:
|
|||
}
|
||||
void setActivePlayer(int newPlayer);
|
||||
void setActivePhase(int newPhase);
|
||||
qint64 generateArrowId();
|
||||
void removeArrows(int newPhase, bool force = false);
|
||||
void nextTurn();
|
||||
int getSecondsElapsed() const
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||
#include <libcockatrice/rng/rng_abstract.h>
|
||||
#include <libcockatrice/utility/color.h>
|
||||
#include <libcockatrice/utility/trice_limits.h>
|
||||
#include <libcockatrice/utility/string_limits.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
|
||||
Server_Player::Server_Player(Server_Game *_game,
|
||||
|
|
|
|||
|
|
@ -190,6 +190,25 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session,
|
|||
return authState;
|
||||
}
|
||||
|
||||
void Server::broadcastUserInfoUpdate(Server_ProtocolHandler *source)
|
||||
{
|
||||
Event_UserJoined event;
|
||||
event.mutable_user_info()->CopyFrom(source->copyUserInfo(false));
|
||||
|
||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
|
||||
clientsLock.lockForRead();
|
||||
for (auto &client : clients) {
|
||||
if (client->getAcceptsUserListChanges()) {
|
||||
client->sendProtocolItem(*se);
|
||||
}
|
||||
}
|
||||
clientsLock.unlock();
|
||||
|
||||
sendIsl_SessionEvent(*se);
|
||||
delete se;
|
||||
}
|
||||
|
||||
void Server::addPersistentPlayer(const QString &userName, int roomId, int gameId, int playerId)
|
||||
{
|
||||
QWriteLocker locker(&persistentPlayersLock);
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ public:
|
|||
QString &clientid,
|
||||
QString &clientVersion,
|
||||
QString &connectionType);
|
||||
void broadcastUserInfoUpdate(Server_ProtocolHandler *source);
|
||||
|
||||
const QMap<int, Server_Room *> &getRooms()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#include <libcockatrice/protocol/pb/response_list_users.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_login.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||
#include <libcockatrice/utility/trice_limits.h>
|
||||
#include <libcockatrice/utility/string_limits.h>
|
||||
|
||||
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server,
|
||||
Server_DatabaseInterface *_databaseInterface,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
#include <libcockatrice/protocol/pb/room_commands.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_chat_message.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_room.pb.h>
|
||||
#include <libcockatrice/utility/trice_limits.h>
|
||||
#include <libcockatrice/utility/string_limits.h>
|
||||
|
||||
Server_Room::Server_Room(int _id,
|
||||
int _chatHistorySize,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue