int main( int argc, char *argv[] ) { QApplication app( argc, argv ); IRCClient *irc = new IRCClient(); MessageHandler *mh = new MessageHandler( irc ); QObject::connect( &app, SIGNAL( aboutToQuit() ), irc, SLOT( quit() ) ); mh->show(); irc->connectAndRegister( argc > 1 ? argv[1] : "dev1", 6667, argc > 2 ? argv[2] : "Test", "correlr", "Correl Roush" ); return app.exec(); }
int main(int argc, char* argv[]) { if (argc < 3) { std::cout << "Insuficient parameters: host port [nick] [user]" << std::endl; return 1; } char* host = argv[1]; int port = atoi(argv[2]); std::string nick("MyIRCClient"); std::string user("IRCClient"); if (argc >= 4) nick = argv[3]; if (argc >= 5) user = argv[4]; IRCClient client; client.Debug(true); // Start the input thread Thread thread; thread.Start(&inputThread, &client); if (client.InitSocket()) { std::cout << "Socket initialized. Connecting..." << std::endl; if (client.Connect(host, port)) { std::cout << "Connected. Loggin in..." << std::endl; if (client.Login(nick, user)) { std::cout << "Logged." << std::endl; running = true; signal(SIGINT, signalHandler); while (client.Connected() && running) client.ReceiveData(); } if (client.Connected()) client.Disconnect(); std::cout << "Disconnected." << std::endl; } } }
int main ( int argc, char *argv[] ) { client.setDebugLevel(5); // clear the log fclose(fopen("irc.log","wt")); fclose(fopen("botlog.log","wt")); // set the log client.setLogfile("irc.log"); client.registerEventHandler(eIRCNoticeEvent,&startupCallback); client.registerCommandHandler(&allCallback); client.connect("irc.efnet.net",6667); std::string name = std::string("billybot"); std::string username = std::string("billy"); std::string meh = std::string(""); std::string fullname = std::string("William Shatner"); client.login(name, username, meh, fullname); while (client.process()) { IRCOSSleep(1); } return 0; }
int main(){ char* host = "irc.freenode.net"; int port = 6667; std::string nick("MyIRCBot2"); std::string user("IRCClient"); IRCClient client; client.Debug(true); if (client.InitSocket()) { std::cout << "Socket initialized. Connecting..." << std::endl; if (client.Connect(host, port)) { std::cout << "Connected. Loggin in..." << std::endl; if (client.Login(nick, user)) { std::cout << "Logged." << std::endl; client.SendIRC("JOIN #mybottest"); while (client.Connected()) client.ReceiveData(); } if (client.Connected()) client.Disconnect(); std::cout << "Disconnected." << std::endl; } } return 0; }
void Container::newStatusWindow(const QString &server, const int port) { // Create the new status window StatusWindow *statusWindow = new StatusWindow(mdiArea, parser); statusWindow->setWindowTitle(tr("Not Connected")); // Create the new IRCClient IRCClient *client = new IRCClient(this); statusWindow->setClient(client); // Add an entry in the window tree this->windowTree->addStatusWindow(client->cid, server, statusWindow); QHash<QString, MdiWindow *> windowHash; windowHash.insert(statusWindow->hashName(), statusWindow); this->windows.insert(client->cid, windowHash); if ((!server.isEmpty()) && (port > 0)) { // TODO: Connect to the server statusWindow->append(Config::Theme("INFO"),"--- Connecting to " + server + " (" + QString::number(port) + ")"); client->connectToHost(server, port); } // Connect the IRCClient signals to the Container slots connect(client, SIGNAL(connected(IRCClient *)), this, SLOT(connected(IRCClient *))); connect(client, SIGNAL(disconnected(IRCClient *)), this, SLOT(disconnected(IRCClient *))); //connect(client, SIGNAL(ircError(IRCClient *, QAbstractSocket::SocketError)), this, SLOT(ircError(IRCClient *, QAbstractSocket::SocketError))); connect(client, SIGNAL(privateMessageReceived(IRCClient *, const QString &, const QString &, const QString &)), this, SLOT(privateMessageReceived(IRCClient *, const QString &, const QString &, const QString &))); connect(client, SIGNAL(channelMessageReceived(IRCClient *, const QString &, const QString &, const QString &, const QString &, const QString &)), this, SLOT(channelMessageReceived(IRCClient *, const QString &, const QString &, const QString &, const QString &, const QString &))); connect(client, SIGNAL(incomingData(IRCClient *, const QString &)), this, SLOT(incomingData(IRCClient *, const QString &))); connect(client, SIGNAL(channelJoined(IRCClient *, const QString &, const QString &)), this, SLOT(channelJoined(IRCClient *, const QString &, const QString &))); connect(client, SIGNAL(channelParted(IRCClient *, const QString &, const QString &)), this, SLOT(channelParted(IRCClient *, const QString &, const QString &))); connect(client, SIGNAL(channelJoinCompleteNickList(IRCClient *, const QString &, const QStringList &)), this, SLOT(channelJoinCompleteNickList(IRCClient *, const QString &, const QStringList &))); // connect the new status button to new status window connect(statusWindow, SIGNAL(newStatusWin()), this, SLOT(newStatusWindow())); connect(statusWindow, SIGNAL(closeEventTriggered(const int, const QString &)), this, SLOT(subWindowClosed(const int, const QString &))); statusWindow->show(); }
void monitorIRC(void* i) { IRCClient* ircc = (IRCClient*)((IRCManager*)i)->ircc; std::string data; data = ircc->readRaw(); ircc->setServerName(data.substr(1, data.find_first_of(" ") -1)); while(true) { data = ircc->readRaw(); // Check if connection was lost if(data.empty()) { // Close connections and exit ((IRCManager*)i)->stop(); return; } std::cout << data; fflush(stdout); // Handle data parseData(ircc, data, ((IRCManager*)i)->getIRCCommandPrefix()); } }
MainUI::MainUI(QtEnvironment& env, SimpleSetup& setup, IRCClient& client) : client(client) { ui = new Ui::MainUI(); ui->setupUi(this); ui->topLayout->addWidget(env.GetGLWidget()); client.JoinedChannelEvent().Attach(*this); chan = NULL; show(); }
bool myEndMOTDCallback::process ( IRCClient &ircClient, teIRCEventType eventType, trBaseEventInfo &info ) { printf("********************** starting up ************************\n"); ircClient.join("#libirc"); return true; }
IRCCity::IRCCity(IRCClient& c, ISceneNode* n, TextureLoader& l) : client(c),root(n), loader(l) { c.JoinedChannelEvent().Attach(*this); }
DWORD JoinGameDelegate::onMessage(SimObject *sender, DWORD msg) { //get the root SimGui::Canvas *root; if (curGui) root = curGui->getCanvas(); else return Parent::onMessage(sender, msg); if (! root) return -1; IRCClient *objIRCClient = static_cast<IRCClient *>(IRCClient::find(manager)); AssertFatal(objIRCClient, "JoinDelegate: could not locate IRC client"); //check for a new MOTD verifyMasterMOTD(); if (msg == IDCTG_SERVER_REFRESH_LIST) { mbMasterTimedOut = FALSE; Console->evaluate("rebuildServerList();", FALSE); if (cg.gameServerList) cg.gameServerList->rebuildList(); //grey out the refresh button SimGui::ActiveCtrl *ctrl = dynamic_cast<SimGui::ActiveCtrl*>(curGui->findControlWithTag(IDCTG_SERVER_REFRESH_LIST)); if (ctrl) ctrl->active = FALSE; ctrl = dynamic_cast<SimGui::ActiveCtrl*>(curGui->findControlWithTag(IDCTG_SERVER_REFRESH_VISIBLE)); if (ctrl) ctrl->active = FALSE; //initialize the progress controls FearGui::FearGuiBox *boxCtrl = dynamic_cast<FearGui::FearGuiBox*>(curGui->findControlWithTag(IDCTG_SERVER_REFRESH_BOX)); if (boxCtrl) { boxCtrl->setVisible(TRUE); boxCtrl->setUpdate(); } SimGui::ProgressCtrl *prog = dynamic_cast<SimGui::ProgressCtrl*>(curGui->findControlWithTag(IDCTG_SERVER_REFRESH_PROGRESS)); if (prog) prog->setPercentDone(0.0f); SimGui::SimpleText *textCtrl = dynamic_cast<SimGui::SimpleText*>(curGui->findControlWithTag(IDCTG_SERVER_REFRESH_TEXT)); if (textCtrl) { bool lanOnly = Console->getBoolVariable("pref::lanOnly", false) || Console->getIntVariable("Server::NumMasters", 0) == 0; if (lanOnly) textCtrl->setText("Searching for LAN servers"); else textCtrl->setText("Querying master servers"); } return -1; } else if (msg == IDCTG_SERVER_REFRESH_VISIBLE) { mbMasterTimedOut = TRUE; bool result = FALSE; if (cg.gameServerList) { result = cg.gameServerList->refreshVisible(); } if (! result) return -1; //grey out the refresh button SimGui::ActiveCtrl *ctrl = dynamic_cast<SimGui::ActiveCtrl*>(curGui->findControlWithTag(IDCTG_SERVER_REFRESH_LIST)); if (ctrl) ctrl->active = FALSE; ctrl = dynamic_cast<SimGui::ActiveCtrl*>(curGui->findControlWithTag(IDCTG_SERVER_REFRESH_VISIBLE)); if (ctrl) ctrl->active = FALSE; //initialize the progress controls FearGui::FearGuiBox *boxCtrl = dynamic_cast<FearGui::FearGuiBox*>(curGui->findControlWithTag(IDCTG_SERVER_REFRESH_BOX)); if (boxCtrl) { boxCtrl->setVisible(TRUE); boxCtrl->setUpdate(); } SimGui::ProgressCtrl *prog = dynamic_cast<SimGui::ProgressCtrl*>(curGui->findControlWithTag(IDCTG_SERVER_REFRESH_PROGRESS)); if (prog) prog->setPercentDone(0.0f); SimGui::SimpleText *textCtrl = dynamic_cast<SimGui::SimpleText*>(curGui->findControlWithTag(IDCTG_SERVER_REFRESH_TEXT)); if (textCtrl) { textCtrl->setText("Pinging visible servers"); } return -1; } else if (msg == IDCTG_SERVER_REFRESH_CANCEL) { if (cg.csDelegate) { cg.csDelegate->clearPingRequestList(); cg.csDelegate->clearGameRequestList(); } if (cg.gameServerList) cg.gameServerList->rebuildCancel(); mbMasterTimedOut = TRUE; queryFinished(); return -1; } else if (msg == IDDLG_MASTER_MOTD) { char buf[1024]; const char *newMOTD; const char *name; newMOTD = Console->getVariable("pref::MSMOTD"); name = Console->getVariable("pref::MSName"); //push the dialog Console->executef(3, "GuiPushDialog", "MainWindow", "gui\\MasterMOTD.gui"); //set the server name in the dialog box sprintf(buf, "<f1>Message of the day from: %s<f0>\n\n", name); int length = 1023 - strlen(buf); strncpy(&buf[strlen(buf)], newMOTD, length); buf[1023] = '\0'; //set the message of the day in the dialog box FearGui::FGTextFormat *motd = dynamic_cast<FearGui::FGTextFormat*>(root->getTopDialog()->findControlWithTag(IDCTG_MASTER_MOTD)); if (motd) motd->formatControlString(buf, motd->extent.x); //now update the pref variable Console->setVariable("pref::MSprevMOTD", newMOTD); verifyMasterMOTD(); return -1; } else if (msg == IDCTG_SERVER_JOIN) { if (cg.csDelegate) { cg.csDelegate->clearPingRequestList(); cg.csDelegate->clearGameRequestList(); } if (cg.gameServerList) cg.gameServerList->rebuildCancel(); mbMasterTimedOut = TRUE; queryFinished(); //find the server list ctrl, and the server info FearGui::ServerListCtrl *slCtrl = (FearGui::ServerListCtrl*)curGui->findControlWithTag(IDCTG_SERVER_SELECT_LIST); FearCSDelegate::ServerInfo *info = NULL; bool infoAvail; if (slCtrl) info = slCtrl->getServerSelected(infoAvail); if (! info) return -1; //see if the server requires a password if (info->password) { CMDConsole::getLocked()->executef(3, "GuiPushDialog", "MainWindow", "gui\\Password.gui"); } else { //join the game... if (Console->getBoolVariable("$IRC::BroadcastIP")) { objIRCClient->onJoinServer(info->missionName, info->name, Console->getVariable("$Server::Address"), false, info->password); } Console->evaluate("JoinGame();", FALSE); } return -1; } else if (msg == IDCTG_SERVER_JOIN_PASSWORD) { //kill the dialog root->makeFirstResponder(NULL); root->popDialogControl(); //join the game... if (Console->getBoolVariable("$IRC::BroadcastIP")) { //find the server list ctrl, and the server info FearGui::ServerListCtrl *slCtrl = (FearGui::ServerListCtrl*)curGui->findControlWithTag(IDCTG_SERVER_SELECT_LIST); FearCSDelegate::ServerInfo *info = NULL; bool infoAvail; if (slCtrl) info = slCtrl->getServerSelected(infoAvail); if (info) { objIRCClient->onJoinServer(info->missionName, info->name, Console->getVariable("$Server::Address"), false, info->password); } } Console->evaluate("JoinGame();", FALSE); } //used to quit while in the process of joining a server else if (msg == IDCTG_SERVER_JOIN_CANCEL) { if(cg.packetStream) { cg.packetStream->disconnect(); manager->unregisterObject(cg.packetStream); delete cg.packetStream; cg.packetStream = NULL; } else if (cg.csDelegate) { cg.csDelegate->cancelDuringConnection(); } Console->executef(3, "GuiLoadContentCtrl", "MainWindow", "gui\\JoinGame.gui"); } else if (msg == IDDLG_SERVER_INFO) { //find the server list dialog FearGui::ServerListCtrl *slCtrl = (FearGui::ServerListCtrl*)curGui->findControlWithTag(IDCTG_SERVER_SELECT_LIST); //push the dialog const char *dlgName = SimTagDictionary::getString(manager, msg); CMDConsole::getLocked()->executef(3, "GuiPushDialog", "MainWindow", dlgName); //get the info char buf[256]; SimGui::SimpleText *ctrl; FearGui::FGUniversalButton *btnCtrl; FearCSDelegate::ServerInfo *info = NULL; bool infoAvail; if (slCtrl) info = slCtrl->getServerSelected(infoAvail); //plug the info into the various controls if (info && infoAvail) { //server name ctrl = (SimGui::SimpleText*)root->getTopDialog()->findControlWithTag(IDCTG_SRVR_INFO_NAME); if (ctrl) ctrl->setText(info->name); //server address ctrl = (SimGui::SimpleText*)root->getTopDialog()->findControlWithTag(IDCTG_SRVR_INFO_ADDRESS); if (ctrl) ctrl->setText(info->transportAddress); //server version ctrl = (SimGui::SimpleText*)root->getTopDialog()->findControlWithTag(IDCTG_SRVR_INFO_VERSION); if (ctrl) ctrl->setText(info->version); //server Ping ctrl = (SimGui::SimpleText*)root->getTopDialog()->findControlWithTag(IDCTG_SRVR_INFO_PING); if (ctrl) { sprintf(buf, "%d", info->pingTime); ctrl->setText(buf); } //server dedicated ctrl = (SimGui::SimpleText*)root->getTopDialog()->findControlWithTag(IDCTG_SRVR_INFO_DEDICATED); if (ctrl) ctrl->setText((info->dedicated ? "YES" : "NO")); //server game ctrl = (SimGui::SimpleText*)root->getTopDialog()->findControlWithTag(IDCTG_SRVR_INFO_GAME); if (ctrl) ctrl->setText(info->modName); //server mission ctrl = (SimGui::SimpleText*)root->getTopDialog()->findControlWithTag(IDCTG_SRVR_INFO_MISSION); if (ctrl) ctrl->setText(info->missionName); //server password ctrl = (SimGui::SimpleText*)root->getTopDialog()->findControlWithTag(IDCTG_SRVR_INFO_PASSWORD); if (ctrl) ctrl->setText((info->password ? "YES" : "NO")); //server favorite btnCtrl = (FearGui::FGUniversalButton*)root->getTopDialog()->findControlWithTag(IDCTG_SERVER_INFO_FAVORITE); if (btnCtrl) btnCtrl->setMode(info->favorite); //server neverPing btnCtrl = (FearGui::FGUniversalButton*)root->getTopDialog()->findControlWithTag(IDCTG_SERVER_INFO_NEVER_PING); if (btnCtrl) btnCtrl->setMode(info->neverPing); //server text Console->executef(3, "Control::setValue", "ServerInfoText", info->hostInfo); //server info list FearGui::ServerInfoCtrl *siCtrl = dynamic_cast<FearGui::ServerInfoCtrl*>(root->getTopDialog()->findControlWithTag(IDCTG_SRVR_INFO_LIST)); if (siCtrl) siCtrl->setServerInfo(info); } return -1; } else if (msg == IDCTG_SERVER_INFO_FAVORITE) { //find the server list dialog FearGui::ServerListCtrl *slCtrl = (FearGui::ServerListCtrl*)curGui->findControlWithTag(IDCTG_SERVER_SELECT_LIST); //get the info FearGui::FGUniversalButton *btnCtrl; FearCSDelegate::ServerInfo *info = NULL; bool infoAvail; if (slCtrl) info = slCtrl->getServerSelected(infoAvail); btnCtrl = (FearGui::FGUniversalButton*)root->getTopDialog()->findControlWithTag(IDCTG_SERVER_INFO_FAVORITE); if (info && infoAvail && btnCtrl) { slCtrl->setFavorite(info->transportAddress, btnCtrl->isSet()); } return -1; } else if (msg == IDCTG_SERVER_INFO_NEVER_PING) { //find the server list dialog FearGui::ServerListCtrl *slCtrl = (FearGui::ServerListCtrl*)curGui->findControlWithTag(IDCTG_SERVER_SELECT_LIST); //get the info FearGui::FGUniversalButton *btnCtrl; FearCSDelegate::ServerInfo *info = NULL; bool infoAvail; if (slCtrl) info = slCtrl->getServerSelected(infoAvail); btnCtrl = (FearGui::FGUniversalButton*)root->getTopDialog()->findControlWithTag(IDCTG_SERVER_INFO_NEVER_PING); if (info && infoAvail && btnCtrl) { slCtrl->setNeverPing(info->transportAddress, btnCtrl->isSet()); } return -1; } else if (msg == IDCTG_SERVER_INFO_REFRESH) { //find the server list dialog FearGui::ServerListCtrl *slCtrl = (FearGui::ServerListCtrl*)curGui->findControlWithTag(IDCTG_SERVER_SELECT_LIST); //get the info FearCSDelegate::ServerInfo *info = NULL; bool infoAvail; if (slCtrl) info = slCtrl->getServerSelected(infoAvail); if (info && infoAvail && cg.csDelegate) { cg.csDelegate->pushPingInfoRequest(info->transportAddress); } } else { //since there are more than a few things that alter the current server... verifyServer(); } return Parent::onMessage(sender, msg); }