feat: stuff happend
This commit is contained in:
parent
b8d2cd7b09
commit
fa37331780
11 changed files with 511 additions and 343 deletions
|
|
@ -1,3 +1,7 @@
|
|||
#![allow(async_fn_in_trait)]
|
||||
|
||||
pub mod auth;
|
||||
|
||||
use macros::method_id;
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Add;
|
||||
|
|
@ -10,16 +14,18 @@ use paste::paste;
|
|||
use tokio::sync::{Mutex, Notify};
|
||||
use tokio::time::{sleep_until, Instant};
|
||||
use crate::prudp::socket::{ExternalConnection, SendingConnection};
|
||||
use crate::rmc::response::ErrorCode;
|
||||
use crate::rmc::structures::connection_data::ConnectionData;
|
||||
use crate::rmc::structures::Error;
|
||||
use crate::rmc::structures::matchmake::AutoMatchmakeParam;
|
||||
|
||||
pub struct RmcConnection(pub SendingConnection, pub RmcResponseReceiver);
|
||||
|
||||
pub struct RmcResponseReceiver(Notify, Mutex<HashMap<(u16, u32), Vec<u8>>>);
|
||||
pub struct RmcResponseReceiver(Notify, Mutex<HashMap<(u32), Vec<u8>>>);
|
||||
|
||||
impl RmcResponseReceiver{
|
||||
// returns none if timed out
|
||||
pub async fn get_response_data(&self, proto: u16, method: u32) -> Option<Vec<u8>>{
|
||||
pub async fn get_response_data(&self, call_id: u32) -> Option<Vec<u8>>{
|
||||
let mut end_wait_time = Instant::now();
|
||||
end_wait_time += Duration::from_secs(5);
|
||||
|
||||
|
|
@ -29,13 +35,15 @@ impl RmcResponseReceiver{
|
|||
loop {
|
||||
let mut locked = self.1.lock().await;
|
||||
|
||||
if let Some(v) = locked.remove(&(proto, method)){
|
||||
if let Some(v) = locked.remove(&call_id){
|
||||
return Some(v);
|
||||
}
|
||||
|
||||
drop(locked);
|
||||
|
||||
|
||||
let notif_fut = self.0.notified();
|
||||
|
||||
drop(locked);
|
||||
|
||||
tokio::select! {
|
||||
_ = &mut sleep_fut => {
|
||||
|
|
@ -49,6 +57,10 @@ impl RmcResponseReceiver{
|
|||
}
|
||||
}
|
||||
|
||||
pub trait HasRmcConnection{
|
||||
fn get_response_receiver(&self) -> &RmcConnection;
|
||||
}
|
||||
|
||||
pub trait RemoteObject{
|
||||
fn new(conn: RmcConnection) -> Self;
|
||||
}
|
||||
|
|
@ -57,84 +69,36 @@ impl RemoteObject for (){
|
|||
fn new(_: RmcConnection) -> Self {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub trait RmcCallable{
|
||||
//type Remote: RemoteObject;
|
||||
//fn new_callable(remote: Self::Remote);
|
||||
async fn rmc_call(&self, protocol_id: u16, method_id: u32, rest: Vec<u8>);
|
||||
async fn rmc_call(&self, responder: &SendingConnection, protocol_id: u16, method_id: u32, call_id: u32, rest: Vec<u8>);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! define_rmc_proto {
|
||||
(proto $name:ident{
|
||||
$($protocol:path),*
|
||||
}) => {
|
||||
paste!{
|
||||
paste::paste!{
|
||||
trait [<Local $name>]: std::any::Any $( + [<Raw $protocol>] + $protocol)* {
|
||||
async fn rmc_call(&self, protocol_id: u16, method_id: u32, rest: Vec<u8>){
|
||||
async fn rmc_call(&self, remote_response_connection: &crate::prudp::socket::SendingConnection, protocol_id: u16, method_id: u32, call_id: u32, rest: Vec<u8>){
|
||||
match protocol_id{
|
||||
$(
|
||||
[<Raw $protocol Info>]::PROTOCOL_ID => <Self as [<Raw $protocol>]>::rmc_call_proto(self, method_id, rest).await,
|
||||
[<Raw $protocol Info>]::PROTOCOL_ID => <Self as [<Raw $protocol>]>::rmc_call_proto(self, remote_response_connection, method_id, call_id, rest).await,
|
||||
)*
|
||||
v => log::error!("invalid protocol called on rmc object {}", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct [<Remote $name>](crate::rmc::protocols::RmcConnection);
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
trait RawNotif{
|
||||
async fn rmc_call_proto(&self, method_id: u32, rest: Vec<u8>){
|
||||
|
||||
}
|
||||
}
|
||||
trait Notif{
|
||||
|
||||
}
|
||||
|
||||
struct RawNotifInfo;
|
||||
impl RawNotifInfo{
|
||||
const PROTOCOL_ID: u16 = 10;
|
||||
}
|
||||
|
||||
pub trait ImplementRemoteCalls{}
|
||||
|
||||
#[rmc_proto(1, NoReturn)]
|
||||
pub trait Another{
|
||||
#[method_id(1)]
|
||||
async fn test(&self, thing: AutoMatchmakeParam);
|
||||
}
|
||||
|
||||
define_rmc_proto!{
|
||||
proto TestProto{
|
||||
Notif,
|
||||
Another
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[rmc_struct(TestProto)]
|
||||
struct TestProtoImplementor{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl Notif for TestProtoImplementor{
|
||||
|
||||
}
|
||||
|
||||
impl RawNotif for TestProtoImplementor{
|
||||
|
||||
}
|
||||
|
||||
impl Another for TestProtoImplementor{
|
||||
async fn test(&self, thing: AutoMatchmakeParam) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl ImplementRemoteCalls for TestProtoImplementor{}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue