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

Method flushtolog

source/src/packetqueue.cpp:22–52  ·  view source on GitHub ↗

writes all currently queued packets to disk and clears the queue

Source from the content-addressed store, hash-verified

20
21// writes all currently queued packets to disk and clears the queue
22bool packetqueue::flushtolog(const char *logfile)
23{
24 if(packets.empty()) return false;
25
26 stream *f = NULL;
27 if(logfile && logfile[0]) f = openfile(logfile, "w");
28 if(!f) return false;
29
30 // header
31 f->printf("AC v%d PACKET LOG : proto %d : @ %11s\n", AC_VERSION, PROTOCOL_VERSION, numtime());
32 // serialize each packet
33 loopv(packets)
34 {
35 ENetPacket *p = packets[i];
36
37 f->printf("\nENET PACKET\n");
38 f->printf("flags == %d\n", p->flags);
39 f->printf("referenceCount == %d\n", (int)p->referenceCount);
40 f->printf("dataLength == %d\n", (int)p->dataLength);
41 f->printf("data == \n");
42 // print whole buffer char-wise
43 loopj(p->dataLength)
44 {
45 f->printf("%6d 0x%02x '%c'\n", p->data[j], p->data[j], isprint(p->data[j]) ? p->data[j] : '-');
46 }
47 }
48
49 delete f;
50 clear();
51 return true;
52}
53
54// clear queue
55void packetqueue::clear()

Callers 1

neterrFunction · 0.80

Calls 5

openfileFunction · 0.85
numtimeFunction · 0.85
clearFunction · 0.85
emptyMethod · 0.45
printfMethod · 0.45

Tested by

no test coverage detected