mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 10:41:01 +00:00
welcome & leave
This commit is contained in:
@@ -512,11 +512,19 @@ impl Server {
|
||||
}
|
||||
|
||||
info!("Disconnecting client {}...", id);
|
||||
for client in &self.clients {
|
||||
if client.id == i as u8 {continue}
|
||||
client.queue_packet(Packet::Notification(NotificationPacket::left(
|
||||
self.clients[i].info.as_ref().unwrap().username.clone()
|
||||
))).await;
|
||||
}
|
||||
|
||||
if i == self.clients.len() - 1 {
|
||||
self.clients.remove(i);
|
||||
} else {
|
||||
self.clients.swap_remove(i);
|
||||
}
|
||||
|
||||
info!("Client {} disconnected!", id);
|
||||
}
|
||||
}
|
||||
@@ -795,9 +803,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]
|
||||
@@ -809,6 +816,13 @@ impl Server {
|
||||
))))
|
||||
.await;
|
||||
|
||||
for client in &self.clients { // welcome the player
|
||||
if client.id == client_idx as u8 {continue}
|
||||
client.queue_packet(Packet::Notification(NotificationPacket::welcome(
|
||||
self.clients[client_idx].info.as_ref().unwrap().username.clone()
|
||||
))).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,8 @@ impl NotificationPacket {
|
||||
pub fn new<S: Into<String>>(msg: S) -> Self {
|
||||
Self(format!("J{}", msg.into()))
|
||||
}
|
||||
pub fn welcome<S: Into<String>>(msg: S) -> Self { Self(format!("JWelcome {}!", msg.into()))}
|
||||
pub fn left<S: Into<String>>(msg: S) -> Self { Self(format!("L{} left the server!", msg.into()))}
|
||||
}
|
||||
|
||||
/// Protocol:
|
||||
|
||||
Reference in New Issue
Block a user