public static void Load() { string basePath = Path.Combine("Saves", "CTFScore"); string idxPath = Path.Combine( basePath, "CTFLScore.idx"); string binPath = Path.Combine( basePath, "CTFLScore.bin"); if (File.Exists(idxPath) && File.Exists(binPath)) { // Declare and initialize reader objects. FileStream idx = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read); FileStream bin = new FileStream(binPath, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReader idxReader = new BinaryReader(idx); BinaryFileReader binReader = new BinaryFileReader(new BinaryReader(bin)); // Start by reading the number of duels from an index file int playerCount = idxReader.ReadInt32(); for (int i = 0; i < playerCount; ++i) { CTFPlayer player = new CTFPlayer(); // Read start-position and length of current order from index file long startPos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); // Point the reading stream to the proper position binReader.Seek(startPos, SeekOrigin.Begin); try { player.Deserialize( binReader ); if (binReader.Position != (startPos + length)) throw new Exception(String.Format("***** Bad serialize on CTFScore[{0}] *****", i)); } catch { //handle } if ( player != null && player.Mobile != null ) Players.Add( player.Mobile, player ); } // Remember to close the streams idxReader.Close(); binReader.Close(); } }
public static void Returned( Mobile m ) { CTFPlayer player = Players[m] as CTFPlayer; if ( player == null ) { player = new CTFPlayer( m ); Players.Add( m, player ); } player.Returns++; }