예제 #1
0
int IrcClient::OnNICK ( const IrcMessage& msg )
{
  if (events)
    events->OnNick (  msg.GetParameters()[0].c_str(), msg.GetPrefixNick().c_str() ); 
  
  return S_OK;
}
예제 #2
0
int IrcClient::OnKICK ( const IrcMessage& msg )
{
  if (events)
    events->OnKick ( msg.GetParameters()[0].c_str(), msg.GetPrefixNick().c_str(), msg.GetParameters()[1].c_str(),
		    msg.GetParameters().size() > 2 ? msg.GetParameters()[2].c_str() : "" );
  return S_OK;
}
예제 #3
0
int IrcClient::OnPRIVMSG ( const IrcMessage& msg )
{
  if (events)
    events->OnPrivmsg ( msg.GetPrefixNick().c_str(), msg.GetParameters()[0].c_str(),
		       msg.GetParameters()[1].c_str() );
  return S_OK;
}
예제 #4
0
/*!
    This is an overloaded function.

    This convenience function creates a new message from \a data, \a encoding and \a parent.
 */
IrcMessage* IrcMessage::fromData(const QByteArray& data, const QByteArray& encoding, QObject* parent)
{
    IrcMessage* message = fromData(data, parent);
    if (message)
        message->setEncoding(encoding);
    return message;
}
예제 #5
0
/*!
    Creates a new message from \a data and \a parent.
 */
IrcMessage* IrcMessage::fromData(const QByteArray& data, QObject* parent)
{
    IrcMessage* message = 0;

    IrcParser parser;
    if (parser.parse(data))
    {
        const QMetaObject* metaObject = irc_command_meta_object(parser.command());
        Q_ASSERT(metaObject);
        message = qobject_cast<IrcMessage*>(metaObject->newInstance(Q_ARG(QObject*, parent)));
        Q_ASSERT(message);
        message->d_ptr->parser = parser;

        IrcSession* session = qobject_cast<IrcSession*>(parent);
        if (session)
        {
            IrcSender sender = message->sender();
            if (sender.isValid() && sender.name() == session->nickName())
                message->d_ptr->flags |= Own;

            if (session->d_ptr->capabilities.contains("identify-msg") &&
               (message->d_ptr->type == Private || message->d_ptr->type == Notice))
            {
                QString msg = message->property("message").toString();
                if (msg.startsWith("+"))
                    message->d_ptr->flags |= Identified;
                else if (msg.startsWith("-"))
                    message->d_ptr->flags |= Unidentified;
            }
        }
    }
    return message;
}
예제 #6
0
void IrcMessageComposer::finishCompose(IrcMessage* message)
{
    if (!d.messages.isEmpty()) {
        IrcMessage* composed = d.messages.pop();
        composed->setTimeStamp(message->timeStamp());
        if (message->testFlag(IrcMessage::Implicit))
            composed->setFlag(IrcMessage::Implicit);
        emit messageComposed(composed);
    }
}
예제 #7
0
/*!
    Creates a new message from \a prefix, \a command and \a parameters with \a connection.
 */
