Accueil > > > INTÉGRATION SIMPLE D'UN CLIENT IRC À UNE APPLICATION
INTÉGRATION SIMPLE D'UN CLIENT IRC À UNE APPLICATION
Information sur la source
Description
IRClib est une bibliothèque qui permet d'intégrer un client IRC rapidement et simplement dans une application C++. Pour l'utiliser, il suffit de l'initialiser, de se connecter, puis de définir un gestionnaire d'évènements qui va se charger de gérer les interactions entre votre client IRC et le serveur. La source suivante montre l'utilisation d'IRClib.
Source
- #include <iostream>
- #include <irclib.h>
-
- // ---------------------------------------------------------------------------
-
- using namespace IRCLib;
- using namespace std;
-
- // ---------------------------------------------------------------------------
-
- class evts;
-
- // ---------------------------------------------------------------------------
-
- IClientManager* pMgr = NULL;
- IClient* pClient = NULL;
-
- // ---------------------------------------------------------------------------
-
- int main(int argc, char** av)
- {
- // Create the manager
- pMgr = CreateClientManager();
-
- // Set the server information
- TServerInfo server("irc.uni-irc.net", 6667);
-
- // Set the client information
- TClientInfo me("test42");
-
- // Create the client
- pClient = pMgr->NewClient(server, me);
-
- // Create the messages handler
- pClient->CreateHandler<evts>();
-
- // Connect the client
- pClient->Connect();
-
- // Wait for the client to be connected and registered
- while (!pClient->IsRegistered())
- ;
-
- // Create the #test channel
- IChannel* pChan = pClient->AddChannel("#test");
-
- // Wait for the #test channel to be created
- while (!(pChan = pClient->FindChannel("#test")))
- ;
-
- // Wait for the channel to be joined
- while (!pChan->OnThere())
- ;
-
- // Wait for the user to type a message
- char buffer[512] = {0};
- std::cin.getline(buffer, sizeof(buffer));
-
- // Send the message
- pChan->Message(buffer);
-
- // Quit the server
- pClient->Quit("Goodbye cruel world!");
-
- // Destroy the handler
- pClient->DestroyHandler<evts>();
-
- // Release the manager
- pMgr->Release();
-
- return 0;
- }
-
- // ---------------------------------------------------------------------------
-
- class evts : public IEventHandler
- {
- protected:
-
- // Network error
- //
- //
- void OnError(IClient* pClient, int nError)
- {
- if (nError != CER_UNKCMODE)
- {
- cout << "Error(" << nError << "): " << pClient->GetLastErrorMessage() << endl;
- }
-
- if (nError == CER_NICKINUSE)
- {
- pClient->Nick(pClient->GetNickName() + "_");
- }
-
- pClient->ClearLastError();
- }
-
- // Connecting to a server
- //
- //
- void OnConnecting(IClient* pClient)
- {
- cout << "Connecting to server..." << endl;
- }
-
- // Connected
- //
- //
- void OnConnect(IClient* pClient)
- {
- cout << "Connected!" << endl;
- }
-
- // We receive a notice
- //
- //
- void OnNotice(IClient* pClient, const string& strFrom, const string& str)
- {
- cout << "(" << strFrom << ") " << str << endl;
- }
-
- // We receive a channel message
- //
- //
- void OnMessage(IClient* pClient, IChannel* pChan, IUser* pUser, const string& strMessage)
- {
- cout << "<" << pUser->GetName() << "@" << pChan->GetName() << "> " << strMessage << endl;
- }
-
- // We receive a private message
- //
- //
- void OnQuery(IClient* pCl, const string& strUser, const string& strMessage)
- {
- cout << "[" << ToNick(strUser) << "@" << ToHost(strUser) << "] " << strMessage << endl;
- }
-
- // Disconnected
- //
- //
- void OnDisconnect(IClient* pClient)
- {
- cout << "Disconnected." << endl;
- }
-
- // We, or someone, join a channel
- //
- //
- void OnJoin(IClient* pClient, IChannel* pChan, IUser* pUser)
- {
- if (pClient->IsMe(pUser))
- {
- // We entered the channel
- }
- else
- {
- // Someone entered the channel
- cout << pUser->GetName() << " has joined " << pChan->GetName() << endl;
- }
- }
-
- // Someone (might be us, use pClient->IsMe(pUser) to check) left the channel
- //
- //
- void OnPart(IClient* pClient, IChannel* pChan, IUser* pUser)
- {
- cout << pUser->GetName() << " has left " << pChan->GetName() << endl;
- }
-
- // Someone has been kicked
- //
- //
- void OnKick(IClient* pCl, IChannel* pChan, IUser* pBy, IUser* pWho, const string& why)
- {
- if (pCl->IsMe(pWho))
- {
- cout << "You were kicked from " << pChan->GetName() << " by " << pBy->GetName() << " (" << why << ")" << endl;
- }
- else
- {
- cout << pWho->GetName() << " was kicked from " << pChan->GetName() << " by " << pBy->GetName() << " (" << why << ")" << endl;
- }
- }
-
- // The channel mode has changed
- //
- //
- void OnMode(IClient* pCl, IChannel* pChan, IUser* pBy, const string& strModes)
- {
- cout << pBy->GetName() << " sets mode: " << strModes << endl;
- }
-
- // The user mode has changed
- //
- //
- void OnUMode(IClient* pCl, const string& strModes)
- {
- cout << "Modes changed to " << strModes << endl;
- }
-
- // We receive the name list for a channel
- //
- //
- void OnNames(IClient* pCl, IChannel* pChan)
- {
- TUserList users = pChan->LockUsers();
- for (TUserList::iterator itr = users.begin(); itr != users.end(); ++itr)
- {
- IUser* pUser = *itr;
- cout << "--> " << pUser->GetName() << " [" << pUser->GetModes() << "]" << endl;
- }
- pChan->UnlockUsers();
- }
-
- // Someone has changed his nick
- //
- //
- void OnNick(IClient* pCl, IUser* pUser, const string& to)
- {
- cout << pUser->GetName() << " is now known as " << to << endl;
- }
-
- // Received the topic for channel
- //
- //
- void OnGotTopic(IClient* pCl, IChannel* pChan, const string& strTopic)
- {
- cout << "Topic for " << pChan->GetName() << " is " << strTopic << endl;
- }
-
- // The topic has changed
- //
- //
- void OnTopic(IClient* pCl, IChannel* pChan, IUser* pUser, const string& strTopic)
- {
- cout << pUser->GetName() << " changes topic to '" << strTopic << "'" << endl;
- }
-
- // We have been invited to a channel
- //
- //
- void OnInvite(IClient* pCl, const string& strWho, const string& strChan)
- {
- cout << strWho << " invites you to join " << strChan << endl;
- }
-
- // Received channel modes
- //
- //
- void OnGotModes(IClient* pCl, IChannel* pChan, const string& strModes)
- {
- cout << "Channel " << pChan->GetName() << " modes: " << strModes << endl;
- }
-
- // Someone has quit IRC
- //
- //
- void OnQuit(IClient* pCl, IChannel* pChan, IUser* pUser, const string& strMsg)
- {
- cout << pUser->GetName() << " has quit IRC (" << strMsg << ")" << endl;
- }
-
- // You've been killed
- //
- //
- void OnKill(IClient* pCl, const string& str)
- {
- cout << "You've been killed: " << str << endl;
- }
-
- // An operator has changed the modes
- //
- //
- void OnOpMode(IClient* pCl, IChannel* pChan, IUser* pBy, IUser* pWho, const string& strModes)
- {
- cout << pBy->GetName() << " sets mode: " << strModes << " " << pWho->GetName() << endl;
- }
-
- // Someone has been banned
- //
- //
- void OnBanMode(IClient* pCl, IChannel* pChan, IUser* pBy, const string& strMask, const string& strModes)
- {
- cout << pBy->GetName() << " sets mode: " << strModes << " " << strMask << endl;
- }
-
- // Receive a whois result
- //
- //
- void OnWhois(IClient* pCl, const TWhois& w)
- {
- cout << w.UserInfo.Nickname << endl;
- }
-
- // Received the MOTD
- //
- //
- void OnMotd(IClient* pCl, const string& motd)
- {
- cout << motd << endl;
- }
- };
#include <iostream>
#include <irclib.h>
// ---------------------------------------------------------------------------
using namespace IRCLib;
using namespace std;
// ---------------------------------------------------------------------------
class evts;
// ---------------------------------------------------------------------------
IClientManager* pMgr = NULL;
IClient* pClient = NULL;
// ---------------------------------------------------------------------------
int main(int argc, char** av)
{
// Create the manager
pMgr = CreateClientManager();
// Set the server information
TServerInfo server("irc.uni-irc.net", 6667);
// Set the client information
TClientInfo me("test42");
// Create the client
pClient = pMgr->NewClient(server, me);
// Create the messages handler
pClient->CreateHandler<evts>();
// Connect the client
pClient->Connect();
// Wait for the client to be connected and registered
while (!pClient->IsRegistered())
;
// Create the #test channel
IChannel* pChan = pClient->AddChannel("#test");
// Wait for the #test channel to be created
while (!(pChan = pClient->FindChannel("#test")))
;
// Wait for the channel to be joined
while (!pChan->OnThere())
;
// Wait for the user to type a message
char buffer[512] = {0};
std::cin.getline(buffer, sizeof(buffer));
// Send the message
pChan->Message(buffer);
// Quit the server
pClient->Quit("Goodbye cruel world!");
// Destroy the handler
pClient->DestroyHandler<evts>();
// Release the manager
pMgr->Release();
return 0;
}
// ---------------------------------------------------------------------------
class evts : public IEventHandler
{
protected:
// Network error
//
//
void OnError(IClient* pClient, int nError)
{
if (nError != CER_UNKCMODE)
{
cout << "Error(" << nError << "): " << pClient->GetLastErrorMessage() << endl;
}
if (nError == CER_NICKINUSE)
{
pClient->Nick(pClient->GetNickName() + "_");
}
pClient->ClearLastError();
}
// Connecting to a server
//
//
void OnConnecting(IClient* pClient)
{
cout << "Connecting to server..." << endl;
}
// Connected
//
//
void OnConnect(IClient* pClient)
{
cout << "Connected!" << endl;
}
// We receive a notice
//
//
void OnNotice(IClient* pClient, const string& strFrom, const string& str)
{
cout << "(" << strFrom << ") " << str << endl;
}
// We receive a channel message
//
//
void OnMessage(IClient* pClient, IChannel* pChan, IUser* pUser, const string& strMessage)
{
cout << "<" << pUser->GetName() << "@" << pChan->GetName() << "> " << strMessage << endl;
}
// We receive a private message
//
//
void OnQuery(IClient* pCl, const string& strUser, const string& strMessage)
{
cout << "[" << ToNick(strUser) << "@" << ToHost(strUser) << "] " << strMessage << endl;
}
// Disconnected
//
//
void OnDisconnect(IClient* pClient)
{
cout << "Disconnected." << endl;
}
// We, or someone, join a channel
//
//
void OnJoin(IClient* pClient, IChannel* pChan, IUser* pUser)
{
if (pClient->IsMe(pUser))
{
// We entered the channel
}
else
{
// Someone entered the channel
cout << pUser->GetName() << " has joined " << pChan->GetName() << endl;
}
}
// Someone (might be us, use pClient->IsMe(pUser) to check) left the channel
//
//
void OnPart(IClient* pClient, IChannel* pChan, IUser* pUser)
{
cout << pUser->GetName() << " has left " << pChan->GetName() << endl;
}
// Someone has been kicked
//
//
void OnKick(IClient* pCl, IChannel* pChan, IUser* pBy, IUser* pWho, const string& why)
{
if (pCl->IsMe(pWho))
{
cout << "You were kicked from " << pChan->GetName() << " by " << pBy->GetName() << " (" << why << ")" << endl;
}
else
{
cout << pWho->GetName() << " was kicked from " << pChan->GetName() << " by " << pBy->GetName() << " (" << why << ")" << endl;
}
}
// The channel mode has changed
//
//
void OnMode(IClient* pCl, IChannel* pChan, IUser* pBy, const string& strModes)
{
cout << pBy->GetName() << " sets mode: " << strModes << endl;
}
// The user mode has changed
//
//
void OnUMode(IClient* pCl, const string& strModes)
{
cout << "Modes changed to " << strModes << endl;
}
// We receive the name list for a channel
//
//
void OnNames(IClient* pCl, IChannel* pChan)
{
TUserList users = pChan->LockUsers();
for (TUserList::iterator itr = users.begin(); itr != users.end(); ++itr)
{
IUser* pUser = *itr;
cout << "--> " << pUser->GetName() << " [" << pUser->GetModes() << "]" << endl;
}
pChan->UnlockUsers();
}
// Someone has changed his nick
//
//
void OnNick(IClient* pCl, IUser* pUser, const string& to)
{
cout << pUser->GetName() << " is now known as " << to << endl;
}
// Received the topic for channel
//
//
void OnGotTopic(IClient* pCl, IChannel* pChan, const string& strTopic)
{
cout << "Topic for " << pChan->GetName() << " is " << strTopic << endl;
}
// The topic has changed
//
//
void OnTopic(IClient* pCl, IChannel* pChan, IUser* pUser, const string& strTopic)
{
cout << pUser->GetName() << " changes topic to '" << strTopic << "'" << endl;
}
// We have been invited to a channel
//
//
void OnInvite(IClient* pCl, const string& strWho, const string& strChan)
{
cout << strWho << " invites you to join " << strChan << endl;
}
// Received channel modes
//
//
void OnGotModes(IClient* pCl, IChannel* pChan, const string& strModes)
{
cout << "Channel " << pChan->GetName() << " modes: " << strModes << endl;
}
// Someone has quit IRC
//
//
void OnQuit(IClient* pCl, IChannel* pChan, IUser* pUser, const string& strMsg)
{
cout << pUser->GetName() << " has quit IRC (" << strMsg << ")" << endl;
}
// You've been killed
//
//
void OnKill(IClient* pCl, const string& str)
{
cout << "You've been killed: " << str << endl;
}
// An operator has changed the modes
//
//
void OnOpMode(IClient* pCl, IChannel* pChan, IUser* pBy, IUser* pWho, const string& strModes)
{
cout << pBy->GetName() << " sets mode: " << strModes << " " << pWho->GetName() << endl;
}
// Someone has been banned
//
//
void OnBanMode(IClient* pCl, IChannel* pChan, IUser* pBy, const string& strMask, const string& strModes)
{
cout << pBy->GetName() << " sets mode: " << strModes << " " << strMask << endl;
}
// Receive a whois result
//
//
void OnWhois(IClient* pCl, const TWhois& w)
{
cout << w.UserInfo.Nickname << endl;
}
// Received the MOTD
//
//
void OnMotd(IClient* pCl, const string& motd)
{
cout << motd << endl;
}
};
Conclusion
Vous pouvez télécharger IRClib (libs et headers) à l'adresse http://www.julz.fr/projects/irclib/vs2005/
Cette version n'est malheureusement pas documentée, faute de temps. Je pense néanmoins que la plupart des informations nécessaires sont assez faciles à comprendre par la simple lecture du fichier .h ;)
A noter que le projet n'aura une chance d'évoluer que s'il se montre intéressant pour plusieurs utilisateurs.
Historique
- 07 juillet 2010 16:27:15 :
- Changement du titre, plus clair.
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
C++ Builder: Client irc (a laide!) [ par Psyc0s ]
Bon je suis en train de faire un client irc avec C++ builder Mais le socket ne veux pas envoyer les message au serveur:(La connexion au serveur foncti
client IRC ?? [ par crAzYJoJoo ]
Slt, je cherche le code source d'un client irc pour voir comment ca marcheest ce que qq1 sait ou je peux trouver ca ?merci d'avance ++
Programmer un chat avec un serveur en java et un client en c++ [ par Snake655 ]
J'aimerais savoir si déjà c'est possible (je pense que oui quand meme :-D) et si oui, que vous m'eclaireriez sur la méthode. Mon but serait de creer u
Probleme de Client Serveur [ par Krox68 ]
voila jaimerais faire un programme client qui puisse se connecter a ce serveur : #include <winsock.h> void main(){ WSADATA WSAData; WSAStartup(M
CDialog + Sockey ? [ par mickeydisn ]
je suis entrin de realiser une application un a serveur Socket en Consol . L'application console pas de PB . Le clien j'ai cree une forme avec un edit
Evènement sur un socket client [ par darsh99 ]
J'aimerais savoir si la méthode utilisée par BlackGoddess pour son serveur (http://www.cppfrance.com/article.aspx?ID=1287) est récupérable pour gérer
Thread et socket besoin de conseil [ par kawito ]
Salut,je desire realiser un client/serveur TCPle probleme est que les fonctions accept et recv sont bloquante.donc cela bloque l'affichage etc...mon p
Socket + http [ par Akylon ]
Voila je veux recuperer des documents par le protocole http avec la fonction suivante: void traitement(SOCKET client){ int lg; char* requete="GE
Client IRC [ par SAtaN ]
quelqu'un aurait il un tutoriel, des infos, pour m'aider à creer un client IRC ???PS : j'utilise Borland C++a+
recvfrom + udp + '\n' [ par vegetaline ]
salutune appli client / serveur sous linux qui communique (enfin qui essaye) avec des sockets INTERNET en mode NON CONNECTE (en udp :)pb -> le recv
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|