Skip to content

Commit 5acf3d5

Browse files
committed
More changes to incoming packets
1 parent 1a9a4c4 commit 5acf3d5

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

Diff for: dist/hypercube.exe

-4.5 KB
Binary file not shown.

Diff for: hypercube

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ hc_help() {
1111
hc_build() {
1212
rm -rf dist/
1313
#TODO: Use other compilers
14-
dmd src/*.d -of./dist/hypercube.exe -v
14+
dmd src/*.d -of./dist/hypercube.exe #-v
1515
}
1616

1717
hc_run() {
18-
if [ ! -f "/dist/hypercube.exe" ]; then
18+
if [ -f "/dist/hypercube.exe" ]; then
1919
hc_build
2020
fi
21-
if [ -f "/dist/hypercube.exe" ]; then
21+
if [ ! -f "/dist/hypercube.exe" ]; then
2222
dist/hypercube -debug -h=localhost -p=25565
2323
fi
2424
}
2525

26+
hc_reboot() {
27+
hc_build
28+
hc_run
29+
}
30+
2631
if [ -z $1 ]; then
2732
hc_help
2833
exit

Diff for: src/hypercube.d

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ void setupSockets() {
5151
ubyte[1024] buffer;
5252
int ptr = 0;
5353
s.receive(buffer);
54-
int size = readVarInt(buffer, &ptr); /// size of packet
54+
new IncomingPacket(buffer);
55+
/*int size = readVarInt(buffer, &ptr); /// size of packet
5556
int id = readVarInt(buffer, &ptr); /// packet id
5657
int protocolVersion = readVarInt(buffer, &ptr); /// protocol version
5758
string address = readString(buffer, &ptr); /// the client is stupid and sends the address to the address
@@ -65,7 +66,7 @@ void setupSockets() {
6566
"\nPort: " ~ to!string(port) ~
6667
"\nState: " ~ to!string(state)
6768
);
68-
}
69+
}*/
6970
/*ptr = 0;
7071
while(ptr <= buffer.length) {
7172
write(to!string(readVarInt(buffer, &ptr)) ~ " ");

Diff for: src/protocol.d

+10-8
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class PacketField {
3131
}
3232

3333
class Packet {
34-
enum To : string{
34+
enum To : string {
3535
Server = "Server",
3636
Client = "Client",
3737
}
38-
enum State : string{
38+
enum State : string {
3939
HandShake = "HandShake",
4040
Status = "Status",
4141
Login = "Login",
@@ -76,11 +76,12 @@ class Packet {
7676
}
7777
}
7878

79-
Packet[] allPackets;
79+
Packet[] allPackets = void;
8080

8181
Packet getPacketById(ubyte id) {
8282
foreach(p; allPackets) {
83-
if(p.getId()) {
83+
log(to!string(p.getId()));
84+
if(p.getId() == id) {
8485
return p;
8586
}
8687
}
@@ -98,9 +99,10 @@ void parseProtocol(char[] s) {
9899
packets ~= parsePackets(p["states"]["login"]["toServer"], Packet.State.Login, Packet.To.Server);
99100
packets ~= parsePackets(p["states"]["play"]["toClient"], Packet.State.Play, Packet.To.Client);
100101
packets ~= parsePackets(p["states"]["play"]["toServer"], Packet.State.Play, Packet.To.Server);
101-
102+
103+
log("Packets Found: " ~ to!string(packets.length));
102104
allPackets = packets;
103-
105+
104106
foreach(packet; packets) {
105107
log(packet.toString());
106108
}
@@ -137,10 +139,10 @@ class IncomingPacket {
137139

138140
this(ubyte[] buffer) {
139141
this.data = buffer;
142+
this.ptr = 0;
140143
int size = readVarInt(data, &ptr); /// size of packet
141144
int id = readVarInt(data, &ptr); /// packet id
142145
Packet p = getPacketById(cast(ubyte)id);
143-
switch(id) {
144-
}
146+
log("Incoming Packet: " ~ to!string(id) ~ ":" ~ p.toString());
145147
}
146148
}

0 commit comments

Comments
 (0)