...
 
Commits (1)
  • Rob Swindell's avatar
    New functions to return a user's birthdate in multiple formats · 22e529cd
    Rob Swindell authored
    e.g. MM/DD/YY for drop files that assume that format, or either MM/DD/YY or
    DD/MM/YY (depending on sysop preference) for backwards compatibility in
    expanded @-codes, Guru chat keyword.
    
    Fixed the birthdate check while logging on to work with new/all birthdate
    formats.
    22e529cd
......@@ -822,7 +822,7 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen, long* pmode, bool
return(client_name);
if(!strcmp(sp,"BDATE"))
return(useron.birth);
return getbirthdstr(&cfg, useron.birth, str, sizeof(str));
if(!strcmp(sp,"AGE")) {
safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
......
......@@ -1657,7 +1657,7 @@ void sbbs_t::guruchat(char* line, char* gurubuf, int gurunum, char* last_answer)
break;
case 'B':
if(sys_status&SS_USERON) {
SAFECAT(theanswer,useron.birth);
getbirthdstr(&cfg, useron.birth, theanswer, sizeof(theanswer));
} else {
SAFECAT(theanswer,"00/00/00");
}
......
......@@ -217,8 +217,8 @@ bool sbbs_t::logon()
bputs(text[LoggingOn]);
if(useron.rows)
rows=useron.rows;
unixtodstr(&cfg,(time32_t)logontime,str);
if(!strncmp(str,useron.birth,5) && !(useron.rest&FLAG('Q'))) {
if(tm.tm_mon == getbirthmonth(&cfg, useron.birth) && tm.tm_mday == getbirthday(&cfg, useron.birth)
&& !(useron.rest&FLAG('Q'))) {
if(text[HappyBirthday][0]) {
bputs(text[HappyBirthday]);
pause();
......
......@@ -736,7 +736,7 @@ int putusername(scfg_t* cfg, int number, char *name)
#define DECVAL(ch, mul) (DEC_CHAR_TO_INT(ch) * (mul))
int getbirthyear(const char *birth)
int getbirthyear(const char* birth)
{
if(isdigit(birth[2])) // CCYYMMYY format
return DECVAL(birth[0], 1000)
......@@ -755,7 +755,7 @@ int getbirthyear(const char *birth)
return year;
}
int getbirthmonth(scfg_t* cfg, const char *birth)
int getbirthmonth(scfg_t* cfg, const char* birth)
{
if(isdigit(birth[5])) // CCYYMMYY format
return DECVAL(birth[4], 10) + DECVAL(birth[5], 1);
......@@ -766,7 +766,7 @@ int getbirthmonth(scfg_t* cfg, const char *birth)
}
}
int getbirthday(scfg_t* cfg, const char *birth)
int getbirthday(scfg_t* cfg, const char* birth)
{
if(isdigit(birth[5])) // CCYYMMYY format
return DECVAL(birth[6], 10) + DECVAL(birth[7], 1);
......@@ -777,6 +777,35 @@ int getbirthday(scfg_t* cfg, const char *birth)
}
}
// Always returns string in MM/DD/YY format
char* getbirthmmddyy(scfg_t* cfg, const char* birth, char* buf, size_t max)
{
safe_snprintf(buf, max, "%02u/%02u/%02u"
, getbirthmonth(cfg, birth)
, getbirthday(cfg, birth)
, getbirthyear(birth) % 100);
return buf;
}
// Always returns string in DD/MM/YY format
char* getbirthddmmyy(scfg_t* cfg, const char* birth, char* buf, size_t max)
{
safe_snprintf(buf, max, "%02u/%02u/%02u"
, getbirthday(cfg, birth)
, getbirthmonth(cfg, birth)
, getbirthyear(birth) % 100);
return buf;
}
char* getbirthdstr(scfg_t* cfg, const char* birth, char* buf, size_t max)
{
if(cfg->sys_misc & SM_EURODATE)
getbirthddmmyy(cfg, birth, buf, max);
else
getbirthmmddyy(cfg, birth, buf, max);
return buf;
}
/****************************************************************************/
/* Returns the age derived from the string 'birth' in the format CCYYMMDD */
/* or legacy: MM/DD/YY or DD/MM/YY */
......
......@@ -84,6 +84,9 @@ DLLEXPORT int getage(scfg_t*, const char* birthdate);
DLLEXPORT int getbirthmonth(scfg_t*, const char* birthdate);
DLLEXPORT int getbirthday(scfg_t*, const char* birthdate);
DLLEXPORT int getbirthyear(const char* birthdate);
DLLEXPORT char* getbirthdstr(scfg_t*, const char* birthdate, char* buf, size_t);
DLLEXPORT char* getbirthmmddyy(scfg_t*, const char* birthdate, char* buf, size_t);
DLLEXPORT char* getbirthddmmyy(scfg_t*, const char* birthdate, char* buf, size_t);
DLLEXPORT char* username(scfg_t*, int usernumber, char * str);
DLLEXPORT char* usermailaddr(scfg_t*, char* addr, const char* name);
DLLEXPORT int opennodedat(scfg_t*);
......
......@@ -237,7 +237,7 @@ void sbbs_t::xtrndat(const char *name, const char *dropdir, uchar type, ulong tl
safe_snprintf(str, sizeof(str), "%u\n%u\n%s\n%c\n%u\n%s\n"
,useron.level /* User main level */
,useron.level /* User transfer level */
,useron.birth /* User birthday */
,getbirthmmddyy(&cfg, useron.birth, tmp, sizeof(tmp)) /* User birthday (MM/DD/YY) */
,useron.sex ? useron.sex : '?' /* User sex (M/F) */
,useron.number /* User number */
,useron.phone); /* User phone number */
......@@ -452,7 +452,7 @@ void sbbs_t::xtrndat(const char *name, const char *dropdir, uchar type, ulong tl
"\n%s\n%02d:%02d\n%c\n"
,0 /* 30: Kbytes downloaded today */
,(useron.cdt+useron.freecdt)/1024UL /* 31: Max Kbytes to download today */
,useron.birth /* 32: User birthday */
,getbirthmmddyy(&cfg, useron.birth, tmp, sizeof(tmp)) /* 32: User birthday (MM/DD/YY) */
,node_dir /* 33: Path to MAIN directory */
,data_dir /* 34: Path to GEN directory */
,cfg.sys_op /* 35: Sysop name */
......@@ -617,7 +617,7 @@ void sbbs_t::xtrndat(const char *name, const char *dropdir, uchar type, ulong tl
write(file,&w,sizeof(w)); /* Len */
write(file,&w,sizeof(w)); /* CombinedPtr */
write(file,&w,sizeof(w)); /* AliasPtr */
l=0;
l = strtol(useron.birth, NULL, 10);
write(file,&l,sizeof(l)); /* Birthday (as a long?) */
/* EventInfo */
c=0;
......@@ -777,7 +777,7 @@ void sbbs_t::xtrndat(const char *name, const char *dropdir, uchar type, ulong tl
,8 /* Data bits */
,online==ON_LOCAL?"LOCAL":"REMOTE" /* Online local or remote */
,cfg.com_port /* COMx port */
,useron.birth /* User birthday */
,getbirthmmddyy(&cfg, useron.birth, tmp, sizeof(tmp)) /* User birthday (MM/DD/YY) */
,dte_rate /* DTE rate */
,"FALSE" /* Already connected? */
,"Normal Connection"); /* Normal or ARQ connect */
......@@ -1151,7 +1151,7 @@ void sbbs_t::xtrndat(const char *name, const char *dropdir, uchar type, ulong tl
,tleft/60 /* Minutes left */
,useron.phone /* User's phone number */
,useron.location /* User's city and state */
,useron.birth /* User's birth date */
,getbirthmmddyy(&cfg, useron.birth, tmp, sizeof(tmp)) /* User's birth date (MM/DD/YY) */
);
lfexpand(str,misc);
write(file,str,strlen(str));
......