/***************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Dystopia Mud improvements copyright (C) 2000, 2001 by Brian Graversen *
* *
* Much time and thought has gone into this software and you are *
* benefitting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************/
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "merc.h"
void load_mudinfo()
{
FILE *fp;
int i;
if ((fp = fopen("../txt/mudinfo.txt", "r")) == NULL)
{
log_string("Error: mudinfo.txt not found!");
exit(1);
}
for (i = 0; i < (MUDINFO_MAX - 2); i++)
{
mudinfo[i] = fread_number(fp);
}
mudinfo[MUDINFO_MAX - 2] = 0;
mudinfo[MUDINFO_MAX - 1] = 0;
fclose(fp);
}
void load_ccenter()
{
FILE *fp;
int i;
if ((fp = fopen("../txt/ccenter.txt", "r")) == NULL)
{
log_string("Error: ccenter.txt not found!");
exit(1);
}
for (i = 0; i < CCENTER_MAX; i++)
{
ccenter[i] = fread_number(fp);
}
fclose(fp);
}
void save_ccenter()
{
FILE *fp;
int i;
if ((fp = fopen("../txt/ccenter.txt", "w")) == NULL)
{
bug("could not write to ccenter.txt!", 0);
return;
}
for (i = 0; i < CCENTER_MAX; i++)
{
fprintf(fp, "%d\n", ccenter[i]);
}
fclose(fp);
}
void load_coreinfo()
{
FILE *fp;
if ((fp = fopen("../txt/coreinfo.txt", "r")) == NULL)
{
log_string("Error: coreinfo.txt not found!");
exit(1);
}
top_playerid = fread_number(fp);
pulse_exp = fread_number(fp);
pulse_dt = fread_number(fp);
pulse_arena = fread_number(fp);
pulse_cp = fread_number(fp);
if (pulse_exp > 0)
global_exp = TRUE;
if (pulse_dt > 0)
global_dt = TRUE;
if (pulse_cp > 0)
global_cp = TRUE;
fclose(fp);
}
void write_mudinfo_database()
{
FILE *fp;
int ratio, mspusers, avusers, a, b, c;
if ((fp = fopen("../txt/mud_data.txt", "a")) == NULL)
{
log_string("Error writing to mud_data.txt");
return;
}
/*
* Calculate the ratio of users that use msp
*/
mspusers =
(100 * mudinfo[MUDINFO_MSP_USERS] /
(mudinfo[MUDINFO_MCCP_USERS] +
mudinfo[MUDINFO_OTHER_USERS]));
/*
* Calculate the ratio of users that use mccp
*/
ratio = (100 * mudinfo[MUDINFO_MCCP_USERS] /
(mudinfo[MUDINFO_MCCP_USERS] +
mudinfo[MUDINFO_OTHER_USERS]));
/*
* Calculate the amount of average players online
*/
avusers =
(mudinfo[MUDINFO_MCCP_USERS] +
mudinfo[MUDINFO_OTHER_USERS]) / mudinfo[MUDINFO_UPDATED];
/*
* Calculate the average tranfer rate in kbyte
*/
a = mudinfo[MUDINFO_MBYTE] * 1024 + mudinfo[MUDINFO_BYTE] / 1024;
b = a / (mudinfo[MUDINFO_UPDATED] * 3);
c = b / 10;
c = c * 10;
c = b - c;
/*
* Append it all to the file
*/
fprintf(fp, "\nMudinfo Database Entry\n");
fprintf(fp, "Average Online Users %d\n", avusers);
fprintf(fp, "Peak Users Online %d\n",
mudinfo[MUDINFO_PEAK_USERS]);
fprintf(fp, "Mccp Ratio %d %%\n", ratio);
fprintf(fp, "MSP Ratio %d %%\n", mspusers);
fprintf(fp, "Amount of MB send %d MB\n",
mudinfo[MUDINFO_MBYTE]);
fprintf(fp, "Datatransfer Average %d.%d\n", b / 10, c);
/*
* Calculating the peak transfer rate
*/
b = mudinfo[MUDINFO_DATA_PEAK] / (3 * 1024);
c = b / 10;
c = c * 10;
c = b - c;
fprintf(fp, "Datatransfer Peak %d.%d\n", b / 10, c);
fclose(fp);
}
void save_mudinfo()
{
FILE *fp;
int i;
if ((fp = fopen("../txt/mudinfo.txt", "w")) == NULL)
{
log_string("Error writing to mudinfo.txt");
return;
}
for (i = 0; i < (MUDINFO_MAX - 2); i++)
{
fprintf(fp, "%d\n", mudinfo[i]);
}
fclose(fp);
}
void save_coreinfo()
{
FILE *fp;
int i;
for (i = 0; i < 2; i++)
{
if (i == 0)
{
if ((fp = fopen("../txt/coreinfo.bck","w")) == NULL)
{
log_string("Error writing to coreinfo.bck");
return;
}
}
else
{
if ((fp = fopen("../txt/coreinfo.txt","w")) == NULL)
{
log_string("Error writing to coreinfo.txt");
return;
}
}
fprintf(fp, "%d\n", top_playerid);
fprintf(fp, "%d\n", pulse_exp);
fprintf(fp, "%d\n", pulse_dt);
fprintf(fp, "%d\n", pulse_arena);
fprintf(fp, "%d\n", pulse_cp);
fprintf(fp, "%d\n", pulse_qp);
fclose(fp);
}
}