Well. Now I'm working on importing the accounts and their characters.
First of all I'd like to work with a check which sees if there are duplicate accounts. Anyhow, I tried running it now without that check to see if it'd work.
It begins importing the characters but at the first character the server crashes and gives me in crash-log.
Exception:
System.FormatException: Indatastring had a wrong format.
at System.Number.ParseDouble(String s, NumberStyles style, NumberFormatInfo info)
at System.Double.Parse(String s, NumberStyles style, IFormatProvider provider)
at System.Convert.ToDouble(String value)
at Server.Scripts.Commands.POLAccounting.POLAccounting_OnCommand(CommandEventArgs e)
at Server.Commands.Handle(Mobile from, String text)
at Server.Mobile.DoSpeech(String text, Int32[] keywords, MessageType type, Int32 hue)
at Server.Network.PacketHandlers.UnicodeSpeech(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)
The compilation didn't like [code:1]newchar.Female = (tmpCharGender == "0"
? false : true;"[/code:1] so I went with the [code:1]
if (tempCharGender == "0"
newChar.Female = false;
else
newChar.Female = true; [/code:1]
My current work-code is:
[code:1]
// ****************************************************************
// by Omophorus, feel free to improve on this mostly messy code
// First release, 23 Jul 2003
// Edited by Xan (www.icronticshard.org) for Trammel / Felluca worldpackage distro.
// ****************************************************************
using System;
using System.IO;
using System.Globalization;
using Server.Accounting;
using Server.Misc;
using Server.Mobiles;
using Server.Items;
using Server.Network;
namespace Server.Scripts.Commands
{
public class POLAccounting
{
private static void Item2Container( Item item, Container container )
{
item.LootType = LootType.Newbied;
if ( container != null )
container.DropItem( item );
else
item.Delete();
}
private static void AddRandomHair( Mobile m, int hue )
{
Item item;
switch ( Utility.Random(10) )
{
case 0: item = new Mohawk( hue ); break;
case 1: item = new PageboyHair( hue ); break;
case 2: item = new BunsHair( hue ); break;
case 3: item = new Afro( hue ); break;
case 4: item = new ReceedingHair( hue ); break;
case 5: item = new TwoPigTails( hue ); break;
case 6: item = new KrisnaHair( hue ); break;
case 7: item = new ShortHair( hue ); break;
case 8: item = new LongHair( hue ); break;
case 9: item = new PonyTail( hue ); break;
default: return;
}
m.AddItem( item );
}
private static void AddRandomBeard( Mobile m, int hue )
{
if ( m.Female )
return;
Item item;
switch ( Utility.Random(7) )
{
case 0: item = new LongBeard( hue ); break;
case 1: item = new ShortBeard( hue ); break;
case 2: item = new Goatee( hue ); break;
case 3: item = new Mustache( hue ); break;
case 4: item = new MediumShortBeard( hue ); break;
case 5: item = new MediumLongBeard( hue ); break;
case 6: item = new Vandyke( hue ); break;
default: return;
}
m.AddItem( item );
}
private static int AccountVacancy(Account acct)
{
for ( int i = 0; i < 5; ++i )
if ( acct
== null )
return (i);
return 0;
}
public static void Initialize()
{
Server.Commands.Register( "POLAccounting", AccessLevel.Administrator, new CommandEventHandler( POLAccounting_OnCommand ) );
}
private static void POLAccounting_OnCommand( CommandEventArgs e )
{
Mobile from = e.Mobile;
int accountCount = 0;
int characterCount = 0;
string text, text2;
string[] textArray, text2Array;
FileStream fsTime, fs2Time;
PlayerMobile newChar;
Account newCharAcct;
// Edit these to point to your POL data files
string filename = "C:/shard/accounts.txt";
string pcsfilename = "C:/shard/pcs.txt";
try
{
// Open the file and start to read
fsTime = new FileStream( filename, FileMode.Open );
fs2Time = new FileStream( pcsfilename, FileMode.Open );
}
catch
{
from.SendMessage( 63, "Couldn't find one of the required files. " );
return;
}
// READING ACCOUNTS:
StreamReader srTime = new StreamReader(fsTime);
from.SendMessage( 63, "Importing accounts ..." );
// Scan through the file and create the accounts
while( srTime.Peek() > -1 )
{
text = srTime.ReadLine().Trim();
string tmpAccountName = "";
string tmpAccountPassword = "";
string tmpAccountBanned = "0";
string tmpAccountEmail = "[email protected]";
if( text == "{" )
{
// Read the account data that we need
while ( text != "}" )
{
text = srTime.ReadLine().Trim();
textArray = text.Split( '\t' );
switch (textArray[0]) {
case "Name":
tmpAccountName = textArray[1];
break;
case "Password":
tmpAccountPassword = textArray[1];
break;
case "Banned":
tmpAccountBanned = textArray[1];
break;
default:
break;
}
}
// create the account ...
// todo: check whether this account name exists already ...
if (tmpAccountBanned != "1" {
Accounts.AddAccount(tmpAccountName,tmpAccountPassword,tmpAccountEmail); // tmpAccountEmail added for Trammel/Felucca spawned word distro
accountCount++;
}
}
}
// Stop reading and close the file.
srTime.Close();
fsTime.Close();
from.SendMessage( 63, "Done importing " + accountCount + " accounts." );
// READING CHARACTERS:
from.SendMessage( 63, "Importing characters ..." );
StreamReader sr2Time = new StreamReader(fs2Time);
// Scan through the file and create the characters
while( sr2Time.Peek() > -1 )
{
text2 = sr2Time.ReadLine().Trim();
string tmpCharName = "";
string tmpCharAccountString = "";
string tmpCharCmdlevel = "0";
string tmpCharGender = "0"; // defaults as male
string tmpCharHue = "0x83ea"; // some arb default
string tmpCharStr = "30";
string tmpCharDex = "30";
string tmpCharInt = "30";
double[] tSkills = new double[52];
if( text2 == "{" )
{
// 1. Read the character data that we need
while ( text2 != "}" )
{
text2 = sr2Time.ReadLine().Trim();
text2Array = text2.Split( '\t' );
switch (text2Array[0]) {
case "Name":
tmpCharName = text2Array[1];
from.SendMessage( 63, "character="+tmpCharName );
break;
case "Account":
tmpCharAccountString = text2Array[1];
from.SendMessage( 63, "account="+tmpCharAccountString );
break;
case "CmdLevel":
tmpCharCmdlevel = text2Array[1];
break;
case "Gender":
tmpCharGender = text2Array[1];
break;
case "Color":
tmpCharHue = text2Array[1] ;
break;
// STATS
case "Strength":
tmpCharStr = text2Array[1];
break;
case "Dexterity":
tmpCharDex = text2Array[1];
break;
case "Intelligence":
tmpCharInt = text2Array[1];
break;
// END STATS
// SKILLS
case "Alchemy" : tSkills[0] = Convert.ToDouble(text2Array[1]); break;
case "Anatomy" : tSkills[1] = Convert.ToDouble(text2Array[1]); break;
case "AnimalLore" : tSkills[2] = Convert.ToDouble(text2Array[1]); break;
case "ItemId" : tSkills[3] = Convert.ToDouble(text2Array[1]); break;
case "ArmsLore" : tSkills[4] = Convert.ToDouble(text2Array[1]); break;
case "Parry" : tSkills[5] = Convert.ToDouble(text2Array[1]); break;
case "Begging" : tSkills[6] = Convert.ToDouble(text2Array[1]); break;
case "Blacksmithy" : tSkills[7] = Convert.ToDouble(text2Array[1]); break;
case "Bowcraft" : tSkills[8] = Convert.ToDouble(text2Array[1]); break;
case "Peacemaking" : tSkills[9] = Convert.ToDouble(text2Array[1]); break;
case "Camping" : tSkills[10] = Convert.ToDouble(text2Array[1]); break;
case "Carpentry" : tSkills[11] = Convert.ToDouble(text2Array[1]); break;
case "Cartography" : tSkills[12] = Convert.ToDouble(text2Array[1]); break;
case "Cooking" : tSkills[13] = Convert.ToDouble(text2Array[1]); break;
case "DetectingHidden" : tSkills[14] = Convert.ToDouble(text2Array[1]); break;
// Enticement -> Discordance
case "Enticement" : tSkills[15] = Convert.ToDouble(text2Array[1]); break;
case "EvaluatingIntelligence" : tSkills[16] = Convert.ToDouble(text2Array[1]); break;
case "Healing" : tSkills[17] = Convert.ToDouble(text2Array[1]); break;
case "Fishing" : tSkills[18] = Convert.ToDouble(text2Array[1]); break;
case "ForensicEvaluation" : tSkills[19] = Convert.ToDouble(text2Array[1]); break;
case "Herding" : tSkills[20] = Convert.ToDouble(text2Array[1]); break;
case "Hiding" : tSkills[21] = Convert.ToDouble(text2Array[1]); break;
case "Provocation" : tSkills[22] = Convert.ToDouble(text2Array[1]); break;
case "Inscription" : tSkills[23] = Convert.ToDouble(text2Array[1]); break;
case "Lockpicking" : tSkills[24] = Convert.ToDouble(text2Array[1]); break;
case "Magery" : tSkills[25] = Convert.ToDouble(text2Array[1]); break;
case "MagicResistance" : tSkills[26] = Convert.ToDouble(text2Array[1]); break;
case "Tactics" : tSkills[27] = Convert.ToDouble(text2Array[1]); break;
case "Snooping" : tSkills[28] = Convert.ToDouble(text2Array[1]); break;
case "Musicianship" : tSkills[29] = Convert.ToDouble(text2Array[1]); break;
case "Poisoning" : tSkills[30] = Convert.ToDouble(text2Array[1]); break;
case "Archery" : tSkills[31] = Convert.ToDouble(text2Array[1]); break;
case "SpiritSpeak" : tSkills[32] = Convert.ToDouble(text2Array[1]); break;
case "Stealing" : tSkills[33] = Convert.ToDouble(text2Array[1]); break;
case "Tailoring" : tSkills[34] = Convert.ToDouble(text2Array[1]); break;
case "AnimalTaming" : tSkills[35] = Convert.ToDouble(text2Array[1]); break;
case "TasteIdentification" : tSkills[36] = Convert.ToDouble(text2Array[1]); break;
case "Tinkering" : tSkills[37] = Convert.ToDouble(text2Array[1]); break;
case "Tracking" : tSkills[38] = Convert.ToDouble(text2Array[1]); break;
case "Veterinary" : tSkills[39] = Convert.ToDouble(text2Array[1]); break;
case "Swordsmanship" : tSkills[40] = Convert.ToDouble(text2Array[1]); break;
case "Macefighting" : tSkills[41] = Convert.ToDouble(text2Array[1]); break;
case "Fencing" : tSkills[42] = Convert.ToDouble(text2Array[1]); break;
case "Wrestling" : tSkills[43] = Convert.ToDouble(text2Array[1]); break;
case "Lumberjacking" : tSkills[44] = Convert.ToDouble(text2Array[1]); break;
case "Mining" : tSkills[45] = Convert.ToDouble(text2Array[1]); break;
case "Meditation" : tSkills[46] = Convert.ToDouble(text2Array[1]); break;
case "Stealth" : tSkills[47] = Convert.ToDouble(text2Array[1]); break;
case "RemoveTrap" : tSkills[48] = Convert.ToDouble(text2Array[1]); break;
// customize skills from here on - you may want to make some changes to this list
case "Necromancy" : tSkills[49] = Convert.ToDouble(text2Array[1]); break;
// END SKILLS
default:
break;
}
}
// 2. create the character
newChar = new PlayerMobile();
// 3. set up the character's specific properties
newCharAcct = Accounts.GetAccount(tmpCharAccountString);
newChar.Name = tmpCharName;
newChar.Player = true;
// newchar.Female = (tmpCharGender == "0" ? false : true;
if (tmpCharGender == "0"
newChar.Female = false;
else
newChar.Female = true;
newChar.Body = newChar.Female ? 0x191 : 0x190;
newChar.Hue = int.Parse(tmpCharHue.Substring(2),NumberStyles.HexNumber);
newChar.Hunger = 20;
CityInfo city = new CityInfo( "Britain", "Sweet Dreams Inn", 1496, 1628, 10 );
newChar.Location = city.Location;
newChar.Map = Map.Trammel;
// stats
newChar.InitStats((int)Math.Round(Convert.ToDecimal(tmpCharStr)),
(int)Math.Round(Convert.ToDecimal(tmpCharDex)),
(int)Math.Round(Convert.ToDecimal(tmpCharInt)));
// skills
newChar.Skills[SkillName.Alchemy].Base = tSkills[0];
newChar.Skills[SkillName.Anatomy].Base = tSkills[1];
newChar.Skills[SkillName.AnimalLore].Base = tSkills[2];
newChar.Skills[SkillName.ItemID].Base = tSkills[3];
newChar.Skills[SkillName.ArmsLore].Base = tSkills[4];
newChar.Skills[SkillName.Parry].Base = tSkills[5];
newChar.Skills[SkillName.Begging].Base = tSkills[6];
newChar.Skills[SkillName.Blacksmith].Base = tSkills[7];
newChar.Skills[SkillName.Fletching].Base = tSkills[8];
newChar.Skills[SkillName.Peacemaking].Base = tSkills[9];
newChar.Skills[SkillName.Camping].Base = tSkills[10];
newChar.Skills[SkillName.Carpentry].Base = tSkills[11];
newChar.Skills[SkillName.Cartography].Base = tSkills[12];
newChar.Skills[SkillName.Cooking].Base = tSkills[13];
newChar.Skills[SkillName.DetectHidden].Base = tSkills[14];
newChar.Skills[SkillName.Discordance].Base = tSkills[15];
newChar.Skills[SkillName.EvalInt].Base = tSkills[16];
newChar.Skills[SkillName.Healing].Base = tSkills[17];
newChar.Skills[SkillName.Fishing].Base = tSkills[18];
newChar.Skills[SkillName.Forensics].Base = tSkills[19];
newChar.Skills[SkillName.Herding].Base = tSkills[20];
newChar.Skills[SkillName.Hiding].Base = tSkills[21];
newChar.Skills[SkillName.Provocation].Base = tSkills[22];
newChar.Skills[SkillName.Inscribe].Base = tSkills[23];
newChar.Skills[SkillName.Lockpicking].Base = tSkills[24];
newChar.Skills[SkillName.Magery].Base = tSkills[25];
newChar.Skills[SkillName.MagicResist].Base = tSkills[26];
newChar.Skills[SkillName.Tactics].Base = tSkills[27];
newChar.Skills[SkillName.Snooping].Base = tSkills[28];
newChar.Skills[SkillName.Musicianship].Base = tSkills[29];
newChar.Skills[SkillName.Poisoning].Base = tSkills[30];
newChar.Skills[SkillName.Archery].Base = tSkills[31];
newChar.Skills[SkillName.SpiritSpeak].Base = tSkills[32];
newChar.Skills[SkillName.Stealing].Base = tSkills[33];
newChar.Skills[SkillName.Tailoring].Base = tSkills[34];
newChar.Skills[SkillName.AnimalTaming].Base = tSkills[35];
newChar.Skills[SkillName.TasteID].Base = tSkills[36];
newChar.Skills[SkillName.Tinkering].Base = tSkills[37];
newChar.Skills[SkillName.Tracking].Base = tSkills[38];
newChar.Skills[SkillName.Veterinary].Base = tSkills[39];
newChar.Skills[SkillName.Swords].Base = tSkills[40];
newChar.Skills[SkillName.Macing].Base = tSkills[41];
newChar.Skills[SkillName.Fencing].Base = tSkills[42];
newChar.Skills[SkillName.Wrestling].Base = tSkills[43];
newChar.Skills[SkillName.Lumberjacking].Base = tSkills[44];
newChar.Skills[SkillName.Mining].Base = tSkills[45];
newChar.Skills[SkillName.Meditation].Base = tSkills[46];
newChar.Skills[SkillName.Stealth].Base = tSkills[47];
newChar.Skills[SkillName.RemoveTrap].Base = tSkills[48];
// (these last 3 does not neccessarily exist under default POL :
newChar.Skills[SkillName.Necromancy].Base = tSkills[49];
newChar.Skills[SkillName.Focus].Base = tSkills[50];
newChar.Skills[SkillName.Chivalry].Base = tSkills[51];
// access level
if ((tmpCharCmdlevel == "test" | (tmpCharCmdlevel == "admin")
{
newCharAcct.AccessLevel = AccessLevel.Administrator;
newChar.AccessLevel = AccessLevel.Administrator;
}
// 4. Try to add character to account:
if ((tmpCharName != "" && (tmpCharAccountString != "")
{
int i = 0;
while (i < 5)
{
if ( newCharAcct == null )
{
from.SendMessage( 63, "Adding character " + tmpCharName + " to account "+tmpCharAccountString+"["+i+"]" );
newCharAcct = newChar;
i = 5;
characterCount++;
// create a backpack & some items for the character:
Container pack = newChar.Backpack;
if ( pack == null )
{
pack = new Backpack();
pack.Movable = false;
newChar.AddItem( pack );
}
Item2Container( new RedBook( "a book", newChar.Name, 20, true ), pack );
Item2Container( new Gold( 1000 ), pack ); // Starting gold can be customized here
Item2Container( new Dagger(), pack );
Item2Container( new Candle(), pack );
// creation successful : give the character some items ...
BankBox bank = newChar.BankBox;
bank.DropItem( new BankCheck( 1000 ) );
// hair & beard
AddRandomHair(newChar, 0x455); // some arb colour ...
AddRandomBeard(newChar, 0x455);
}
i++;
}
}
}
}
// Stop reading and close the file.
sr2Time.Close();
fs2Time.Close();
from.SendMessage( 63, "Done importing " + characterCount + " characters." );
}
}
}
[/code:1]
Here's an example from my character-data which is also the first character it imports.
[code:1]
Character
{
Account mikef
CharIdx 1
Name Joe E Bastard
Serial 0x2a0248
ObjType 0x190
Graphic 0x190
Color 0x83ea
X 1503
Y 1875
Z 5
Facing 2
CProp Fixwipe syes
CProp HighSkill i45
CProp HungerTimer i23
CProp LastLog i41050483
CProp LastTinkerItem i3854
CProp Mstats a3:i3i3i3
CProp NewRegenRateForStamina i1200
CProp OnCreate i40992582
CProp SkillArray a3:i45i37i21
CProp SkillBonus i0
CProp autoTinker i1
CProp cap_pid i2751839
CProp hunger i4
CProp lockdex i10
CProp lockint i32
CProp lockstr i51
CProp logontime i41050183
CProp mining i1
CProp onlinetimer i8892
CProp skill a50:i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1i1
TrueColor 0x83ea
TrueObjtype 0x190
Gender 0
Strength 56.9
Intelligence 43.4
Dexterity 10.3
Hiding 0.1
Tinkering 50
Mining 50.1
Life 56
Mana 43
Stamina 10
CreatedAt 40992582
TitleSuffix ", Apprentice Miner"
}
Item
{
Serial 0x6cab09a9
ObjType 0x203b
Graphic 0x203b
Color 0x44e
X 0
Y 0
Z 0
CProp faceloc i11
Layer 11
Container 0x2a0248
DecayAt 40993182
}
Item
{
Serial 0x6cab09aa
ObjType 0xe75
Graphic 0xe75
X 0
Y 0
Z 0
CProp Owner i2753096
Layer 21
Container 0x2a0248
DecayAt 40993182
}
[/code:1]