]> jfr.im git - irc/rizon/znc.git/commitdiff
Merge branch 'master' of https://github.com/pfn/znc
authorUli Schlachter <redacted>
Sat, 21 May 2011 11:58:29 +0000 (13:58 +0200)
committerUli Schlachter <redacted>
Sat, 21 May 2011 11:58:41 +0000 (13:58 +0200)
Conflicts:
modules/extra/away.cpp

Signed-off-by: Uli Schlachter <redacted>
1  2 
modules/extra/away.cpp

index 175a0c07efaa050d68ba15b06bc659bf583e3534,ed71e1bb39e979b84d9643a7e451d73593cfb8cd..0f939d050cac2d4793d3b7e57b11fad6ee4524bf
@@@ -11,8 -11,7 +11,9 @@@
  
  #define REQUIRESSL
  
++#include "Client.h"
  #include "User.h"
 +#include "FileUtils.h"
  #include <sys/stat.h>
  
  #define CRYPT_VERIFICATION_TOKEN "::__:AWAY:__::"
@@@ -33,139 -32,6 +34,148 @@@ protected
  
  class CAway : public CModule
  {
 +      void AwayCommand(const CString& sCommand) {
 +              CString sReason;
 +
 +              if (sCommand.Token(1) != "-quiet") {
 +                      sReason = sCommand.Token(1, true);
 +                      PutModNotice("You have been marked as away");
 +              } else {
 +                      sReason = sCommand.Token(2, true);
 +              }
 +
 +              Away(false, sReason);
 +      }
 +
 +      void BackCommand(const CString& sCommand) {
 +              if ((m_vMessages.empty()) && (sCommand.Token(1) != "-quiet"))
 +                      PutModNotice("Welcome Back!");
 +              Back();
 +      }
 +
 +      void MessagesCommand(const CString& sCommand) {
 +              for (u_int a = 0; a < m_vMessages.size(); a++)
 +                      PutModule(m_vMessages[a]);
 +      }
 +
++      void ReplayCommand(const CString& sCommand) {
++              CString nick = GetClient()->GetNick();
++              for (u_int a = 0; a < m_vMessages.size(); a++) {
++                      CString sWhom = m_vMessages[a].Token(1, false, ":");
++                      CString sMessage = m_vMessages[a].Token(2, true, ":");
++                      PutUser(":" + sWhom + " PRIVMSG " + nick + " :" + sMessage);
++              }
++      }
++
 +      void DeleteCommand(const CString& sCommand) {
 +              CString sWhich = sCommand.Token(1);
 +              if (sWhich == "all") {
 +                      PutModNotice("Deleted " + CString(m_vMessages.size()) + " Messages.");
 +                      for (u_int a = 0; a < m_vMessages.size(); a++)
 +                              m_vMessages.erase(m_vMessages.begin() + a--);
 +              } else if (sWhich.empty()) {
 +                      PutModNotice("USAGE: delete <num|all>");
 +                      return;
 +              } else {
 +                      u_int iNum = sWhich.ToUInt();
 +                      if (iNum >= m_vMessages.size()) {
 +                              PutModNotice("Illegal Message # Requested");
 +                              return;
 +                      } else {
 +                              m_vMessages.erase(m_vMessages.begin() + iNum);
 +                              PutModNotice("Message Erased.");
 +                      }
 +                      SaveBufferToDisk();
 +              }
 +      }
 +
 +      void SaveCommand(const CString& sCommand) {
 +              if (m_saveMessages) {
 +                      SaveBufferToDisk();
 +                      PutModNotice("Messages saved to disk.");
 +              } else {
 +                      PutModNotice("There are no messages to save.");
 +              }
 +      }
 +
 +      void PingCommand(const CString& sCommand) {
 +              Ping();
 +              if (m_bIsAway)
 +                      Back();
 +      }
 +
 +      void PassCommand(const CString& sCommand) {
 +              m_sPassword = sCommand.Token(1);
 +              PutModNotice("Password Updated to [" + m_sPassword + "]");
 +      }
 +
 +      void ShowCommand(const CString& sCommand) {
 +              map< CString, vector< CString> > msvOutput;
 +              for (u_int a = 0; a < m_vMessages.size(); a++) {
 +                      CString sTime = m_vMessages[a].Token(0, false, ":");
 +                      CString sWhom = m_vMessages[a].Token(1, false, ":");
 +                      CString sMessage = m_vMessages[a].Token(2, true, ":");
 +
 +                      if ((sTime.empty()) || (sWhom.empty()) || (sMessage.empty())) {
 +                              // illegal format
 +                              PutModule("Corrupt message! [" + m_vMessages[a] + "]");
 +                              m_vMessages.erase(m_vMessages.begin() + a--);
 +                              continue;
 +                      }
 +
 +                      time_t iTime = sTime.ToULong();
 +                      char szFormat[64];
 +                      struct tm t;
 +                      localtime_r(&iTime, &t);
 +                      size_t iCount = strftime(szFormat, 64, "%F %T", &t);
 +
 +                      if (iCount <= 0) {
 +                              PutModule("Corrupt time stamp! [" + m_vMessages[a] + "]");
 +                              m_vMessages.erase(m_vMessages.begin() + a--);
 +                              continue;
 +                      }
 +
 +                      CString sTmp = "    " + CString(a) + ") [";
 +                      sTmp.append(szFormat, iCount);
 +                      sTmp += "] ";
 +                      sTmp += sMessage;
 +                      msvOutput[sWhom].push_back(sTmp);
 +              }
 +
 +              for (map< CString, vector< CString> >::iterator it = msvOutput.begin(); it != msvOutput.end(); ++it) {
 +                      PutModule(it->first);
 +                      for (u_int a = 0; a < it->second.size(); a++)
 +                              PutModule(it->second[a]);
 +              }
 +
 +              PutModule("#--- End Messages");
 +      }
 +
 +      void EnableTimerCommand(const CString& sCommand) {
 +              SetAwayTime(300);
 +              PutModule("Timer set to 300 seconds");
 +      }
 +
 +      void DisableTimerCommand(const CString& sCommand) {
 +              SetAwayTime(0);
 +              PutModule("Timer disabled");
 +      }
 +
 +      void SetTimerCommand(const CString& sCommand) {
 +              int iSetting = sCommand.Token(1).ToInt();
 +
 +              SetAwayTime(iSetting);
 +
 +              if (iSetting == 0)
 +                      PutModule("Timer disabled");
 +              else
 +                      PutModule("Timer set to " + CString(iSetting) + " seconds");
 +      }
 +
 +      void TimerCommand(const CString& sCommand) {
 +              PutModule("Current timer setting: " + CString(GetAwayTime()) + " seconds");
 +      }
 +
  public:
        MODCONSTRUCTOR(CAway)
        {
                m_saveMessages = true;
                SetAwayTime(300);
                AddTimer(new CAwayJob(this, 60, 0, "AwayJob", "Checks for idle and saves messages every 1 minute"));
 +
 +              AddHelpCommand();
 +              AddCommand("Away",         static_cast<CModCommand::ModCmdFunc>(&CAway::AwayCommand),
 +                      "[-quiet]");
 +              AddCommand("Back",         static_cast<CModCommand::ModCmdFunc>(&CAway::BackCommand),
 +                      "[-quiet]");
 +              AddCommand("Messages",     static_cast<CModCommand::ModCmdFunc>(&CAway::BackCommand));
 +              AddCommand("Delete",       static_cast<CModCommand::ModCmdFunc>(&CAway::DeleteCommand),
 +                      "delete <num|all>");
 +              AddCommand("Save",         static_cast<CModCommand::ModCmdFunc>(&CAway::SaveCommand));
 +              AddCommand("Ping",         static_cast<CModCommand::ModCmdFunc>(&CAway::PingCommand));
 +              AddCommand("Pass",         static_cast<CModCommand::ModCmdFunc>(&CAway::PassCommand));
 +              AddCommand("Show",         static_cast<CModCommand::ModCmdFunc>(&CAway::ShowCommand));
++              AddCommand("Replay",       static_cast<CModCommand::ModCmdFunc>(&CAway::ReplayCommand));
 +              AddCommand("EnableTimer",  static_cast<CModCommand::ModCmdFunc>(&CAway::EnableTimerCommand));
 +              AddCommand("DisableTimer", static_cast<CModCommand::ModCmdFunc>(&CAway::DisableTimerCommand));
 +              AddCommand("SetTimer",     static_cast<CModCommand::ModCmdFunc>(&CAway::SetTimerCommand),
 +                      "<secs>");
 +              AddCommand("Timer",        static_cast<CModCommand::ModCmdFunc>(&CAway::TimerCommand));
 +
        }
 +
        virtual ~CAway()
        {
                if (!m_bBootError)