mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 00:05:34 +00:00
Merge pull request #9 from OfficialLambdax/welcome/leave-notification
Welcome on full sync- and Leave on disconnect messages
This commit is contained in:
commit
efbd2a4bb8
@ -507,6 +507,10 @@ impl Server {
|
||||
}
|
||||
|
||||
info!("Disconnecting client {}...", id);
|
||||
self.broadcast(Packet::Notification(NotificationPacket::player_left( // broadcast left message
|
||||
self.clients[i].info.as_ref().unwrap().username.clone()
|
||||
)), Some(i as u8)).await;
|
||||
|
||||
if i == self.clients.len() - 1 {
|
||||
self.clients.remove(i);
|
||||
} else {
|
||||
@ -790,9 +794,8 @@ impl Server {
|
||||
} else {
|
||||
let packet_identifier = packet.data[0] as char;
|
||||
match packet_identifier {
|
||||
'H' => {
|
||||
// Full sync with server
|
||||
self.clients[client_idx]
|
||||
'H' => { // Player Full sync with server
|
||||
self.clients[client_idx] // tell the new player their playername
|
||||
.queue_packet(Packet::Raw(RawPacket::from_str(&format!(
|
||||
"Sn{}",
|
||||
self.clients[client_idx]
|
||||
@ -804,6 +807,10 @@ impl Server {
|
||||
))))
|
||||
.await;
|
||||
|
||||
self.broadcast(Packet::Notification(NotificationPacket::player_welcome( // welcome the player
|
||||
self.clients[client_idx].info.as_ref().unwrap().username.clone()
|
||||
)), Some(client_idx as u8)).await;
|
||||
|
||||
// TODO: Sync all existing cars on server (this code is broken)
|
||||
for client in &self.clients {
|
||||
let pid = client.id as usize;
|
||||
|
@ -54,6 +54,12 @@ impl NotificationPacket {
|
||||
pub fn new<S: Into<String>>(msg: S) -> Self {
|
||||
Self(format!("J{}", msg.into()))
|
||||
}
|
||||
pub fn player_welcome<S: Into<String>>(msg: S) -> Self {
|
||||
Self(format!("JWelcome {}!", msg.into()))
|
||||
}
|
||||
pub fn player_left<S: Into<String>>(msg: S) -> Self {
|
||||
Self(format!("L{} left the server!", msg.into()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Protocol:
|
||||
|
Loading…
x
Reference in New Issue
Block a user