28 #include <sys/types.h>
29 #include <netinet/in.h>
31 #include <arpa/inet.h>
39 #include <curl/curl.h>
40 #include <curl/easy.h>
57 if (
pl->ob->map == NULL)
67 if (
pl->socket->is_bot)
147 size_t realsize = size*nmemb;
148 LOG(
llevError,
"Message from metaserver:\n%s\n", (
const char*)ptr);
153 static void metaserver2_build_form(
struct curl_httppost **formpost) {
154 struct curl_httppost *lastptr = NULL;
163 curl_formadd(formpost, &lastptr,
164 CURLFORM_COPYNAME,
"hostname",
169 curl_formadd(formpost, &lastptr,
170 CURLFORM_COPYNAME,
"port",
171 CURLFORM_COPYCONTENTS,
buf,
174 curl_formadd(formpost, &lastptr,
175 CURLFORM_COPYNAME,
"html_comment",
179 curl_formadd(formpost, &lastptr,
180 CURLFORM_COPYNAME,
"text_comment",
184 curl_formadd(formpost, &lastptr,
185 CURLFORM_COPYNAME,
"archbase",
189 curl_formadd(formpost, &lastptr,
190 CURLFORM_COPYNAME,
"mapbase",
194 curl_formadd(formpost, &lastptr,
195 CURLFORM_COPYNAME,
"codebase",
199 curl_formadd(formpost, &lastptr,
200 CURLFORM_COPYNAME,
"flags",
207 curl_formadd(formpost, &lastptr,
208 CURLFORM_COPYNAME,
"num_players",
209 CURLFORM_COPYCONTENTS,
buf,
213 curl_formadd(formpost, &lastptr,
214 CURLFORM_COPYNAME,
"in_bytes",
215 CURLFORM_COPYCONTENTS,
buf,
219 curl_formadd(formpost, &lastptr,
220 CURLFORM_COPYNAME,
"out_bytes",
221 CURLFORM_COPYCONTENTS,
buf,
225 curl_formadd(formpost, &lastptr,
226 CURLFORM_COPYNAME,
"uptime",
227 CURLFORM_COPYCONTENTS,
buf,
235 curl_formadd(formpost, &lastptr,
236 CURLFORM_COPYNAME,
"version",
241 curl_formadd(formpost, &lastptr,
242 CURLFORM_COPYNAME,
"sc_version",
243 CURLFORM_COPYCONTENTS,
buf,
247 curl_formadd(formpost, &lastptr,
248 CURLFORM_COPYNAME,
"cs_version",
249 CURLFORM_COPYCONTENTS,
buf,
261 struct curl_httppost *formpost = NULL;
262 metaserver2_build_form(&formpost);
265 CURL *curl = curl_easy_init();
267 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30000);
270 curl_easy_setopt(curl, CURLOPT_URL, hostname.c_str());
271 curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
279 char errbuf[CURL_ERROR_SIZE];
280 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
282 CURLcode
res = curl_easy_perform(curl);
284 LOG(
llevError,
"metaserver update failed: %s\n", errbuf);
288 curl_easy_cleanup(curl);
290 LOG(
llevError,
"metaserver: could not initialize curl\n");
294 curl_formfree(formpost);
325 static int has_init = 0;
337 curl_global_init(CURL_GLOBAL_ALL);
361 if ((fp = fopen(
buf,
"r")) == NULL) {
365 while (fgets(
buf,
sizeof(
buf), fp) != NULL) {
369 if ((cp = strrchr(
buf,
'\n')) != NULL)
378 if ((cp = strpbrk(
buf,
" \t")) != NULL) {
394 LOG(
llevError,
"metaserver2: Unknown value for metaserver2_notification: %s\n", cp);
400 LOG(
llevError,
"metaserver2: metaserver2_server must have a value.\n");
406 LOG(
llevError,
"metaserver2: localhostname must have a value.\n");
412 LOG(
llevError,
"metaserver2: portnumber must have a value.\n");
442 LOG(
llevError,
"metaserver2 file is set to do notification, but libcurl is not found.\n");
443 LOG(
llevError,
"Either fix your compilation, or turn off metaserver2 notification in \n");
473 catch (
const std::system_error &err) {
474 LOG(
llevError,
"metaserver2_init: failed to create thread, code %d, what %s\n", err.code().value(), err.what());