| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1 |
/* |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2 |
Block Attack - Rise of the Blocks, SDL game, besed on Nintendo's Tetris Attack |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
3 |
Copyright (C) 2008 Poul Sander |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
4 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
5 |
This program is free software; you can redistribute it and/or modify |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
6 |
it under the terms of the GNU General Public License as published by |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
7 |
the Free Software Foundation; either version 2 of the License, or |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
8 |
(at your option) any later version. |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
9 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
10 |
This program is distributed in the hope that it will be useful, |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
13 |
GNU General Public License for more details. |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
14 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
15 |
You should have received a copy of the GNU General Public License |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
16 |
along with this program; if not, write to the Free Software |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
17 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
18 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
19 |
Poul Sander |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
20 |
R�vehjvej 36, V. 1111 |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
21 |
2800 Kgs. Lyngby |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
22 |
DENMARK |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
23 |
blockattack@poulsander.com |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
24 |
http://blockattack.sf.net |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
25 |
*/ |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
26 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
27 |
#include "uploadReplay.h" |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
28 |
#include "common.h" |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
29 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
30 |
bool isDownloading; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
31 |
bool uploadReplayInitialized; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
32 |
bool thresholdUp2Date; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
33 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
34 |
SDL_Thread *threadThresholdFile; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
35 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
36 |
void uploadReplay_init() |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
37 |
{ |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
38 |
if(uploadReplayInitialized) |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
39 |
return; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
40 |
//mutDownload = SDL_CreateMutex(); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
41 |
mutUpload = SDL_CreateMutex(); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
42 |
thresholdUp2Date = false; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
43 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
44 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
45 |
int downloadThresholdFile(void *ptr) |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
46 |
{ |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
47 |
//if(SDL_mutexP(mutDownload)==-1){ |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
48 |
// isDownloading = false; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
49 |
// return -1; //We don't crash if we can't lock. Just failing to do so |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
50 |
//} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
51 |
FILE *outfile; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
52 |
CURL *easyhandle = curl_easy_init(); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
53 |
if(!easyhandle){ |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
54 |
isDownloading=false; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
55 |
//SDL_mutexV(mutDownload); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
56 |
return -1; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
57 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
58 |
string filename = getPathToSaveFiles()+"/scoreThreshold"; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
59 |
outfile = fopen(filename.c_str(), "w"); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
60 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
61 |
curl_easy_setopt(easyhandle, CURLOPT_URL, "http://localhost/~poul/blockattackHighscores/result/threshold"); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
62 |
curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, outfile); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
63 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
64 |
CURLcode res = curl_easy_perform(easyhandle); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
65 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
66 |
fclose(outfile); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
67 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
68 |
if(res == 200) |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
69 |
thresholdUp2Date = true; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
70 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
71 |
curl_easy_cleanup(easyhandle); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
72 |
isDownloading=false; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
73 |
//if(SDL_mutexV(mutDownload)==-1){ |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
74 |
//return 0; //We don't crash if we can't lock. Just failing to do so |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
75 |
//} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
76 |
return 0; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
77 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
78 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
79 |
bool uploadReplay_canUpload() |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
80 |
{ |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
81 |
if(thresholdUp2Date) |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
82 |
return true; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
83 |
if(isDownloading) |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
84 |
return false; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
85 |
isDownloading=true; //We mark before start the thread |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
86 |
threadThresholdFile = SDL_CreateThread(downloadThresholdFile, NULL); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
87 |
return thresholdUp2Date; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
88 |
} |
|
|
1970-01-01 00:00 |
89 |
|