writes all currently queued packets to disk and clears the queue
| 20 | |
| 21 | // writes all currently queued packets to disk and clears the queue |
| 22 | bool 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 |
| 55 | void packetqueue::clear() |