void CDeathmatchVehicle::ResetDamageModelSync(void) { for (int i = 0; i < MAX_DOORS; i++) m_ucLastDoorStates[i] = GetDoorStatus(i); for (int i = 0; i < MAX_WHEELS; i++) m_ucLastWheelStates[i] = GetWheelStatus(i); for (int i = 0; i < MAX_PANELS; i++) m_ucLastPanelStates[i] = GetPanelStatus(i); for (int i = 0; i < MAX_LIGHTS; i++) m_ucLastLightStates[i] = GetLightStatus(i); }
void CDataPush::DoFibaroPush() { std::string fibaroIP = ""; std::string fibaroUsername = ""; std::string fibaroPassword = ""; int iIsVersion4 = 0; m_sql.GetPreferencesVar("FibaroIP", fibaroIP); m_sql.GetPreferencesVar("FibaroUsername", fibaroUsername); m_sql.GetPreferencesVar("FibaroPassword", fibaroPassword); m_sql.GetPreferencesVar("FibaroVersion4", iIsVersion4); int fibaroDebugActiveInt; bool fibaroDebugActive = false; m_sql.GetPreferencesVar("FibaroDebug", fibaroDebugActiveInt); if (fibaroDebugActiveInt == 1) { fibaroDebugActive = true; } bool bIsV4 = (iIsVersion4 != 0); if ( (fibaroIP == "") || (fibaroUsername == "") || (fibaroPassword == "") ) return; std::vector<std::vector<std::string> > result; result = m_sql.safe_query( "SELECT A.DeviceID, A.DelimitedValue, B.ID, B.Type, B.SubType, B.nValue, B.sValue, A.TargetType, A.TargetVariable, A.TargetDeviceID, A.TargetProperty, A.IncludeUnit, B.SwitchType FROM FibaroLink as A, DeviceStatus as B " "WHERE (A.DeviceID == '%llu' AND A.Enabled = '1' AND A.DeviceID==B.ID)", m_DeviceRowIdx); if (result.size()>0) { std::string sendValue; std::vector<std::vector<std::string> >::const_iterator itt; for (itt=result.begin(); itt!=result.end(); ++itt) { std::vector<std::string> sd=*itt; int delpos = atoi(sd[1].c_str()); int dType = atoi(sd[3].c_str()); int dSubType = atoi(sd[4].c_str()); int nValue = atoi(sd[5].c_str()); std::string sValue = sd[6].c_str(); int targetType = atoi(sd[7].c_str()); std::string targetVariable = sd[8].c_str(); int targetDeviceID = atoi(sd[9].c_str()); std::string targetProperty = sd[10].c_str(); int includeUnit = atoi(sd[11].c_str()); int metertype = atoi(sd[12].c_str()); std::string lstatus=""; if ((targetType==0)||(targetType==1)) { if (delpos == 0) { int llevel=0; bool bHaveDimmer=false; bool bHaveGroupCmd=false; int maxDimLevel=0; GetLightStatus(dType,dSubType,(_eSwitchType)metertype,nValue,sValue,lstatus,llevel,bHaveDimmer,maxDimLevel,bHaveGroupCmd); sendValue = lstatus; } else if (delpos>0) { std::vector<std::string> strarray; if (sValue.find(";")!=std::string::npos) { StringSplit(sValue, ";", strarray); if (int(strarray.size())>=delpos) { std::string rawsendValue = strarray[delpos-1].c_str(); sendValue = ProcessSendValue(rawsendValue,delpos,nValue,includeUnit,metertype); } } } } else { // scenes/reboot, only on/off int llevel=0; bool bHaveDimmer=false; bool bHaveGroupCmd=false; int maxDimLevel=0; GetLightStatus(dType,dSubType, STYPE_OnOff,nValue,sValue,lstatus,llevel,bHaveDimmer,maxDimLevel,bHaveGroupCmd); sendValue = lstatus; } if (sendValue !="") { std::string sResult; std::stringstream sPostData; std::stringstream Url; std::vector<std::string> ExtraHeaders; sendValue = CURLEncode::URLEncode(sendValue); if (targetType==0) { Url << "http://" << fibaroUsername << ":" << fibaroPassword << "@" << fibaroIP << "/api/globalVariables"; if (bIsV4) Url << "/" << targetVariable; sPostData << "{\"name\": \"" << targetVariable << "\", \"value\": \"" << sendValue << "\"}"; if (fibaroDebugActive) { _log.Log(LOG_NORM,"FibaroLink: sending global variable %s with value: %s",targetVariable.c_str(),sendValue.c_str()); } if (!HTTPClient::PUT(Url.str(),sPostData.str(),ExtraHeaders,sResult)) { _log.Log(LOG_ERROR,"Error sending data to Fibaro!"); } } else if (targetType==1) { Url << "http://" << fibaroUsername << ":" << fibaroPassword << "@" << fibaroIP << "/api/callAction?deviceid=" << targetDeviceID << "&name=setProperty&arg1=" << targetProperty << "&arg2=" << sendValue; if (fibaroDebugActive) { _log.Log(LOG_NORM,"FibaroLink: sending value %s to property %s of virtual device id %d",sendValue.c_str(),targetProperty.c_str(),targetDeviceID); } if (!HTTPClient::GET(Url.str(),sResult)) { _log.Log(LOG_ERROR,"Error sending data to Fibaro!"); } } else if (targetType==2) { if (((delpos==0)&&(lstatus=="Off"))||((delpos==1)&&(lstatus=="On"))) { Url << "http://" << fibaroUsername << ":" << fibaroPassword << "@" << fibaroIP << "/api/sceneControl?id=" << targetDeviceID << "&action=start"; if (fibaroDebugActive) { _log.Log(LOG_NORM,"FibaroLink: activating scene %d",targetDeviceID); } if (!HTTPClient::GET(Url.str(),sResult)) { _log.Log(LOG_ERROR,"Error sending data to Fibaro!"); } } } else if (targetType==3) { if (((delpos==0)&&(lstatus=="Off"))||((delpos==1)&&(lstatus=="On"))) { Url << "http://" << fibaroUsername << ":" << fibaroPassword << "@" << fibaroIP << "/api/settings/reboot"; if (fibaroDebugActive) { _log.Log(LOG_NORM,"FibaroLink: reboot"); } if (!HTTPClient::POST(Url.str(),sPostData.str(),ExtraHeaders,sResult)) { _log.Log(LOG_ERROR,"Error sending data to Fibaro!"); } } } } } } }
bool CDeathmatchVehicle::SyncDamageModel(void) { SVehicleDamageSync damage(true, true, true, true, true); bool bChanges = false; // Copy current door states to the sync structure and mark those that changed for (unsigned int i = 0; i < MAX_DOORS; ++i) { damage.data.ucDoorStates[i] = GetDoorStatus(i); if (damage.data.ucDoorStates[i] != m_ucLastDoorStates[i]) { bChanges = true; damage.data.bDoorStatesChanged[i] = true; } else damage.data.bDoorStatesChanged[i] = false; } // Copy current wheel states to the sync structure and mark those that changed for (unsigned int i = 0; i < MAX_WHEELS; ++i) { damage.data.ucWheelStates[i] = GetWheelStatus(i); if (damage.data.ucWheelStates[i] != m_ucLastWheelStates[i]) { bChanges = true; damage.data.bWheelStatesChanged[i] = true; } else damage.data.bWheelStatesChanged[i] = false; } // Copy current panel states to the sync structure and mark those that changed for (unsigned int i = 0; i < MAX_PANELS; ++i) { damage.data.ucPanelStates[i] = GetPanelStatus(i); if (damage.data.ucPanelStates[i] != m_ucLastPanelStates[i]) { bChanges = true; damage.data.bPanelStatesChanged[i] = true; } else damage.data.bPanelStatesChanged[i] = false; } // Copy current light states to the sync structure and mark those that changed for (unsigned int i = 0; i < MAX_LIGHTS; ++i) { damage.data.ucLightStates[i] = GetLightStatus(i); if (damage.data.ucLightStates[i] != m_ucLastLightStates[i]) { bChanges = true; damage.data.bLightStatesChanged[i] = true; } else damage.data.bLightStatesChanged[i] = false; } // Something has changed? if (bChanges) { // Set the last state to current m_ucLastDoorStates = damage.data.ucDoorStates; m_ucLastWheelStates = damage.data.ucWheelStates; m_ucLastPanelStates = damage.data.ucPanelStates; m_ucLastLightStates = damage.data.ucLightStates; // Sync it NetBitStreamInterface* pBitStream = g_pNet->AllocateNetBitStream(); if (pBitStream) { // Write the vehicle id and the damage model data pBitStream->Write(m_ID); pBitStream->Write(&damage); // Send and delete it g_pNet->SendPacket(PACKET_ID_VEHICLE_DAMAGE_SYNC, pBitStream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED); g_pNet->DeallocateNetBitStream(pBitStream); } return true; } return false; }