IrcMessage* IrcMessage::fromParameters(const QString& prefix, const QString& command, const QStringList& parameters, IrcConnection* connection)
{
    IrcMessage* message = 0;
    const QMetaObject* metaObject = irc_command_meta_object(command);
    if (metaObject) {
        message = qobject_cast<IrcMessage*>(metaObject->newInstance(Q_ARG(IrcConnection*, connection)));
        Q_ASSERT(message);
        message->setPrefix(prefix);
        message->setCommand(command);
        message->setParameters(parameters);
    }
    return message;
}
예제 #8
0
void tst_IrcMessage::testNoticeMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, target);
    QFETCH(QString, content);
    QFETCH(bool, priv);
    QFETCH(bool, reply);

    IrcConnection connection;
    connection.setNickName("communi");
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Notice);
    QCOMPARE(message->command(), QString("NOTICE"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("target").toString(), target);
    QCOMPARE(message->property("content").toString(), content);
    QCOMPARE(message->property("private").toBool(), priv);
    QCOMPARE(message->property("reply").toBool(), reply);

    IrcNoticeMessage* noticeMessage = qobject_cast<IrcNoticeMessage*>(message);
    QVERIFY(noticeMessage);
    QCOMPARE(noticeMessage->isValid(), valid);
    QCOMPARE(noticeMessage->target(), target);
    QCOMPARE(noticeMessage->content(), content);
    QCOMPARE(noticeMessage->isPrivate(), priv);
    QCOMPARE(noticeMessage->isReply(), reply);
}
예제 #9
0
	QObject* ServerParticipantEntry::CreateMessage (IMessage::MessageType,
			const QString&, const QString& body)
	{
 		IrcMessage *message = new IrcMessage (IMessage::MTChatMessage,
				IMessage::DOut,
				ISH_->GetServerID (),
				Nick_,
				Account_->GetClientConnection ().get ());

		message->SetBody (body);
		message->SetDateTime (QDateTime::currentDateTime ());

		return message;
	}
