mirror of
https://github.com/osmarks/ngircd.git
synced 2024-10-28 04:46:17 +00:00
- bessere Fehler-Abfragen, diverse Bugfixes.
- Nicks werden nur einmal vergeben :-) - /MOTD wird unterstuetzt.
This commit is contained in:
parent
cfd78b90ac
commit
bbfe9e8ba8
121
src/ngircd/irc.c
121
src/ngircd/irc.c
@ -9,11 +9,16 @@
|
|||||||
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
|
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
|
||||||
* der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS.
|
* der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS.
|
||||||
*
|
*
|
||||||
* $Id: irc.c,v 1.3 2001/12/24 01:34:06 alex Exp $
|
* $Id: irc.c,v 1.4 2001/12/25 19:19:30 alex Exp $
|
||||||
*
|
*
|
||||||
* irc.c: IRC-Befehle
|
* irc.c: IRC-Befehle
|
||||||
*
|
*
|
||||||
* $Log: irc.c,v $
|
* $Log: irc.c,v $
|
||||||
|
* Revision 1.4 2001/12/25 19:19:30 alex
|
||||||
|
* - bessere Fehler-Abfragen, diverse Bugfixes.
|
||||||
|
* - Nicks werden nur einmal vergeben :-)
|
||||||
|
* - /MOTD wird unterstuetzt.
|
||||||
|
*
|
||||||
* Revision 1.3 2001/12/24 01:34:06 alex
|
* Revision 1.3 2001/12/24 01:34:06 alex
|
||||||
* - USER und NICK wird nun in beliebiger Reihenfolge akzeptiert (wg. BitchX)
|
* - USER und NICK wird nun in beliebiger Reihenfolge akzeptiert (wg. BitchX)
|
||||||
* - MOTD-Ausgabe begonnen zu implementieren.
|
* - MOTD-Ausgabe begonnen zu implementieren.
|
||||||
@ -44,10 +49,14 @@
|
|||||||
#include "irc.h"
|
#include "irc.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define CONNECTED TRUE
|
||||||
|
#define DISCONNECTED FALSE
|
||||||
|
|
||||||
|
|
||||||
LOCAL BOOLEAN Check_Valid_User( CLIENT *Client );
|
LOCAL BOOLEAN Check_Valid_User( CLIENT *Client );
|
||||||
|
|
||||||
LOCAL VOID Hello_User( CLIENT *Client );
|
LOCAL BOOLEAN Hello_User( CLIENT *Client );
|
||||||
LOCAL VOID Show_MOTD( CLIENT *Client );
|
LOCAL BOOLEAN Show_MOTD( CLIENT *Client );
|
||||||
|
|
||||||
|
|
||||||
GLOBAL VOID IRC_Init( VOID )
|
GLOBAL VOID IRC_Init( VOID )
|
||||||
@ -60,11 +69,12 @@ GLOBAL VOID IRC_Exit( VOID )
|
|||||||
} /* IRC_Exit */
|
} /* IRC_Exit */
|
||||||
|
|
||||||
|
|
||||||
GLOBAL VOID IRC_WriteStr_Client( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... )
|
GLOBAL BOOLEAN IRC_WriteStr_Client( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... )
|
||||||
{
|
{
|
||||||
/* Text an Clients, lokal bzw. remote, senden. */
|
/* Text an Clients, lokal bzw. remote, senden. */
|
||||||
|
|
||||||
CHAR buffer[1000];
|
CHAR buffer[1000];
|
||||||
|
BOOLEAN ok = CONNECTED;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
assert( Client != NULL );
|
assert( Client != NULL );
|
||||||
@ -76,15 +86,17 @@ GLOBAL VOID IRC_WriteStr_Client( CLIENT *Client, CLIENT *Prefix, CHAR *Format, .
|
|||||||
{
|
{
|
||||||
/* Lokaler Client */
|
/* Lokaler Client */
|
||||||
vsnprintf( buffer, 1000, Format, ap );
|
vsnprintf( buffer, 1000, Format, ap );
|
||||||
if( Prefix ) Conn_WriteStr( Client->conn_id, ":%s %s", Prefix->host, buffer );
|
if( Prefix ) ok = Conn_WriteStr( Client->conn_id, ":%s %s", Prefix->host, buffer );
|
||||||
else Conn_WriteStr( Client->conn_id, buffer );
|
else ok = Conn_WriteStr( Client->conn_id, buffer );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Remote-Client */
|
/* Remote-Client */
|
||||||
Log( LOG_DEBUG, "not implemented: IRC_WriteStr_Client()" );
|
Log( LOG_DEBUG, "not implemented: IRC_WriteStr_Client()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
va_end( ap );
|
va_end( ap );
|
||||||
|
return ok;
|
||||||
} /* IRC_WriteStr_Client */
|
} /* IRC_WriteStr_Client */
|
||||||
|
|
||||||
|
|
||||||
@ -93,41 +105,49 @@ GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req )
|
|||||||
assert( Client != NULL );
|
assert( Client != NULL );
|
||||||
assert( Req != NULL );
|
assert( Req != NULL );
|
||||||
|
|
||||||
IRC_WriteStr_Client( Client, This_Server, ERR_UNKNOWNCOMMAND_MSG, Req->command );
|
return IRC_WriteStr_Client( Client, This_Server, ERR_UNKNOWNCOMMAND_MSG, Req->command );
|
||||||
return TRUE;
|
|
||||||
} /* IRC_PASS */
|
} /* IRC_PASS */
|
||||||
|
|
||||||
|
|
||||||
GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
|
GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
|
||||||
{
|
{
|
||||||
|
CLIENT *c;
|
||||||
|
|
||||||
assert( Client != NULL );
|
assert( Client != NULL );
|
||||||
assert( Req != NULL );
|
assert( Req != NULL );
|
||||||
|
|
||||||
if( Client->type == CLIENT_UNKNOWN || Client->type == CLIENT_PASS || Client->type == CLIENT_USER )
|
if( Client->type != CLIENT_SERVER && Client->type != CLIENT_SERVICE )
|
||||||
{
|
{
|
||||||
/* Neuer Client */
|
/* Falsche Anzahl Parameter? */
|
||||||
if( Req->argc == 1 )
|
if( Req->argc != 1 ) return IRC_WriteStr_Client( Client, This_Server, ERR_NEEDMOREPARAMS_MSG );
|
||||||
|
|
||||||
|
/* Nick zu lang? */
|
||||||
|
if( strlen( Req->argv[0] ) > CLIENT_NICK_LEN ) return IRC_WriteStr_Client( Client, This_Server, ERR_ERRONEUSNICKNAME_MSG, Req->argv[0] );
|
||||||
|
|
||||||
|
/* pruefen, ob Nick bereits vergeben */
|
||||||
|
c = My_Clients;
|
||||||
|
while( c )
|
||||||
{
|
{
|
||||||
if( strlen( Req->argv[0] ) <= CLIENT_NICK_LEN )
|
if( strcasecmp( c->nick, Req->argv[0] ) == 0 )
|
||||||
{
|
{
|
||||||
|
/* den Nick gibt es bereits */
|
||||||
|
return IRC_WriteStr_Client( Client, This_Server, ERR_NICKNAMEINUSE_MSG, Req->argv[0] );
|
||||||
|
}
|
||||||
|
c = c->next;
|
||||||
|
}
|
||||||
|
|
||||||
/* Client-Nick registrieren */
|
/* Client-Nick registrieren */
|
||||||
strcpy( Client->nick, Req->argv[0] );
|
strcpy( Client->nick, Req->argv[0] );
|
||||||
if( Client->type == CLIENT_USER ) Hello_User( Client );
|
|
||||||
Client->type = CLIENT_NICK;
|
|
||||||
}
|
|
||||||
else IRC_WriteStr_Client( Client, This_Server, ERR_ERRONEUSNICKNAME_MSG, Req->argv[0] );
|
|
||||||
}
|
|
||||||
else IRC_WriteStr_Client( Client, This_Server, ERR_NEEDMOREPARAMS_MSG );
|
|
||||||
}
|
|
||||||
else if( Client->type == CLIENT_USER )
|
|
||||||
{
|
|
||||||
/* Nick-Aenderung eines Users */
|
|
||||||
if( ! Check_Valid_User( Client )) return TRUE;
|
|
||||||
Log( LOG_DEBUG, "not implemented: IRC_NICK()" );
|
|
||||||
}
|
|
||||||
else IRC_WriteStr_Client( Client, This_Server, ERR_ALREADYREGISTRED_MSG );
|
|
||||||
|
|
||||||
return TRUE;
|
if( Client->type != CLIENT_USER )
|
||||||
|
{
|
||||||
|
/* Neuer Client */
|
||||||
|
if( Client->type == CLIENT_GOTUSER ) return Hello_User( Client );
|
||||||
|
else Client->type = CLIENT_GOTNICK;
|
||||||
|
}
|
||||||
|
return CONNECTED;
|
||||||
|
}
|
||||||
|
else return IRC_WriteStr_Client( Client, This_Server, ERR_ALREADYREGISTRED_MSG );
|
||||||
} /* IRC_NICK */
|
} /* IRC_NICK */
|
||||||
|
|
||||||
|
|
||||||
@ -136,29 +156,42 @@ GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req )
|
|||||||
assert( Client != NULL );
|
assert( Client != NULL );
|
||||||
assert( Req != NULL );
|
assert( Req != NULL );
|
||||||
|
|
||||||
if( Client->type == CLIENT_UNKNOWN || Client->type == CLIENT_NICK )
|
if( Client->type == CLIENT_UNKNOWN || Client->type == CLIENT_GOTNICK || Client->type == CLIENT_GOTPASS )
|
||||||
{
|
|
||||||
if( Req->argc == 4 )
|
|
||||||
{
|
{
|
||||||
|
/* Falsche Anzahl Parameter? */
|
||||||
|
if( Req->argc != 4 ) return IRC_WriteStr_Client( Client, This_Server, ERR_NEEDMOREPARAMS_MSG );
|
||||||
|
|
||||||
strncpy( Client->user, Req->argv[0], CLIENT_USER_LEN );
|
strncpy( Client->user, Req->argv[0], CLIENT_USER_LEN );
|
||||||
Client->user[CLIENT_USER_LEN] = '\0';
|
Client->user[CLIENT_USER_LEN] = '\0';
|
||||||
strncpy( Client->name, Req->argv[3], CLIENT_NAME_LEN );
|
strncpy( Client->name, Req->argv[3], CLIENT_NAME_LEN );
|
||||||
Client->name[CLIENT_NAME_LEN] = '\0';
|
Client->name[CLIENT_NAME_LEN] = '\0';
|
||||||
if( Client->type == CLIENT_NICK ) Hello_User( Client );
|
|
||||||
Client->type = CLIENT_USER;
|
if( Client->type == CLIENT_GOTNICK ) return Hello_User( Client );
|
||||||
}
|
else Client->type = CLIENT_GOTUSER;
|
||||||
else IRC_WriteStr_Client( Client, This_Server, ERR_NEEDMOREPARAMS_MSG );
|
return CONNECTED;
|
||||||
}
|
}
|
||||||
else if( Client->type == CLIENT_USER || Client->type == CLIENT_SERVER || Client->type == CLIENT_SERVICE )
|
else if( Client->type == CLIENT_USER || Client->type == CLIENT_SERVER || Client->type == CLIENT_SERVICE )
|
||||||
{
|
{
|
||||||
IRC_WriteStr_Client( Client, This_Server, ERR_ALREADYREGISTRED_MSG );
|
return IRC_WriteStr_Client( Client, This_Server, ERR_ALREADYREGISTRED_MSG );
|
||||||
}
|
}
|
||||||
else IRC_WriteStr_Client( Client, This_Server, ERR_NOTREGISTERED_MSG );
|
else return IRC_WriteStr_Client( Client, This_Server, ERR_NOTREGISTERED_MSG );
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
} /* IRC_USER */
|
} /* IRC_USER */
|
||||||
|
|
||||||
|
|
||||||
|
GLOBAL BOOLEAN IRC_MOTD( CLIENT *Client, REQUEST *Req )
|
||||||
|
{
|
||||||
|
assert( Client != NULL );
|
||||||
|
assert( Req != NULL );
|
||||||
|
|
||||||
|
if( ! Check_Valid_User( Client )) return CONNECTED;
|
||||||
|
|
||||||
|
/* Falsche Anzahl Parameter? */
|
||||||
|
if( Req->argc != 0 ) return IRC_WriteStr_Client( Client, This_Server, ERR_NEEDMOREPARAMS_MSG );
|
||||||
|
|
||||||
|
return Show_MOTD( Client );
|
||||||
|
} /* IRC_MOTD */
|
||||||
|
|
||||||
|
|
||||||
LOCAL BOOLEAN Check_Valid_User( CLIENT *Client )
|
LOCAL BOOLEAN Check_Valid_User( CLIENT *Client )
|
||||||
{
|
{
|
||||||
assert( Client != NULL );
|
assert( Client != NULL );
|
||||||
@ -172,22 +205,26 @@ LOCAL BOOLEAN Check_Valid_User( CLIENT *Client )
|
|||||||
} /* Check_Valid_User */
|
} /* Check_Valid_User */
|
||||||
|
|
||||||
|
|
||||||
LOCAL VOID Hello_User( CLIENT *Client )
|
LOCAL BOOLEAN Hello_User( CLIENT *Client )
|
||||||
{
|
{
|
||||||
Log( LOG_INFO, "User \"%s!%s@%s\" (%s) registered.", Client->nick, Client->user, Client->host, Client->name );
|
Log( LOG_INFO, "User \"%s!%s@%s\" (%s) registered.", Client->nick, Client->user, Client->host, Client->name );
|
||||||
|
|
||||||
IRC_WriteStr_Client( Client, This_Server, RPL_WELCOME_MSG, Client->nick, Client->nick, Client->user, Client->host );
|
IRC_WriteStr_Client( Client, This_Server, RPL_WELCOME_MSG, Client->nick, Client->nick, Client->user, Client->host );
|
||||||
IRC_WriteStr_Client( Client, This_Server, RPL_YOURHOST_MSG, Client->nick, This_Server->host );
|
IRC_WriteStr_Client( Client, This_Server, RPL_YOURHOST_MSG, Client->nick, This_Server->host );
|
||||||
IRC_WriteStr_Client( Client, This_Server, RPL_CREATED_MSG, Client->nick );
|
IRC_WriteStr_Client( Client, This_Server, RPL_CREATED_MSG, Client->nick );
|
||||||
IRC_WriteStr_Client( Client, This_Server, RPL_MYINFO_MSG, Client->nick, This_Server->host );
|
IRC_WriteStr_Client( Client, This_Server, RPL_MYINFO_MSG, Client->nick, This_Server->host );
|
||||||
Show_MOTD( Client );
|
|
||||||
|
Client->type = CLIENT_USER;
|
||||||
|
|
||||||
|
return Show_MOTD( Client );
|
||||||
} /* Hello_User */
|
} /* Hello_User */
|
||||||
|
|
||||||
|
|
||||||
LOCAL VOID Show_MOTD( CLIENT *Client )
|
LOCAL BOOLEAN Show_MOTD( CLIENT *Client )
|
||||||
{
|
{
|
||||||
IRC_WriteStr_Client( Client, This_Server, RPL_MOTDSTART_MSG, Client->nick, This_Server->host );
|
IRC_WriteStr_Client( Client, This_Server, RPL_MOTDSTART_MSG, Client->nick, This_Server->host );
|
||||||
IRC_WriteStr_Client( Client, This_Server, RPL_MOTD_MSG, Client->nick, "Some cool IRC server welcome message ;-)" );
|
IRC_WriteStr_Client( Client, This_Server, RPL_MOTD_MSG, Client->nick, "Some cool IRC server welcome message ;-)" );
|
||||||
IRC_WriteStr_Client( Client, This_Server, RPL_ENDOFMOTD_MSG, Client->nick );
|
return IRC_WriteStr_Client( Client, This_Server, RPL_ENDOFMOTD_MSG, Client->nick );
|
||||||
} /* Show_MOTD */
|
} /* Show_MOTD */
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,11 +9,16 @@
|
|||||||
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
|
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
|
||||||
* der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS.
|
* der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS.
|
||||||
*
|
*
|
||||||
* $Id: irc.h,v 1.2 2001/12/23 21:57:16 alex Exp $
|
* $Id: irc.h,v 1.3 2001/12/25 19:19:30 alex Exp $
|
||||||
*
|
*
|
||||||
* irc.h: IRC-Befehle (Header)
|
* irc.h: IRC-Befehle (Header)
|
||||||
*
|
*
|
||||||
* $Log: irc.h,v $
|
* $Log: irc.h,v $
|
||||||
|
* Revision 1.3 2001/12/25 19:19:30 alex
|
||||||
|
* - bessere Fehler-Abfragen, diverse Bugfixes.
|
||||||
|
* - Nicks werden nur einmal vergeben :-)
|
||||||
|
* - /MOTD wird unterstuetzt.
|
||||||
|
*
|
||||||
* Revision 1.2 2001/12/23 21:57:16 alex
|
* Revision 1.2 2001/12/23 21:57:16 alex
|
||||||
* - erste IRC-Befehle zu implementieren begonnen.
|
* - erste IRC-Befehle zu implementieren begonnen.
|
||||||
*
|
*
|
||||||
@ -31,12 +36,14 @@
|
|||||||
GLOBAL VOID IRC_Init( VOID );
|
GLOBAL VOID IRC_Init( VOID );
|
||||||
GLOBAL VOID IRC_Exit( VOID );
|
GLOBAL VOID IRC_Exit( VOID );
|
||||||
|
|
||||||
GLOBAL VOID IRC_WriteStr_Client( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... );
|
GLOBAL BOOLEAN IRC_WriteStr_Client( CLIENT *Client, CLIENT *Prefix, CHAR *Format, ... );
|
||||||
|
|
||||||
GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req );
|
GLOBAL BOOLEAN IRC_PASS( CLIENT *Client, REQUEST *Req );
|
||||||
GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req );
|
GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req );
|
||||||
GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req );
|
GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req );
|
||||||
|
|
||||||
|
GLOBAL BOOLEAN IRC_MOTD( CLIENT *Client, REQUEST *Req );
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user