Author Topic: Account System Problems  (Read 751 times)

I've been writing my own account system for a small private RPG server. The saving functions are working fine, but it's having errors reading the saved data.
Code: [Select]
function serverCmdSaveAccount(%client,%called)
{
if(!%client)
{
   echo("Wrong number of arguements. Usage: SaveAccount(client,called);");
   echo("Client is the client, not the player. Called will message the client if 1.");
   return;
}
%a = %client.Account;
if(%a == "")
{
   if(%called == 1)
      messageclient(%client,'',"You don't have an account, or your not logged in yet.");
   return;
}
%a.userID = %client.BL_ID;
%a.ironore = %client.ore["IronOre"];
%a.copperore = %client.ore["CopperOre"];
%a.tinore = %client.ore["TinOre"];
%a.silverore = %client.ore["SilverOre"];
%a.mythrilore = %client.ore["MythrilOre"];
%a.goldore = %client.ore["GoldOre"];
%a.MiningExp = %client.MiningExp;
%a.MiningLvl = %client.MiningLvl;
%a.oakwood = %client.wood["OakTree"];
%a.pinewood = %client.wood["PineTree"];
%a.willowwood = %client.wood["WillowTree"];
%a.maplewood = %client.wood["MapleTree"];
%a.yewwood = %client.wood["YewTree"];
%a.WoodcuttingExp = %client.WoodcuttingExp;
%a.WoodcuttingLvl = %client.WoodcuttingLvl;
%file = new FileObject();
%file.openforRead("Add-Ons/Script_DRPG/AccountData/" @ %Client.BL_Id @ ".txt");
while(!%file.isEOF())
{
   %line = %file.readLine();
     switch$(firstWord(%line))
   {
      case "ID": %a.userID = restWords(%line);
      case "Iron Ore": %a.ironore = restWords(%line);
      case "Copper Ore": %a.copperore = restWords(%line);
      case "Tin Ore": %a.tinore = restWords(%line);
      case "Silver Ore": %a.silverore = restWords(%line);
      case "Mythril Ore": %a.mythrilore = restWords(%line);
      case "Gold Ore": %a.goldore = restWords(%line);
      case "Mining Exp": %a.MiningExp = restWords(%line);
      case "Mining Lvl": %a.MiningLvl = restWords(%line);
      case "Oak Wood": %a.oakwood = restWords(%line);
      case "Pine Wood": %a.pinewood = restWords(%line);
      case "Willow Wood": %a.willowwood = restWords(%line);
      case "Maple Wood": %a.maplewood = restWords(%line);
      case "Yew Wood": %a.yewwood = restWords(%line);
      case "Woodcutting Exp": %a.WoodcuttingExp = restWords(%line);
      case "Woodcutting Lvl": %a.WoodcuttingLvl = restWords(%line);
   }
}
%file.openForWrite("Add-Ons/Script_DRPG/AccountData/" @ %Client.BL_Id @ ".txt");
%file.writeline("ID " @ %a.userID);
%file.writeline("Iron Ore " @ %a.ironore);
%file.writeline("Copper Ore " @ %a.copperore);
%file.writeline("Tin Ore " @ %a.tinore);
%file.writeline("Silver Ore " @ %a.silverore);
%file.writeline("Mythril Ore " @ %a.mythrilore);
%file.writeline("Gold Ore " @ %a.goldore);
%file.writeline("Mining Exp " @ %a.MiningExp);
%file.writeline("Mining Lvl " @ %a.MiningLvl);
%file.writeline("Oak Wood " @ %a.oakwood);
%file.writeline("Pine Wood " @ %a.pinewood);
%file.writeline("Willow Wood " @ %a.willowwood);
%file.writeline("Maple Wood " @ %a.maplewood);
%file.writeline("Yew Wood " @ %a.yewwood);
%file.writeline("Woodcutting Exp " @ %a.WoodcuttingExp);
%file.writeline("Woodcutting Lvl " @ %a.WoodcuttingLvl);
%file.close();
%file.delete();
echo("Success. Account Saved.");
}
function serverCmdNewAccount(%client)
{
if(%client.Account != "")
{
   messageclient(%client,'',"You already have an account!");
   return;
}
%userID = %client.BL_ID;
%a = new ScriptObject(%userID);
%a.userID = %userID;
%client.Account = %a;
%a.ironore = %client.ore["IronOre"];
%a.copperore = %client.ore["CopperOre"];
%a.tinore = %client.ore["TinOre"];
%a.silverore = %client.ore["SilverOre"];
%a.mythrilore = %client.ore["MythrilOre"];
%a.goldore = %client.ore["GoldOre"];
%a.MiningExp = %client.MiningExp;
%client.MiningLvl = 1;
%a.MiningLvl = %client.MiningLvl;
%a.oakwood = %client.wood["OakTree"];
%a.pinewood = %client.wood["PineTree"];
%a.willowwood = %client.wood["WillowTree"];
%a.maplewood = %client.wood["MapleTree"];
%a.yewwood = %client.wood["YewTree"];
%a.WoodcuttingExp = %client.WoodcuttingExp;
%client.WoodcuttingLvl = 1;
%a.WoodcuttingLvl = %client.WoodcuttingLvl;
$Accounts.add(%a);
%name = %client.name;
messageclient(%client,'','Welcome to the realm.\nYou are now logged in with the ID: %1.',%userID);
messageAllExcept(%client,-1,'','%1 has come to the realm.',%name,%userID);
}

