aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code
diff options
context:
space:
mode:
authorwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-07-19 16:29:04 +0000
committerwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-07-19 16:29:04 +0000
commit0dce71da309262fe3591e73d8f0fcfd955b1d5c2 (patch)
tree3797f5af5fa2d7d5dfffd64bebc6ecde4b0138da /Game/Code
parent13e06d779bcd70ffa4bac1f0ff47c7810c1a629e (diff)
downloadusdx-0dce71da309262fe3591e73d8f0fcfd955b1d5c2.tar.gz
usdx-0dce71da309262fe3591e73d8f0fcfd955b1d5c2.tar.xz
usdx-0dce71da309262fe3591e73d8f0fcfd955b1d5c2.zip
Some changes in ReadScore and WriteScore to prevent for crashes caused by more than 5 score entrys per song/difficulty
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1216 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code')
-rw-r--r--Game/Code/Classes/UDataBase.pas17
1 files changed, 14 insertions, 3 deletions
diff --git a/Game/Code/Classes/UDataBase.pas b/Game/Code/Classes/UDataBase.pas
index bbdce9ec..20b44c75 100644
--- a/Game/Code/Classes/UDataBase.pas
+++ b/Game/Code/Classes/UDataBase.pas
@@ -155,10 +155,10 @@ begin
SetLength (Song.Score[1], 0);
SetLength (Song.Score[2], 0);
- while not TableData.Eof do //Go through all Entrys
+ while (not TableData.Eof) do //Go through all Entrys
begin //Add one Entry to Array
Difficulty := StrToIntDef(TableData.FieldAsString(TableData.FieldIndex['Difficulty']), -1);
- if (Difficulty >= 0) AND (Difficulty <= 2) then
+ if ((Difficulty >= 0) AND (Difficulty <= 2)) AND (Length(Song.Score[Difficulty]) < 5) then
begin
SetLength(Song.Score[Difficulty], Length(Song.Score[Difficulty]) + 1);
@@ -212,13 +212,24 @@ begin
//Create new Entry
ScoreDB.ExecSQL('INSERT INTO `'+cUS_Scores+'` ( `SongID` , `Difficulty` , `Player` , `Score` ) VALUES ("' + InttoStr(ID) + '", "' + InttoStr(Level) + '", "' + Name + '", "' + InttoStr(Score) + '");');
- //Delete Last Position when there are more than 5 Entrys
+ {//Old Deletion
if ScoreDB.GetTableValue('SELECT COUNT(`SongID`) FROM `'+cUS_Scores+'` WHERE `SongID` = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'"') > 5 then
begin
TableData := ScoreDB.GetTable('SELECT `Player`, `Score` FROM `'+cUS_Scores+'` WHERE SongID = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'" ORDER BY `Score` ASC LIMIT 1');
ScoreDB.ExecSQL('DELETE FROM `US_Scores` WHERE SongID = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'" AND `Player` = "' + TableData.FieldAsString(TableData.FieldIndex['Player']) + '" AND `Score` = "' + TableData.FieldAsString(TableData.FieldIndex['Score']) + '"');
+ end;}
+
+ //Delete Last Position when there are more than 5 Entrys - Fixes Crash when there are > 5 ScoreEntrys
+ TableData := ScoreDB.GetTable('SELECT `Player`, `Score` FROM `'+cUS_Scores+'` WHERE SongID = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'" ORDER BY `Score` DESC LIMIT -1 OFFSET 5');
+
+ While not TableData.Eof do
+ begin
+ ScoreDB.ExecSQL('DELETE FROM `US_Scores` WHERE SongID = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'" AND `Player` = "' + TableData.FieldAsString(TableData.FieldIndex['Player']) + '" AND `Score` = "' + TableData.FieldAsString(TableData.FieldIndex['Score']) + '"');
+
+ TableData.Next;
end;
+
end;
finally
//ScoreDB.Free;