MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / readFromFile

Method readFromFile

src/net/Ping.cpp:364–391  ·  view source on GitHub ↗

de serialize packet from file must read from a binary file if we use plain "unpack"

Source from the content-addressed store, hash-verified

362// de serialize packet from file
363// must read from a binary file if we use plain "unpack"
364bool PingPacket::readFromFile(std::istream& in) {
365 if (!in) { return false; }
366
367 char buffer[PingPacket::PacketSize], serverVersion[9];
368 uint16_t len, code;
369
370 // get packet
371 in.read(buffer, sizeof(buffer));
372 if ((size_t)in.gcount() < sizeof(buffer)) {
373 return false;
374 }
375
376 // decode header
377 void* buf = buffer;
378 buf = nboUnpackUInt16(buf, len);
379 buf = nboUnpackUInt16(buf, code);
380
381 // make sure we got the rest of the message
382 if (len != in.gcount() - 4) {
383 return false;
384 }
385
386 // unpack body of reply
387 buf = unpack(buf, serverVersion);
388
389 // compare protocol version against my protocol version.
390 return (strncmp(serverVersion, getServerVersion(), 8) == 0);
391}
392
393// Local Variables: ***
394// mode: C++ ***

Callers

nothing calls this directly

Calls 3

nboUnpackUInt16Function · 0.85
getServerVersionFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected