MCPcopy Create free account
hub / github.com/assaultcube/AC / currentserver

Function currentserver

source/src/clientgame.cpp:359–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

357COMMAND(teaminfo, "ss");
358
359const char *currentserver(int i) // [client version]
360{
361 static string curSRVinfo;
362 // using the curpeer directly we can get the info of our currently connected server
363 string r;
364 r[0] = '\0';
365 if(curpeer)
366 {
367 switch(i)
368 {
369 case 1: // IP
370 {
371 uchar *ip = (uchar *)&curpeer->address.host;
372 formatstring(r)("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
373 break;
374 }
375 case 2: // HOST
376 {
377 char hn[1024];
378 formatstring(r)("%s", (enet_address_get_host(&curpeer->address, hn, sizeof(hn))==0) ? hn : "unknown");
379 break;
380 }
381 case 3: // PORT
382 {
383 formatstring(r)("%d", curpeer->address.port);
384 break;
385 }
386 case 4: // STATE
387 {
388 const char *statenames[] =
389 {
390 "disconnected",
391 "connecting",
392 "acknowledging connect",
393 "connection pending",
394 "connection succeeded",
395 "connected",
396 "disconnect later",
397 "disconnecting",
398 "acknowledging disconnect",
399 "zombie"
400 };
401 if(curpeer->state>=0 && curpeer->state<int(sizeof(statenames)/sizeof(statenames[0])))
402 copystring(r, statenames[curpeer->state]);
403 break; // 5 == Connected (compare ../enet/include/enet/enet.h +165)
404 }
405 // CAUTION: the following are only filled if the serverbrowser was used or the scoreboard shown
406 // SERVERNAME
407 case 5: { serverinfo *si = getconnectedserverinfo(); if(si) copystring(r, si->name); break; }
408 // DESCRIPTION (3)
409 case 6: { serverinfo *si = getconnectedserverinfo(); if(si) copystring(r, si->sdesc); break; }
410 case 7: { serverinfo *si = getconnectedserverinfo(); if(si) copystring(r, si->description); break; }
411 // CAUTION: the following is only the last full-description _seen_ in the serverbrowser!
412 case 8: { serverinfo *si = getconnectedserverinfo(); if(si) copystring(r, si->full); break; }
413 // just IP & PORT as default response - always available, no lookup-delay either
414 default:
415 {
416 uchar *ip = (uchar *)&curpeer->address.host;

Callers 1

clientgame.cppFile · 0.85

Calls 3

copystringFunction · 0.85
getconnectedserverinfoFunction · 0.85
enet_address_get_hostFunction · 0.50

Tested by

no test coverage detected