Here is Phaelax's Tier 1 code converted into Tier 2, if anyone is interested:
// Includes
#include "template.h"
#include <string.h>
// Namespace
using namespace AGK;
app App;
//definitions
unsigned int getScore(char *gameKey);
void MainLoop();
unsigned int getSubmissionResponse(int s);
char* getScoreResponse(int s);
unsigned int submitScore(char *player, char *score, char *gameKey);
void LoopforScores();
char *GetFromWeb(char *host, char *urlpath);
char *GAME_KEY = "c4d423cb7f2f4492ed48079ba76ef59d08cd144b";
int scoreObject = 0;
int submitObject = 0;
int score=23;
struct ScoreUDT
{
char *name;
int score;
}scoreboard [20];
// Begin app, called once at the start
void app::Begin( void )
{
//agk::SetVirtualResolution(800,600);
MainLoop();
}
// Main loop, called every frame
void app::Loop ( void )
{
LoopforScores();
agk::Sync();
}
// Called when the app ends
void app::End ( void )
{
//clean up pointer from structure
for (int i = 0; i < 19; i++)
{
delete scoreboard[i].name;
scoreboard[i].name=NULL;
scoreboard[i].score=0;
}
}
void LoopforScores()
{
int res=0;
int size=21;
//testing
// Press SPACE key
if (agk::GetRawKeyPressed(32)==1)
{
//int score=0;
score = score + 23;
submitObject = submitScore("JB", agk::Str(score), GAME_KEY);
}
// Press ENTER key
if (agk::GetRawKeyPressed(13)==1)
{
scoreObject = getScore(GAME_KEY);
}
///end testing
if (submitObject > 0)
{
res = getSubmissionResponse(submitObject);
if (res = 1){submitObject = 0;}
}
if (scoreObject > 0)
{
char *scores$, *player$;
int count,j,score;
scores$ = getScoreResponse(scoreObject);
if (strcmp(scores$,"") != 0)
{
scoreObject = 0;
count = agk::CountStringTokens(scores$, ",");
size = agk::Val(agk::GetStringToken(scores$, ",", 1));
//dim scoreboard[size] as ScoreUDT
j = 0;
for (int i = 2; i <= count; i=i+2)// step 2
{
player$ = agk::GetStringToken(scores$, ",", i);
score = agk::Val(agk::GetStringToken(scores$, ",", i+1));
scoreboard[j].name = player$;
scoreboard[j].score = score;
j++;
}
}
}
if (res == 1){agk::Print("Submission Successful");}
for (int i = 0; i < (size-1); i++)
{
agk::Print(scoreboard[i].name);
agk::Print(agk::Str(scoreboard[i].score));
}
return;
}
void MainLoop()
{
char *Response;
Response = GetFromWeb("zimnox.com","gamespace/test.php");
//while(agk::GetRawKeyPressed(27) != 1)
//{
// agk::Print(Response);
// if (agk::GetPointerPressed()==1){
// //clean up pointer
// delete[] Response;
// Response=NULL;
// return;
// }
// agk::Sync();
//}
agk::Print(Response);
agk::Sync();
//clean up pointer
delete[] Response;
Response=NULL;
return;
}
unsigned int getScore(char *gameKey)
{
unsigned int http;
//unsigned int r;
char vars[200] = "gamekey=";
http = agk::CreateHTTPConnection();
//agk::SetHTTPHost(http, "zimnox.com", 0, "", "");//original code
agk::SetHTTPHost(http, "secure.fastdomain.com", 1, "", "");
strcat(vars,gameKey);
//agk::SendHTTPRequestASync(http, "gamespace/test.php", vars);//original code
agk::SendHTTPRequestASync(http, "~zimnoxco/gamespace/update/index.php", vars);
return http;
}
char* getScoreResponse(int s)
{
int res;
char *scores = "";
res = agk::GetHTTPResponseReady(s);
if (res == -1)
{
// Error
}
else if (res == 1)
{
scores = agk::GetHTTPResponse(s);
}
if (res != 0)
{
agk::CloseHTTPConnection(s);
agk::DeleteHTTPConnection(s);
}
return scores;
}
unsigned int getSubmissionResponse(int s)
{
int res;
res = agk::GetHTTPResponseReady(s);
if (res == -1)
{
// Error
}
else if (res == 1)
{
res = agk::Val(agk::GetHTTPResponse(s));
}
if (res != 0)
{
agk::CloseHTTPConnection(s);
agk::DeleteHTTPConnection(s);
}
return res;
}
unsigned int submitScore(char *player, char *score, char *gameKey)
{
unsigned int http;
char vars[200]="";
http = agk::CreateHTTPConnection();
//agk::SetHTTPHost(http, "zimnox.com", 0, "", ""); //original code
agk::SetHTTPHost(http, "secure.fastdomain.com", 1, "", "");
//vars = "player="+player+"&score="+score+"&gamekey="+gameKey
strcat(vars,"player=");
strcat(vars,player);
strcat(vars,"&score=");
strcat(vars,score);
strcat(vars,"&gamekey=");
strcat(vars,gameKey);
//agk::SendHTTPRequestASync(http, "gamespace/test.php", vars); //original code
agk::SendHTTPRequestASync(http, "~zimnoxco/gamespace/update/index.php", vars);
return http;
}
char *GetFromWeb(char *host, char *urlpath)
{
char *Response;
char *szUser$;
char *szPass$;
unsigned int iHTTP;
int iSecure,ret;
Response="";
if (agk::GetInternetState()==1)
{
iHTTP=agk::CreateHTTPConnection();
iSecure=0;
szUser$="";
szPass$="";
if (agk::SetHTTPHost( iHTTP, host, iSecure, szUser$, szPass$ )==1)
{
if (agk::SendHTTPRequestASync( iHTTP, urlpath )==1)
{
while(true)
{
ret=agk::GetHTTPResponseReady( iHTTP );
if (ret== -1){break;} //Cancel
if (ret==1){break;} //Ready
agk::Print("wait ...");
agk::Sync();
}
if (ret==1)
{
Response=agk::GetHTTPResponse( iHTTP );
}
} //Get
agk::CloseHTTPConnection( iHTTP );
} //Host
agk::DeleteHTTPConnection( iHTTP );
} //Internet
return Response;
}
Joeisms
KG2Entertainment.com