From 6992c732af767431c25fd79616b104ab0f98602c Mon Sep 17 00:00:00 2001 From: lotodore Date: Sun, 27 Oct 2013 00:41:13 +0200 Subject: [PATCH] Preparing "allow spectators" flag in network protocol (#215). --- pokerth.proto | 1 + src/gamedata.h | 13 +-- .../gamelobbydialog/gamelobbydialogimpl.cpp | 2 +- src/net/common/netpacket.cpp | 2 + src/net/common/servergame.cpp | 3 +- src/third_party/protobuf/pokerth.pb.cc | 33 ++++++++ src/third_party/protobuf/pokerth.pb.h | 34 +++++++- tests/src/de/pokerth/protocol/ProtoBuf.java | 81 +++++++++++++++++++ 8 files changed, 160 insertions(+), 9 deletions(-) diff --git a/pokerth.proto b/pokerth.proto index 169ca5da..04e4f2a1 100644 --- a/pokerth.proto +++ b/pokerth.proto @@ -110,6 +110,7 @@ message NetGameInfo { required uint32 firstSmallBlind = 12; required uint32 startMoney = 13; repeated uint32 manualBlinds = 14 [packed = true]; + optional bool allowSpectators = 15 [default = true]; } // Message Part containing player result. diff --git a/src/gamedata.h b/src/gamedata.h index cb5a463a..9f7586ed 100644 --- a/src/gamedata.h +++ b/src/gamedata.h @@ -72,13 +72,14 @@ enum AfterManualBlindsMode { // For the sake of simplicity, this is a struct. struct GameData { - GameData() : gameType(GAME_TYPE_NORMAL), maxNumberOfPlayers(0), startMoney(0), - firstSmallBlind(0), raiseIntervalMode(RAISE_ON_HANDNUMBER), - raiseSmallBlindEveryHandsValue(8), raiseSmallBlindEveryMinutesValue(1), - raiseMode(DOUBLE_BLINDS), afterManualBlindsMode(AFTERMB_DOUBLE_BLINDS), - afterMBAlwaysRaiseValue(0), guiSpeed(4), delayBetweenHandsSec(6), - playerActionTimeoutSec(20) {} + GameData() : gameType(GAME_TYPE_NORMAL), allowSpectators(true), + maxNumberOfPlayers(0), startMoney(0), firstSmallBlind(0), + raiseIntervalMode(RAISE_ON_HANDNUMBER), raiseSmallBlindEveryHandsValue(8), + raiseSmallBlindEveryMinutesValue(1), raiseMode(DOUBLE_BLINDS), + afterManualBlindsMode(AFTERMB_DOUBLE_BLINDS), afterMBAlwaysRaiseValue(0), + guiSpeed(4), delayBetweenHandsSec(6), playerActionTimeoutSec(20) {} GameType gameType; + bool allowSpectators; int maxNumberOfPlayers; int startMoney; int firstSmallBlind; diff --git a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp index 5e55f775..29b16437 100644 --- a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp +++ b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp @@ -352,6 +352,7 @@ void gameLobbyDialogImpl::createGame() gameData.delayBetweenHandsSec = myCreateInternetGameDialog->spinBox_netDelayBetweenHands->value(); gameData.playerActionTimeoutSec = myCreateInternetGameDialog->spinBox_netTimeOutPlayerAction->value(); gameData.gameType = GameType(myCreateInternetGameDialog->comboBox_gameType->itemData(myCreateInternetGameDialog->comboBox_gameType->currentIndex(), Qt::UserRole).toInt()); + gameData.allowSpectators = myCreateInternetGameDialog->checkBox_allowSpectators->isChecked(); currentGameName = myCreateInternetGameDialog->lineEdit_gameName->text().simplified(); @@ -384,7 +385,6 @@ void gameLobbyDialogImpl::createGame() label_StartCash->setText(QString("%L1").arg(gameData.startMoney)); updateDialogBlinds(gameData); label_GameTiming->setText(QString::number(gameData.playerActionTimeoutSec)+" "+tr("sec (action)")+"\n"+QString::number(gameData.delayBetweenHandsSec)+" "+tr("sec (hand delay)")); -// TODO gameData.allowSpectators = myCreateInternetGameDialog->checkBox_allowSpectators->isChecked(); mySession->clientCreateGame(gameData, currentGameName.toUtf8().constData(), myCreateInternetGameDialog->lineEdit_Password->text().toUtf8().constData()); diff --git a/src/net/common/netpacket.cpp b/src/net/common/netpacket.cpp index 1385724e..c07cc7a7 100644 --- a/src/net/common/netpacket.cpp +++ b/src/net/common/netpacket.cpp @@ -98,6 +98,7 @@ void NetPacket::SetGameData(const GameData &inData, NetGameInfo &outData) { outData.set_netgametype(static_cast(inData.gameType)); + outData.set_allowspectators(inData.allowSpectators); outData.set_maxnumplayers(inData.maxNumberOfPlayers); outData.set_raiseintervalmode(static_cast(inData.raiseIntervalMode)); if (inData.raiseIntervalMode == RAISE_ON_HANDNUMBER) { @@ -124,6 +125,7 @@ NetPacket::GetGameData(const NetGameInfo &inData, GameData &outData) int numManualBlinds = inData.manualblinds_size(); outData.gameType = static_cast(inData.netgametype()); + outData.allowSpectators = inData.allowspectators(); outData.maxNumberOfPlayers = inData.maxnumplayers(); outData.raiseIntervalMode = static_cast(inData.raiseintervalmode()); outData.raiseSmallBlindEveryHandsValue = outData.raiseSmallBlindEveryMinutesValue = 0; diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index 592b5c35..bf7102b0 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -1144,7 +1144,8 @@ ServerGame::CheckSettings(const GameData &data, const string &password, ServerMo || (data.raiseIntervalMode != RAISE_ON_HANDNUMBER) || (data.raiseMode != DOUBLE_BLINDS) || (data.raiseSmallBlindEveryHandsValue != RANKING_GAME_RAISE_EVERY_HAND) - || (!password.empty())) { + || (!password.empty()) + || (!data.allowSpectators)) { retVal = false; } } diff --git a/src/third_party/protobuf/pokerth.pb.cc b/src/third_party/protobuf/pokerth.pb.cc index 02fd38af..50f6ea2a 100644 --- a/src/third_party/protobuf/pokerth.pb.cc +++ b/src/third_party/protobuf/pokerth.pb.cc @@ -465,6 +465,7 @@ const int NetGameInfo::kPlayerActionTimeoutFieldNumber; const int NetGameInfo::kFirstSmallBlindFieldNumber; const int NetGameInfo::kStartMoneyFieldNumber; const int NetGameInfo::kManualBlindsFieldNumber; +const int NetGameInfo::kAllowSpectatorsFieldNumber; #endif // !_MSC_VER NetGameInfo::NetGameInfo() @@ -496,6 +497,7 @@ void NetGameInfo::SharedCtor() { playeractiontimeout_ = 0u; firstsmallblind_ = 0u; startmoney_ = 0u; + allowspectators_ = true; ::memset(_has_bits_, 0, sizeof(_has_bits_)); } @@ -556,6 +558,7 @@ void NetGameInfo::Clear() { playeractiontimeout_ = 0u; firstsmallblind_ = 0u; startmoney_ = 0u; + allowspectators_ = true; } manualblinds_.Clear(); ::memset(_has_bits_, 0, sizeof(_has_bits_)); @@ -798,6 +801,22 @@ bool NetGameInfo::MergePartialFromCodedStream( } else { goto handle_uninterpreted; } + if (input->ExpectTag(120)) goto parse_allowSpectators; + break; + } + + // optional bool allowSpectators = 15 [default = true]; + case 15: { + if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { + parse_allowSpectators: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( + input, &allowspectators_))); + set_has_allowspectators(); + } else { + goto handle_uninterpreted; + } if (input->ExpectAtEnd()) return true; break; } @@ -898,6 +917,11 @@ void NetGameInfo::SerializeWithCachedSizes( this->manualblinds(i), output); } + // optional bool allowSpectators = 15 [default = true]; + if (has_allowspectators()) { + ::google::protobuf::internal::WireFormatLite::WriteBool(15, this->allowspectators(), output); + } + } int NetGameInfo::ByteSize() const { @@ -994,6 +1018,11 @@ int NetGameInfo::ByteSize() const { this->startmoney()); } + // optional bool allowSpectators = 15 [default = true]; + if (has_allowspectators()) { + total_size += 1 + 1; + } + } // repeated uint32 manualBlinds = 14 [packed = true]; { @@ -1068,6 +1097,9 @@ void NetGameInfo::MergeFrom(const NetGameInfo& from) { if (from.has_startmoney()) { set_startmoney(from.startmoney()); } + if (from.has_allowspectators()) { + set_allowspectators(from.allowspectators()); + } } } @@ -1099,6 +1131,7 @@ void NetGameInfo::Swap(NetGameInfo* other) { std::swap(firstsmallblind_, other->firstsmallblind_); std::swap(startmoney_, other->startmoney_); manualblinds_.Swap(&other->manualblinds_); + std::swap(allowspectators_, other->allowspectators_); std::swap(_has_bits_[0], other->_has_bits_[0]); std::swap(_cached_size_, other->_cached_size_); } diff --git a/src/third_party/protobuf/pokerth.pb.h b/src/third_party/protobuf/pokerth.pb.h index 7c8f0293..326abd18 100644 --- a/src/third_party/protobuf/pokerth.pb.h +++ b/src/third_party/protobuf/pokerth.pb.h @@ -746,6 +746,13 @@ class NetGameInfo : public ::google::protobuf::MessageLite { inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_manualblinds(); + // optional bool allowSpectators = 15 [default = true]; + inline bool has_allowspectators() const; + inline void clear_allowspectators(); + static const int kAllowSpectatorsFieldNumber = 15; + inline bool allowspectators() const; + inline void set_allowspectators(bool value); + // @@protoc_insertion_point(class_scope:NetGameInfo) private: inline void set_has_gamename(); @@ -774,6 +781,8 @@ class NetGameInfo : public ::google::protobuf::MessageLite { inline void clear_has_firstsmallblind(); inline void set_has_startmoney(); inline void clear_has_startmoney(); + inline void set_has_allowspectators(); + inline void clear_has_allowspectators(); ::std::string* gamename_; int netgametype_; @@ -790,9 +799,10 @@ class NetGameInfo : public ::google::protobuf::MessageLite { ::google::protobuf::uint32 startmoney_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > manualblinds_; mutable int _manualblinds_cached_byte_size_; + bool allowspectators_; mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(14 + 31) / 32]; + ::google::protobuf::uint32 _has_bits_[(15 + 31) / 32]; #ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER friend void protobuf_AddDesc_pokerth_2eproto_impl(); @@ -11668,6 +11678,28 @@ NetGameInfo::mutable_manualblinds() { return &manualblinds_; } +// optional bool allowSpectators = 15 [default = true]; +inline bool NetGameInfo::has_allowspectators() const { + return (_has_bits_[0] & 0x00004000u) != 0; +} +inline void NetGameInfo::set_has_allowspectators() { + _has_bits_[0] |= 0x00004000u; +} +inline void NetGameInfo::clear_has_allowspectators() { + _has_bits_[0] &= ~0x00004000u; +} +inline void NetGameInfo::clear_allowspectators() { + allowspectators_ = true; + clear_has_allowspectators(); +} +inline bool NetGameInfo::allowspectators() const { + return allowspectators_; +} +inline void NetGameInfo::set_allowspectators(bool value) { + set_has_allowspectators(); + allowspectators_ = value; +} + // ------------------------------------------------------------------- // PlayerResult diff --git a/tests/src/de/pokerth/protocol/ProtoBuf.java b/tests/src/de/pokerth/protocol/ProtoBuf.java index 57e1a4ae..79c9946e 100644 --- a/tests/src/de/pokerth/protocol/ProtoBuf.java +++ b/tests/src/de/pokerth/protocol/ProtoBuf.java @@ -628,6 +628,16 @@ public final class ProtoBuf { * repeated uint32 manualBlinds = 14 [packed = true]; */ int getManualBlinds(int index); + + // optional bool allowSpectators = 15 [default = true]; + /** + * optional bool allowSpectators = 15 [default = true]; + */ + boolean hasAllowSpectators(); + /** + * optional bool allowSpectators = 15 [default = true]; + */ + boolean getAllowSpectators(); } /** * Protobuf type {@code NetGameInfo} @@ -770,6 +780,11 @@ public final class ProtoBuf { input.popLimit(limit); break; } + case 120: { + bitField0_ |= 0x00002000; + allowSpectators_ = input.readBool(); + break; + } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -1270,6 +1285,22 @@ public final class ProtoBuf { } private int manualBlindsMemoizedSerializedSize = -1; + // optional bool allowSpectators = 15 [default = true]; + public static final int ALLOWSPECTATORS_FIELD_NUMBER = 15; + private boolean allowSpectators_; + /** + * optional bool allowSpectators = 15 [default = true]; + */ + public boolean hasAllowSpectators() { + return ((bitField0_ & 0x00002000) == 0x00002000); + } + /** + * optional bool allowSpectators = 15 [default = true]; + */ + public boolean getAllowSpectators() { + return allowSpectators_; + } + private void initFields() { gameName_ = ""; netGameType_ = de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType.normalGame; @@ -1285,6 +1316,7 @@ public final class ProtoBuf { firstSmallBlind_ = 0; startMoney_ = 0; manualBlinds_ = java.util.Collections.emptyList(); + allowSpectators_ = true; } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -1384,6 +1416,9 @@ public final class ProtoBuf { for (int i = 0; i < manualBlinds_.size(); i++) { output.writeUInt32NoTag(manualBlinds_.get(i)); } + if (((bitField0_ & 0x00002000) == 0x00002000)) { + output.writeBool(15, allowSpectators_); + } } private int memoizedSerializedSize = -1; @@ -1458,6 +1493,10 @@ public final class ProtoBuf { } manualBlindsMemoizedSerializedSize = dataSize; } + if (((bitField0_ & 0x00002000) == 0x00002000)) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(15, allowSpectators_); + } memoizedSerializedSize = size; return size; } @@ -1577,6 +1616,8 @@ public final class ProtoBuf { bitField0_ = (bitField0_ & ~0x00001000); manualBlinds_ = java.util.Collections.emptyList(); bitField0_ = (bitField0_ & ~0x00002000); + allowSpectators_ = true; + bitField0_ = (bitField0_ & ~0x00004000); return this; } @@ -1657,6 +1698,10 @@ public final class ProtoBuf { bitField0_ = (bitField0_ & ~0x00002000); } result.manualBlinds_ = manualBlinds_; + if (((from_bitField0_ & 0x00004000) == 0x00004000)) { + to_bitField0_ |= 0x00002000; + } + result.allowSpectators_ = allowSpectators_; result.bitField0_ = to_bitField0_; return result; } @@ -1714,6 +1759,9 @@ public final class ProtoBuf { } } + if (other.hasAllowSpectators()) { + setAllowSpectators(other.getAllowSpectators()); + } return this; } @@ -2357,6 +2405,39 @@ public final class ProtoBuf { return this; } + // optional bool allowSpectators = 15 [default = true]; + private boolean allowSpectators_ = true; + /** + * optional bool allowSpectators = 15 [default = true]; + */ + public boolean hasAllowSpectators() { + return ((bitField0_ & 0x00004000) == 0x00004000); + } + /** + * optional bool allowSpectators = 15 [default = true]; + */ + public boolean getAllowSpectators() { + return allowSpectators_; + } + /** + * optional bool allowSpectators = 15 [default = true]; + */ + public Builder setAllowSpectators(boolean value) { + bitField0_ |= 0x00004000; + allowSpectators_ = value; + + return this; + } + /** + * optional bool allowSpectators = 15 [default = true]; + */ + public Builder clearAllowSpectators() { + bitField0_ = (bitField0_ & ~0x00004000); + allowSpectators_ = true; + + return this; + } + // @@protoc_insertion_point(builder_scope:NetGameInfo) }