begin process at 2012 05 27 20:03:34
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Réseaux & Internet

 > INTÉGRATION SIMPLE D'UN CLIENT IRC À UNE APPLICATION

INTÉGRATION SIMPLE D'UN CLIENT IRC À UNE APPLICATION


 Information sur la source

Note :
Aucune note
Catégorie :Réseaux & Internet Classé sous :irc, socket, client, chat Niveau :Débutant Date de création :07/07/2010 Date de mise à jour :07/07/2010 16:27:15 Vu / téléchargé :2 710 / 97

Auteur : PJulot

Ecrire un message privé
Site perso
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 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.

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  •   inc
  •   lib
    • irclib2005-MD.libTélécharger ce fichier [Réservé aux membres club]3 753 038 octets
    • irclib2005-MDd.libTélécharger ce fichier [Réservé aux membres club]1 748 462 octets
    • irclib2005-MT.libTélécharger ce fichier [Réservé aux membres club]2 714 092 octets
    • irclib2005-MTd.libTélécharger ce fichier [Réservé aux membres club]3 324 692 octets
  •   Sample
  • Readme.txtTélécharger ce fichier [Réservé aux membres club]Voir ce fichier3 671 octets

Télécharger le zip


 Historique

07 juillet 2010 16:27:15 :
Changement du titre, plus clair.

 Sources de la même categorie

Source avec Zip Source avec une capture MINI SERVEUR HTTP [WINDOWS] par ganjarasta
Source avec Zip Source avec une capture CLIENT DE TEST MODBUS TCP par brunovan
Source avec Zip Source avec une capture SCANIP [ARP / ICMP] par ganjarasta
Source avec Zip Source avec une capture TRACEROUTE [WINPCAP] par ganjarasta
Source avec Zip SERVEUR MULTITHREAD [LINUX/WIN] par nipepsinicolas

 Sources en rapport avec celle ci

Source avec Zip MINICHAT MULTI-CLIENT par wisar
Source avec Zip Source avec une capture CLIENT IRC SIMPLE AVEC DEV-CPP par TeniX
Source avec Zip Source avec une capture CLIENT/SERVEUR UTILISANT LES IOCP RÉALISÉ AVEC BORLAND BUILD... par goodboy21
Source avec Zip SERVEUR/CLIENT LINUX par ghost4
Source avec Zip MINI CHAT C/C++ par edf102

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


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 &lt;winsock.h&gt; 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 -&gt; le recv


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,640 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales