Hacktacular

posted in Ubertainment
Published June 18, 2005
Advertisement
Psycho Boy 3D Progress:

I'm testing out the new online highscore for psychoboy, check out the Hack my highscore thread. I'm working hard on making it at least semi-hack proof, at least secure enough to stop someone like XY.

In other news:
The results came through for my degree and I got a first, hooray!
Previous Entry Psycho update
Next Entry New stuff
0 likes 5 comments

Comments

JTippetts
That hand-drawn house in the screenshot in your previous journal entry kicks much ass. I think it would be cool if somebody made an entire game with hand-drawn textured models like that. [grin]
June 19, 2005 07:02 PM
Patbert
Thanks, that was originally a placeholder texture to test it out but I decided to keep it. The game does have quite a mishmash of styles due to the fact I have no artistic talent and I was learning OpenGL and such at the time. Someone did make a hand-drawn space invaders game.
June 19, 2005 09:06 PM
Rob Loach
Congrats. Make sure you make a extendable highscore system. I got stuck with mine as all I included were their name and score. Another good thing would be to have a number key embedded in the highscores so that you could adapt the same system to a completely different game.
June 20, 2005 11:14 AM
Patbert
Good point, psychoboy does pass a gameid value via the url but its not actually used server side. Hopefully I can extend it to other games without too much of a problem.
June 21, 2005 12:54 PM
Patbert

<% Option Explicit %>

<html><head>
<title>Patbert's High Score Table</title>
</head><body text=#FFFFFF bgcolor=#000000>
HIGHSCORE TABLE

<%

const databaseFile="/psychoscore/database/highscore.mdb"                        'Database that stores the scores
const gameIdColumn=0, positionColumn=1, scoreColumn=2, levelColumn=3, playerColumn=4  'column numbers for fields
const MAXSCORES=80                                                              ' Maximum number of highscores
Dim SQLStatement                                                                'SQL statement used to retrieve highscores
' SQL will retrieve all highscores for the requested GAMEID (passed via URL):
SQLStatement = "SELECT * FROM hiscore WHERE (gameid="∫(request("gameid"))&") ORDER BY position"

Dim Conn, RS                                                                    'Declares the Conn (Connection) and RS (Recordset) variables
dim currRecord, targetRecord, nextRecord                                        'arrays for highscores
Dim result, message                                                             'Stores HTML of highscore table (result) and a message (message)
Dim positionFound                                                               'boolean, true if submitted highscore has been found
Dim lastPosition                                                                'Stores last highscore position
Dim scoreValid                                                                   'Boolean: true if submitted highscore is valid

Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.Recordset") 

targetRecord=getTargetRecord                                                    'Get submitted highscore (target score)
' Check player's name is not empty
if targetRecord(playerColumn)="" then scoreValid=false else scoreValid=true
positionFound=false
lastPosition=-1

'Open database for writing (how this is done depends on your provider - consult your provider's documentation)
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath(databaseFile)
RS.Open SQLStatement, Conn, 3, 3  'Open the database for writing while allowing others to still read it.

if not RS.EOF then RS.MoveFirst                                                 'If table is not empty go to first record
Do Until RS.EOF                                                                 'Loop until no records 

  currRecord=getRecord(RS)                                                      'Get record from database
  if isDuplicate(currRecord,targetRecord) then scoreValid=false                 'If submitted score is already in database, score is invalid

   'If score is valid and this is the position to insert the target highscore:
   if scoreValid and positionFound=false and int(currRecord(scoreColumn))<=int(targetRecord(scoreColumn)) then 
     positionFound=true                                       
     nextRecord=currRecord                                                      'Set the next record as the current one 
     targetRecord(positionColumn)=currRecord(positionColumn)                    'Set position number same as current one
     nextRecord(positionColumn)=nextRecord(positionColumn)+1                    'Move position of next record on one
     currRecord=targetRecord                                                    'Set the current record as the submitted record
     saveRecord(currRecord)                                                     'Save to database
     result=result+recordToString(currRecord,"<td align=center bgcolor=#800000>")  'Add to table    
     message="Well done! You got to position #"&(targetRecord(positionColumn)+1)&" in the highscore table!"

   elseif positionFound then                                                    'If current record is below the submitted record    
     swapArray currRecord,nextRecord                                            'Move records down to accommadate the inserted highscore
     nextRecord(positionColumn)=nextRecord(positionColumn)+1                    'add one to next record
     saveRecord(currRecord)                                                     'Save to database
     result=result+recordToString(currRecord,"<td align=center>")               'Display to table

   else                                                                         'If the target highscore hasn't been found yet
     result=result+recordToString(currRecord,"<td align=center>")               'Just display to table
   end if

   lastPosition=currRecord(positionColumn)  
   RS.MoveNext                                                                  'Go to next record 
Loop 

if scoreValid then             
  if positionFound=false and lastPosition>=MAXSCORES-1 then                     'If the submitted highscore is off the table
    message="Sorry, you did not qualify for the highscore table"
  elseif positionFound=false then                                               'If submitted highscore is on the bottom of the highscore table
    targetRecord(positionColumn)=lastPosition+1                                 'Set position to the last highscore plus one
    addRecord(targetRecord)                                                     'Add record to database
    message="Well done! You got to position #"&(targetRecord(positionColumn)+1)&" in the highscore table!"
    result=result+recordToString(targetRecord,"<td align=center bgcolor=#800000>")    'Display
  else                                                                          'If submitted highscore has already been added 
    addRecord(nextRecord)                                                       'Add the last record that has been moved along
    result=result+recordToString(nextRecord,"<td align=center>")                'Display
  end if
end if

RS.Close  'Close database
Conn.Close

Response.Write message                                                          'Display message
Response.Write "<table border=0 cellspacing=3><tr>"  'Display table header
Response.Write "<td align=center bgcolor=#333333> POSITION </td>"
Response.Write "<td align=center bgcolor=#333333> SCORE </td>"
Response.Write "<td align=center bgcolor=#333333> LEVEL </td>"
Response.Write "<td align=center bgcolor=#333333> PLAYER </td>"
Response.Write result                                                            'Display highscores

'Returns a string for adding into the HTML table
function recordToString(detail,prefix)
  recordToString= "<tr>"&prefix& _
    detail(positionColumn)+1&"</td>"&prefix& _                                  '1 is added to position as it is zero indexed
    detail(scoreColumn)&"</td>"&prefix& _
    detail(levelColumn)&"</td>"&prefix& _
    detail(playerColumn)&"</td></tr>"
end function

'Edits current database record
sub saveRecord(detail)
    RS.Fields("Player").Value =detail(playerColumn)
    RS.Fields("Level").Value=detail(levelColumn)
    RS.Fields("Score").Value=detail(scoreColumn)    
    RS.Update
end sub

'Adds new record to database
sub addRecord(detail)
    RS.AddNew 
    RS.Fields("Position")=detail(PositionColumn)
    RS.Fields("GameId").Value=detail(gameIdColumn)    
    saveRecord(detai
July 12, 2005 08:34 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

go wagonwheels

1130 views

My new slogan

1194 views

Swing the Cat

1280 views

PB3D

1175 views

Cat swinging

1019 views

1W1B

1285 views

shooty goodness

1031 views

More sudoku

915 views
Advertisement