commit - cfd78b90acb6637ac9b296d7091a511caa40201f
commit + bbfe9e8ba83ac80474f2950a74f3334b0c86680c
blob - 4c9dc139d6a35110faf3ed90405e706596b560a4
blob + 47f224b86b55ef2acdbe49c6a4804a026b599616
--- src/ngircd/irc.c
+++ src/ngircd/irc.c
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
* 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
*
* $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
* - USER und NICK wird nun in beliebiger Reihenfolge akzeptiert (wg. BitchX)
* - MOTD-Ausgabe begonnen zu implementieren.
#include "irc.h"
+#define CONNECTED TRUE
+#define DISCONNECTED FALSE
+
+
LOCAL BOOLEAN Check_Valid_User( CLIENT *Client );
-LOCAL VOID Hello_User( CLIENT *Client );
-LOCAL VOID Show_MOTD( CLIENT *Client );
+LOCAL BOOLEAN Hello_User( CLIENT *Client );
+LOCAL BOOLEAN Show_MOTD( CLIENT *Client );
GLOBAL VOID IRC_Init( VOID )
} /* 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. */
CHAR buffer[1000];
+ BOOLEAN ok = CONNECTED;
va_list ap;
assert( Client != NULL );
{
/* Lokaler Client */
vsnprintf( buffer, 1000, Format, ap );
- if( Prefix ) Conn_WriteStr( Client->conn_id, ":%s %s", Prefix->host, buffer );
- else Conn_WriteStr( Client->conn_id, buffer );
+ if( Prefix ) ok = Conn_WriteStr( Client->conn_id, ":%s %s", Prefix->host, buffer );
+ else ok = Conn_WriteStr( Client->conn_id, buffer );
}
else
{
/* Remote-Client */
Log( LOG_DEBUG, "not implemented: IRC_WriteStr_Client()" );
}
+
va_end( ap );
+ return ok;
} /* IRC_WriteStr_Client */
assert( Client != NULL );
assert( Req != NULL );
- IRC_WriteStr_Client( Client, This_Server, ERR_UNKNOWNCOMMAND_MSG, Req->command );
- return TRUE;
+ return IRC_WriteStr_Client( Client, This_Server, ERR_UNKNOWNCOMMAND_MSG, Req->command );
} /* IRC_PASS */
GLOBAL BOOLEAN IRC_NICK( CLIENT *Client, REQUEST *Req )
{
+ CLIENT *c;
+
assert( Client != 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 */
- if( Req->argc == 1 )
+ /* Falsche Anzahl Parameter? */
+ 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 )
{
- /* Client-Nick registrieren */
- strcpy( Client->nick, Req->argv[0] );
- if( Client->type == CLIENT_USER ) Hello_User( Client );
- Client->type = CLIENT_NICK;
+ /* den Nick gibt es bereits */
+ return IRC_WriteStr_Client( Client, This_Server, ERR_NICKNAMEINUSE_MSG, Req->argv[0] );
}
- else IRC_WriteStr_Client( Client, This_Server, ERR_ERRONEUSNICKNAME_MSG, Req->argv[0] );
+ c = c->next;
}
- 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 );
+
+ /* Client-Nick registrieren */
+ strcpy( Client->nick, Req->argv[0] );
- 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 */
assert( Client != 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 )
- {
- strncpy( Client->user, Req->argv[0], CLIENT_USER_LEN );
- Client->user[CLIENT_USER_LEN] = '\0';
- strncpy( Client->name, Req->argv[3], CLIENT_NAME_LEN );
- Client->name[CLIENT_NAME_LEN] = '\0';
- if( Client->type == CLIENT_NICK ) Hello_User( Client );
- Client->type = CLIENT_USER;
- }
- else IRC_WriteStr_Client( Client, This_Server, ERR_NEEDMOREPARAMS_MSG );
+ /* 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 );
+ Client->user[CLIENT_USER_LEN] = '\0';
+ strncpy( Client->name, Req->argv[3], CLIENT_NAME_LEN );
+ Client->name[CLIENT_NAME_LEN] = '\0';
+
+ if( Client->type == CLIENT_GOTNICK ) return Hello_User( Client );
+ else Client->type = CLIENT_GOTUSER;
+ return CONNECTED;
}
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 );
-
- return TRUE;
+ else return IRC_WriteStr_Client( Client, This_Server, ERR_NOTREGISTERED_MSG );
} /* 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 )
{
assert( Client != NULL );
} /* 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 );
+
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_CREATED_MSG, Client->nick );
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 */
-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_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 */
blob - 14f1b04a5222d8570bf9a8a414e56c13215dfdf6
blob + d0c18b8761d312859dd34a9d80c6c6fbf64adf26
--- src/ngircd/irc.h
+++ src/ngircd/irc.h
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
* 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)
*
* $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
* - erste IRC-Befehle zu implementieren begonnen.
*
GLOBAL VOID IRC_Init( 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_NICK( CLIENT *Client, REQUEST *Req );
GLOBAL BOOLEAN IRC_USER( CLIENT *Client, REQUEST *Req );
+GLOBAL BOOLEAN IRC_MOTD( CLIENT *Client, REQUEST *Req );
+
#endif