+ if(!stricmp(argv[1], "001")) {
+ free(session->nick);
+ session->nick = strdup(argv[2]);
+ client->fully_connected = 1;
+ }
+ if(!stricmp(argv[1], "005")) {
+ //parse 005 raw
+ ircclient_raw005_parse(client, argv+3, argc-3);
+ }
+ if(!stricmp(argv[1], "001") ||
+ !stricmp(argv[1], "002") ||
+ !stricmp(argv[1], "003") ||
+ !stricmp(argv[1], "004") ||
+ !stricmp(argv[1], "005") ||
+ !stricmp(argv[1], "375") ||
+ !stricmp(argv[1], "372") ||
+ !stricmp(argv[1], "376")
+ ) {
+ //save these raw's for recovering the connection later
+ struct IRCLine *recover_line = NULL, *new_line;
+ if(client->recover_header)
+ for(recover_line = client->recover_header; recover_line->next; recover_line = recover_line->next) {};
+ new_line = malloc(sizeof(*new_line));
+ if(new_line) {
+ new_line->line = strdup(line);
+ new_line->next = NULL;
+ if(recover_line)
+ recover_line->next = new_line;
+ else
+ client->recover_header = new_line;
+ }
+ } else if(!stricmp(argv[1], "JOIN")) {
+ struct IRCUser from = ircclient_parse_user(argv[0]);
+ struct IRCChannel *channel;
+ if(!stricmp(from.nick, session->nick)) {
+ struct IRCChannel *lchannel = NULL;
+ channel = calloc(1, sizeof(*channel));
+ if(client->channel)
+ for(lchannel = client->channel; lchannel->next; lchannel = lchannel->next) {}
+ channel->name = strdup(argv[2]);
+ channel->prev = lchannel;
+ if(lchannel)
+ lchannel->next = channel;
+ else
+ client->channel = channel;
+ } else {
+ for(channel = client->channel; channel; channel = channel->next) {
+ if(!stricmp(channel->name, argv[2])) {
+ ircclient_userlist_add(channel, from.nick);
+ break;
+ }
+ }
+ }
+ } else if(!stricmp(argv[1], "PART")) {
+ struct IRCUser from = ircclient_parse_user(argv[0]);
+ struct IRCChannel *channel;
+ for(channel = client->channel; channel; channel = channel->next) {
+ if(!stricmp(channel->name, argv[2])) {
+ if(!stricmp(from.nick, session->nick)) {
+ ircclient_userlist_clear(channel);
+ if(channel->prev)
+ channel->prev->next = channel->next;
+ else
+ client->channel = channel->next;
+ if(channel->next)
+ channel->next->prev = channel->prev;
+ free(channel->name);
+ free(channel);
+ } else {
+ ircclient_userlist_del(channel, from.nick);
+ }
+ break;
+ }
+ }
+ } else if(!stricmp(argv[1], "KICK")) {
+ struct IRCChannel *channel;
+ for(channel = client->channel; channel; channel = channel->next) {
+ if(!stricmp(channel->name, argv[2])) {
+ if(!stricmp(argv[3], session->nick)) {
+ ircclient_userlist_clear(channel);
+ if(channel->prev)
+ channel->prev->next = channel->next;
+ else
+ client->channel = channel->next;
+ if(channel->next)
+ channel->next->prev = channel->prev;
+ free(channel->name);
+ free(channel);
+ } else {
+ ircclient_userlist_del(channel, argv[3]);
+ }
+ break;
+ }
+ }
+ } else if(!stricmp(argv[1], "NICK")) {
+ struct IRCUser from = ircclient_parse_user(argv[0]);
+ if(!stricmp(from.nick, session->nick)) {
+ free(session->nick);
+ session->nick = strdup(argv[2]);
+ }
+ struct IRCChannel *channel;
+ struct IRCChannelMember *member;
+ for(channel = client->channel; channel; channel = channel->next) {
+ for(member = channel->userlist; member; member = member->next) {
+ if(!stricmp(member->nick, from.nick)) {
+ free(member->nick);
+ member->nick = strdup(argv[2]);
+ break;
+ }
+ }
+ }
+ } else if(!stricmp(argv[1], "MODE")) {
+ if(!stricmp(argv[2], session->nick)) {
+ //user mode
+ } else if(ircclient_is_channel_prefix(client, argv[2][0])) {
+ struct IRCChannel *channel;
+ struct IRCChannelMember *member;
+ for(channel = client->channel; channel; channel = channel->next) {
+ for(member = channel->userlist; member; member = member->next) {
+ ircclient_chanmode_parse(client, channel, argv[3], argv+4, argc-4);
+ }
+ }
+ }
+ } else if(!stricmp(argv[1], "353")) {
+ struct IRCChannel *channel;
+ struct IRCChannelMember *member;
+ for(channel = client->channel; channel; channel = channel->next) {
+ if(!stricmp(channel->name, argv[4])) {
+ if(!channel->synchronizing_userlist) {
+ channel->synchronizing_userlist = 1;
+ ircclient_userlist_clear(channel);
+ }
+ char *a = argv[5];
+ char *b, *c;
+ do {
+ b = strchr(a, ' ');
+ if(b) *b = '\0';
+ if((c = strchr(a, '!'))) {
+ *c = '\0';
+ }
+ int prefix_id;
+ int member_modes = 0;
+ while(ircclient_is_chanuser_prefix(client, *a, &prefix_id)) {
+ member_modes |= (1 << prefix_id);
+ a++;
+ }
+ member = ircclient_userlist_add(channel, a);
+ member->modes = member_modes;
+ if(b) a = b+1;
+ } while(b);
+ break;
+ }
+ }
+ } else if(!stricmp(argv[1], "366")) {
+ struct IRCChannel *channel;
+ for(channel = client->channel; channel; channel = channel->next) {
+ if(!stricmp(channel->name, argv[3])) {
+ channel->synchronizing_userlist = 0;
+ }
+ }
+ }