Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Update steven for emscripten #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
483 changes: 183 additions & 300 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ opt-level = 1
[dependencies]
sdl2 = "0.30.0"
byteorder = "0.5.0"
hyper = "0.8.0"
hyper = "0.10.10"
serde = "0.7.0"
serde_json = "0.7.0"
flate2 = "0.2.13"
Expand All @@ -25,7 +25,7 @@ log = "0.3.5"
cgmath = "0.7.0"
lazy_static = "0.1.15"
collision = {git = "https://github.com/TheUnnamedDude/collision-rs", rev = "f80825e"}
openssl = "0.7.8"
# #openssl = "0.7.8"
# clippy = "*"

[dependencies.steven_gl]
Expand Down
3 changes: 3 additions & 0 deletions pre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Module.preRun.push(function() {
ENV.RUST_BACKTRACE = "1";
})
14 changes: 14 additions & 0 deletions src/gl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,19 @@ impl Shader {
ret
}

#[cfg(target_os = "emscripten")]
pub fn get_info_log(&self) -> String {
let len = self.get_parameter(INFO_LOG_LENGTH);

let mut data = Vec::<u8>::with_capacity(len as usize);
unsafe {
data.set_len(len as usize);
gl::GetShaderInfoLog(self.0, len, ptr::null_mut(), data.as_mut_ptr() as *mut u8);
}
String::from_utf8(data).unwrap()
}

#[cfg(not(target_os = "emscripten"))]
pub fn get_info_log(&self) -> String {
let len = self.get_parameter(INFO_LOG_LENGTH);

Expand All @@ -557,6 +570,7 @@ impl Shader {
}
String::from_utf8(data).unwrap()
}

}

#[derive(Clone, Copy)]
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern crate image;
extern crate time;
extern crate byteorder;
extern crate serde_json;
extern crate openssl;
//extern crate openssl;
extern crate hyper;
extern crate flate2;
extern crate rand;
Expand Down
16 changes: 13 additions & 3 deletions src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#![allow(dead_code)]

use openssl::crypto::symm;
//use openssl::crypto::symm;
use serde_json;
use hyper;

Expand Down Expand Up @@ -742,7 +742,9 @@ pub struct Conn {
direction: Direction,
pub state: State,

/* TODO
cipher: Option<symm::Crypter>,
*/

compression_threshold: i32,
compression_read: Option<ZlibDecoder<io::Cursor<Vec<u8>>>>,
Expand All @@ -769,7 +771,7 @@ impl Conn {
port: parts[1].parse().unwrap(),
direction: Direction::Serverbound,
state: State::Handshaking,
cipher: Option::None,
//TODO cipher: Option::None,
compression_threshold: -1,
compression_read: Option::None,
compression_write: Option::None,
Expand Down Expand Up @@ -857,9 +859,11 @@ impl Conn {
}

pub fn enable_encyption(&mut self, key: &[u8], decrypt: bool) {
/* TODO
let cipher = symm::Crypter::new(symm::Type::AES_128_CFB8);
cipher.init(if decrypt { symm::Mode::Decrypt } else { symm::Mode::Encrypt }, key, key);
self.cipher = Option::Some(cipher);
*/
}

pub fn set_compresssion(&mut self, threshold: i32) {
Expand Down Expand Up @@ -963,6 +967,7 @@ pub struct StatusPlayer {

impl Read for Conn {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
/* TODO
match self.cipher.as_mut() {
Option::None => self.stream.read(buf),
Option::Some(cipher) => {
Expand All @@ -974,11 +979,14 @@ impl Read for Conn {
Ok(ret)
}
}
*/
Ok(0)
}
}

impl Write for Conn {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
/*
match self.cipher.as_mut() {
Option::None => self.stream.write(buf),
Option::Some(cipher) => {
Expand All @@ -987,6 +995,8 @@ impl Write for Conn {
Ok(buf.len())
}
}
*/
Ok(0)
}

fn flush(&mut self) -> io::Result<()> {
Expand All @@ -1002,7 +1012,7 @@ impl Clone for Conn {
port: self.port,
direction: self.direction,
state: self.state,
cipher: Option::None,
//TODO cipher: Option::None,
compression_threshold: self.compression_threshold,
compression_read: Option::None,
compression_write: Option::None,
Expand Down
6 changes: 5 additions & 1 deletion src/protocol/mojang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use openssl::crypto::hash;
//use openssl::crypto::hash;
use serde_json;
use serde_json::builder::ObjectBuilder;
use hyper;
Expand Down Expand Up @@ -102,6 +102,7 @@ impl Profile {

pub fn join_server(&self, server_id: &str, shared_key: &[u8], public_key: &[u8]) -> Result<(), super::Error> {
use std::io::Write;
/* TODO
let mut sha1 = hash::Hasher::new(hash::Type::SHA1);
sha1.write_all(server_id.as_bytes()).unwrap();
sha1.write_all(shared_key).unwrap();
Expand Down Expand Up @@ -136,10 +137,13 @@ impl Profile {
.send());

if res.status == hyper::status::StatusCode::NoContent {
*/
Ok(())
/*
} else {
Err(super::Error::Err("Failed to auth with server".to_owned()))
}
*/
}

pub fn is_complete(&self) -> bool {
Expand Down
10 changes: 6 additions & 4 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ macro_rules! handle_packet {
impl Server {

pub fn connect(resources: Arc<RwLock<resources::Manager>>, profile: mojang::Profile, address: &str) -> Result<Server, protocol::Error> {
use openssl::crypto::pkey;
use openssl::crypto::rand::rand_bytes;
//use openssl::crypto::pkey;
//use openssl::crypto::rand::rand_bytes;
let mut conn = try!(protocol::Conn::new(address));

let host = conn.host.clone();
Expand Down Expand Up @@ -145,6 +145,7 @@ impl Server {
};
}

/* TODO
let mut key = pkey::PKey::new();
key.load_pub(&packet.public_key.data);
let shared = rand_bytes(16);
Expand All @@ -158,12 +159,13 @@ impl Server {
shared_secret: protocol::LenPrefixedBytes::new(shared_e),
verify_token: protocol::LenPrefixedBytes::new(token_e),
}));
*/

let mut read = conn.clone();
let mut write = conn.clone();

read.enable_encyption(&shared, true);
write.enable_encyption(&shared, false);
//read.enable_encyption(&shared, true);
//write.enable_encyption(&shared, false);

let username;
let uuid;
Expand Down
Loading