예제 #10
0
void tst_IrcMessage::testNumericMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(int, code);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Numeric);
    QVERIFY(message->command().toInt() > 0);
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("code").toInt(), code);

    IrcNumericMessage* numericMessage = qobject_cast<IrcNumericMessage*>(message);
    QVERIFY(numericMessage);
    QCOMPARE(numericMessage->isValid(), valid);
    QCOMPARE(numericMessage->code(), code);
}
예제 #11
0
void tst_IrcMessage::testJoinMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, channel);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Join);
    QCOMPARE(message->command(), QString("JOIN"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("channel").toString(), channel);

    IrcJoinMessage* joinMessage = qobject_cast<IrcJoinMessage*>(message);
    QVERIFY(joinMessage);
    QCOMPARE(joinMessage->isValid(), valid);
    QCOMPARE(joinMessage->channel(), channel);
}
예제 #12
0
void tst_IrcMessage::testErrorMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, error);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Error);
    QCOMPARE(message->command(), QString("ERROR"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("error").toString(), error);

    IrcErrorMessage* errorMessage = qobject_cast<IrcErrorMessage*>(message);
    QVERIFY(errorMessage);
    QCOMPARE(errorMessage->isValid(), valid);
    QCOMPARE(errorMessage->error(), error);
}
예제 #13
0
void tst_IrcMessage::testQuitMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, reason);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Quit);
    QCOMPARE(message->command(), QString("QUIT"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("reason").toString(), reason);

    IrcQuitMessage* quitMessage = qobject_cast<IrcQuitMessage*>(message);
    QVERIFY(quitMessage);
    QCOMPARE(quitMessage->isValid(), valid);
    QCOMPARE(quitMessage->reason(), reason);
}
예제 #14
0
파일: joinchans.cpp 프로젝트: S1M0NE/IrcBot
bool JoinChans::onChannelMessage(IrcModuleConnection& connection, IrcMessage& message) {
	if(connection.getNick() == message.getUsername()) {
		return true;
	}

	std::vector<JoinedChannel>::iterator iter;
	for(iter=mTranslateMap.begin(); iter!=mTranslateMap.end(); ++iter) {
		if((*iter).fromChannel == message.target && ((*iter).fromChannelServerID.empty() || (*iter).fromChannelServerID == connection.getID())) {
			if((*iter).fromChannelServerID == (*iter).toChannelServerID || (*iter).toChannelServerID.empty()) {
				connection.sendMessage((*iter).toChannel, "<"+message.getUsername()+"> "+message.params);
			}
			else {
				mIRC.getConnection((*iter).toChannelServerID).sendMessage((*iter).toChannel, "<"+message.getUsername()+"> "+message.params);
			}
		}
	}

	return true;
}
예제 #15
0
void tst_IrcMessage::testNickMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, oldNick);
    QFETCH(QString, newNick);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Nick);
    QCOMPARE(message->command(), QString("NICK"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("oldNick").toString(), oldNick);
    QCOMPARE(message->property("newNick").toString(), newNick);

    IrcNickMessage* nickMessage = qobject_cast<IrcNickMessage*>(message);
    QVERIFY(nickMessage);
    QCOMPARE(nickMessage->isValid(), valid);
    QCOMPARE(nickMessage->oldNick(), oldNick);
    QCOMPARE(nickMessage->newNick(), newNick);
}
예제 #16
0
void tst_IrcMessage::testPrivateMessage()
{
    QFETCH(bool, valid);
    QFETCH(QString, cap);
    QFETCH(QByteArray, data);
    QFETCH(QString, target);
    QFETCH(QString, content);
    QFETCH(bool, priv);
    QFETCH(bool, action);
    QFETCH(bool, request);
    QFETCH(uint, flags);

    IrcConnection connection;
    connection.setNickName("communi");
    TestProtocol protocol(cap, &connection);
    static_cast<FriendConnection*>(&connection)->setProtocol(&protocol);

    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Private);
    QCOMPARE(message->command(), QString("PRIVMSG"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("target").toString(), target);
    QCOMPARE(message->property("content").toString(), content);
    QCOMPARE(message->property("private").toBool(), priv);
    QCOMPARE(message->property("action").toBool(), action);
    QCOMPARE(message->property("request").toBool(), request);
    QCOMPARE(message->property("flags").toUInt(), flags);

    IrcPrivateMessage* privateMessage = qobject_cast<IrcPrivateMessage*>(message);
    QVERIFY(privateMessage);
    QCOMPARE(privateMessage->isValid(), valid);
    QCOMPARE(privateMessage->target(), target);
    QCOMPARE(privateMessage->content(), content);
    QCOMPARE(privateMessage->isPrivate(), priv);
    QCOMPARE(privateMessage->isAction(), action);
    QCOMPARE(privateMessage->isRequest(), request);
    QCOMPARE(static_cast<uint>(privateMessage->flags()), flags);
}
예제 #17
0
int IrcClient::WaitResponse (int response )
{
  char buf[1024];
  IrcMessage msg;
  
  while (true)
    {
      int res = socket.ReadMessage ( buf );
      if (res > 0)
	{
	  std::printf ("IRC MESSAGE: %s\n", buf );
	  msg = IrcMessage ( 0, buf, true );

	  if ( (res = DispatchMessage ( msg )) != S_OK)
	    return res;
	  		   
	  if ( msg.GetResponse() == response ||
	       msg.GetResponse() >= 400  /* error */ )
	    return msg.GetResponse();
	}
    }
  return S_OK;
}
예제 #18
0
	void IrcServerHandler::IncomingMessage (const QString& nick,
			const QString& target, const QString& msg, IMessage::Type type)
	{
		if (ChannelsManager_->IsChannelExists (target))
			ChannelsManager_->ReceivePublicMessage (target, nick, msg);
		else
		{
			//TODO Work only for exists entries
			IrcMessage *message = new IrcMessage (type,
					IMessage::Direction::In,
					ServerID_,
					nick,
					Account_->GetClientConnection ().get ());
			message->SetBody (msg);
			message->SetDateTime (QDateTime::currentDateTime ());

			bool found = false;
			for (const auto entryObj : ChannelsManager_->GetParticipantsByNick (nick))
			{
				const auto entry = qobject_cast<EntryBase*> (entryObj);
				if (!entry)
					continue;

				found = true;
				entry->HandleMessage (message);
			}

			if (!found)
			{
				if (Nick2Entry_.contains (nick))
					Nick2Entry_ [nick]->HandleMessage (message);
				else
					GetParticipantEntry (nick)->HandleMessage (message);
			}
		}
	}
