KoRn69 | Bonjour j'ai fait un bot irc qui devrais ce connecter a l'irc (je sais le code n'est pas beau )mais le compilos ne veux pas lancer et je ne voie pas pourkoi il met aucun message d'erreur...
Code :
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #ifdef WIN32
- #include <winsock.h>
- #else
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <sys/types.h>
- #include <arpa/inet.h>
- #endif
- #define JOIN_CMD "JOIN %s\n"
- #define PART_CMD "PART %s\n"
- #define NICK_CMD "NICK %s\n"
- #define PRIVMSG_CMD "PRIVMSG %s :%s\n"
- #define QUIT_CMD "QUIT %s\n"
- #define USER_CMD "USER %s %s %s :%s\n"
- #define NOTICE_CMD "NOTICE %s :%s\n"
- #define TOPIC_CMD "TOPIC %s :%s\n"
- #define MAXBUF 512
- char version[]="Smybot V.0.6b made in C by KoRn69",nick[35];
- char botident[]="lol",bothost[]="prout",botname[]="Test",realname[]="SmyBot V3.01",botnick[]="Smybot";
- fd_set master;
- int fdmax;
- int sock_irc;
- int log(char *yo)
- {
- FILE *f = fopen("log.txt", "w" );
- fprintf(f,"%s\n",yo);
- fclose(f);
- }
- void parser(char *ligne,int mon_sock){
- char buffer[1447];
- char *cmd=NULL,*reste=NULL,*utilisateur=NULL,*dest=NULL,*guest=NULL,*host=NULL;
- if(*ligne == ':'){
- ligne++;
- if(cmd=strchr(ligne,' ')) *cmd++ = '\0';
- else return;
- if(dest=strchr(cmd,' ')) *dest++ ='\0';
- else return;
- if(reste=strchr(dest,' ')) *reste++ = '\0';
- else return;
- utilisateur=ligne;
- if(guest=strchr(utilisateur,'!')) *guest++ = '\0';
- else return;
- if(host=strchr(guest,'@')) *host++ = '\0';
- else return;
- }else{
- if(utilisateur=strchr(ligne,' ')) *utilisateur++ = '\0';
- else return;
- if(reste=strchr(utilisateur,' ')) *reste++ = '\0';
- else return;
- cmd=ligne;
- }
- }
- }
- int connection(char *server, int port){
- struct hostent *h;
- struct sockaddr_in sockname;
- if((sock_irc = socket(AF_INET, SOCK_STREAM,0))<0) {
- return(-1);
- }
- if((h = gethostbyname(server))==NULL) {
- if((h = gethostbyaddr(server, sizeof(server), AF_INET))==NULL){
- return(-1);
- }
- }
- memcpy(&sockname.sin_addr.s_addr, h->h_addr, h->h_length);
- sockname.sin_family=AF_INET;
- sockname.sin_port=htons(port);
- if(connect(sock_irc, (struct sockaddr *)&sockname, sizeof(sockname))<0) {
- return(-1);
- }
- FD_SET(sock_irc, &master);
- if (sock_irc > fdmax) {
- fdmax = sock_irc;
- }
- return sock_irc;
- }
- int join_chan(char *file,int mon_sock)
- {
- FILE *f;
- char zeus[65];
- char buffer[1447];
- f =fopen(file, "r" );
- if(!f)
- {
- printf("Fichier %s inexistant; merci d'editer ce fichier et de relancer le bot",file);
- return 0;
- }
- while(feof(f)!=1)
- {
- snprintf (buffer, 256,JOIN_CMD, zeus);
- send (mon_sock, buffer, strlen(buffer), 0);
- if (feof (f))
- break;
- fgets(zeus, 64, f);
- printf("%s\n",zeus);
- }
- fclose (f);
- return 0;
- }
- int main (void)
- {
- #ifdef WIN32
- WSADATA Data;
- WSAStartup (MAKEWORD (2, 2), &Data);
- #endif
- char buffer[1447];
- int mon_sock, taille;
- while (1)
- {
- if((mon_sock=connection("irc.voila.fr",6667))==-1){
- printf("Le bot n'a pa pu se connecte verifiez l'host/ip et port du serveur svp.\n" );
- }
- else{
- snprintf(buffer, 500,NICK_CMD,botnick);
- send (mon_sock, buffer, strlen(buffer), 0);
- snprintf(buffer, 500,USER_CMD,botident,bothost,botname,realname);
- send (mon_sock, buffer, strlen(buffer), 0);
- printf("Bot by KoRn69\n" );
- printf("Socket %i connecte\n",mon_sock);
- printf("Je vais maintenant joindre le(s) chan(s):\n" );
- join_chan("chan.txt",mon_sock);
- while (1)
- {
- taille = recv(mon_sock, buffer, 1446, 0);
- if (taille == 0)
- break;
- buffer[taille] = 0;
- printf("%s\n",buffer);
- if(!strncmp(buffer, "PING ", 5))
- {
- buffer[1]= 'O';
- send(mon_sock, buffer, strlen(buffer), 0);
- }
- parser(buffer,mon_sock);
- }
- }
- }
- getchar ();
- return 0;
- }
|
Merci d'avance Message édité par KoRn69 le 28-04-2005 à 16:17:25
|