Загрузить файлы в «C»
Fixed bugs in parser
This commit is contained in:
parent
a25dbc52fd
commit
614470bc94
14
C/irc.c
14
C/irc.c
@ -42,15 +42,16 @@ unsigned int IRCC_register(IRCC_client *irc, const char *nickname){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IRCC_parse(char *tmp, IRCC_client *irc){
|
void IRCC_parse(char *tmp, IRCC_client *irc){
|
||||||
|
irc->raw[strcspn(irc->raw, "\r\n")] = '\0';
|
||||||
if (tmp != NULL){
|
if (tmp != NULL){
|
||||||
//Message
|
//Message
|
||||||
if (strstr(tmp, ":") != NULL)
|
if (strstr(tmp, ":") != NULL)
|
||||||
irc->msg = strstr(tmp, ":");
|
irc->msg = strstr(tmp, ":");
|
||||||
|
|
||||||
//Channel
|
//Channel
|
||||||
if (strstr(tmp, "#") != NULL){
|
if (strstr(tmp, " ") != NULL){
|
||||||
irc->channel = strstr(tmp, "#");
|
irc->channel = strstr(tmp, " ") + 1;
|
||||||
irc->channel[strcspn(irc->channel, " ")] = '\0';
|
irc->channel[strcspn(irc->channel, ":") - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
//Nickname
|
//Nickname
|
||||||
@ -77,9 +78,12 @@ unsigned int IRCC_recv(IRCC_client *irc){
|
|||||||
|
|
||||||
else {
|
else {
|
||||||
//puts(irc->raw);
|
//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);
|
IRCC_parse(strstr(irc->raw, "PRIVMSG "), irc);
|
||||||
return IRCC_PRIVMSG;
|
return IRCC_PRIVMSG;
|
||||||
}
|
}
|
||||||
|
19
C/irc.h
19
C/irc.h
@ -9,15 +9,18 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#define IRCC_NICK 8
|
enum {
|
||||||
#define IRCC_PRIVMSG 7
|
IRCC_CONNECTED = 1,
|
||||||
#define IRCC_JOIN 6
|
IRCC_NICK,
|
||||||
#define IRCC_PART 5
|
IRCC_PRIVMSG,
|
||||||
#define IRCC_PING 4
|
IRCC_JOIN,
|
||||||
|
IRCC_PART,
|
||||||
|
IRCC_PING,
|
||||||
|
|
||||||
#define IRCC_DISCONNECTED 2
|
IRCC_DISCONNECTED,
|
||||||
#define IRCC_ERROR 1
|
IRCC_ERROR,
|
||||||
#define IRCC_SUCCESS 0
|
IRCC_SUCCESS
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int socket;
|
int socket;
|
||||||
|
Loading…
Reference in New Issue
Block a user