From ba90715d26e84fd176a0d44bd8e5dde826067d93 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 8 Nov 2009 13:42:14 -0500 Subject: Added global highscore list You can now view and submit highscores to the global highscore list. If the connection fails, you are allowed to retry sending it so your score is not lost. The actual global highscore list is a PHP file and MySQL database that will need to be uploaded to Four Island Other for this to work. Some other things were done. Because it was discovered that the frequent window caption changes were making Maze Of Life crash, they were removed and the player is now notified of their score by the level number appearing in 100 point font at the beginning of each level during the doneWorking stage. Also, a cheat was added that allows you to play the game in fullscreen if you press F4 on a supporting platform. The player is now also slightly faster. Closes #104 --- hslist.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'hslist.cpp') diff --git a/hslist.cpp b/hslist.cpp index d2901b4..ec99a77 100644 --- a/hslist.cpp +++ b/hslist.cpp @@ -76,10 +76,123 @@ std::vector HighscoreList::getLocalHighscores() std::vector HighscoreList::getGlobalHighscores() { + IPaddress ipaddress; + if (SDLNet_ResolveHost(&ipaddress, "other.fourisland.com", 80) == -1) + { + printf("Could not resolve host \"other.fourisland.com\": %s\n", SDLNet_GetError()); + throw 1; + } + + TCPsocket tcpsock = SDLNet_TCP_Open(&ipaddress); + if (!tcpsock) + { + printf("Could not connect to host \"other.fourisland.com\": %s\n", SDLNet_GetError()); + throw 2; + } + + char* headers = "GET /mol/hslist.php HTTP/1.1\nHost: other.fourisland.com\nUser-Agent: Maze Of Life v2.0\nAccept: text/plain\nKeep-Alive: 300\nConnection: keep-alive\n\n"; + if (SDLNet_TCP_Send(tcpsock, headers, strlen(headers)+1) < strlen(headers)) + { + printf("Connection closed by peer: %s\n", SDLNet_GetError()); + throw 3; + } + + std::stringstream download(std::stringstream::in | std::stringstream::out); + char hslist[1024]; + SDLNet_TCP_Recv(tcpsock, hslist, 1024); + download << hslist; + SDLNet_TCP_Close(tcpsock); + + char temps[256]; + download.getline(temps,256); + while (strlen(temps) != 1) + { + download.getline(temps,256); + } + + std::vector temp = std::vector(); + int scores; + download.getline(temps, 256); + if (sscanf(temps, "%d%*c", &scores) != 1) + { + printf("Recieved data is of an invalid format: %s\n", temps); + throw 4; + } + + for (int i=0; ihslist = getLocalHighscores(); } + +GlobalHighscoreList::GlobalHighscoreList() +{ + fail = false; + + try + { + this->hslist = getGlobalHighscores(); + } catch (int e) + { + fail = true; + } +} + +SDL_Surface* GlobalHighscoreList::render() +{ + if (fail) + { + SDL_Surface* tmp = SDL_CreateRGBSurface(SDL_SWSURFACE || SDL_SRCCOLORKEY, 480, 480, 32, 0,0,0,0); + Uint32 bgColor = SDL_MapRGB(tmp->format, 255, 255, 255); + SDL_FillRect(tmp, NULL, bgColor); + SDL_SetColorKey(tmp, SDL_SRCCOLORKEY, bgColor); + TTF_Font* dataFont = loadFont(25); + SDL_Color fontColor = {0, 0, 0, 0}; + SDL_Surface* text = TTF_RenderText_Blended(dataFont, "Error retrieving highscores", fontColor); + SDL_Rect tSpace = {240-(text->w/2), 240-(text->h/2), text->w, text->h}; + SDL_BlitSurface(text, NULL, tmp, &tSpace); + + return tmp; + } else { + return super::render(); + } +} -- cgit 1.4.1