void XaUserAddressGeoType::Create() { vector<string> FieldName; vector<string> FieldValue; CreatePrepare({"XaUserAddressGeoType"},"/XaUserAddressGeoType/fieldset/field",FieldName,FieldValue); RESPONSE.Content=CreateResponse(CreateExecute("XaUserAddressGeoType",FieldName,FieldValue)); };
void XaUserAddressPhone::Create() { vector<string> FieldName; vector<string> FieldValue; CreatePrepare({"XaUserAddressPhone"},"/XaUserAddressPhone/fieldset/field",FieldName,FieldValue); string XaTable="XaUser"; string XaUserId=HTTP.GetHttpParam("XaUser_ID"); string XaUserAddressPhoneTypeId=HTTP.GetHttpParam("XaUserAddressPhoneType_ID"); string XaUserAddressPhoneCodeId=HTTP.GetHttpParam("XaUserAddressPhoneCode_ID"); unique_ptr<XaLibSql> LibSql (new XaLibSql()); if (LibSql->CheckRow(DB_READ,XaTable,XaUserId,"1","")==0) { LOG.Write("ERR", __FILE__, __FUNCTION__,__LINE__,"Requested Record ID -> "+XaUserId+" does not exist into Table -> "+XaTable); throw 302; } if (LibSql->CheckRow(DB_READ,"XaUserAddressPhoneType",XaUserAddressPhoneTypeId,"1","")==0) { LOG.Write("ERR", __FILE__, __FUNCTION__,__LINE__,"Requested Record ID -> "+XaUserAddressPhoneTypeId+" does not exist into Table -> XaUserAddressPhoneType"); throw 302; } if (LibSql->CheckRow(DB_READ,"XaUserAddressPhoneCode",XaUserAddressPhoneCodeId,"1","")==0) { LOG.Write("ERR", __FILE__, __FUNCTION__,__LINE__,"Requested Record ID -> "+XaUserAddressPhoneCodeId+" does not exist into Table -> XaUserAddressPhoneCode"); throw 302; } RESPONSE.Content=CreateResponse(CreateExecute("XaUserAddressPhone",FieldName,FieldValue)); };
CResponsePtr CStimResponseCollection::AddResponse(idEntity *Owner, int type, bool bRemovable, bool bDefault) { CResponsePtr rv; int n = m_Responses.Num(); for (int i = 0; i < n; ++i) { if (m_Responses[i]->m_StimTypeId == type) { DM_LOG(LC_STIM_RESPONSE, LT_DEBUG)LOGSTRING("Response of that type is already in collection, returning it\r"); rv = m_Responses[i]; break; } } if (rv == NULL) { rv = CreateResponse(Owner, static_cast<StimType>(type)); m_Responses.Append(rv); } if (rv != NULL) { rv->m_Default = bDefault; rv->m_Removable = bRemovable; gameLocal.AddResponse(Owner); } // Optimization: Update clip contents to include contents_response return rv; }
/* void XaUser::GetXmlModel() { ifstream MyFile; string Content; vector<string> XmlFiles=AddXmlFile({"XaUser"}); for (auto i=0;i<XmlFiles.size();i++) { MyFile.open(XmlFiles[i].c_str()); if (MyFile.is_open()) { string TmpString; while(getline(MyFile,TmpString)) { XaLibChar::ClearReturn(TmpString); Content.append(TmpString); } } } RESPONSE.Content="<model>"+Content+"</model>"; }; */ void XaUser::Create() { vector<string> FieldName; vector<string> FieldValue; CreatePrepare({"XaUser"},"/XaUser/fieldset/field",FieldName,FieldValue); int NextId=CreateExecute("XaUser",FieldName,FieldValue); RESPONSE.Content=CreateResponse(NextId); };
void XaLanguage::Create() { vector<string> FieldName; vector<string> FieldValue; CreatePrepare({"XaLanguage"},"/XaLanguage/fieldset/field",FieldName,FieldValue); int NextId=CreateExecute("XaLanguage",FieldName,FieldValue); if (NextId!=0) { unique_ptr<XaLibSql> LibSql (new XaLibSql()); string qry="SELECT XaLabel_ID FROM XaLabelTranslation, XaLabel WHERE XaLanguage_ID NOT IN ("+FromIntToString(NextId)+") AND XaLabel_id=XaLabel.id GROUP BY XaLabel_ID"; DbResMap DbRes=LibSql->FreeQuerySelect(DB_READ,qry); for(unsigned n=0; n<DbRes.size(); ++n){ vector<string> VectorFields; VectorFields.push_back("XaLabel_ID"); VectorFields.push_back("XaLanguage_ID"); vector<string> VectorValues; VectorValues.push_back(DbRes[n]["XaLabel_ID"]); VectorValues.push_back(FromIntToString(NextId)); LibSql->Insert(DB_WRITE,"XaLabelTranslation",VectorFields,VectorValues); VectorFields.clear(); VectorValues.clear(); } XaLanguageGen(); } RESPONSE.Content=CreateResponse(NextId); };
int Satori::request( const string& i_protocol, const string& i_protocol_version, const string& i_command, const strpairvec& i_data, string& o_protocol, string& o_protocol_version, strpairvec& o_data) { SenderEnableBuffering seb(GetSender()); //------------------------------------------------- // リクエスト単位のクラスメンバを初期化 mRequestMap.clear(); mRequestID = ""; mReferences.clear(); mReferences.reserve(8); // 最小値 // 引数をクラスメンバに設定 mRequestCommand = i_command; mRequestType = i_protocol; mRequestVersion = i_protocol_version; mStatusLine = i_command + " " + i_protocol + "/" + i_protocol_version; // 返すプロトコルのデフォルト値 o_protocol = "SHIORI"; o_protocol_version = "3.0"; // 喋るごとに初期化する変数 return_empty = false; surface_restore_at_talk_onetime = SR_INVALID; auto_anchor_enable_onetime = auto_anchor_enable; is_quick_section = false; // スクリプトヘッダ header_script = ""; // プロトコルを判別 if ( i_protocol=="SAORI" && i_protocol_version[0]>='1' ) { o_protocol = i_protocol; o_protocol_version = "1.0"; mRequestMode = SAORI; } else if ( i_protocol=="SHIORI" && i_protocol_version[0]>='3' ) { mRequestMode = SHIORI3; } else if ( i_protocol=="SHIORI" && i_protocol_version[0]=='2' ) { mRequestMode = SHIORI2; // 2.xにもバージョンとしては3.0を返す } else if ( i_protocol=="MAKOTO" && i_protocol_version[0]>='2' ) { o_protocol = i_protocol; o_protocol_version = "2.0"; mRequestMode = MAKOTO2; } else if ( i_protocol=="UNKNOWN" ) { mRequestMode = UNKNOWN; } else { // 未対応のプロトコルだった。 return 400; } // データ部をmRequestMapに格納。 // SHOIRI/3.0以外のプロトコルの場合、SHOIRI/3.0に変換を行う。 for ( strpairvec::const_iterator it = i_data.begin() ; it != i_data.end() ; ++it ) { string key = it->first; const string& value = it->second; switch ( mRequestMode ) { case SAORI: if ( compare_head(key, "Argument") ) { int n = stoi_internal(key.c_str()+8); if ( n==0 ) key = "ID"; else key = "Reference" + itos(n-1); } break; case SHIORI2: // こっちはてきとー if ( key=="Event" ) key="ID"; break; case MAKOTO2: if ( key=="String" ) key="Reference0"; break; default: break; } mRequestMap[key] = value; if ( compare_head(key, "Reference") ) { int n = stoi_internal(key.c_str()+9); if ( n>=0 && n<65536 ) { if ( n>=mReferences.size() ) mReferences.resize(n+1); mReferences[n]=value; } } } if ( mRequestMode == MAKOTO2 ) { mRequestMap["ID"] = "OnMakoto"; } mRequestID = mRequestMap["ID"]; mIsMateria = ( mRequestMap["Sender"] == "embryo" ); mIsStatusHeaderExist = ( mRequestMap["Sender"] == "SSP" ); //------------------------------------------------- // リクエストを解釈 if ( mRequestCommand=="GET Version" ) { if ( mRequestMode == SHIORI2 ) { o_data.push_back( strpair("ID", gSatoriName) ); o_data.push_back( strpair("Craftman", gSatoriCraftman) ); o_data.push_back( strpair("Version", gSatoriVersion) ); } return 200; } // 選択分岐記録を変数に代入。ref0を元に戻す。 if ( compare_head(mRequestID, "OnChoice") ) // OnChoiceSelect/OnChoiceEnterの両方 { strvec vec; int ref_no = ( mRequestID=="OnChoiceEnter" || mRequestID=="OnChoiceSelectEx" )?1:0; string& info = mRequestMap[string("Reference")+itos(ref_no)]; if ( split(info, byte1_dlmt, vec)==3 ) // \1区切りの3文字列であるならば { info=mReferences[ref_no]=variables["選択ID"]=vec[0]; variables["選択ラベル"]=vec[1]; variables["選択番号"]=vec[2]; } } // ログについて色々 bool log_disable_soft = ( mRequestID=="OnSurfaceChange" || mRequestID=="OnSecondChange" || mRequestID=="OnMinuteChange" || mRequestID=="OnMouseMove" || mRequestID=="OnTranslate"); bool log_disable_hard = ( /*compare_tail(mRequestID, "caption") || */compare_tail(mRequestID, "visible") || compare_head(mRequestID, "menu.") || mRequestID.find(".color.")!=string::npos ); GetSender().next_event(); if(fRequestLog) { GetSender().sender() << "--- Request ---" << std::endl << mStatusLine <<std::endl; // << iRequest <<std::endl; for(strmap::const_iterator i=mRequestMap.begin() ; i!=mRequestMap.end() ; ++i) if ( !i->first.empty() && !i->second.empty() && i->first!="SecurityLevel" && i->first!="Sender" && i->first!="Charset" ) { GetSender().sender() << i->first << ": " << i->second <<std::endl; } } // せきゅあ? strmap::const_iterator it = mRequestMap.find("SecurityLevel"); secure_flag = ( it!=mRequestMap.end() && stricmp(it->second.c_str(), "local")==0 ); // メイン処理 GetSender().sender() << "--- Operation ---" << std::endl; int status_code = 500; if ( mRequestID=="enable_log" || mRequestID=="enable_debug" ) { if ( secure_flag ) { bool flag = false; if ( mReferences.size() > 0 ) { flag = atoi(mReferences[0].c_str()) != 0; } if ( mRequestID=="enable_debug" ) { fDebugMode = flag; } else { GetSender().validate(flag); } status_code = 200; } else { GetSender().sender() << "local/Localでないので蹴りました: ShioriEcho" <<std::endl; status_code = 403; } } else if ( mRequestID=="ShioriEcho" ) { // ShioriEcho実装 if ( fDebugMode && secure_flag ) { string result = SentenceToSakuraScriptExec_with_PreProcess(mReferences); if ( result.length() ) { static const char* const dangerous_tag[] = {"\\![updatebymyself]", "\\![vanishbymyself]", "\\![enter,passivemode]", "\\![enter,inductionmode]", "\\![leave,passivemode]", "\\![leave,inductionmode]", "\\![lock,repaint]", "\\![unlock,repaint]", "\\![biff]", "\\![open,browser", "\\![open,mailer", "\\![raise", "\\j["}; std::string replace_to; for ( int i = 0 ; i < (sizeof(dangerous_tag)/sizeof(dangerous_tag[0])) ; ++i ) { replace_to = "¥["; replace_to += dangerous_tag[i]+2; //\をヌキ replace(result,dangerous_tag[i],replace_to); } //Translate(result); - Translateは後でかかる mResponseMap["Value"] = result; status_code = 200; } else { status_code = 204; } } else { if ( fDebugMode ) { GetSender().sender() << "local/Localでないので蹴りました: ShioriEcho" <<std::endl; status_code = 403; } else { static const std::string dbgmsg = "デバッグモードが無効です。使用するためには$デバッグ=有効にしてください。: ShioriEcho"; GetSender().sender() << dbgmsg <<std::endl; mResponseMap["Value"] = "\\0" + dbgmsg + "\\e"; status_code = 200; } } } else if (mRequestID == "SatolistEcho"){ #ifndef POSIX // さとりすとデバッガ実装 if (fDebugMode && secure_flag) { //R0は除去される strvec customRef; for (int i = 1; i < mReferences.size(); i++){ customRef.push_back(mReferences[i]); } string result = SentenceToSakuraScriptExec_with_PreProcess(customRef); if (result.length()) { result = string("SSTP 200 OK\r\nCharset: Shift_JIS\r\nResult: ") + result + "\r\n\r\n"; } else{ //情報なし result = string("SSTP 204 No Content\r\nCharset: Shift_JIS\r\n\r\n"); } char* copyData = new char[result.length() + 1]; strcpy(copyData, result.c_str()); COPYDATASTRUCT cds; cds.dwData = 0; cds.cbData = result.length() + 1; cds.lpData = copyData; DWORD ret; SendMessageTimeout((HWND)stoi_internal(mReferences[0]), WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds, 0, 1000, &ret); //ここで204を返すと非対応時のエラーを出すので200で通知メッセージを表示する status_code = 200; mResponseMap["Value"] = "\\0\\_q■情報を送信しました。\\e"; } else { if (fDebugMode) { GetSender().sender() << "local/Localでないので蹴りました: SatolistEcho" <<std::endl; status_code = 403; } else { static const std::string dbgmsg = "デバッグモードが無効です。使用するためには$デバッグ=有効にしてください。: SatolistEcho"; GetSender().sender() << dbgmsg <<std::endl; mResponseMap["Value"] = "\\0" + dbgmsg + "\\e"; status_code = 200; } } #endif // POSIX } else { status_code = CreateResponse(mResponseMap); } // 後処理1 default_surface = next_default_surface; //-------------------------------------------------------------------- // Valueに対する最終処理 if ( status_code==200 ) { // && compare_head(mRequestID, "On") strmap::iterator i = mResponseMap.find("Value"); if ( i!=mResponseMap.end() ) { if ( return_empty ) { status_code = 204; mResponseMap.erase(i); } else { if ( !Translate(i->second) ) { status_code = 204; mResponseMap.erase(i); } else { second_from_last_talk = 0; if ( compare_head(mRequestID, "On") ) { mResponseHistory.push_front(i->second); if ( mResponseHistory.size() >= RESPONSE_HISTORY_SIZE ) mResponseHistory.pop_back(); } } } } } GetSender().sender() << "status code : " << itos(status_code) <<std::endl; //-------------------------------------------------------------------- for(strmap::const_iterator i=mResponseMap.begin() ; i!=mResponseMap.end() ; ++i) { string key=i->first, value=i->second; switch ( mRequestMode ) { case SAORI: if ( key=="Value" ) { key = "Result"; value = header_script + value; } else if ( compare_head(key, "Reference") ) { key = string() + "Value" + (key.c_str()+9); } break; case SHIORI2: if ( key=="Value" ) { key = "Sentence"; value = header_script + value; } break; case MAKOTO2: if ( key=="Value" ) { key = "String"; value = header_script + value; } break; default: if ( key=="Value" ) { value = header_script + value; } break; } o_data.push_back( strpair(key, value) ); } if ( GetSender().errsender().get_log_mode() ) { const std::vector<string> &errlog = GetSender().errsender().get_log(); std::string errmsg; std::string errlevel; for ( std::vector<string>::const_iterator itr = errlog.begin() ; itr != errlog.end(); ++itr ) { errmsg += "SATORI - "; errmsg += mRequestID; errmsg += " > "; errmsg += *itr; errmsg += "\1"; errlevel += "critical\1"; } if ( errmsg.length() ) { errmsg.erase(errmsg.end()-1,errmsg.end()); errlevel.erase(errlevel.end()-1,errlevel.end()); o_data.push_back( strpair("ErrorLevel",errlevel) ); o_data.push_back( strpair("ErrorDescription",errmsg) ); } GetSender().errsender().clear_log(); } GetSender().validate(); if(fResponseLog) { GetSender().sender() << "--- Response ---" <<std::endl << mResponseMap <<std::endl; } mResponseMap.clear(); if ( log_disable_hard ) { GetSender().delete_last_request(); } else if ( log_disable_soft ) { if ( status_code != 200 ) { GetSender().delete_last_request(); } } GetSender().flush(); //-------------------------------------------------------------------- // リロード処理 if ( reload_flag ) { reload_flag = false; string tmp = mBaseFolder; GetSender().sender() << "■■reloading." <<std::endl; unload(); load(tmp); GetSender().sender() << "■■reloaded." <<std::endl; GetSender().flush(); } return status_code; }
bool CStimResponseCollection::ParseSpawnArg( const idDict &args, idEntity *owner, const char sr_class, int index ) { bool rc = false; idStr str; CStimPtr stim; CResponsePtr resp; CStimResponsePtr sr; StimState state( SS_DISABLED ); StimType typeOfStim; // Check if the entity contains either a stim or a response. if( sr_class != 'S' && sr_class != 'R' ) { DM_LOG( LC_STIM_RESPONSE, LT_ERROR )LOGSTRING( "Invalid sr_class value [%s]\r", str.c_str() ); goto Quit; } // Get the id of the stim/response type so we know what sub-class to create args.GetString( va( "sr_type_%u", index ), "-1", str ); // This is invalid as an entity definition if( str == "-1" ) { sr.reset(); goto Quit; } // If the first character is alphanumeric, we check if it // is a known id and convert it. /* StimType */ typeOfStim = ST_DEFAULT; if( ( str[0] >= 'a' && str[0] <= 'z' ) || ( str[0] >= 'A' && str[0] <= 'Z' ) ) { // Try to recognise the string as known Stim type typeOfStim = CStimResponse::GetStimType( str ); // If the string hasn't been found, we have id == ST_DEFAULT. if( typeOfStim == ST_DEFAULT ) { DM_LOG( LC_STIM_RESPONSE, LT_ERROR )LOGSTRING( "Invalid sr_type id [%s]\r", str.c_str() ); sr.reset(); goto Quit; } } else if( str[0] >= '0' && str[0] <= '9' ) { // Is it numeric? typeOfStim = ( StimType ) atol( str.c_str() ); } else { // neither a character nor a number, thus it is invalid. DM_LOG( LC_STIM_RESPONSE, LT_ERROR )LOGSTRING( "Invalid sr_type id [%s]\r", str.c_str() ); sr.reset(); goto Quit; } if( sr_class == 'S' ) { stim = CreateStim( owner, typeOfStim ); if( stim == NULL ) { // grayman #2862 goto Quit; // nasty goto!! } sr = stim; } else if( sr_class == 'R' ) { resp = CreateResponse( owner, typeOfStim ); sr = resp; } // Set stim response type sr->m_StimTypeId = typeOfStim; // Set stim response name string sr->m_StimTypeName = str; // Read stim response state from the def file state = static_cast<StimState>( args.GetInt( va( "sr_state_%u", index ), "1" ) ); sr->SetEnabled( state == SS_ENABLED ); sr->m_Chance = args.GetFloat( va( "sr_chance_%u", index ), "1.0" ); // A stim also may have a radius if( sr_class == 'S' ) { stim->m_Radius = args.GetFloat( va( "sr_radius_%u", index ), "0" ); stim->m_RadiusFinal = args.GetFloat( va( "sr_radius_final_%u", index ), "-1" ); stim->m_FallOffExponent = args.GetInt( va( "sr_falloffexponent_%u", index ), "0" ); stim->m_bUseEntBounds = args.GetBool( va( "sr_use_bounds_%u", index ), "0" ); stim->m_bCollisionBased = args.GetBool( va( "sr_collision_%u", index ), "0" ); stim->m_Velocity = args.GetVector( va( "sr_velocity_%u", index ), "0 0 0" ); stim->m_Bounds[0] = args.GetVector( va( "sr_bounds_mins_%u", index ), "0 0 0" ); stim->m_Bounds[1] = args.GetVector( va( "sr_bounds_maxs_%u", index ), "0 0 0" ); // set up time interleaving so the stim isn't fired every frame stim->m_TimeInterleave = args.GetInt( va( "sr_time_interval_%u", index ), "0" ); // greebo: Add fuzzyness to the timer (ranging from 0.9 - 1.3); stim->m_TimeInterleave = static_cast<int>( stim->m_TimeInterleave * ( 0.9f + gameLocal.random.RandomFloat() * 0.4f ) ); // userfriendly stim duration time stim->m_Duration = args.GetInt( va( "sr_duration_%u", index ), "0" ); stim->m_Magnitude = args.GetFloat( va( "sr_magnitude_%u", index ), "1.0" ); stim->m_MaxFireCount = args.GetInt( va( "sr_max_fire_count_%u", index ), "-1" ); // Check if we have a timer on this stim. CreateTimer( args, stim, index ); } else { // this is only for responses sr->m_ChanceTimer = args.GetInt( va( "sr_chance_timeout_%u", index ), "-1" ); resp->m_NumRandomEffects = args.GetInt( va( "sr_random_effects_%u", index ), "0" ); // Get the name of the script function for processing the response args.GetString( "sr_script_" + str, "", str ); resp->m_ScriptFunction = str; // Try to identify the ResponseEffect spawnargs int effectIdx = 1; while( effectIdx > 0 ) { // Try to find a string like "sr_effect_2_1" args.GetString( va( "sr_effect_%u_%u", index, effectIdx ), "", str ); if( str.IsEmpty() ) { // Set the index to negative values to end the loop effectIdx = -1; } else { // Assemble the postfix of this effect for later key/value lookup // This is passed to the effect script eventually DM_LOG( LC_STIM_RESPONSE, LT_DEBUG )LOGSTRING( "Adding response effect\r" ); resp->AddResponseEffect( str, va( "%u_%u", index, effectIdx ), args ); effectIdx++; } } } rc = true; Quit: if( sr != NULL ) { if( stim != NULL ) { DM_LOG( LC_STIM_RESPONSE, LT_DEBUG )LOGSTRING( "Stim %s added to collection for %s\r", stim->m_StimTypeName.c_str(), owner->name.c_str() ); AddStim( stim ); stim->m_State = state; } if( resp != NULL ) { DM_LOG( LC_STIM_RESPONSE, LT_DEBUG )LOGSTRING( "Response %s added to collection for %s\r", resp->m_StimTypeName.c_str(), owner->name.c_str() ); AddResponse( resp ); } } return rc; }
QString Client::CommandErrorResponse(QString cmd, QString msg) { return CreateResponse("error", cmd, msg); }
QString Client::CommandResponse(QString cmd, QString msg) { return CreateResponse("response", cmd, msg); }