summaryrefslogtreecommitdiffstats
path: root/PacketParser.cpp
blob: 488c81232ee4a3532bde741b8ee7b44e2e09508f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "PacketParser.hpp"

void PacketParser::Parse(Packet &packet, ConnectionState state, bool ClientBound) {
    if (ClientBound) {
        switch (state) {
            case Login:
                ParseLogin(packet);
                break;
            case Handshaking:
                break;
            case Play:
                ParsePlay(packet);
                break;
            case Status:

                break;
        }
    } else {
        ParseServerBound(packet, state);
    }
}

void PacketParser::ParseServerBound(Packet &packet, ConnectionState state) {
    throw 107;
}

void PacketParser::ParseLogin(Packet &packet) {
    switch (packet.GetId()) {
        case 0x00:
            ParseLogin0x00(packet);
            break;
        case 0x02:
            ParseLogin0x02(packet);
            break;
        default:
        {
            int i = packet.GetId();
            //throw 112;
        }
    }
}

void PacketParser::ParsePlay(Packet &packet) {
    switch (packet.GetId()) {
        case 0x23:
            ParsePlay0x23(packet);
            break;
        case 0x1F:
            ParsePlay0x1F(packet);
            break;
        case 0x0D:
            ParsePlay0x0D(packet);
            break;
        case 0x2B:
            ParsePlay0x2B(packet);
            break;
        case 0x43:
            ParsePlay0x43(packet);
            break;
        case 0x2E:
            ParsePlay0x2E(packet);
            break;
        case 0x1A:
            ParsePlay0x1A(packet);
            break;
        case 0x20:
            ParsePlay0x20(packet);
            break;
        case 0x07:
            ParsePlay0x07(packet);
        default:
            //throw 113;
            break;
    }
}

void PacketParser::ParseLogin0x00(Packet &packet) {
    packet.ParseField(String);
}

void PacketParser::ParseLogin0x02(Packet &packet) {
    packet.ParseField(String);
    packet.ParseField(String);
}

void PacketParser::ParsePlay0x23(Packet &packet) {
    packet.ParseField(Int);
    packet.ParseField(UnsignedByte);
    packet.ParseField(Int);
    packet.ParseField(UnsignedByte);
    packet.ParseField(UnsignedByte);
    packet.ParseField(String);
    packet.ParseField(Boolean);
}

void PacketParser::ParsePlay0x1F(Packet &packet) {
    packet.ParseField(VarInt);
}

void PacketParser::ParsePlay0x0D(Packet &packet) {
    packet.ParseField(UnsignedByte);
}

void PacketParser::ParsePlay0x2B(Packet &packet) {
    packet.ParseField(Byte8_t);
    packet.ParseField(Float);
    packet.ParseField(Float);
}

void PacketParser::ParsePlay0x43(Packet &packet) {
    packet.ParseField(Position);
}

void PacketParser::ParsePlay0x2E(Packet &packet) {
    packet.ParseField(Double);
    packet.ParseField(Double);
    packet.ParseField(Double);
    packet.ParseField(Float);
    packet.ParseField(Float);
    packet.ParseField(Byte8_t);
    packet.ParseField(VarInt);
}

void PacketParser::ParsePlay0x1A(Packet &packet) {
    packet.ParseField(String);
}

void PacketParser::ParsePlay0x20(Packet &packet) {
    packet.ParseField(Int);
    packet.ParseField(Int);
    packet.ParseField(Boolean);
    packet.ParseField(VarInt);
    packet.ParseField(VarInt);
    packet.ParseField(ByteArray, packet.GetField(4).GetVarInt());
    packet.ParseField(VarInt);
    //packet.ParseField(NbtTag);
    //packet.GetField(7).SetArray(packet.GetField(6).GetVarInt());
}

void PacketParser::ParsePlay0x07(Packet &packet) {
    packet.ParseField(VarInt);
    packet.AddField(Field());
    for (int i=0;i<packet.GetField(0).GetVarInt();i++){
        packet.ParseFieldArray(packet.GetField(1), String, 0);
        packet.ParseFieldArray(packet.GetField(1), VarInt, 0);
    }
}