src/irc.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Fri, 27 Dec 2013 12:24:39 +0100
changeset 61 fb2cfcee38bd
parent 60 67a32e9d95f2
permissions -rw-r--r--
URL Changed
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 <netdb.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
#include <pwd.h>
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
13
d3554afaa768 mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 12
diff changeset
    18
#include <compat.h>
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
#include <irc.h>
33
56571d34d754 safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 29
diff changeset
    20
#include "common.h"
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
37
85891f91096c enumerated types for irc.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 34
diff changeset
    22
enum command_map {
33
56571d34d754 safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 29
diff changeset
    23
    NOTICE, MODE, JOIN, PART, TOPIC, PING, ENOMEM, ERROR, VERSION, PRIVMSG, QUIT, NICK, KICK
56571d34d754 safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 29
diff changeset
    24
};
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
    25
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
#define VERSION_STRING "MCBOT on GNU/LINUX"
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
const char *IRC_Commands[] = {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
    "NOTICE", "MODE", "JOIN", "PART",
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
    "TOPIC", "PING", "ENOMEM", "ERROR",
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
    "VERSION", "PRIVMSG", "QUIT", "NICK",
19
66114d944208 op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 18
diff changeset
    32
    "KICK", NULL
0
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
58
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    35
FILE *irc_connect (char *server, char *port)
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
{
58
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    37
    struct addrinfo hints;
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    38
    struct addrinfo *result, *rp;
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    39
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    40
    int csocket = -1;
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    41
    FILE *stream;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
58
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    43
    memset (&hints, 0, sizeof (struct addrinfo));
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    44
    hints.ai_family = AF_UNSPEC;
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    45
    hints.ai_socktype = SOCK_STREAM;
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    46
    hints.ai_flags = 0;
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    47
    hints.ai_protocol = IPPROTO_TCP;
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    48
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    49
    if (getaddrinfo (server, port, &hints, &result) != 0) {
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    50
        perror ("getaddrinfo");
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
        return NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
    }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    53
58
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    54
    for (rp = result; rp != NULL; rp = rp->ai_next) {
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    55
        if ((csocket = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol)) == -1)
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    56
            continue;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
58
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    58
        if (connect (csocket, rp->ai_addr, rp->ai_addrlen) != -1) {
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    59
            fprintf (stderr, "Connected via %s\n", (rp->ai_family == AF_INET6) ? "IPv6" : "IPv4");
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    60
            break;
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    61
        }
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    62
        close (csocket);
59
e8f15b159e19 irc_login: csocket holds a valid descriptor or -1 on error
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 58
diff changeset
    63
        csocket = -1;
58
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    64
    }
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    65
58
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    66
    if (result != NULL)
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    67
        freeaddrinfo (result);
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    68
59
e8f15b159e19 irc_login: csocket holds a valid descriptor or -1 on error
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 58
diff changeset
    69
    if (csocket == -1) {
58
500a5ea7fcb8 IPv6 Support for mcbot
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 50
diff changeset
    70
        perror ("Cannot connect");
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    71
        return NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    72
    }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    73
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    74
    /*
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    75
     * rw mode,but many seek errors ...
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    76
     */
5
7c7fc8906920 FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 2
diff changeset
    77
#ifdef NETBSD
6
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    78
    /*
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    79
     * BEGIN OF STREAM
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    80
     */
5
7c7fc8906920 FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 2
diff changeset
    81
    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
    82
#else
6
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    83
    /*
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    84
     * END OF STREAM
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    85
     */
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    86
    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
    87
#endif
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    88
    return stream;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    89
}
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    90
6
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
    91
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
    92
{
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    93
    MSG message = { NULL, 0, 0, 0, 0, 0, 0 };
33
56571d34d754 safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 29
diff changeset
    94
    char msg[DEFAULT_BUF_SIZE];
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    95
    char *user;
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    96
    struct passwd *pwd;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    97
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    98
    if ((user = getenv ("USER")) == NULL)
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    99
        return IRC_GENERAL_ERROR;
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   100
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   101
    if ((pwd = getpwnam (user)) == NULL)
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   102
        return IRC_GENERAL_ERROR;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   103
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   104
    if (stream == NULL)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   105
        return IRC_GENERAL_ERROR;
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   106
    else
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   107
        message.stream = stream;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   108
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   109
    fprintf (stream, "NICK %s\r\n", nick);
6
7eb12be31bb5 Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 5
diff changeset
   110
    fprintf (stream, "USER %s 0 %s %s\r\n", user, server, pwd->pw_gecos);
18
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   111
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   112
    if (password != NULL)
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   113
        fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   114
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   115
    for (;;) {
47
a689b6a8e6ed fgets may return a NULL pointer...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 44
diff changeset
   116
        if (fgets (msg, sizeof (msg), stream) == NULL)
a689b6a8e6ed fgets may return a NULL pointer...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 44
diff changeset
   117
            break;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   118
        if ((user = irc_parsemessage (msg, &message)) != NULL)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   119
            printf ("%10s %s\n", user, message.line);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   120
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   121
        if (strstr (msg, "VERSION") != NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   122
            printf ("%10s %s", "VERSION", msg);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   123
            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
   124
            fprintf (stream, "VERSION :%s\r\n", VERSION_STRING);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   125
        }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   126
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   127
        if (strstr (msg, ":Password accepted") != NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   128
            break;
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
41
7260f61566b5 Login Error after Server Software has changed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 37
diff changeset
   131
        if (strstr (msg, ":You are now identified for") != NULL) {
7260f61566b5 Login Error after Server Software has changed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 37
diff changeset
   132
            break;
7260f61566b5 Login Error after Server Software has changed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 37
diff changeset
   133
        }
7260f61566b5 Login Error after Server Software has changed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 37
diff changeset
   134
1
5d249c79842d quick and dirty freenode connect fix
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 0
diff changeset
   135
        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
   136
            break;
5d249c79842d quick and dirty freenode connect fix
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 0
diff changeset
   137
        }
5d249c79842d quick and dirty freenode connect fix
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 0
diff changeset
   138
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   139
        if (strstr (msg, ":Password Incorrect") != NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   140
            return IRC_LOGIN_ERROR;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   141
        }
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
        if (strstr (msg, "ERROR :Closing Link") != NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   144
            return IRC_GENERAL_ERROR;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   145
        }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   146
50
412ac658eb97 No such username(402) status code updated
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 49
diff changeset
   147
        if (strstr (msg, "is not a registered") != NULL) {
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   148
            return IRC_LOGIN_ERROR;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   149
        }
18
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   150
        if (strstr (msg, ":Nickname is already in use") != NULL) {
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   151
            return IRC_LOGIN_ERROR;
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   152
        }
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   153
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   154
        if (password == NULL)
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   155
            break;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   156
    }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   157
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   158
    sleep (2);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   159
    return 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
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   162
static char *irc_getmessage (const char *line, MSG * message)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   163
{
12
213c3d4abc66 A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 11
diff changeset
   164
    static char *garbage_collector = NULL;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   165
    char *theLine;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   166
    char *token;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   167
    char *ptr;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   168
13
d3554afaa768 mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 12
diff changeset
   169
    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
   170
        free (garbage_collector);
13
d3554afaa768 mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 12
diff changeset
   171
        garbage_collector = NULL;
d3554afaa768 mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 12
diff changeset
   172
    }
12
213c3d4abc66 A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 11
diff changeset
   173
13
d3554afaa768 mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 12
diff changeset
   174
    if ((theLine = compat_strdup (line)) == NULL)
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   175
        return "ENOMEM";
12
213c3d4abc66 A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 11
diff changeset
   176
    else
213c3d4abc66 A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 11
diff changeset
   177
        garbage_collector = theLine;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   178
48
34094173351c message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 47
diff changeset
   179
    message->user = message->domain = NULL;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   180
    message->command = NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   181
    message->channel = message->line = NULL;
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
    token = strtok (theLine, " ");
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   184
    if (*token != ':') {        /* SERVER MESSAGES */
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   185
        if ((ptr = strtok (NULL, "\r\n")) != NULL)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   186
            ++ptr;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   187
        message->line = ptr;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   188
        return token;
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
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   191
    message->user = ++token;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   192
    message->command = strtok (NULL, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   193
    message->line = strtok (NULL, "\r\n");
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
    return message->command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   196
}
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   197
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   198
/**
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   199
 * 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
   200
 * This functions makes sure, that there will be someting to print...
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   201
 */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   202
char *irc_parsemessage (const char *line, MSG * message)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   203
{
37
85891f91096c enumerated types for irc.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 34
diff changeset
   204
    enum command_map map;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   205
    char *command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   206
    char *ptr;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   207
    int value;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   208
37
85891f91096c enumerated types for irc.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 34
diff changeset
   209
    map = 0;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   210
    if ((command = irc_getmessage (line, message)) != NULL) {
37
85891f91096c enumerated types for irc.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 34
diff changeset
   211
        while (IRC_Commands[map] != NULL) {
85891f91096c enumerated types for irc.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 34
diff changeset
   212
            if (strcmp (IRC_Commands[map], command) == 0) {
85891f91096c enumerated types for irc.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 34
diff changeset
   213
                switch (map) {
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   214
                case NOTICE:
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   215
                    if (message->line == NULL) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   216
                        message->channel = "*";
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   217
                        message->line = "*";
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   218
                    } else {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   219
                        message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   220
                        if ((message->line = strtok (NULL, "\r\n")) != NULL)
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   221
                            ++message->line;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   222
                    }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   223
                    return command;
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   224
                case MODE:
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   225
                    message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   226
                    message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   227
                    return command;
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   228
                case JOIN:
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   229
                case PART:
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   230
                    if ((message->channel = strchr (message->line, ':')))
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   231
                        ++message->channel;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   232
                    message->line = message->user;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   233
                    return command;
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   234
                case TOPIC:
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   235
                    message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   236
                    if ((message->line = strtok (NULL, "\r\n")))
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   237
                        ++message->line;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   238
                    return command;
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   239
                case PING:
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   240
#ifdef DEBUG
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   241
                    /*
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   242
                     * 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
   243
                     */
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   244
                    printf ("%10s %s localhost\n", "PING", message->line);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   245
#endif
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   246
                    fprintf (message->stream, "PONG :%s\r\n", message->line);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   247
                    message->channel = "localhost";
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   248
#ifdef DEBUG
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   249
                    return "PONG";
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   250
#else
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   251
                    return NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   252
#endif
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   253
                case ENOMEM:
29
08ec6ddd6eea command must be freed - makes valgrind happy trivial changes to the debian build process
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 23
diff changeset
   254
                    return "ENOMEM";
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   255
                case ERROR:
29
08ec6ddd6eea command must be freed - makes valgrind happy trivial changes to the debian build process
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 23
diff changeset
   256
                    free (command);
08ec6ddd6eea command must be freed - makes valgrind happy trivial changes to the debian build process
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 23
diff changeset
   257
                    return "ERROR";
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   258
                case VERSION:
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   259
                    if ((ptr = strchr (message->user, ' ')))
11
a769385a59c6 Many Memory Leaks in config.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 10
diff changeset
   260
                        *ptr = '\0';
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   261
                    return command;
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   262
                case PRIVMSG:
48
34094173351c message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 47
diff changeset
   263
                    if ((message->domain = strchr (message->user, '@')))
34094173351c message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 47
diff changeset
   264
                        ++message->domain;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   265
                    if ((ptr = strchr (message->user, '!')))
11
a769385a59c6 Many Memory Leaks in config.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 10
diff changeset
   266
                        *ptr = '\0';
0
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
                    message->channel = strtok (message->line, " ");
49
59b09b0aeb96 safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 48
diff changeset
   269
                    safe_strncpy (message->current_channel, message->channel, sizeof (message->current_channel));
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   270
                    message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   271
                    message->line++;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   272
                    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
   273
                    return NULL;
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   274
                case QUIT:
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   275
                    message->channel = message->user;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   276
                    return command;
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   277
                case NICK:
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   278
                    message->channel = message->user;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   279
                    return command;
19
66114d944208 op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 18
diff changeset
   280
                case KICK:
66114d944208 op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 18
diff changeset
   281
                    message->channel = message->user;
66114d944208 op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 18
diff changeset
   282
                    return command;
0
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
            }
37
85891f91096c enumerated types for irc.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 34
diff changeset
   285
            map++;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   286
        }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   287
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   288
        if ((value = atoi (command)) != 0) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   289
            switch (value) {
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   290
            case 1:            /* CONNECTION INFOS */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   291
            case 2:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   292
            case 3:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   293
            case 4:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   294
            case 5:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   295
            case 250:
23
1cd79bb84e9c ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 22
diff changeset
   296
            case 251:          /* NUMBER OF USERS */
1cd79bb84e9c ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 22
diff changeset
   297
            case 252:          /* STAFF MEMBERS */
1cd79bb84e9c ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 22
diff changeset
   298
            case 254:          /* CHANNELS */
1cd79bb84e9c ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 22
diff changeset
   299
            case 255:          /* CLIENTS */
1cd79bb84e9c ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 22
diff changeset
   300
            case 265:          /* LOCAL USERS */
1cd79bb84e9c ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 22
diff changeset
   301
            case 266:          /* GLOBAL USERS */
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   302
                /*
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   303
                 * prints as is in irc_login
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   304
                 */
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 311:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   307
            case 312:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   308
            case 315:          /* END OF WHO */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   309
            case 318:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   310
                message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   311
                message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   312
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   313
            case 319:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   314
                message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   315
                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
   316
                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
   317
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   318
            case 320:
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   319
            case 328:          /* INFORMATION */
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   320
            case 332:          /* TOPIC OF CHANNEL */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   321
            case 333:          /* NAMES IN CHANNEL */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   322
            case 351:          /* SVERSION */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   323
            case 352:          /* WHO LIST */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   324
            case 353:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   325
            case 365:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   326
            case 366:          /* END OF NAMES */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   327
                message->channel = strtok (message->line, " ");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   328
                message->line = strtok (NULL, "\r\n");
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   329
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   330
            case 372:          /* MOTD MESSAGES */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   331
            case 375:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   332
            case 376:          /* END OF MOTD */
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   333
                return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   334
            case 401:          /* NO SUCH NICK/CHANNEL */
50
412ac658eb97 No such username(402) status code updated
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 49
diff changeset
   335
            case 402:          /* NO SUCH USER */
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   336
            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
   337
            case 412:          /* NO TEXT TO SEND */
10
311ea5fa60dd Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   338
            case 441:          /* THEY AREN'T ON THIS CHANNEL */
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   339
                message->channel = strtok (message->line, " ");
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   340
                message->line = strtok (NULL, "\r\n");
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   341
                return command;
18
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   342
            case 433:          /* NICK ALREADY IN USE */
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   343
            case 451:          /* REGISTER FIRST */
4435146391ae LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 15
diff changeset
   344
                return command;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   345
            case 474:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   346
            case 475:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   347
            case 476:
23
1cd79bb84e9c ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 22
diff changeset
   348
            case 477:          /* HOW TO GET HELP */
22
b786b5f92a93 Bot responses reduced
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 19
diff changeset
   349
            case 486:          /* MUST BE REGISTERED TO SEND PRIVATE MESSAGES */
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   350
            case 482:
2
6a2e88214b80 freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 1
diff changeset
   351
            case 901:          /* notify or some crap */
6a2e88214b80 freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 1
diff changeset
   352
                message->channel = strtok (message->line, " ");
6a2e88214b80 freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 1
diff changeset
   353
                message->line = strtok (NULL, "\r\n");
15
f19c1f9b4cd3 ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 13
diff changeset
   354
                fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line);
2
6a2e88214b80 freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 1
diff changeset
   355
                return command;
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   356
            default:
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   357
                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
   358
                printf ("Unknown Command Value: %d\n", value);
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   359
            }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   360
        }
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   361
        printf ("DEBUG   %s", line);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   362
        printf ("Unknown Command: %s\n", command);
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   363
        return command;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   364
    }
9
aff6726b8b87 Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 6
diff changeset
   365
    printf ("NOT PARSEABLE   %s", line);
0
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   366
    return NULL;
586472add385 Initial Layout
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   367
}