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