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