📄 mail.c
字号:
savefile, strerror(errno )); } else { log( "回复邮件: 删除邮件 " "%u 从 %s(%s) to %s(%s)\n", mailbuf[i].message_id, mailbuf[i].id_from, mailbuf[i].charname_from, mailbuf[i].id_to, mailbuf[i].charname_to ); } memset( &mailbuf[i], 0 , sizeof( mailbuf[0] )); return; } else { log( "回复邮件: 无用信息或ID或名称或声明严重错误" ); log( "use[%d] h[%d][%d] id[%s][%s] nm[%s][%s] st[%d]\n", mailbuf[i].use, mailbuf[i].id_charname_hash, h, mailbuf[i].id_to, id, mailbuf[i].charname_to, charname, mailbuf[i].state); } } } log( "回复邮件: 邮件 %u 不能从 %s(%s) 找到\n", mesgid, id,charname );}void flushMail( int fd, char *id, char *charname ){ int i,c=0; unsigned int h ; char id_charname[1000];#define MAX_FLUSH_MAIL 1024 int flush_index[MAX_FLUSH_MAIL]; int flush_i=0; snprintf( id_charname, sizeof( id_charname ) , "%s_%s", id, charname ); h = hashpjw( id_charname ); // Nuke +1 log("邮件缓冲大小:%d (%s)\n",mailbufsize,chartime()); // Nuke *1 for(i=0;(i<mailbufsize)&&(i<MAX_FLUSH_MAIL);i++){ if( mailbuf[i].id_charname_hash == h && mailbuf[i].use && strcmp( mailbuf[i].id_to , id ) == 0 && strcmp( mailbuf[i].charname_to, charname ) == 0 ){ log( "消息ID:%u\n", mailbuf[i].message_id ); flush_index[flush_i++] = i; c++; } } for(i=0; i< flush_i ; i++ ){ int j; for(j=0; j < flush_i-1 ; j++ ){ if( mailbuf[flush_index[j]].message_id > mailbuf[flush_index[j+1]].message_id ){ int sw = flush_index[j]; flush_index[j] = flush_index[j+1]; flush_index[j+1] = sw; log( "inverted %d and %d in %d \n", flush_index[j], flush_index[j+1], j ); } } } /* 端卞霜耨允月 */ for(i=0;i< flush_i; i++ ){ /* flush 及桦宁反}flush毛霜耨仄化五凶必□丞扔□田□卞 覆仄化分仃霜耨允木壬中中 */ saacproto_Message_send( fd, mailbuf[flush_index[i]].id_from, mailbuf[flush_index[i]].charname_from, mailbuf[flush_index[i]].id_to, mailbuf[flush_index[i]].charname_to, mailbuf[flush_index[i]].text, mailbuf[flush_index[i]].option, mailbuf[flush_index[i]].message_id ); mailbuf[flush_index[i]].state = MS_WAIT_ACK; log( "分类邮件ID:%u\n", mailbuf[flush_index[i]].message_id ); } // Nuke *1 log( "邮件: 发送 %d 封邮件到 %s(%s)(%s)\n", c, id, charname ,chartime());}// Nuke start: To expire undelivered mail#define MAIL_EXPIRE_TIME 3600voidexpireMail(){ int i,c=0; unsigned int h ; char id_charname[1000]; time_t now=time(NULL); /* 1荚及flush 匹霜耨允月 醒 */#define MAX_FLUSH_MAIL 1024 int flush_index[MAX_FLUSH_MAIL]; int flush_i=0; // Nuke +1 log("邮件缓冲大小:%d (%s)\n",mailbufsize,chartime()); // Nuke *1 for(i=0;(i<mailbufsize)&&(i<MAX_FLUSH_MAIL);i++){ if(mailbuf[i].use && (now - mailbuf[i].recv_time >= MAIL_EXPIRE_TIME)) { log( "消息ID:%u 已过期\n", mailbuf[i].message_id ); flush_index[flush_i++] = i; c++; } } /* 端卞霜耨允月 */ for(i=0;i< flush_i; i++ ){ snprintf( id_charname, sizeof( id_charname), "%s_%s", mailbuf[flush_index[i]].id_to, mailbuf[flush_index[i]].charname_to ); h = hashpjw( id_charname ) & 0xff ; { char savefile[1024]; char childname[1000]; snprintf( childname,sizeof(childname),"%u", mailbuf[flush_index[i]].message_id ); makeDirFilename( savefile, sizeof(savefile),maildir, h, childname ); if( unlink( savefile ) != 0 ){ log( "failed to unlink %s: %s\n", savefile, strerror(errno )); } else { log( "过期邮件: 删除游戏 " "%u 从 %s(%s) 到 %s(%s)\n", mailbuf[flush_index[i]].message_id, mailbuf[flush_index[i]].id_from, mailbuf[flush_index[i]].charname_from, mailbuf[flush_index[i]].id_to, mailbuf[flush_index[i]].charname_to ); } memset( &mailbuf[flush_index[i]], 0 , sizeof( mailbuf[0] )); } } // Nuke *1 log( "过期邮件: 过期 %d 消息 (%s)\n", c ,chartime());}int readMail( char *dir ){ int i, read_count=0; for( i=0; i<256; i++){ char dirname[1000]; DIR *d; snprintf(dirname, sizeof( dirname ), "%s/0x%x", dir, i ); d = opendir(dirname); if(d == NULL ){ mkdir( dirname, 0755); log("创建 %s\n", dirname); continue; } while(1){ struct dirent *de; de = readdir( d ); if( de == NULL )break; if( de->d_name[0] != '.' ){ char filename[1000]; FILE *fp; struct stat s; snprintf( filename, sizeof( filename), "%s/%s", dirname, de->d_name ); if( stat( filename, &s ) < 0 ){ continue; } if( !(s.st_mode & S_IFREG)) continue; fp = fopen( filename, "r" ); if( fp == NULL ){ log( "不能打开文件 %s %s\n",filename,strerror(errno)); continue; } { char line[16384]; char toid[1000] , fromid[1000]; char tochar[CHARNAME_MAX*2+1]; char fromchar[CHARNAME_MAX*2+1]; char text[TEXT_MAX*2+1]; int opt=0; toid[0] = fromid[0] = tochar[0] = fromchar[0] = text[0] = 0; fgets( line, sizeof(line), fp ); chop(line); if( strncmp( TO_ID_HEAD , line, strlen(TO_ID_HEAD) )==0){ snprintf( toid , sizeof( toid ),"%s", line+strlen(TO_ID_HEAD )); } fgets( line, sizeof( line ), fp ); chop(line); if( strncmp( TO_CHAR_HEAD, line,strlen(TO_CHAR_HEAD))==0){ snprintf( tochar, sizeof( tochar ), "%s", line+strlen( TO_CHAR_HEAD )); makeStringFromEscaped( tochar ); } fgets( line, sizeof( line ),fp ); chop(line); if( strncmp( FROM_ID_HEAD,line,strlen(FROM_ID_HEAD))==0){ snprintf( fromid, sizeof( fromid ),"%s", line + strlen( FROM_ID_HEAD )); } fgets( line,sizeof(line),fp); chop(line); if(strncmp(FROM_CHAR_HEAD,line,strlen(FROM_CHAR_HEAD))==0){ snprintf( fromchar, sizeof( fromchar ), line + strlen(FROM_CHAR_HEAD )); makeStringFromEscaped( fromchar ); } fgets( line,sizeof(line),fp); chop(line); if( strncmp( OPTION_HEAD,line, strlen(OPTION_HEAD))==0){ opt = atoi( line + strlen( OPTION_HEAD ) ); } fgets( line, sizeof( line),fp); chop(line); if( strncmp(TEXT_HEAD,line,strlen(TEXT_HEAD))==0){ snprintf( text, sizeof( text), "%s", line + strlen( TEXT_HEAD )); makeStringFromEscaped( text ); } if( toid[0] == 0 || fromid[0] == 0 || tochar[0] == 0 || fromchar[0] == 0 || text[0] == 0 ){ log( "有问题邮件! %s 接收ID[%c] 接收名字[%c]" " 发送ID[%c] 发送名字[%c] 文本[%c]\n", filename, toid[0], tochar[0], fromid[0], fromchar[0], text[0] ); // Nuke +1 1027: Close for safe fclose(fp); continue; } receiveMail( fromid, fromchar, toid, tochar, text, opt , 1, strtoul(de->d_name,NULL,10)); read_count++; } fclose(fp); } } closedir(d); } log( "读取邮件: 在'%s'目录里读取到 %d 封邮件 \n", dir, read_count ); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -