version 0.1.12
[fms.git] / src / freenet / introductionpuzzleinserter.cpp
index ea78ace..66635bb 100644 (file)
@@ -27,11 +27,17 @@ void IntroductionPuzzleInserter::CheckForNeededInsert()
        \r
        while(!rs.AtEnd())\r
        {\r
+               std::string localidentityidstr;\r
                DateTime now;\r
                now.SetToGMTime();\r
 \r
+               if(rs.GetField(0))\r
+               {\r
+                       localidentityidstr=rs.GetField(0);\r
+               }\r
+\r
                // if this identity has any non-solved puzzles for today, we don't need to insert a new puzzle\r
-               SQLite3DB::Recordset rs2=m_db->Query("SELECT UUID FROM tblIntroductionPuzzleInserts WHERE Day='"+now.Format("%Y-%m-%d")+"' AND FoundSolution='false';");\r
+               SQLite3DB::Recordset rs2=m_db->Query("SELECT UUID FROM tblIntroductionPuzzleInserts WHERE Day='"+now.Format("%Y-%m-%d")+"' AND FoundSolution='false' AND LocalIdentityID="+localidentityidstr+";");\r
 \r
                // identity doesn't have any non-solved puzzles for today - start a new insert\r
                if(rs2.Empty()==true)\r
@@ -118,7 +124,7 @@ const bool IntroductionPuzzleInserter::HandlePutFailed(FCPMessage &message)
                m_db->Execute("UPDATE tblIntroductionPuzzleInserts SET Day='"+idparts[5]+"', InsertIndex="+idparts[2]+", FoundSolution='true' WHERE UUID='"+idparts[3]+"';");\r
        }\r
 \r
-       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" failed to insert puzzle "+idparts[3]);\r
+       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IntroductionPuzzleInserter::HandlePutFailed failed to insert puzzle "+idparts[3]);\r
 \r
        return true;\r
 }\r
@@ -149,7 +155,7 @@ const bool IntroductionPuzzleInserter::HandlePutSuccessful(FCPMessage &message)
        st.Step();\r
        st.Finalize();\r
 \r
-       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" inserted puzzle "+idparts[3]);\r
+       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IntroductionPuzzleInserter::HandlePutSuccessful inserted puzzle "+idparts[3]);\r
 \r
        return true;\r
 }\r
@@ -195,7 +201,9 @@ void IntroductionPuzzleInserter::StartInsert(const long localidentityid)
        FCPMessage message;\r
        std::string xmldata;\r
        std::string xmldatasizestr;\r
-       std::string privatekey;\r
+       std::string privatekey="";\r
+       std::string publickey="";\r
+       std::string keypart="";\r
 \r
        StringFunctions::Convert(localidentityid,idstring);\r
        now.SetToGMTime();\r
@@ -211,20 +219,29 @@ void IntroductionPuzzleInserter::StartInsert(const long localidentityid)
        }\r
        StringFunctions::Convert(index,indexstr);\r
 \r
-       SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";");\r
+       SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";");\r
        if(rs2.Empty()==false && rs2.GetField(0)!=NULL)\r
        {\r
                privatekey=rs2.GetField(0);\r
+               if(rs2.GetField(1))\r
+               {\r
+                       publickey=rs2.GetField(1);\r
+               }\r
+               if(publickey.size()>=50)\r
+               {\r
+                       // remove - and ~\r
+                       keypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~","");\r
+               }\r
        }\r
 \r
-       Option::instance()->Get("MessageBase",messagebase);\r
+       Option::Instance()->Get("MessageBase",messagebase);\r
 \r
        GenerateCaptcha(encodedpuzzle,solutionstring);\r
 \r
        xml.SetType("captcha");\r
-       xml.SetUUID(uuid.Generate());\r
+       xml.SetUUID(uuid.Generate()+"@"+keypart);\r
        xml.SetPuzzleData(encodedpuzzle);\r
-       xml.SetMimeType("bitmap/image");\r
+       xml.SetMimeType("image/bmp");\r
 \r
        xmldata=xml.GetXML();\r
        StringFunctions::Convert(xmldata.size(),xmldatasizestr);\r
@@ -240,6 +257,6 @@ void IntroductionPuzzleInserter::StartInsert(const long localidentityid)
        m_db->Execute("UPDATE tblLocalIdentity SET InsertingPuzzle='true' WHERE LocalIdentityID="+idstring+";");\r
        m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');");\r
 \r
-       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" started insert for id "+idstring);\r
+       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IntroductionPuzzleInserter::StartInsert started insert for id "+idstring);\r
 \r
 }\r