diff --git a/src/WASimClient/WASimClient.cpp b/src/WASimClient/WASimClient.cpp index ac9fd57..4365817 100644 --- a/src/WASimClient/WASimClient.cpp +++ b/src/WASimClient/WASimClient.cpp @@ -952,10 +952,14 @@ class WASimClient::Private HRESULT setVariable(const VariableRequest &v, const double value) { - const string sValue = buildVariableCommandString(v, true); - if (sValue.empty() || sValue.length() >= STRSZ_CMD) - return E_INVALIDARG; - return sendServerCommand(Command(v.createLVar && v.variableType == 'L' ? CommandId::SetCreate : CommandId::Set, v.variableType, sValue.c_str(), value)); + if (Utilities::isSettableVariableType(v.variableType)) { + const string sValue = buildVariableCommandString(v, true); + if (sValue.empty() || sValue.length() >= STRSZ_CMD) + return E_INVALIDARG; + return sendServerCommand(Command(v.createLVar && v.variableType == 'L' ? CommandId::SetCreate : CommandId::Set, v.variableType, sValue.c_str(), value)); + } + LOG_WRN << "Cannot Set a variable of type '" << v.variableType << "'."; + return E_INVALIDARG; } #pragma endregion diff --git a/src/shared/utilities.h b/src/shared/utilities.h index e388b43..625bbd6 100644 --- a/src/shared/utilities.h +++ b/src/shared/utilities.h @@ -89,6 +89,11 @@ namespace WASimCommander { return find(VAR_TYPES_UNIT_BASED.cbegin(), VAR_TYPES_UNIT_BASED.cend(), type) != VAR_TYPES_UNIT_BASED.cend(); } + static bool isSettableVariableType(const char type) { + static const std::vector VAR_TYPES_SETTABLE = { 'A', 'C', 'H', 'K', 'L', 'Z' }; + return find(VAR_TYPES_SETTABLE.cbegin(), VAR_TYPES_SETTABLE.cend(), type) != VAR_TYPES_SETTABLE.cend(); + } + // returns actual byte size from given size which may be one of the SimConnect_AddToClientDataDefinition() dwSizeOrType constants static constexpr uint32_t getActualValueSize(DWORD dwSizeOrType) {