serverstate::handle now returns a result (patch/login converted)
This commit is contained in:
		
							parent
							
								
									929f0e7f85
								
							
						
					
					
						commit
						d86f5caca1
					
				@ -36,8 +36,16 @@ fn recv_from_clientpool<STATE, S, R, E>(state: &mut STATE,
 | 
			
		||||
                    },
 | 
			
		||||
                    ClientPoolAction::Packet(client_id, pkt) => {
 | 
			
		||||
                        let to_send = state.handle(client_id, &pkt);
 | 
			
		||||
                        for s in to_send {
 | 
			
		||||
                            pool_send.send(ClientAction::Packet(s.0, s.1)).unwrap();
 | 
			
		||||
                        match to_send {
 | 
			
		||||
                            Ok(pkts) =>  {
 | 
			
		||||
                                for p in pkts {
 | 
			
		||||
                                    pool_send.send(ClientAction::Packet(p.0, p.1)).unwrap();
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            Err(err) => {
 | 
			
		||||
                                // TODO: break?
 | 
			
		||||
                                println!("[handler error]: {:?} {:?}", client_id, err);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@ -23,6 +23,7 @@ pub trait ServerState {
 | 
			
		||||
    type PacketError;
 | 
			
		||||
    
 | 
			
		||||
    fn on_connect(&mut self, id: ClientId) -> Vec<OnConnect<Self::SendPacket>>;
 | 
			
		||||
    fn handle(&mut self, id: ClientId, pkt: &Self::RecvPacket) -> Box<dyn Iterator<Item = (ClientId, Self::SendPacket)>>;
 | 
			
		||||
    fn handle(&mut self, id: ClientId, pkt: &Self::RecvPacket)
 | 
			
		||||
              -> Result<Box<dyn Iterator<Item = (ClientId, Self::SendPacket)>>, Self::PacketError>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -133,8 +133,9 @@ impl<DA: DataAccess> ServerState for LoginServerState<DA> {
 | 
			
		||||
        ]
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn handle(&mut self, id: ClientId, pkt: &Self::RecvPacket) -> Box<dyn Iterator<Item = (ClientId, Self::SendPacket)>> {
 | 
			
		||||
        match pkt {
 | 
			
		||||
    fn handle(&mut self, id: ClientId, pkt: &Self::RecvPacket)
 | 
			
		||||
              -> Result<Box<dyn Iterator<Item = (ClientId, Self::SendPacket)>>, LoginError> {
 | 
			
		||||
        Ok(match pkt {
 | 
			
		||||
            RecvLoginPacket::Login(login) => {
 | 
			
		||||
                Box::new(self.validate_login(login)
 | 
			
		||||
                         .into_iter()
 | 
			
		||||
@ -142,7 +143,7 @@ impl<DA: DataAccess> ServerState for LoginServerState<DA> {
 | 
			
		||||
                             (id, pkt)
 | 
			
		||||
                         }))
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -180,8 +180,9 @@ impl ServerState for PatchServerState {
 | 
			
		||||
        ]
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn handle(&mut self, id: ClientId, pkt: &RecvPatchPacket) -> Box<dyn Iterator<Item = (ClientId, SendPatchPacket)>> {
 | 
			
		||||
        match pkt {
 | 
			
		||||
    fn handle(&mut self, id: ClientId, pkt: &RecvPatchPacket)
 | 
			
		||||
              -> Result<Box<dyn Iterator<Item = (ClientId, SendPatchPacket)>>, PatchError> {
 | 
			
		||||
        Ok(match pkt {
 | 
			
		||||
            RecvPatchPacket::PatchWelcomeReply(_pkt) => {
 | 
			
		||||
                Box::new(vec![SendPatchPacket::RequestLogin(RequestLogin {})].into_iter().map(move |pkt| (id, pkt)))
 | 
			
		||||
            },
 | 
			
		||||
@ -208,7 +209,7 @@ impl ServerState for PatchServerState {
 | 
			
		||||
                ];
 | 
			
		||||
                Box::new(p.into_iter().chain(SendFileIterator::new(&self)).map(move |pkt| (id, pkt)))
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user