Загрузить файлы в «C»
This commit is contained in:
parent
614470bc94
commit
ad09f6fba5
23
C/irc.c
23
C/irc.c
@ -5,6 +5,7 @@ unsigned int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int p
|
||||
if (!ghbn)
|
||||
return IRCC_ERROR;
|
||||
|
||||
//Only ipv4
|
||||
struct sockaddr_in client_str;
|
||||
memset(&client_str, 0, sizeof(client_str));
|
||||
client_str.sin_family = AF_INET;
|
||||
@ -23,18 +24,14 @@ unsigned int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int p
|
||||
}
|
||||
|
||||
unsigned int IRCC_register(IRCC_client *irc, const char *nickname){
|
||||
size_t size = strlen("USER \r\n 0 0 ") + strlen(nickname) + strlen(nickname);
|
||||
char *tmp = (char *)malloc(size + 1);
|
||||
size_t size = strlen("NICK %s\r\nUSER %s 0 localhost :%s \r\n") + (strlen(nickname) * 3);
|
||||
char *tmp = (char *)malloc(size);
|
||||
if (tmp == NULL){
|
||||
fprintf(stderr, "malloc returned NULL (IRCC_register)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sleep(2);
|
||||
snprintf(tmp, size, "USER %s 0 0 %s\r\n", nickname, nickname);
|
||||
send(irc->socket, tmp, strlen(tmp), 0);
|
||||
|
||||
snprintf(tmp, size, "NICK %s\r\n", nickname);
|
||||
snprintf(tmp, size, "NICK %s\r\nUSER %s 0 localhost :%s\r\n", nickname, nickname, nickname);
|
||||
send(irc->socket, tmp, strlen(tmp), 0);
|
||||
|
||||
free(tmp);
|
||||
@ -80,9 +77,10 @@ unsigned int IRCC_recv(IRCC_client *irc){
|
||||
//puts(irc->raw);
|
||||
|
||||
//Check end of motd
|
||||
if (strstr(irc->raw, "PRIVMSG ") == NULL && strstr(irc->raw, "/MOTD"))
|
||||
if (strstr(irc->raw, "PRIVMSG ") == NULL && strstr(irc->raw, "MOTD"))
|
||||
return IRCC_CONNECTED;
|
||||
|
||||
//Other
|
||||
else if (strstr(irc->raw, "PRIVMSG ")){
|
||||
IRCC_parse(strstr(irc->raw, "PRIVMSG "), irc);
|
||||
return IRCC_PRIVMSG;
|
||||
@ -136,9 +134,7 @@ unsigned int IRCC_init(IRCC_client *irc, size_t size){
|
||||
exit(1);
|
||||
}
|
||||
|
||||
irc->msg = NULL;
|
||||
irc->nick = NULL;
|
||||
irc->channel = NULL;
|
||||
irc->msg = irc->nick = irc->channel = NULL;
|
||||
|
||||
irc->size = size;
|
||||
return IRCC_SUCCESS;
|
||||
@ -148,10 +144,7 @@ void IRCC_close(IRCC_client *irc){
|
||||
close(irc->socket);
|
||||
|
||||
free(irc->raw);
|
||||
irc->raw = NULL;
|
||||
irc->msg = NULL;
|
||||
irc->nick = NULL;
|
||||
irc->channel = NULL;
|
||||
irc->raw = irc->msg = irc->nick = irc->channel = NULL;
|
||||
|
||||
irc->size = 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user