void Connection::Process(bool executeAfterRead) { log_info("Process: fd=" << socket_.GetFileDescriptor()); bool newMessage = true; while (newMessage) { newMessage = false; if ((connectionState_ == READ_HEADER) && (!ReadHeader())) { connectionState_ = CLOSE_CONNECTION; break; } if ((connectionState_ == READ_REQUEST) && (!ReadRequest())) { connectionState_ = CLOSE_CONNECTION; break; } // When operating a thread pool, the main thread will read the request // but stop to transfer it to a worker thread for execution if (executeAfterRead) { if ((connectionState_ == EXECUTE_REQUEST) && (!ExecuteRequest())) { connectionState_ = CLOSE_CONNECTION; break; } } // When operating a thread pool, the main thread might need to continue // to write a long response to the socket after the connection is returned if (connectionState_ == WRITE_RESPONSE) { if (!WriteResponse()) { connectionState_ = CLOSE_CONNECTION; break; } newMessage = (connectionState_ == READ_HEADER) && (bufferLength_ > 0); } } }
bool psNPCLoader::WriteTrigger(csRef<iDocumentNode> specificsNode, csString &trigger,int priorID, int questID) { // <trigger> // <phrase value=".."> // <phrase value=".."> // <attitude min="0" max="100"> // <response say=".. "/> // <trigger> // .. // </trigger> // </attitude> // </trigger> Result result; Result phrases; csString escArea; csString escTrigger; db->Escape(escArea, area); db->Escape(escTrigger, trigger); if(questID == -1) { result = db->Select("SELECT response_id, " " min_attitude_required, " " max_attitude_required " "FROM npc_triggers " "WHERE prior_response_required=\"%i\" and trigger=\"%s\" and area=\"%s\" and quest_id<1;", priorID, escTrigger.GetData(), escArea.GetData()); // all triggers that have the same response id will be grouped together // and written to the xml file as <phrase value=".."> phrases = db->Select("SELECT id, trigger " "FROM npc_triggers " "WHERE response_id=\"%i\" and area=\"%s\" and quest_id<1;", result[0].GetInt(0), escArea.GetData()); } else { result = db->Select("SELECT response_id, " " min_attitude_required, " " max_attitude_required " "FROM npc_triggers " "WHERE prior_response_required=\"%i\" and trigger=\"%s\" and quest_id=\"%i\";", priorID, escTrigger.GetData(), questID); // all triggers that have the same response id will be grouped together // and written to the xml file as <phrase value=".."> phrases = db->Select("SELECT id, trigger, area " "FROM npc_triggers " "WHERE response_id=\"%i\" and quest_id=\"%i\";", result[0].GetInt(0), questID); } csString temp; csRef<iDocumentNode> triggerNode; for(int i=0; i< (int)phrases.Count(); i++) { int triggerID = phrases[i].GetInt(0); bool duplicate=false; for(size_t j=0; j<triggers.GetSize(); j++) { if(triggerID==triggers[j]) duplicate=true; } // if the trigger hasn't already been added if(!duplicate) { triggers.Push(triggerID); if(!triggerNode) { triggerNode = specificsNode->CreateNodeBefore(CS_NODE_ELEMENT); triggerNode->SetValue("trigger"); csString area(phrases[0][2]); if(this->area.IsEmpty() && !area.IsEmpty()) triggerNode->SetAttribute("area", area); } csRef<iDocumentNode> phraseNode = triggerNode->CreateNodeBefore(CS_NODE_ELEMENT); phraseNode->SetValue("phrase"); phraseNode->SetAttribute("value", phrases[i][1]); } } if(triggerNode) { for(int i=0; i<(int)result.Count(); i++) { int responseID = result[i].GetInt(0); int minAttitude = result[i].GetInt(1); int maxAttitude = result[i].GetInt(2); csRef<iDocumentNode> attitudeNode = triggerNode->CreateNodeBefore(CS_NODE_ELEMENT); attitudeNode->SetValue("attitude"); attitudeNode->SetAttributeAsInt("min", minAttitude); attitudeNode->SetAttributeAsInt("max", maxAttitude); if(!WriteResponse(attitudeNode, responseID, questID)) return false; // check if this trigger contains other triggers Result childResult(db->Select("SELECT DISTINCT trigger " "FROM npc_triggers " "WHERE prior_response_required=%i;" ,responseID)); if(childResult.IsValid()) { for(int j=0; j<(int)childResult.Count(); j++) { csString res(childResult[j][0]); if(!WriteTrigger(attitudeNode, res, responseID, questID)) return false; } } } } return true; }