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() {
time_t theTime;
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 c;
unsigned long d;
time_t lastread;
unsigned long lastid;
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);
fptr = fopen(buffer, "r+");
if (fptr) {
flock(fileno(fptr), LOCK_EX);
fread(&lastread, sizeof(time_t), 1, fptr);
fread(&lastid, sizeof(unsigned long), 1, fptr);
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);
fwrite(&lastread, sizeof(time_t), 1, fptr);
fwrite(&lastid, sizeof(unsigned long), 1, fptr);
flock(fileno(fptr), LOCK_UN);
fclose(fptr);
} else {
fptr = fopen(buffer, "w");
if (fptr) {
lastread = time(NULL);
lastid = 1;
flock(fileno(fptr), LOCK_EX);
fwrite(&lastread, sizeof(time_t), 1, fptr);
fwrite(&lastid, sizeof(unsigned long), 1, fptr);
flock(fileno(fptr), LOCK_UN);
fclose(fptr);
@ -116,9 +74,7 @@ unsigned long generate_msgid() {
}
}
msgid += lastid;
return msgid;
return lastid;
}
void free_message_headers(struct msg_headers *msghs) {