Загрузить файлы в «C»

Fixed bugs in parser
This commit is contained in:
8nlight 2023-08-07 18:06:44 +03:00
parent a25dbc52fd
commit 614470bc94
2 changed files with 20 additions and 13 deletions

14
C/irc.c
View File

@ -42,15 +42,16 @@ unsigned int IRCC_register(IRCC_client *irc, const char *nickname){
}
void IRCC_parse(char *tmp, IRCC_client *irc){
irc->raw[strcspn(irc->raw, "\r\n")] = '\0';
if (tmp != NULL){
//Message
if (strstr(tmp, ":") != NULL)
irc->msg = strstr(tmp, ":");
//Channel
if (strstr(tmp, "#") != NULL){
irc->channel = strstr(tmp, "#");
irc->channel[strcspn(irc->channel, " ")] = '\0';
if (strstr(tmp, " ") != NULL){
irc->channel = strstr(tmp, " ") + 1;
irc->channel[strcspn(irc->channel, ":") - 1] = '\0';
}
//Nickname
@ -77,9 +78,12 @@ unsigned int IRCC_recv(IRCC_client *irc){
else {
//puts(irc->raw);
irc->raw[strcspn(irc->raw, "\r\n")] = '\0';
if (strstr(irc->raw, "PRIVMSG ")){
//Check end of motd
if (strstr(irc->raw, "PRIVMSG ") == NULL && strstr(irc->raw, "/MOTD"))
return IRCC_CONNECTED;
else if (strstr(irc->raw, "PRIVMSG ")){
IRCC_parse(strstr(irc->raw, "PRIVMSG "), irc);
return IRCC_PRIVMSG;
}

19
C/irc.h
View File

@ -9,15 +9,18 @@
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define IRCC_NICK 8
#define IRCC_PRIVMSG 7
#define IRCC_JOIN 6
#define IRCC_PART 5
#define IRCC_PING 4
enum {
IRCC_CONNECTED = 1,
IRCC_NICK,
IRCC_PRIVMSG,
IRCC_JOIN,
IRCC_PART,
IRCC_PING,
#define IRCC_DISCONNECTED 2
#define IRCC_ERROR 1
#define IRCC_SUCCESS 0
IRCC_DISCONNECTED,
IRCC_ERROR,
IRCC_SUCCESS
};
typedef struct {
int socket;