Limited username length to 20 characters
This commit is contained in:
parent
92be982856
commit
cea07a8e19
@ -4,10 +4,13 @@ use std;
|
|||||||
use std::io::*;
|
use std::io::*;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use self::colored::*;
|
|
||||||
use self::chrono::Local;
|
|
||||||
use std::collections::hash_map::DefaultHasher;
|
use std::collections::hash_map::DefaultHasher;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
use self::colored::*;
|
||||||
|
use self::chrono::Local;
|
||||||
|
|
||||||
|
// TODO: Limit usernames to ascii
|
||||||
|
// TODO: implement requests 1.x from protocol
|
||||||
|
|
||||||
fn hash_name(name: &str) -> usize {
|
fn hash_name(name: &str) -> usize {
|
||||||
let mut s = DefaultHasher::new();
|
let mut s = DefaultHasher::new();
|
||||||
@ -26,6 +29,10 @@ fn get_name(writer: &mut BufWriter<&TcpStream>) {
|
|||||||
loop {
|
loop {
|
||||||
let mut line = &*get_entry();
|
let mut line = &*get_entry();
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
|
if line.len() > 20 {
|
||||||
|
println!("Nickname too long, it must be at most 20 characters long");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
match line {
|
match line {
|
||||||
"" => {
|
"" => {
|
||||||
continue;
|
continue;
|
||||||
@ -38,7 +45,6 @@ fn get_name(writer: &mut BufWriter<&TcpStream>) {
|
|||||||
}
|
}
|
||||||
line => {
|
line => {
|
||||||
let line_str: String = String::from(line);
|
let line_str: String = String::from(line);
|
||||||
// let spliced: Vec<&str> = line_str.split(" ").collect();
|
|
||||||
let spliced: Vec<&str> = line_str.split_whitespace().collect();
|
let spliced: Vec<&str> = line_str.split_whitespace().collect();
|
||||||
if spliced.len() > 1 {
|
if spliced.len() > 1 {
|
||||||
println!("Cannot use whitespace in username.");
|
println!("Cannot use whitespace in username.");
|
||||||
@ -175,8 +181,7 @@ fn exchange_with_server(stream: TcpStream) {
|
|||||||
}
|
}
|
||||||
"JOIN" => {
|
"JOIN" => {
|
||||||
let date = Local::now();
|
let date = Local::now();
|
||||||
let name_hash: usize =
|
let name_hash: usize = hash_name(spliced_input[1].clone()) % COLORS.len();
|
||||||
hash_name(spliced_input[1].clone()) % COLORS.len();
|
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{}{}{}{}",
|
"{}{}{}{}",
|
||||||
@ -188,8 +193,7 @@ fn exchange_with_server(stream: TcpStream) {
|
|||||||
}
|
}
|
||||||
"LOGOUT" => {
|
"LOGOUT" => {
|
||||||
let date = Local::now();
|
let date = Local::now();
|
||||||
let name_hash: usize =
|
let name_hash: usize = hash_name(spliced_input[1].clone()) % COLORS.len();
|
||||||
hash_name(spliced_input[1].clone()) % COLORS.len();
|
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{}{}{}{}",
|
"{}{}{}{}",
|
||||||
|
@ -4,6 +4,8 @@ use std::thread;
|
|||||||
use std::sync::{Arc, Mutex, MutexGuard};
|
use std::sync::{Arc, Mutex, MutexGuard};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
// TODO: implement requests 1.x from protocol
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Evolution implementation protocole //
|
// Evolution implementation protocole //
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user