Debian Codegraph @

src/network/protocol.h

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2009 by The qGo Project *
3 * *
4 * This file is part of qGo. *
5 * *
6 * qGo is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <http://www.gnu.org/licenses/> *
18 * or write to the Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22
23 #ifndef PROTOCOL_H
24 #define PROTOCOL_H
25
26 class ProtocolPacket
27 {
28 public:
29 ProtocolPacket() {};
30
31 };
32
33 /* This is a huge pain in the ass and probably just
34 * a waste of time. Its like, if I don't want to allocate
35 * the records and copy the data to them because that's a
36 * waste, then its like I have to override an accessor
37 * function. So then I guess its like a RecordShell that
38 * returns a record offset by the index * sizeof the record.
39 * and then maybe a type case */
40
41 class PacketRecord
42 {
43 public:
44 virtual unsigned int size() = 0;
45 };
46
47 class RecordShell
48 {
49 public:
50 RecordShell(class PacketRecord & p, void * d) : records(p), data(d) {};
51 class PacketRecord & operator[](int i) { return *(PacketRecord *)((char *)data + (i * records.size())); };
52 private:
53 class PacketRecord & records;
54 void * data;
55 };
56
57 class ZeroPaddedString
58 {
59 public:
60 ZeroPaddedString(int s, char * d) : size(s), data(d) {};
61 unsigned char operator[] (int index) { };
62 void operator=(char *) {};
63 private:
64 unsigned int size;
65 char * data;
66 };
67
68 //test
69 class OROPlayerListPacket : public ProtocolPacket
70 {
71 public:
72 OROPlayerListPacket(char * p) : data(p), playerRecord(pr, p) { };
73 void * data;
74 unsigned short unknown(void) { return *(unsigned short * )data; };
75 unsigned char playerRecords(void) { return (unsigned char )((char *)data)[2]; };
76 /* Need to pass it data pointer, but then offset by RecordShell ?
77 * or RecordShell does all offsets, data */
78 class PlayerRecord : public PacketRecord
79 {
80 public:
81 PlayerRecord(void) : name(10) {};
82 unsigned int size(void) { return 0x28; };
83 ZeroPaddedString name;
84 unsigned short id(void) { return (unsigned short)*((char *)this + 0x0a); };
85 unsigned char specialIdByte(void) { return (unsigned char)*((char *)this + 0xc); };
86 unsigned char rankByte(void) { return (unsigned char)*((char *)this + 0xd); };
87 unsigned char unknown2;
88 unsigned char countryCode;
89 unsigned char inviteByte;
90 unsigned char unknown3;
91 unsigned short rankScore;
92 unsigned short wins;
93 unsigned short losses;
94 unsigned short unknown4;
95 unsigned short unknown5;
96 } pr;
97 const class RecordShell playerRecord;
98 };
99
100 #endif //PROTOCOL_H