src/irc.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sat, 13 Dec 2008 15:40:23 +0100
changeset 13 d3554afaa768
parent 12 213c3d4abc66
child 15 f19c1f9b4cd3
permissions -rw-r--r--
mcbot-0.94-5 Changelog Compat.c added: * provides a safe strdup replacement * snprintf and fdopen may follow... garbage_collection improved Nasty compiler warning removed in parse.c committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
 *  $Id: irc.c 51 2008-01-10 00:19:39Z mbroeker $
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
 * $URL: http://localhost/svn/c/mcbot/trunk/src/irc.c $
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 *
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
 */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <stdio.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
#include <stdlib.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
#include <unistd.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
#include <string.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
#include <sys/types.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
#include <sys/socket.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
#include <netinet/in.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
#include <arpa/inet.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
#include <netdb.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
#include <pwd.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
13
d3554afaa768 mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 12
diff changeset
    20
#include <compat.h>
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
#include <irc.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
#define VERSION_STRING "MCBOT on GNU/LINUX"
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
const char *IRC_Commands[] = {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
    "NOTICE", "MODE", "JOIN", "PART",
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
    "TOPIC", "PING", "ENOMEM", "ERROR",
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
    "VERSION", "PRIVMSG", "QUIT", "NICK",
11
a769385a59c6 Many Memory Leaks in config.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 10
diff changeset
    29
    NULL
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
};
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
FILE *irc_connect (char *server, unsigned int port)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
{
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
    struct hostent *he;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
    char *ip;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
    struct sockaddr_in ca;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
    int csocket;
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    38
    FILE *stream;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
    he = gethostbyname (server);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    41
    if (he == NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
        perror ("GETHOSTBYNAME");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    43
        return NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    44
    }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    45
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    46
    if ((ip = inet_ntoa (*((struct in_addr *)he->h_addr_list[0]))) == NULL) {
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    47
        perror ("INET_NTOA");
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
        return NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    49
    } else
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
        printf ("IP: %s\n", ip);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
    ca.sin_family = AF_INET;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    53
    ca.sin_addr.s_addr = inet_addr (ip);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    54
    ca.sin_port = htons (port);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    55
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    56
    csocket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
    if (connect (csocket, (struct sockaddr *)&ca, (socklen_t) sizeof (ca)) == -1) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    58
        perror ("CONNECT");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    59
        return NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    60
    }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    61
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    62
    /*
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
     * rw mode,but many seek errors ...
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    64
     */
5
7c7fc8906920 FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 2
diff changeset
    65
#ifdef NETBSD
6
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    66
    /*
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    67
     * BEGIN OF STREAM
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    68
     */
5
7c7fc8906920 FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 2
diff changeset
    69
    stream = fdopen (csocket, "r+");
7c7fc8906920 FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 2
diff changeset
    70
#else
6
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    71
    /*
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    72
     * END OF STREAM
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    73
     */
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    74
    stream = fdopen (csocket, "a+");
5
7c7fc8906920 FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 2
diff changeset
    75
#endif
6
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    76
    csocket = fileno (stream);
5
7c7fc8906920 FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 2
diff changeset
    77
