Ok, well now I'm fully stumped. I'm trying to allow multi-playing though the account system so that each player tied to the account shares RPP. Here's my current situation: Two players connect using the same account 'test', players are called player1 and player2 to help me explain. I reward player1 10 rpp. Player1 types 'account' to display account info and they see 10 rpp listed. Player2 types 'account' and they show 0 rpp. I look at the physical account file, the account file saved to disk shows 10 rpp.
Its my understanding since the data is being written to the file, anyone on that account should be able to see updated data...I have this feeling I'm missing something simple here, but I'm just not seeing it.
Here's some of the relevant code, if you wish to see more let me know.
First up, the reward function so you can see that its saving the account:
void do_reward( CHAR_DATA *ch, const char *argument )
{
DESCRIPTOR_DATA *d;
ACCOUNT_DATA *account;
CHAR_DATA *victim;
char arg[MSL];
int value;
argument = one_argument( argument, arg );
if( arg[0] == '\0' )
{
send_to_char("&wreward <player's name> <points>\r\n", ch);
return;
}
if( ( victim = get_char_world( ch, arg ) ) == NULL )
{
send_to_char( "They aren't here.\r\n", ch );
return;
}
if( IS_NPC( victim ) )
{
send_to_char( "Not on NPC's.\r\n", ch );
return;
}
if( argument[0] == '\0' )
{
send_to_char("&wreward <player's name> <points>\r\n", ch);
return;
}
value = atoi( argument );
if( value < -500 || value > 1000 )
{
send_to_char("&wInvalid range. Try -500 to 1000.\r\n", ch );
return;
}
if( value == 0 )
{
send_to_char("&wWhat is the use in that?\r\n", ch );
return;
}
if( victim->desc == NULL)
{
victim->rppoints += value;
sprintf (log_buf, "%s rewarded to pfile.", victim->name);
log_string( log_buf );
if( value > 0 )
ch_printf(ch, "&GYou've rewarded %s with %d points.\r\n", victim->name, value );
if( value < 0 )
ch_printf(ch, "&GYou've deducted %d points from %s.\r\n", value, victim->name);
}
if (victim->desc != NULL)
{
d = victim->desc;
account = d->account;
account->points += value;
save_account(account);
if( value > 0 )
{
ch_printf(ch, "&GYou've rewarded %s (%s) with %d points.\r\n", victim->name, victim->desc->account->name, value );
ch_printf(victim, "&G%s has rewarded your account with %d points.\r\n", ch->name, value );
}
if( value < 0 )
{
ch_printf(ch, "&GYou've deducted %d points from %s (%s).\r\n", value, victim->name, victim->desc->account->name );
ch_printf(victim, "&G%s has deducted %d points from your account.\r\n", ch->name, value );
}
}
return;
}
Ok, so, lets take a peek at saving the account:
void save_account(ACCOUNT_DATA *acc)
{
FILE *fp;
ACC_CHAR_DATA *ch;
char filename[256];
if(!acc)
return;
sprintf(filename, "%s%c/%s", ACCOUNT_DIR, tolower(acc->name[0]), capitalize(acc->name));
if( ( fp = fopen( filename, "w" ) ) == NULL )
{
bug( "save_account: fopen", 0 );
perror( filename );
}
else
{
fprintf(fp, "Name %s~\n", acc->name);
fprintf(fp, "Password %s~\n", acc->password);
for(ch = acc->first_acc_char; ch; ch = ch->next)
fprintf(fp, "Char %s~\n", ch->name);
fprintf(fp, "Host %s~\n", acc->host);
fprintf(fp, "Last_played %s~\n", acc->last_played);
fprintf(fp, "Multiplay %d\n", acc->multiplay);
fprintf(fp, "Points %d\n", acc->points);
fprintf(fp, "End\n" );
fclose(fp);
fp = NULL;
}
return;
}
Lastly, lets take a peek at the 'accountstat' command code for in game.
void do_accountstat( CHAR_DATA *ch, const char *argument )
{
ACCOUNT_DATA *account;
CHAR_DATA *victim;
ACC_CHAR_DATA *ach;
if( !argument || argument[0] == '\0' )
victim = ch;
else if( IS_IMMORTAL( ch ) )
{
if( ( victim = get_char_world( ch, argument ) ) == NULL || victim->desc == NULL)
{
send_to_char( "Victim not found.\r\n", ch );
return;
}
if( IS_SET( victim->act, PLR_WIZINVIS ) )
{
send_to_char( "Victim not found.\r\n", ch );
return;
}
}
else
victim = ch;
account = victim->desc->account;
ch_printf(ch, "&c&V[&d&WAccount: %-8s &GFor Player &W%-8s &c|&d&w------&c&V]\r\n", account->name, victim->name );
ch_printf(ch, "&c&V|&d &WPoints: %-15d Immortal: %-5s &c&V|\r\n", account->points, account->immortal ? "Yes" : "No" );
ch_printf(ch, "&c&V|&d &WMultiplay: %-5s &c&V|\r\n", account->multiplay ? "Yes" : "No" );
send_to_char( "&c&V|&d&w--------------&c|&d&WCharacters&c|&d&w-------------------&c&V|\r\n", ch );
for(ach = account->first_acc_char; ach; ach = ach->next)
{
ch_printf(ch, "&c&V|&d %-15s &c&V|\r\n", ach->name );
}
return;
}
Maybe I'm just not understanding something here. I've looked at setship for an example, you set the ship, the ship saves the data via save_ship and then you stat the ship and the changes show up with out having to reload the ship file, shouldn't I be able to do the same with account files? Granted, descriptor and character names will be different, but they are all pointing back to account->name, so it should then pull the most current info. . . Right?
Thanks in advance,
ayuri