~ubuntu-branches/ubuntu/vivid/qgo/vivid-proposed

« back to all changes in this revision

Viewing changes to src/network/protocol.h

  • Committer: Package Import Robot
  • Author(s): Yann Dirson
  • Date: 2012-05-19 19:05:05 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120519190505-b23f5tzx7y8cu946
Tags: 2~svn764-1
* The "Raise dead" release (Closes: #673520), new maintainer.
* New upstream snapshot with Qt4 support (Closes: #604589), adjusted
  build-deps.
* Switched to source format "3.0 (quilt)", adjusted build-deps.
* Switched to dh and debhelper compat level 9, adjusted build-deps.
* Build with -fpermissive.
* New build-dep libasound2-dev, remove obsolete build-dep on libxinerama-dev.
* Refreshed patches 01_gnugo and 04_desktop, leaving 20_kfreebsd away
  for this release, and removing the remaining ones, now obsolete.
* Added patch 02_usrgames for FHS-correct install location.
* Adjusted icon names in menu file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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