X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Fmessage.cpp;h=5861ef03eb021c6ee8659fbfc3fad44795ef819d;hp=2cfb5881ec8b3909e8fdbee1845b13f17f216c60;hb=b9c3763a932cebaa015a27fe111017f6f34dfbaa;hpb=37a8d59548287dcad78ef00e7b18058721eb9935 diff --git a/src/message.cpp b/src/message.cpp index 2cfb588..5861ef0 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -20,6 +20,27 @@ Message::Message(const long messageid) Load(messageid); } +const bool Message::CheckForAdministrationBoard(const std::vector &boards) +{ + std::string name; + SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName FROM tblBoard INNER JOIN tblAdministrationBoard ON tblBoard.BoardID=tblAdministrationBoard.BoardID;"); + st.Step(); + + while(st.RowReturned()) + { + st.ResultText(0,name); + + if(std::find(boards.begin(),boards.end(),name)!=boards.end()) + { + return true; + } + + st.Step(); + } + + return false; +} + const std::string Message::GetNNTPArticleID() const { return "<"+m_messageuuid+"@freenetproject.org>"; @@ -69,6 +90,108 @@ const std::string Message::GetNNTPHeaders() const return rval; } +void Message::HandleAdministrationMessage() +{ + // only continue if this message was actually a reply to another message + if(m_inreplyto.size()>0) + { + int boardid=0; + std::string boardname=""; + std::string identityname=""; + int identityid; + int changemessagetrust=0; + int changetrustlisttrust=0; + int origmessagetrust=0; + int origtrustlisttrust=0; + SQLite3DB::Statement st=m_db->Prepare("SELECT tblBoard.BoardID,BoardName,ModifyLocalMessageTrust,ModifyLocalTrustListTrust FROM tblBoard INNER JOIN tblAdministrationBoard ON tblBoard.BoardID=tblAdministrationBoard.BoardID;"); + st.Step(); + + while(st.RowReturned()) + { + st.ResultInt(0,boardid); + st.ResultText(1,boardname); + st.ResultInt(2,changemessagetrust); + st.ResultInt(3,changetrustlisttrust); + + if(std::find(m_boards.begin(),m_boards.end(),boardname)!=m_boards.end()) + { + SQLite3DB::Statement origmess=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentity.Name,tblIdentity.LocalMessageTrust,tblIdentity.LocalTrustListTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.MessageUUID=?;"); + origmess.Bind(0,m_inreplyto[0]); + origmess.Step(); + + if(origmess.RowReturned()) + { + origmess.ResultInt(0,identityid); + origmess.ResultText(1,identityname); + origmess.ResultInt(2,origmessagetrust); + origmess.ResultInt(3,origtrustlisttrust); + + origmessagetrust+=changemessagetrust; + origtrustlisttrust+=changetrustlisttrust; + + if(origmessagetrust<0) + { + origmessagetrust=0; + } + if(origmessagetrust>100) + { + origmessagetrust=100; + } + if(origtrustlisttrust<0) + { + origtrustlisttrust=0; + } + if(origtrustlisttrust>100) + { + origtrustlisttrust=100; + } + + // update new trust levels + SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=?, LocalTrustListTrust=? WHERE IdentityID=?;"); + update.Bind(0,origmessagetrust); + update.Bind(1,origtrustlisttrust); + update.Bind(2,identityid); + update.Step(); + + // insert message to show what id was changed and what current levels are + int lastid=0; + std::string messagebody; + std::string messagetruststr=""; + std::string trustlisttruststr=""; + UUIDGenerator uuid; + DateTime now; + now.SetToGMTime(); + StringFunctions::Convert(origmessagetrust,messagetruststr); + StringFunctions::Convert(origtrustlisttrust,trustlisttruststr); + messagebody="Trust Changed for "+identityname+"\r\n"; + messagebody+="Local Message Trust : "+messagetruststr+"\r\n"; + messagebody+="Local Trust List Trust : "+trustlisttruststr+"\r\n"; + SQLite3DB::Statement insert=m_db->Prepare("INSERT INTO tblMessage(FromName,MessageDate,MessageTime,Subject,MessageUUID,ReplyBoardID,Body) VALUES('FMS',?,?,?,?,?,?);"); + insert.Bind(0,now.Format("%Y-%m-%d")); + insert.Bind(1,now.Format("%H:%M:%S")); + insert.Bind(2,identityname+" Trust Changed"); + insert.Bind(3,uuid.Generate()); + insert.Bind(4,boardid); + insert.Bind(5,messagebody); + insert.Step(true); + lastid=insert.GetLastInsertRowID(); + + insert=m_db->Prepare("INSERT INTO tblMessageBoard(MessageID,BoardID) VALUES(?,?);"); + insert.Bind(0,lastid); + insert.Bind(1,boardid); + insert.Step(); + + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"Message::HandleAdministrationMessage updated "+identityname+" to "+messagetruststr+" , "+trustlisttruststr); + + } + } + + st.Step(); + } + } + +} + void Message::Initialize() { m_messageid=-1; @@ -386,6 +509,7 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) void Message::StartFreenetInsert() { + //TODO if message was posted to one of the special administration boards - don't really insert it, but perform the action MessageXML xml; int localidentityid=-1;