Preparing "allow spectators" flag in network protocol (#215).

This commit is contained in:
lotodore
2013-10-27 00:41:13 +02:00
parent 11a45cd6d6
commit 6992c732af
8 changed files with 160 additions and 9 deletions
+1
View File
@@ -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.
+7 -6
View File
@@ -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;
@@ -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());
+2
View File
@@ -98,6 +98,7 @@ void
NetPacket::SetGameData(const GameData &inData, NetGameInfo &outData)
{
outData.set_netgametype(static_cast<NetGameInfo::NetGameType>(inData.gameType));
outData.set_allowspectators(inData.allowSpectators);
outData.set_maxnumplayers(inData.maxNumberOfPlayers);
outData.set_raiseintervalmode(static_cast<NetGameInfo::RaiseIntervalMode>(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<GameType>(inData.netgametype());
outData.allowSpectators = inData.allowspectators();
outData.maxNumberOfPlayers = inData.maxnumplayers();
outData.raiseIntervalMode = static_cast<RaiseIntervalMode>(inData.raiseintervalmode());
outData.raiseSmallBlindEveryHandsValue = outData.raiseSmallBlindEveryMinutesValue = 0;
+2 -1
View File
@@ -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;
}
}
+33
View File
@@ -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_);
}
+33 -1
View File
@@ -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
@@ -628,6 +628,16 @@ public final class ProtoBuf {
* <code>repeated uint32 manualBlinds = 14 [packed = true];</code>
*/
int getManualBlinds(int index);
// optional bool allowSpectators = 15 [default = true];
/**
* <code>optional bool allowSpectators = 15 [default = true];</code>
*/
boolean hasAllowSpectators();
/**
* <code>optional bool allowSpectators = 15 [default = true];</code>
*/
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_;
/**
* <code>optional bool allowSpectators = 15 [default = true];</code>
*/
public boolean hasAllowSpectators() {
return ((bitField0_ & 0x00002000) == 0x00002000);
}
/**
* <code>optional bool allowSpectators = 15 [default = true];</code>
*/
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;
/**
* <code>optional bool allowSpectators = 15 [default = true];</code>
*/
public boolean hasAllowSpectators() {
return ((bitField0_ & 0x00004000) == 0x00004000);
}
/**
* <code>optional bool allowSpectators = 15 [default = true];</code>
*/
public boolean getAllowSpectators() {
return allowSpectators_;
}
/**
* <code>optional bool allowSpectators = 15 [default = true];</code>
*/
public Builder setAllowSpectators(boolean value) {
bitField0_ |= 0x00004000;
allowSpectators_ = value;
return this;
}
/**
* <code>optional bool allowSpectators = 15 [default = true];</code>
*/
public Builder clearAllowSpectators() {
bitField0_ = (bitField0_ & ~0x00004000);
allowSpectators_ = true;
return this;
}
// @@protoc_insertion_point(builder_scope:NetGameInfo)
}