Get rid of julian day crap in msgid

and hope sysop dosent delete msgserial :)
This commit is contained in:
Andrew Pamment 2017-03-17 15:06:43 +10:00
parent 37bad93bcd
commit e18ec3a049

View File

@ -42,71 +42,29 @@ s_JamBase *open_jam_base(char *path) {
} }
unsigned long generate_msgid() { unsigned long generate_msgid() {
time_t theTime;
char buffer[1024]; char buffer[1024];
struct tm timeStruct;
struct tm fileStruct;
unsigned long m;
unsigned long y;
unsigned long ya;
unsigned long j;
unsigned long msgid; unsigned long msgid;
unsigned long c;
unsigned long d;
time_t lastread;
unsigned long lastid; unsigned long lastid;
FILE *fptr; FILE *fptr;
theTime = time(NULL);
gmtime_r(&theTime, &timeStruct);
m = timeStruct.tm_mon + 1;
y = timeStruct.tm_year + 1900;
d = timeStruct.tm_mday;
if (m > 2) {
m = m - 3;
} else {
m = m + 9;
y = y - 1;
}
c = y / 100;
ya = y - 100 * c;
j = (146097 * c) / 4 + (1461 * ya) / 4 + (153 * m + 2) / 5 + d + 1721119;
msgid = (j % 0x800) * 0x200000;
snprintf(buffer, 1024, "%s/msgserial", conf.bbs_path); snprintf(buffer, 1024, "%s/msgserial", conf.bbs_path);
fptr = fopen(buffer, "r+"); fptr = fopen(buffer, "r+");
if (fptr) { if (fptr) {
flock(fileno(fptr), LOCK_EX); flock(fileno(fptr), LOCK_EX);
fread(&lastread, sizeof(time_t), 1, fptr); fread(&lastid, sizeof(unsigned long), 1, fptr);
fread(&lastid, sizeof(unsigned long), 1, fptr); lastid++;
gmtime_r(&lastread, &fileStruct);
if (fileStruct.tm_mon != timeStruct.tm_mon || fileStruct.tm_mday != timeStruct.tm_mday || fileStruct.tm_year != timeStruct.tm_year) {
lastread = time(NULL);
lastid = 1;
} else {
lastid++;
}
rewind(fptr); rewind(fptr);
fwrite(&lastread, sizeof(time_t), 1, fptr);
fwrite(&lastid, sizeof(unsigned long), 1, fptr); fwrite(&lastid, sizeof(unsigned long), 1, fptr);
flock(fileno(fptr), LOCK_UN); flock(fileno(fptr), LOCK_UN);
fclose(fptr); fclose(fptr);
} else { } else {
fptr = fopen(buffer, "w"); fptr = fopen(buffer, "w");
if (fptr) { if (fptr) {
lastread = time(NULL);
lastid = 1; lastid = 1;
flock(fileno(fptr), LOCK_EX); flock(fileno(fptr), LOCK_EX);
fwrite(&lastread, sizeof(time_t), 1, fptr);
fwrite(&lastid, sizeof(unsigned long), 1, fptr); fwrite(&lastid, sizeof(unsigned long), 1, fptr);
flock(fileno(fptr), LOCK_UN); flock(fileno(fptr), LOCK_UN);
fclose(fptr); fclose(fptr);
@ -116,9 +74,7 @@ unsigned long generate_msgid() {
} }
} }
msgid += lastid; return lastid;
return msgid;
} }
void free_message_headers(struct msg_headers *msghs) { void free_message_headers(struct msg_headers *msghs) {