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

Function serverpickup

source/src/server.cpp:1831–1869  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1829}
1830
1831bool serverpickup(int i, int sender) // server side item pickup, acknowledge first client that gets it
1832{
1833 const char *hn = sender >= 0 && clients[sender]->type == ST_TCPIP ? clients[sender]->hostname : NULL;
1834 if(!sg->sents.inrange(i))
1835 {
1836 if(hn && !m_coop) mlog(ACLOG_INFO, "[%s] tried to pick up entity #%d - doesn't exist on this map", hn, i);
1837 return false;
1838 }
1839 server_entity &e = sg->sents[i];
1840 if(!e.spawned)
1841 {
1842 if(!e.legalpickup && hn && !m_demo) mlog(ACLOG_INFO, "[%s] tried to pick up entity #%d (%s) - can't be picked up in this gamemode or at all", hn, i, entnames[e.type]);
1843 return false;
1844 }
1845 if(sender>=0)
1846 {
1847 client *cl = clients[sender];
1848 if(cl->type==ST_TCPIP)
1849 {
1850 if(cl->state.state != CS_ALIVE || !cl->state.canpickup(e.type)) return false;
1851 vec v(e.x, e.y, cl->state.o.z);
1852 float dist = cl->state.o.dist(v);
1853 int pdist = check_pdist(cl,dist);
1854 if (pdist)
1855 {
1856 cl->farpickups++;
1857 if (!m_demo) mlog(ACLOG_INFO, "[%s] %s %s up entity #%d (%s), distance %.2f (%d)",
1858 cl->hostname, cl->name, (pdist==2?"tried to pick":"picked"), i, entnames[e.type], dist, cl->farpickups);
1859 if (pdist==2) return false;
1860 }
1861 }
1862 sendf(-1, 1, "ri3", SV_ITEMACC, i, sender);
1863 cl->state.pickup(sg->sents[i].type);
1864 if (m_lss && sg->sents[i].type == I_GRENADE) cl->state.pickup(sg->sents[i].type); // get two nades at lss
1865 }
1866 e.spawned = false;
1867 if(!m_lms) e.spawntime = spawntime(e.type);
1868 return true;
1869}
1870
1871void checkitemspawns(int diff)
1872{

Callers 2

trypickupFunction · 0.85
processeventFunction · 0.85

Calls 8

mlogFunction · 0.85
check_pdistFunction · 0.85
sendfFunction · 0.85
spawntimeFunction · 0.85
inrangeMethod · 0.80
canpickupMethod · 0.80
distMethod · 0.80
pickupMethod · 0.80

Tested by

no test coverage detected