mirror of
https://github.com/MeexReay/sRAC.git
synced 2025-06-24 02:22:57 +03:00
add server-info packet
This commit is contained in:
parent
3c6f9fb006
commit
edd9085304
@ -35,7 +35,7 @@ pub fn on_total_size(ctx: Arc<Context>, _: SocketAddr) -> Result<u64, Box<dyn Er
|
|||||||
pub fn on_total_data(
|
pub fn on_total_data(
|
||||||
ctx: Arc<Context>,
|
ctx: Arc<Context>,
|
||||||
_: SocketAddr,
|
_: SocketAddr,
|
||||||
_: Option<u64>, // sent_size
|
_sent_size: Option<u64>,
|
||||||
) -> Result<Vec<u8>, Box<dyn Error>> {
|
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
if let Some(url) = ctx.args.proxy_to.as_ref() {
|
if let Some(url) = ctx.args.proxy_to.as_ref() {
|
||||||
return read_messages(
|
return read_messages(
|
||||||
@ -69,7 +69,7 @@ pub fn on_total_data(
|
|||||||
pub fn on_chunked_data(
|
pub fn on_chunked_data(
|
||||||
ctx: Arc<Context>,
|
ctx: Arc<Context>,
|
||||||
_: SocketAddr,
|
_: SocketAddr,
|
||||||
_: Option<u64>, // sent_size
|
_sent_size: Option<u64>,
|
||||||
client_has: u64,
|
client_has: u64,
|
||||||
) -> Result<Vec<u8>, Box<dyn Error>> {
|
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
if let Some(url) = ctx.args.proxy_to.as_ref() {
|
if let Some(url) = ctx.args.proxy_to.as_ref() {
|
||||||
@ -203,3 +203,7 @@ pub fn on_register_user(
|
|||||||
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn on_server_info(_: Arc<Context>, _: SocketAddr) -> Result<(u8, String), Box<dyn Error>> {
|
||||||
|
Ok((0x03, format!("sRAC {}", env!("CARGO_PKG_VERSION"))))
|
||||||
|
}
|
||||||
|
@ -44,7 +44,7 @@ pub fn accept_rac_stream(
|
|||||||
|
|
||||||
on_send_message(ctx.clone(), addr, buf)?;
|
on_send_message(ctx.clone(), addr, buf)?;
|
||||||
} else if buf[0] == 0x02 {
|
} else if buf[0] == 0x02 {
|
||||||
let mut buf = vec![0; ctx.args.message_limit + 2 + 512]; // FIXME: softcode this (512 = name + password)
|
let mut buf = vec![0; ctx.args.message_limit + 2 + 512]; // TODO: softcode this (512 = name + password)
|
||||||
let size = stream.read(&mut buf)?;
|
let size = stream.read(&mut buf)?;
|
||||||
buf.truncate(size);
|
buf.truncate(size);
|
||||||
|
|
||||||
@ -84,6 +84,14 @@ pub fn accept_rac_stream(
|
|||||||
if let Some(resp_id) = on_register_user(ctx.clone(), addr, name, password)? {
|
if let Some(resp_id) = on_register_user(ctx.clone(), addr, name, password)? {
|
||||||
stream.write_all(&[resp_id])?;
|
stream.write_all(&[resp_id])?;
|
||||||
}
|
}
|
||||||
|
} else if buf[0] == 0x69 {
|
||||||
|
let (protocol_version, name) = on_server_info(ctx.clone(), addr)?;
|
||||||
|
|
||||||
|
let mut data = Vec::new();
|
||||||
|
data.push(protocol_version);
|
||||||
|
data.append(&mut name.as_bytes().to_vec());
|
||||||
|
|
||||||
|
stream.write_all(&data)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -105,6 +105,15 @@ pub fn accept_wrac_stream(
|
|||||||
websocket.write(Message::Binary(Bytes::from(vec![resp_id])))?;
|
websocket.write(Message::Binary(Bytes::from(vec![resp_id])))?;
|
||||||
websocket.flush()?;
|
websocket.flush()?;
|
||||||
}
|
}
|
||||||
|
} else if id == 0x69 {
|
||||||
|
let (protocol_version, name) = on_server_info(ctx.clone(), addr)?;
|
||||||
|
|
||||||
|
let mut data = Vec::new();
|
||||||
|
data.push(protocol_version);
|
||||||
|
data.append(&mut name.as_bytes().to_vec());
|
||||||
|
|
||||||
|
websocket.write(Message::Binary(Bytes::from(data)))?;
|
||||||
|
websocket.flush()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user