Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "protocol-generator/minecraft-data"]
path = protocol-generator/minecraft-data
url = https://github.com/PrismarineJS/minecraft-data
24 changes: 0 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,3 @@ rust:
matrix:
allow_failures:
- rust: nightly
addons:
apt:
packages:
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- cmake
- gcc
- binutils-dev
- libiberty-dev
after_success: |
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
tar xzf master.tar.gz &&
cd kcov-master &&
mkdir build &&
cd build &&
cmake .. &&
make &&
make install DESTDIR=../../kcov-build &&
cd ../.. &&
rm -rf kcov-master &&
for file in target/debug/minecraft_protocol*; do [ -x "${file}" ] || continue; mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done &&
bash <(curl -s https://codecov.io/bash) &&
echo "Uploaded code coverage"
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
members = [
"protocol",
"protocol-derive",
]
"protocol-generator"
]
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ minecraft-protocol
============
[![crates.io](https://img.shields.io/crates/v/minecraft-protocol.svg)](https://crates.io/crates/minecraft-protocol)
[![Build Status](https://travis-ci.com/eihwaz/minecraft-protocol.svg?branch=master)](https://travis-ci.com/eihwaz/minecraft-protocol)
[![codecov](https://codecov.io/gh/eihwaz/minecraft-protocol/branch/master/graph/badge.svg)](https://codecov.io/gh/eihwaz/minecraft-protocol)

Library for decoding and encoding Minecraft packets
4 changes: 4 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

cargo run
cargo fmt
2 changes: 1 addition & 1 deletion protocol-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description = "Derive macro for reading and writing Minecraft packets"
license = "MIT"
homepage = "https://github.com/eihwaz/minecraft-protocol"
repository = "https://github.com/eihwaz/minecraft-protocol"
keywords = ["minecraft", "protocol", "packet", "io"]
keywords = ["minecraft", "derive", "protocol", "packet", "io"]

[lib]
proc-macro = true
Expand Down
2 changes: 1 addition & 1 deletion protocol-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use proc_macro2::Ident;
use proc_macro2::TokenStream as TokenStream2;
use quote::{quote, TokenStreamExt};
use std::iter::FromIterator;
use syn::export::Span;
use syn::__private::Span;
use syn::{parse_macro_input, Data, DeriveInput, Field, Fields, Lit, Meta, NestedMeta};

#[proc_macro_derive(Packet, attributes(packet))]
Expand Down
17 changes: 17 additions & 0 deletions protocol-generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "minecraft-protocol-generator"
version = "0.0.0"
authors = ["vagola <vladislavs.golubs@yandex.ru>"]
edition = "2018"
description = "CLI for generating Rust code with Minecraft packets"
license = "MIT"
homepage = "https://github.com/eihwaz/minecraft-protocol"
repository = "https://github.com/eihwaz/minecraft-protocol"
keywords = ["minecraft", "cli", "protocol", "packet", "io"]

[dependencies]
serde = "1.0.120"
serde_json = "1.0"
handlebars = "3.5.2"
heck = "0.3.2"
linked-hash-map = { version = "0.5.4", features = ["serde_impl"] }
1 change: 1 addition & 0 deletions protocol-generator/minecraft-data
Submodule minecraft-data added at cc155f
101 changes: 101 additions & 0 deletions protocol-generator/src/backend.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use linked_hash_map::LinkedHashMap;
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct ProtocolHandler {
pub handshaking: Protocol,
pub status: Protocol,
pub login: Protocol,
#[serde(rename = "play")]
pub game: Protocol,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Protocol {
pub to_client: Packets,
pub to_server: Packets,
}

#[derive(Debug, Deserialize)]
pub struct Packets {
pub types: LinkedHashMap<String, Vec<Data>>,
}

#[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum Data {
Type(String),
Containers(Vec<Container>),
Container(Box<Container>),
Mapper {
#[serde(rename = "type")]
mappings_type: String,
mappings: LinkedHashMap<String, String>,
},
Switch(Switch),
List(Box<List>),
Bitfield(Vec<BitField>),
}

#[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum Container {
Value {
name: String,
#[serde(rename = "type")]
data: Data,
},
List {
name: Option<String>,
#[serde(rename = "type")]
data_vec: Vec<Data>,
},
}

#[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum Switch {
Value {
#[serde(rename = "compareTo")]
compare_to: String,
fields: LinkedHashMap<String, Data>,
},
List {
#[serde(rename = "compareTo")]
compare_to: String,
fields: LinkedHashMap<String, Vec<Data>>,
},
Empty {
#[serde(rename = "compareTo")]
compare_to: String,
},
}

#[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum List {
Value {
#[serde(rename = "countType")]
count_type: String,
#[serde(rename = "type")]
list_type: Data,
},
List {
#[serde(rename = "countType")]
count_type: String,
#[serde(rename = "type")]
list_type: Vec<Data>,
},
Empty {
#[serde(rename = "countType")]
count_type: String,
},
}

#[derive(Debug, Deserialize, PartialEq, Eq)]
pub struct BitField {
name: String,
size: usize,
signed: bool,
}
Loading