Web based high score tables
Blitz3D Forums/Blitz3D Programming/Web based high score tables
| ||
Hi, I've noticed that some developers have high score tables on-line for players to upload their scores to. Does anyone know where I could find some code or advice on implementing such a feature? If there are any web geniuses out there I know I musn't be the only one who would be willing to pay a small monthly fee for such a service. It would be cool if someone had a way that we could: 1) Drop the "upload score" code into our games. 2) The scoreboards would be maintained on their 3rd party server. 3) The scores would be accessed in real time on our own websites through a simple drag and drop code like a streaming news server. It can't be that hard to create something like this. Hmmmm. |
| ||
Easy to do using php or a perl script.. I'd write and host such a service if I knew there would enough interest. |
| ||
Look at GNet in the tool box: http://www.blitzbasic.com/toolbox/toolbox.php?tool=61 This uploads info for IP address etc... but I made my high score stuff using this as a basis. You'll also need PHP and MySQL on your webserver and a tool like the free PHPMyAdmin to do it all. I learned how to do it in a weekend. |
| ||
Security in itself is a pain in the ass. I'm sure there are many ways to accomplish this task. I used the following tools: 1. PHP and MySQL (server-side) 2. Wrote a custom DLL that allows communication with web server (client-side). I'm sure this can be done via Blizt3d api calls. Sample code for updating players info to the database online via Blitz3d. mydata$ = "name="+name$+"&level="+level+"&hs="+score$+"&diff="+diff$+"&ver="+CurrentVersion$+"&fv="+fv$+"&bo="+xor2 mydata2$ = "http://www.webappstogo.com/3dblowout/highscore.html?"+mydata$ ret$=HighScoreWebUpdate$(mydata2$);Most of this is self explanatory. HighScoreWebUpdate$ is my entry point to the DLL which communicates with my web server. Sample code on server-side to handle this request (PHP): If (the key takes) { $sql = "insert into 3dbo_highscore_v12 (name, level, difficulty, highscore) values ('$name', '$level', '$diff', '$hs')"; $result = mysql_query($sql); }Here's sample code to grab the top 10 scores from the database (PHP). $sql = "select * from 3dbo_highscore_v12 order by highscore desc LIMIT 0, 10"; $result = mysql_query($sql); If (@mysql_num_rows($result)) { While ($qry = mysql_fetch_array($result)) { $player = $qry[name]; $score = $qry[highscore]; $level = $qry[level]; $diff = $qry[difficulty]; echo $player."~".$level."~".$diff."~".$score."~"; } }In my game, 3D Blowout, the player may choose to view the top 10 world-wide player scores. I wrote an additional script that could be used for advertisment purposes for cummunicating future releases or even new products. This advertisment message would scroll (right to left) right below the top 10 scores in the game. Sample code (PHP): function GetAdvertisement($n1,$s1,$l1,$d1,$fv) { srand((double) microtime() * 1000000); $adv[0] = "--- The top 100 WORLDWIDE scores can be found at www.webappstogo.com --- "; $adv[1] = "--- Check out our 3D Screensavers at www.webappstogo.com --- "; $adv[2] = "--- Free updates to all registered users --- "; $adv[3] = "--- 3D Blowout (Distraction Style) Copyright 2004 WebAppstogo --- "; $adv[4] = "--- Want to see more in this game? Email us your suggestions --- "; If (Rand(0,5) == 5) { $adv = "--- Top Dog Honors go to ".$n1." with a score of ".$s1.", difficulty set on ".$d1.". Congratulations! ---"; echo ":".$adv.";"; } Else { echo ":".$adv[Rand(0,4)].";"; } }Here's the actual function to display top 10 scores. HSList$ contains the players info (name, difficulty, level, high score and advertisment message). You may notice that I use FONText (great tool): Function HallOfFame(HSList$) ScaleFont currfont, 0.40,0.9 FontColor currfont, 150,150,240,1 updateHUDcounter hudTopTen,"Top 10 WorldWide Players" ScaleFont currfont, 0.33,0.6 FontColor currfont, 255,0,0,1 updateHUDcounter hudHSTitle,"Player Level Diff High Score" ScaleFont currfont, 0.25,0.5 For myhudtest.hudtest = Each hudtest num1 = num1 + 1 For b1=1 To 4 loc1 = loc2 + 1 loc2 = Instr( HSList$,"~",loc1) If loc2 <> 0 temp$ = Mid$(HSList$,loc1,loc2-loc1) ;DebugLog (temp$) Select (b1) Case 1: player$ = LSet$(temp$, 16) Case 2: player$ = LSet$(temp$, 6) Case 3: player$ = LSet$(temp$, 10) Case 4: player$ = LSet$(temp$, 7) End Select temp$ = Replace$(player$,"~","") playerdata$ = playerdata$ + temp$ Else Return EndIf Next If num1 = 1 ScaleFont currfont, 0.30,0.4 FontColor currfont, 0,255,0,1 updateHUDcounter myhudtest\hudHSPlayerTest.HUDcounter,playerdata$,8+Rnd(-1,1),290+Rnd(-1,1) Else ScaleFont currfont, 0.30,0.4 FontColor currfont, 0,100,255,1 updateHUDcounter myhudtest\hudHSPlayerTest.HUDcounter,playerdata$ EndIf playerdata$ = "" Next End FunctionSample code for scrolling the advertisment message below the top 10 scores. Again, HSList$ contains the players info (name, difficulty, level, high score and advertisment message): Function Advertisement(HSList$) loc1 = Instr( HSList$,":",1) If loc1 <> 0 loc2 = Instr( HSList$,";",loc1) If loc2 <> 0 adv$ = Mid$(HSList$,loc1+1,loc2-loc1-1) advlen = Len (adv$) * 14 myadvtest = myadvtest - 2 If myadvtest < (-advlen)+2 Then myadvtest = advlen ScaleFont currfont, 0.20,0.3 FontColor currfont, 255,255,255,1 updateHUDcounter hudAdvertisement,adv$,advlen+myadvtest,575 EndIf EndIf End FunctionFinally, code sample of DLL call for sending information to the web server. I have a class (c++) that handles the internals. #define BBDECL extern "C" _declspec(dllexport) #define BBCALL _stdcall BBDECL const char* BBCALL HighScoreWebUpdate(const char* szURL) { CString csContents, csResponse, csErrMsg; int nResult; m_pInternet.httpGet(szURL, csContents, nResult, csErrMsg); return csContents; }Not sure if you will get anything from my source, but it should enlighten you of how much work lies ahead. |