This commit is contained in:
Your Name 2023-12-30 16:55:10 +03:00
parent 751260e234
commit fa2b540550

23
C/irc.c
View File

@ -32,32 +32,29 @@ void IRCC_parse(char *tmp, IRCC_client *irc){
if (tmp != NULL){
//Message
char *val = strchr(tmp, ':');
if (val == NULL)
return;
if (val != NULL) {
val[0] = '\0';
irc->msg = val + 1;
//Del space before :
*(val - 1) = '\0';
}
//Channel
val = strchr(tmp, ' ');
if (val == NULL)
return;
if (val != NULL) {
val[0] = '\0';
irc->channel = val + 1;
}
//Nickname
val = strchr(irc->raw, '!');
if (val == NULL)
return;
if (val != NULL) {
val[0] = '\0';
irc->nick = irc->raw + 1;
}
}
}
int IRCC_recv(IRCC_client *irc){
memset(irc->raw, '\0', IRCC_MSG_MAX);
@ -147,18 +144,18 @@ int IRCC_register(IRCC_client *irc, const char *nickname){
int IRCC_join(IRCC_client *irc, const char *channel, const char *key){
off_t bytes = snprintf(irc->raw, sizeof(irc->raw), "JOIN %s %s\r\n", channel, (key) ? key : "");
if (send(irc->socket, irc->raw, bytes, 0) == -1)
return IRCC_SUCCESS;
return IRCC_ERROR;
return IRCC_SUCCESS;
}
int IRCC_send(IRCC_client *irc, const char *channel, const char *msg){
off_t bytes = snprintf(irc->raw, sizeof(irc->raw), "PRIVMSG %s :%s\r\n", channel, msg);
if (send(irc->socket, irc->raw, bytes, 0) == -1)
return IRCC_SUCCESS;
return IRCC_ERROR;
return IRCC_SUCCESS;
}
int IRCC_init(IRCC_client *irc) {