27 #include <sys/types.h>
28 #include <netinet/in.h>
30 #include <arpa/inet.h>
38 #include <curl/curl.h>
39 #include <curl/easy.h>
54 if (
pl->ob->map == NULL)
64 if (
pl->socket->is_bot)
150 static int has_init = 0;
164 curl_global_init(CURL_GLOBAL_ALL);
188 if ((fp = fopen(
buf,
"r")) == NULL) {
192 while (fgets(
buf,
sizeof(
buf), fp) != NULL) {
196 if ((cp = strrchr(
buf,
'\n')) != NULL)
205 if ((cp = strpbrk(
buf,
" \t")) != NULL) {
221 LOG(
llevError,
"metaserver2: Unknown value for metaserver2_notification: %s\n", cp);
227 LOG(
llevError,
"metaserver2: metaserver2_server must have a value.\n");
233 LOG(
llevError,
"metaserver2: localhostname must have a value.\n");
239 LOG(
llevError,
"metaserver2: portnumber must have a value.\n");
269 LOG(
llevError,
"metaserver2 file is set to do notification, but libcurl is not found.\n");
270 LOG(
llevError,
"Either fix your compilation, or turn off metaserver2 notification in \n");
300 LOG(
llevError,
"metaserver2_init: return code from pthread_create() is %d\n", ret);
322 size_t realsize = size*nmemb;
323 LOG(
llevError,
"Message from metaserver:\n%s\n", (
const char*)ptr);
328 static void metaserver2_build_form(
struct curl_httppost **formpost) {
329 struct curl_httppost *lastptr = NULL;
338 curl_formadd(formpost, &lastptr,
339 CURLFORM_COPYNAME,
"hostname",
344 curl_formadd(formpost, &lastptr,
345 CURLFORM_COPYNAME,
"port",
346 CURLFORM_COPYCONTENTS,
buf,
349 curl_formadd(formpost, &lastptr,
350 CURLFORM_COPYNAME,
"html_comment",
354 curl_formadd(formpost, &lastptr,
355 CURLFORM_COPYNAME,
"text_comment",
359 curl_formadd(formpost, &lastptr,
360 CURLFORM_COPYNAME,
"archbase",
364 curl_formadd(formpost, &lastptr,
365 CURLFORM_COPYNAME,
"mapbase",
369 curl_formadd(formpost, &lastptr,
370 CURLFORM_COPYNAME,
"codebase",
374 curl_formadd(formpost, &lastptr,
375 CURLFORM_COPYNAME,
"flags",
382 curl_formadd(formpost, &lastptr,
383 CURLFORM_COPYNAME,
"num_players",
384 CURLFORM_COPYCONTENTS,
buf,
388 curl_formadd(formpost, &lastptr,
389 CURLFORM_COPYNAME,
"in_bytes",
390 CURLFORM_COPYCONTENTS,
buf,
394 curl_formadd(formpost, &lastptr,
395 CURLFORM_COPYNAME,
"out_bytes",
396 CURLFORM_COPYCONTENTS,
buf,
400 curl_formadd(formpost, &lastptr,
401 CURLFORM_COPYNAME,
"uptime",
402 CURLFORM_COPYCONTENTS,
buf,
410 curl_formadd(formpost, &lastptr,
411 CURLFORM_COPYNAME,
"version",
416 curl_formadd(formpost, &lastptr,
417 CURLFORM_COPYNAME,
"sc_version",
418 CURLFORM_COPYCONTENTS,
buf,
422 curl_formadd(formpost, &lastptr,
423 CURLFORM_COPYNAME,
"cs_version",
424 CURLFORM_COPYCONTENTS,
buf,
436 struct curl_httppost *formpost = NULL;
437 metaserver2_build_form(&formpost);
440 CURL *curl = curl_easy_init();
443 curl_easy_setopt(curl, CURLOPT_URL, hostname.c_str());
444 curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
452 char errbuf[CURL_ERROR_SIZE];
453 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
455 CURLcode
res = curl_easy_perform(curl);
457 LOG(
llevError,
"metaserver update failed: %s\n", errbuf);
461 curl_easy_cleanup(curl);
463 LOG(
llevError,
"metaserver: could not initialize curl\n");
467 curl_formfree(formpost);