use std::{error::Error, rc::Rc};

use common::net::tools::Packet;
use proto::PingRsp;

use crate::player::Player;

use super::get_proto;

pub fn on_ping_req(player: &Rc<Player>, packet: Packet) -> Result<(), Box<dyn Error>> {
    let req = get_proto!(packet, PingReq);

    let mut rsp = PingRsp {
        retcode: -1,
        ..Default::default()
    };

    player.on_ping_req(req, &mut rsp);
    player.send_proto(rsp);

    Ok(())
}
