mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-25 13:30:43 +00:00
welcome & leave
This commit is contained in:
1 parent
cde157fdfe
commit
de398c0208
2 files changed
+19
-3
No files matched your search
+17
-3
@@ -512,11 +512,19 @@ impl Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info!("Disconnecting client {}...", id);
|
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 {
|
if i == self.clients.len() - 1 {
|
||||||
self.clients.remove(i);
|
self.clients.remove(i);
|
||||||
} else {
|
} else {
|
||||||
self.clients.swap_remove(i);
|
self.clients.swap_remove(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Client {} disconnected!", id);
|
info!("Client {} disconnected!", id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -795,9 +803,8 @@ impl Server {
|
|||||||
} else {
|
} else {
|
||||||
let packet_identifier = packet.data[0] as char;
|
let packet_identifier = packet.data[0] as char;
|
||||||
match packet_identifier {
|
match packet_identifier {
|
||||||
'H' => {
|
'H' => { // Player Full sync with server
|
||||||
// Full sync with server
|
self.clients[client_idx] // tell the new player their playername
|
||||||
self.clients[client_idx]
|
|
||||||
.queue_packet(Packet::Raw(RawPacket::from_str(&format!(
|
.queue_packet(Packet::Raw(RawPacket::from_str(&format!(
|
||||||
"Sn{}",
|
"Sn{}",
|
||||||
self.clients[client_idx]
|
self.clients[client_idx]
|
||||||
@@ -809,6 +816,13 @@ impl Server {
|
|||||||
))))
|
))))
|
||||||
.await;
|
.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)
|
// TODO: Sync all existing cars on server (this code is broken)
|
||||||
for client in &self.clients {
|
for client in &self.clients {
|
||||||
let pid = client.id as usize;
|
let pid = client.id as usize;
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ impl NotificationPacket {
|
|||||||
pub fn new<S: Into<String>>(msg: S) -> Self {
|
pub fn new<S: Into<String>>(msg: S) -> Self {
|
||||||
Self(format!("J{}", msg.into()))
|
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:
|
/// Protocol:
|
||||||
|
|||||||
Reference in new issue
Block a user