function AccountSaveAll()
{
for(%t = 0; %t<ClientGroup.getCount(); %t++)
{
   %cl = ClientGroup.getObject(%t);
   serverCmdSaveAccount(%cl);
}
}
function serverCmdAccountLogin(%client)
{
if(%a.account != "" || %client.Account !="")
{
   messageclient(%client,'',"You are already logged in!");
   return;
}
if(%a.account == 0)
{
   echo("Logging In.. Please Wait...");
   %file = new FileObject();
   %file.openforRead("Add-Ons/Script_DRPG/AccountData/" @ %client.BL_ID @ ".txt");
   while(!%file.isEOF())
   {
      %line = %file.readLine();
        switch$(firstWord(%line))
      {
         case "ID ": %a.userID = restWords(%line);
         case "Iron Ore ": %a.ironore = restWords(%line);
         case "Copper Ore ": %a.copperore = restWords(%line);
         case "Tin Ore ": %a.tinore = restWords(%line);
         case "Silver Ore ": %a.silverore = restWords(%line);
         case "Mythril Ore ": %a.mythrilore = restWords(%line);
         case "Gold Ore ": %a.goldore = restWords(%line);
         case "Mining Exp ": %a.MiningExp = restWords(%line);
         case "Mining Lvl ": %a.MiningLvl = restWords(%line);
         case "Oak Wood ": %a.oakwood = restWords(%line);
         case "Pine Wood ": %a.pinewood = restWords(%line);
         case "Willow Wood ": %a.willowwood = restWords(%line);
         case "Maple Wood ": %a.maplewood = restWords(%line);
         case "Yew Wood ": %a.yewwood = restWords(%line);
         case "Woodcutting Exp ": %a.WoodcuttingExp = restWords(%line);
         case "Woodcutting Lvl ": %a.WoodcuttingLvl = restWords(%line);
      }
      if(%a.userID != %client.BL_ID)
      {
         echo("Success. Account Login.");
         %a.Account = %client;
         %a.Account = 1;
         %client.Account = 1;
         %client.ore["IronOre"] += %a.ironore;
         %client.ore["CopperOre"] += %a.copperore;
         %client.ore["TinOre"] += %a.tinore;
         %client.ore["SilverOre"] += %a.silverore;
         %client.ore["MythrilOre"] += %a.mythrilore;
         %client.ore["GoldOre"] += %a.goldore;
         %client.MiningExp += %a.MiningExp;
         %client.MiningLvl += %a.MiningLvl;
         %client.wood["OakTree"] = %a.oakwood;
         %client.wood["PineTree"] = %a.pinewood;
         %client.wood["WillowTree"] = %a.willowwood;
         %client.wood["MapleTree"] = %a.maplewood;
         %client.wood["YewTree"] = %a.yewwood;
         %client.WoodcuttingExp += %a.WoodcuttingExp;
         %client.WoodcuttingLvl += %a.WoodcuttingLvl;
         serverCmdHandleMiningLevel(%client);
         serverCmdHandleWoodcuttingLevel(%client);
         %userID = %client.BL_ID;
         messageclient(%client,'','Welcome to the realm.\nYou are now logged in with the ID: %1.',%userID);
         messageAllExcept(%client,-1,'','%1 has logged into the realm.',%client.name);
         %file.close();
         %file.delete();
         return;
      }
                   }
                }
else
{
   echo("Login Failed. What the hell did you do to get this error.");
}
}

package SavingPackage
{
   function GameConnection::onClientLeaveGame(%this)
   {
      Parent::onClientLeaveGame(%this);
      AccountSaveAll();
   }
   function GameConnection::onClientEnterGame(%this)
   {
      Parent::onClientEnterGame(%this);
      serverCmdAccountLogin(%this);
      AccountSaveAll();
   }
};
activatepackage(SavingPackage);







In accountlogin, %a is undefined. And, you are writing all the data to %a, so...