7c7fc8906920 FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 2
diff changeset
    78
    printf ("Using filedescriptor %d for stream operations\n", csocket);
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    79
    return stream;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    80
}
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    81
6
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    82
int irc_login (FILE * stream, char *server, char *nick, char *password)
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    83
{
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    84
    MSG message = { NULL, 0, 0, 0, 0, 0, 0 };
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    85
    char msg[513];
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    86
    char *user;
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    87
    struct passwd *pwd;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    88
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    89
    if ((user = getenv ("USER")) == NULL)
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    90
        return IRC_GENERAL_ERROR;
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    91
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    92
    if ((pwd = getpwnam (user)) == NULL)
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    93
        return IRC_GENERAL_ERROR;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    94
6
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    95
    if (password == NULL)
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    96
        return IRC_LOGIN_ERROR;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    97
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    98
    if (stream == NULL)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    99
        return IRC_GENERAL_ERROR;
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   100
    else
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   101
        message.stream = stream;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   102
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   103
    fprintf (stream, "NICK %s\r\n", nick);
6
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
   104
    fprintf (stream, "USER %s 0 %s %s\r\n", user, server, pwd->pw_gecos);
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   105
    fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   106
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   107
    for (;;) {
11
a769385a59c6 Many Memory Leaks in config.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 10
diff changeset
   108
        *msg = '\0';
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   109
        fgets (msg, 512, stream);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   110
        if ((user = irc_parsemessage (msg, &message)) != NULL)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   111
            printf ("%10s %s\n", user, message.line);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   112
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   113
        if (strstr (msg, "VERSION") != NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   114
            printf ("%10s %s", "VERSION", msg);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   115
            printf ("%10s %s %s :%s\n", "WRITE", message.command, message.user, VERSION_STRING);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   116
            fprintf (stream, "VERSION :%s\r\n", VERSION_STRING);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   117
        }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   118
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   119
        if (strstr (msg, ":Password accepted") != NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   120
            break;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   121
        }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   122
1
5d249c79842d quick and dirty freenode connect fix
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 0
diff changeset
   123
        if (strstr (msg, ":You are now logged in.") != NULL) {
5d249c79842d quick and dirty freenode connect fix
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 0
diff changeset
   124
            break;
5d249c79842d quick and dirty freenode connect fix
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 0
diff changeset
   125
        }
5d249c79842d quick and dirty freenode connect fix
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 0
diff changeset
   126
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   127
        if (strstr (msg, ":Password Incorrect") != NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   128
            return IRC_LOGIN_ERROR;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   129
        }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   130
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   131
        if (strstr (msg, "ERROR :Closing Link") != NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   132
            return IRC_GENERAL_ERROR;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   133
        }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   134
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   135
        if (strstr (msg, "is not registered") != NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   136
            return IRC_LOGIN_ERROR;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   137
        }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   138
    }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   139
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   140
    sleep (2);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   141
    return 0;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   142
}
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   143
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   144
static char *irc_getmessage (const char *line, MSG * message)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   145
{
12
213c3d4abc66 A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 11
diff changeset
   146
    static char *garbage_collector = NULL;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   147
    char *theLine;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   148
    char *token;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   149
    char *ptr;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   150
13
d3554afaa768 mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 12
diff changeset
   151
    if (garbage_collector != NULL) {
12
213c3d4abc66 A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 11
diff changeset
   152
        free (garbage_collector);
13
d3554afaa768 mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 12
diff changeset
   153
        garbage_collector = NULL;
d3554afaa768 mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 12
diff changeset
   154
    }
12
213c3d4abc66 A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 11
diff changeset
   155
13
d3554afaa768 mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 12
diff changeset
   156
    if ((theLine = compat_strdup (line)) == NULL)
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   157
        return "ENOMEM";
12
213c3d4abc66 A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 11
diff changeset
   158
    else
213c3d4abc66 A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 11
diff changeset
   159
        garbage_collector = theLine;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   160
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   161
    message->user = message->email = NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   162
    message->command = NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   163
    message->channel = message->line = NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   164
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   165
    token = strtok (theLine, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   166
    if (*token != ':') {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   167
        /*
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   168
         * SERVER MESSAGES
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   169
         */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   170
        if ((ptr = strtok (NULL, "\r\n")) != NULL)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   171
            ++ptr;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   172
        message->line = ptr;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   173
        return token;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   174
    }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   175
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   176
    message->user = ++token;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   177
    message->command = strtok (NULL, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   178
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   179
    message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   180
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   181
    return message->command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   182
}
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   183
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   184
/**
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   185
 * Main prints ("%10s %s %s\n", MSG->command MSG->channel MSG->line).
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   186
 * This functions makes sure, that there will be someting to print...
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   187
 */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   188
char *irc_parsemessage (const char *line, MSG * message)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   189
{
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   190
    int i;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   191
    char *command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   192
    char *ptr;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   193
    int value;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   194
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   195
    i = 0;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   196
    if ((command = irc_getmessage (line, message)) != NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   197
        while (IRC_Commands[i] != NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   198
            if (strcmp (IRC_Commands[i], command) == 0) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   199
                switch (i) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   200
                case 0:        /* NOTICE */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   201
                    if (message->line == NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   202
                        message->channel = "*";
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   203
                        message->line = "*";
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   204
                    } else {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   205
                        message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   206
                        if ((message->line = strtok (NULL, "\r\n")) != NULL)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   207
                            ++message->line;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   208
                    }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   209
                    return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   210
                case 1:        /* MODE */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   211
                    message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   212
                    message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   213
                    return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   214
                case 2:        /* JOIN */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   215
                case 3:        /* PART */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   216
                    if ((message->channel = strchr (message->line, ':')))
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   217
                        ++message->channel;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   218
                    message->line = message->user;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   219
                    return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   220
                case 4:        /* TOPIC */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   221
                    message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   222
                    if ((message->line = strtok (NULL, "\r\n")))
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   223
                        ++message->line;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   224
                    return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   225
                case 5:        /* PING */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   226
#ifdef DEBUG
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   227
                    /*
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   228
                     * DONT NERVE WITH PING PONG MESSAGES
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   229
                     */
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   230
                    printf ("%10s %s localhost\n", "PING", message->line);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   231
#endif
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   232
                    fprintf (message->stream, "PONG :%s\r\n", message->line);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   233
                    message->channel = "localhost";
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   234
#ifdef DEBUG
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   235
                    return "PONG";
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   236
#else
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   237
                    return NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   238
#endif
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   239
                case 6:        /* ENOMEM */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   240
                case 7:        /* ERROR */
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   241
                    return command;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   242
                case 8:        /* VERSION */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   243
                    if ((ptr = strchr (message->user, ' ')))
11
a769385a59c6 Many Memory Leaks in config.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 10
diff changeset
   244
                        *ptr = '\0';
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   245
                    return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   246
                case 9:        /* PRIVMSG */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   247
                    if ((message->email = strchr (message->user, '=')))
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   248
                        ++message->email;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   249
                    if ((ptr = strchr (message->user, '!')))
11
a769385a59c6 Many Memory Leaks in config.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 10
diff changeset
   250
                        *ptr = '\0';
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   251
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   252
                    message->channel = strtok (message->line, " ");
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   253
                    message->current_channel = message->channel;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   254
                    message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   255
                    message->line++;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   256
                    printf ("%10s %s %s :%s\n", "READ", message->command, message->channel, message->line);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   257
                    return NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   258
                case 10:       /* QUIT */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   259
                    message->channel = message->user;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   260
                    return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   261
                case 11:       /* NICK */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   262
                    message->channel = message->user;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   263
                    return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   264
                }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   265
            }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   266
            i++;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   267
        }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   268
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   269
        if ((value = atoi (command)) != 0) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   270
            switch (value) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   271
            case 1:            /* CONNECTION INFOS */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   272
            case 2:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   273
            case 3:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   274
            case 4:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   275
            case 5:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   276
            case 250:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   277
            case 251:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   278
            case 252:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   279
            case 254:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   280
            case 255:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   281
            case 265:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   282
            case 266:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   283
                /*
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   284
                 * prints as is in irc_login
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   285
                 */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   286
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   287
            case 311:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   288
            case 312:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   289
            case 315:          /* END OF WHO */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   290
            case 318:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   291
                message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   292
                message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   293
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   294
            case 319:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   295
                message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   296
                message->line = strtok (NULL, "\r\n");
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   297
                fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line);
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   298
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   299
            case 320:
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   300
            case 328:          /* INFORMATION */
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   301
            case 332:          /* TOPIC OF CHANNEL */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   302
            case 333:          /* NAMES IN CHANNEL */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   303
                message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   304
                message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   305
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   306
            case 351:          /* SVERSION */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   307
                message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   308
                message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   309
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   310
            case 352:          /* WHO LIST */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   311
                message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   312
                message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   313
                /*
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   314
                 * MORE THAN 3 LINES AND YOU WILL be KICKED
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   315
                 */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   316
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   317
            case 353:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   318
            case 365:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   319
            case 366:          /* END OF NAMES */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   320
                message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   321
                message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   322
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   323
            case 372:          /* MOTD MESSAGES */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   324
            case 375:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   325
            case 376:          /* END OF MOTD */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   326
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   327
            case 401:          /* NO SUCH NICK/CHANNEL */
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   328
            case 403:          /* THAT CHANNEL DOESN'T EXIST */
13
d3554afaa768 mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 12
diff changeset
   329
            case 412:          /* NO TEXT TO SEND */
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   330
            case 441:          /* THEY AREN'T ON THIS CHANNEL */
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   331
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   332
            case 474:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   333
            case 475:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   334
            case 476:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   335
            case 477:
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   336
            case 482:
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   337
                message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   338
                message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   339
                return command;
2
6a2e88214b80 freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 1
diff changeset
   340
            case 901:          /* notify or some crap */
6a2e88214b80 freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 1
diff changeset
   341
                message->channel = strtok (message->line, " ");
6a2e88214b80 freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 1
diff changeset
   342
                message->line = strtok (NULL, "\r\n");
6a2e88214b80 freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 1
diff changeset
   343
                return command;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   344
            default:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   345
                printf ("DEBUG   %s", line);
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   346
                printf ("Unknown Command Value: %d\n", value);
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   347
            }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   348
        }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   349
        printf ("DEBUG   %s", line);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   350
        printf ("Unknown Command: %s\n", command);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   351
        return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   352
    }
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   353
    printf ("NOT PARSEABLE   %s", line);
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   354
    return NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   355
}