aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicholas George <[email protected]>2021-03-20 23:47:43 -0500
committerNicholas George <[email protected]>2021-03-20 23:47:43 -0500
commit1bf43ef83f87673b66d0f6725df9c5d3b105aea5 (patch)
tree147b58e3ae90d99d0af11892b7552a0e02b6f50d /src
parentchore: create broadcast_to_all_clients() function, rename sub directory (diff)
downloadwhirl-1bf43ef83f87673b66d0f6725df9c5d3b105aea5.tar.xz
whirl-1bf43ef83f87673b66d0f6725df9c5d3b105aea5.zip
Added username support for text
Diffstat (limited to 'src')
-rw-r--r--src/cmd/text.rs13
-rw-r--r--src/server/world.rs3
2 files changed, 9 insertions, 7 deletions
diff --git a/src/cmd/text.rs b/src/cmd/text.rs
index b2cecef..6fc42be 100644
--- a/src/cmd/text.rs
+++ b/src/cmd/text.rs
@@ -1,11 +1,12 @@
-pub fn create_text_command(message: &str) -> Vec<u8> {
- let mut text = Vec::with_capacity(6 + message.len());
+pub fn create_text_command(user: &str, message: &str) -> Vec<u8> {
+ let mut text = Vec::with_capacity(6 + user.len() + message.len());
text.push(0x01); // ?
text.push(0x0E); // Command type
text.push(0x00); // Assumed to be a divider.
- text.push(0x00); // ^
- text.push(message.len() as u8); // `message` length
- for i in message.bytes() { text.push(i); } // `message`
+ text.push(user.len() as u8); // 'user' length
+ for i in user.bytes() { text.push(i); } // Pushing 'user'
+ text.push(message.len() as u8); // 'message' length
+ for i in message.bytes() { text.push(i); } // Pushing `message`
text.insert(0, text.len() as u8 + 1); // Insert data length as first byte.
text // Return created array
@@ -16,4 +17,4 @@ pub fn create_text_command(message: &str) -> Vec<u8> {
// from_utf8(
// &buffer[6..*&buffer.get(0).unwrap().to_owned() as usize]
// ).unwrap()
-// }
+// } \ No newline at end of file
diff --git a/src/server/world.rs b/src/server/world.rs
index ddefd39..a7c65b3 100644
--- a/src/server/world.rs
+++ b/src/server/world.rs
@@ -124,7 +124,8 @@ impl WorldServer {
info!("message: {}", message);
for mut socket in &sockets {
- socket.1.write_all(&create_text_command(message)).unwrap();
+ // Using User as a placeholder. Ideally, this would print out the username of the one who sent it.
+ socket.1.write_all(&create_text_command("User", message)).unwrap();
}
}
// SESSEXIT