diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-08 12:28:48 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-08 12:28:48 +0100 |
| commit | 8681fcf565643f67a36cb1fe571fac7843d2b6af (patch) | |
| tree | 1f022edb267281da0a2fd0fde3b5336293f14cea /src/bin/server/handler.rs | |
| parent | web: match the desktop layout and remove play-money copy (diff) | |
| download | zagan-bet-8681fcf565643f67a36cb1fe571fac7843d2b6af.tar.gz zagan-bet-8681fcf565643f67a36cb1fe571fac7843d2b6af.zip | |
web: disallow crawlers and quiet the game port
Adds robots.txt with Disallow: / plus noindex/X-Robots-Tag on the site and app. The v5 server treats an HTTP request as a malformed frame, closes silently before HELLO, and suppresses the common TLS scanner noise. Deploy now verifies robots.txt.
Diffstat (limited to 'src/bin/server/handler.rs')
| -rw-r--r-- | src/bin/server/handler.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/bin/server/handler.rs b/src/bin/server/handler.rs index e6b623f..55df244 100644 --- a/src/bin/server/handler.rs +++ b/src/bin/server/handler.rs | |||
| @@ -32,13 +32,19 @@ pub fn handle_client_tls(mut stream: TlsStream) { | |||
| 32 | 32 | ||
| 33 | let mut state = ConnectionState::default(); | 33 | let mut state = ConnectionState::default(); |
| 34 | let mut event_seq = 0u64; | 34 | let mut event_seq = 0u64; |
| 35 | println!("[TLS Client connected] {client_addr}"); | 35 | // Port scanners reach the TLS listener too. Do not write a connection log |
| 36 | // until they send a valid frame; v5 drops their HTTP request silently. | ||
| 37 | let mut announced = false; | ||
| 36 | 38 | ||
| 37 | 'connection: loop { | 39 | 'connection: loop { |
| 38 | let mut frame = String::new(); | 40 | let mut frame = String::new(); |
| 39 | match stream.read_frame(&mut frame) { | 41 | match stream.read_frame(&mut frame) { |
| 40 | Ok(0) => break, | 42 | Ok(0) => break, |
| 41 | Ok(_) => { | 43 | Ok(_) => { |
| 44 | if !announced { | ||
| 45 | println!("[TLS Client connected] {client_addr}"); | ||
| 46 | announced = true; | ||
| 47 | } | ||
| 42 | let user = state.user().unwrap_or("guest").to_string(); | 48 | let user = state.user().unwrap_or("guest").to_string(); |
| 43 | println!("[{user} @ {client_addr}] Received: {frame}"); | 49 | println!("[{user} @ {client_addr}] Received: {frame}"); |
| 44 | match parse_request(&frame) { | 50 | match parse_request(&frame) { |
| @@ -70,6 +76,15 @@ pub fn handle_client_tls(mut stream: TlsStream) { | |||
| 70 | { | 76 | { |
| 71 | // No request yet: fall through and let timed games advance. | 77 | // No request yet: fall through and let timed games advance. |
| 72 | } | 78 | } |
| 79 | Err(error) if error.kind() == std::io::ErrorKind::InvalidData => { | ||
| 80 | // A crawler or port scanner speaking HTTP hits a frame length | ||
| 81 | // far over the cap. Close without a reply or a log line; a | ||
| 82 | // real game client that has already greeted is worth logging. | ||
| 83 | if state.greeted() { | ||
| 84 | eprintln!("Protocol error from {client_addr}: {error}"); | ||
| 85 | } | ||
| 86 | break; | ||
| 87 | } | ||
| 73 | Err(error) => { | 88 | Err(error) => { |
| 74 | eprintln!("Read error: {error}"); | 89 | eprintln!("Read error: {error}"); |
| 75 | break; | 90 | break; |
| @@ -92,5 +107,7 @@ pub fn handle_client_tls(mut stream: TlsStream) { | |||
| 92 | } | 107 | } |
| 93 | 108 | ||
| 94 | core.disconnect(&state); | 109 | core.disconnect(&state); |
| 95 | println!("[TLS Client disconnected] {client_addr}"); | 110 | if announced || state.greeted() { |
| 111 | println!("[TLS Client disconnected] {client_addr}"); | ||
| 112 | } | ||
| 96 | } | 113 | } |