예제 #19
0
int IrcClient::DispatchResponse ( const IrcMessage &msg )
{
  switch (msg.GetResponse ())
    {
    case 376: //End of MOTD command
      is_registered = true;
      if (events)
	events->OnRegistered ();
      break;
    }

  if (events)
    events->OnResponse ( msg );
  
  return S_OK;
}
예제 #20
0
int IrcClient::DispatchMessage ( const IrcMessage& msg )
{

  IRC_DISPATCH_MESSAGE(msg, PRIVMSG);  
  IRC_DISPATCH_MESSAGE(msg, PING);   
  IRC_DISPATCH_MESSAGE(msg, JOIN);   
  IRC_DISPATCH_MESSAGE(msg, NICK);
  IRC_DISPATCH_MESSAGE(msg, QUIT);    
  IRC_DISPATCH_MESSAGE(msg, PART);
  IRC_DISPATCH_MESSAGE(msg, KICK);
  IRC_DISPATCH_MESSAGE(msg, KILL);

  if (msg.IsResponse () )
    return DispatchResponse ( msg );
  
  return S_OK;
}
예제 #21
0
void tst_IrcMessage::testPongMessage()
{
    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData("PONG tgt :arg", &connection);
    QCOMPARE(message->type(), IrcMessage::Pong);
    QCOMPARE(message->command(), QString("PONG"));
    QCOMPARE(message->property("command").toString(), QString("PONG"));
    QVERIFY(message->property("valid").toBool());
    QCOMPARE(message->property("argument").toString(), QString("arg"));

    IrcPongMessage* pongMessage = qobject_cast<IrcPongMessage*>(message);
    QVERIFY(pongMessage);
    QVERIFY(pongMessage->isValid());
    QCOMPARE(pongMessage->argument(), QString("arg"));
}
예제 #22
0
void tst_IrcMessage::testModeMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, target);
    QFETCH(QString, mode);
    QFETCH(QString, argument);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Mode);
    QCOMPARE(message->command(), QString("MODE"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("target").toString(), target);
    QCOMPARE(message->property("mode").toString(), mode);
    QCOMPARE(message->property("argument").toString(), argument);

    IrcModeMessage* modeMessage = qobject_cast<IrcModeMessage*>(message);
    QVERIFY(modeMessage);
    QCOMPARE(modeMessage->isValid(), valid);
    QCOMPARE(modeMessage->target(), target);
    QCOMPARE(modeMessage->mode(), mode);
    QCOMPARE(modeMessage->argument(), argument);
}
예제 #23
0
void tst_IrcMessage::testTopicMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, channel);
    QFETCH(QString, topic);
    QFETCH(bool, reply);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Topic);
    QCOMPARE(message->command(), QString("TOPIC"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("channel").toString(), channel);
    QCOMPARE(message->property("topic").toString(), topic);
    QCOMPARE(message->property("reply").toBool(), reply);

    IrcTopicMessage* topicMessage = qobject_cast<IrcTopicMessage*>(message);
    QVERIFY(topicMessage);
    QCOMPARE(topicMessage->isValid(), valid);
    QCOMPARE(topicMessage->channel(), channel);
    QCOMPARE(topicMessage->topic(), topic);
    QCOMPARE(topicMessage->isReply(), reply);
}
예제 #24
0
void tst_IrcMessage::testKickMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, channel);
    QFETCH(QString, user);
    QFETCH(QString, reason);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Kick);
    QCOMPARE(message->command(), QString("KICK"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("channel").toString(), channel);
    QCOMPARE(message->property("user").toString(), user);
    QCOMPARE(message->property("reason").toString(), reason);

    IrcKickMessage* kickMessage = qobject_cast<IrcKickMessage*>(message);
    QVERIFY(kickMessage);
    QCOMPARE(kickMessage->isValid(), valid);
    QCOMPARE(kickMessage->channel(), channel);
    QCOMPARE(kickMessage->user(), user);
    QCOMPARE(kickMessage->reason(), reason);
}
예제 #25
0
void tst_IrcMessage::testCapabilityMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, subCommand);
    QFETCH(QStringList, capabilities);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Capability);
    QCOMPARE(message->command(), QString("CAP"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("subCommand").toString(), subCommand);
    QCOMPARE(message->property("capabilities").toStringList(), capabilities);

    IrcCapabilityMessage* capabilityMessage = qobject_cast<IrcCapabilityMessage*>(message);
    QVERIFY(capabilityMessage);
    QCOMPARE(capabilityMessage->isValid(), valid);
    QCOMPARE(capabilityMessage->subCommand(), subCommand);
    QCOMPARE(capabilityMessage->capabilities(), capabilities);
}
예제 #26
0
void tst_IrcMessage::testPartMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, channel);
    QFETCH(QString, reason);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Part);
    QCOMPARE(message->command(), QString("PART"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("channel").toString(), channel);
    QCOMPARE(message->property("reason").toString(), reason);

    IrcPartMessage* partMessage = qobject_cast<IrcPartMessage*>(message);
    QVERIFY(partMessage);
    QCOMPARE(partMessage->isValid(), valid);
    QCOMPARE(partMessage->channel(), channel);
    QCOMPARE(partMessage->reason(), reason);
}
예제 #27
0
void tst_IrcMessage::testInviteMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, channel);
    QFETCH(QString, user);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Invite);
    QCOMPARE(message->command(), QString("INVITE"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("channel").toString(), channel);
    QCOMPARE(message->property("user").toString(), user);

    IrcInviteMessage* inviteMessage = qobject_cast<IrcInviteMessage*>(message);
    QVERIFY(inviteMessage);
    QCOMPARE(inviteMessage->isValid(), valid);
    QCOMPARE(inviteMessage->channel(), channel);
    QCOMPARE(inviteMessage->user(), user);
}
예제 #28
0
void IrcSessionPrivate::processLine(const QByteArray& line)
{
    Q_Q(IrcSession);

    QString encoded = encoder.encode(line);
    static bool dbg = qgetenv("COMMUNI_DEBUG").toInt();
    if (dbg) qDebug() << encoded;

    IrcMessage* msg = IrcMessage::fromString(encoded);
    if (msg)
    {
        switch (msg->type())
        {
        case IrcMessage::Numeric:
            if (static_cast<IrcNumericMessage*>(msg)->code() == Irc::RPL_WELCOME)
            {
                setNick(msg->parameters().value(0));
                connected = true;
                emit q->connected();
                emit q->connectedChanged(true);
            }
            else if (static_cast<IrcNumericMessage*>(msg)->code() == Irc::RPL_ISUPPORT)
            {
                foreach (const QString& param, msg->parameters().mid(1))
                {
                    const QStringList keyValue = param.split("=", QString::SkipEmptyParts);
                    info.insert(keyValue.value(0), keyValue.value(1));
                }
            }
            break;
        case IrcMessage::Ping:
            q->sendRaw("PONG " + static_cast<IrcPingMessage*>(msg)->argument());
            break;
        case IrcMessage::Private: {
            IrcPrivateMessage* privMsg = static_cast<IrcPrivateMessage*>(msg);
            if (privMsg->isRequest())
            {
                QString reply;
                QString request = privMsg->message().split(" ", QString::SkipEmptyParts).value(0).toUpper();
                if (request == "PING")
                    reply = privMsg->message();
                else if (request == "TIME")
                    reply = "TIME " + QLocale().toString(QDateTime::currentDateTime(), QLocale::ShortFormat);
                else if (request == "VERSION")
                    reply = QString("VERSION Communi ") + Irc::version();
                if (!reply.isNull())
                    q->sendCommand(IrcCommand::createCtcpReply(msg->sender().name(), reply));
            }
            break;
            }
        case IrcMessage::Nick:
            if (msg->sender().name() == nickName)
                setNick(static_cast<IrcNickMessage*>(msg)->nick());
            break;
        default:
            break;
        }

        emit q->messageReceived(msg);
        msg->deleteLater();
    }
예제 #29
0
파일: bot.cpp 프로젝트: thiezn/bot2learn
int IrcBot::start()				// overloading IrcClient::start()
{
  char buf[MAXDATASIZE];			// This will hold the socket recv buffer
  IrcMessage ircMsg;				// This will be used to parse and send Irc messages

  string parameters;     	                // parameters to be sent to IRC server using IrcMessage::send(socket, command, parameters) function
 
  rawsock rawsockfd;				// initialise the raw socket for our SYN packet sender

  while(sockfd.in(buf))
  {
    
    ircMsg.recv(buf);			           // This will parse the received message into seperate variables for easy matching

    if(ircMsg.command == "PING")                   // IRC server sends occational PING message. client has to reply within 30 seconds otherwise will be disconnected
    {
      ircMsg.send(sockfd, "PONG", ircMsg.parameters);
    }

    else if(ircMsg.command == "PRIVMSG")                 // Check if we receive a PRIVMSG
    {
      if(ircMsg.parameters.find(":!shutdown") == 0)
      {
        ircMsg.send(sockfd, "PRIVMSG", "#ThieZn Shutting down myself, was nice to see you again!");

        sockfd.unlink(); 
        cout << endl << endl << "Closed socket, shutting down bot..." << endl << "Thanks, please come again!" << endl << endl;

        return 0;
      }

      else if(ircMsg.parameters.find(":!restart") == 0)
      {
        ircMsg.send(sockfd, "PRIVMSG", "#ThieZn Restarting... bear with me, i should be right back!");

        sockfd.unlink();
        cout << endl << endl << "Closed socket, preparing to restart bot..." << endl << endl;

        return 1;
      }

      else if(ircMsg.parameters.find(":!send") == 0)
      {
        ircMsg.parameters.erase(0, 7);

        if(ircMsg.parameters.find("syn") == 0)
        {
          for(int i = 0; i < 10; i++)
          {
            rawsockfd.sendSYN("10.0.0.1", "127.0.0.1", 6667);
          }
        }
      }

      else if(ircMsg.parameters.find(":!set") == 0)
      {
        ircMsg.parameters.erase(0, 6);					// remove the ":!set " string so we end up with the command

        if(ircMsg.parameters.find("nick") == 0)				// check if we want to change the nick
        {
          ircMsg.parameters.erase(0, 5);				// remove the string 'nick ' from the parameters
          nick = ircMsg.parameters.c_str();				// use all the rest of the parameter string as a nickname

	  ircMsg.send(sockfd, "NICK", nick); 
        } 

        else if(ircMsg.parameters.find("meToOps") == 0)			// promote the user that asks to channel operator
        {
	  parameters = "CHANSERV OP "; 
          parameters += ircMsg.prefixNick.c_str(); 
          parameters += " "; parameters += channel;

          ircMsg.send(sockfd, "PRIVMSG", parameters);
        }

      } // end of !set commands
 
      else if(ircMsg.parameters.find(":!get") == 0)
      {
        ircMsg.parameters.erase(0, 6);

        if(ircMsg.parameters.find("time") == 0)
        {
           parameters = channel; 
           parameters += " my local time is "; 
           parameters += currentDateTime().c_str();

           ircMsg.send(sockfd, "PRIVMSG", parameters);
        }

      }	// end of !get commands

    } // end of PRIVMSG commands

  } // end of while loop (Bot will drop connection)

  sockfd.unlink();							// close the socket as we're no longer receiving data
  return 0;
}
예제 #30
0
int IrcClient::OnPING ( const IrcMessage& msg )
{
  socket.printf("PONG %s\r\n", msg.GetParameters()[0].c_str() );
  return S_OK;
}