/**
 * RELEASECommand.cc
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 *
 * This command allows a user to release their nick if it has been juped.
 */

#include <ctime>

#include "Network.h"

#include "nickserv.h"

namespace gnuworld
{

namespace ns
{

using std::string;

bool RELEASECommand::Exec(iClient* theClient, const string& )
{
bot->theStats->incStat("NS.CMD.RELEASE");

string account = theClient->getAccount();

if(account.empty()) {
  bot->Notice(theClient, "You have not authenticated. Please login before"
                         " trying to use RELEASE.");
  return false;
}

iClient *fakeClient = Network->findNick(account);

if(fakeClient == 0 || ! fakeClient->isFake()) {
  bot->Notice(theClient, "No jupe exists for %s.",
              account.c_str()
             );
  return false;
}

/* The fakeClient now points to the juped client */
bot->getUplink()->DetachClient(fakeClient, "Jupe released.");
delete fakeClient;

bot->Notice(theClient, "%s successfully released.",
            account.c_str()
           );

return true;
} // RELEASECommand::Exec(iClient*, const string&)

} // namespace ns

} // namespace gnuworld
