This commit is contained in:
firebadnofire 2024-04-16 14:16:47 -04:00
parent 58b59d4e5a
commit b28da90a5c
Signed by: firebadnofire
SSH Key Fingerprint: SHA256:bnN1TGRauJN84CxL1IZ/2uHNvJualwYkFjOKaaOilJE
5 changed files with 125 additions and 6 deletions

14
.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

10
Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "rms-client"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
#tokio = { version = "1", features = ["full"] }
chrono = "0.4"

27
LICENSE
View File

@ -1,9 +1,26 @@
MIT License
Libre Open Source Software (LOSS) License
Copyright (c) 2024 firebadnofire
| ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|| |_
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Permissions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
You are granted the freedom to use, modify, and distribute the software.
Any distribution of modified versions must be made available under this same license.
The source code of the software must always be accessible to users along with any modifications.
Limitations:
The licensed software, or any modified version, cannot be used for training or creating machine learning algorithms.
Any patent claims related to the software shall not be enforced against anyone using, modifying, or distributing the software in compliance with this license.
Disclaimer:
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Termination:
If you violate the terms of this license, your rights granted under it will be automatically terminated.

View File

@ -1,3 +1,5 @@
# RMS-client
Rust Messenger Service - Client
Rust Messenger Service - Client
Check out: <a href="https://gitea.archuser.org/firebadnofire/RMS-server">RMS-server</a>

76
src/main.rs Normal file
View File

@ -0,0 +1,76 @@
use std::env;
use std::net::TcpStream;
use std::io::{self, Write, BufRead, BufReader};
use chrono::Local;
use std::process;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: ./rms-client (-p PORT) IP");
process::exit(1);
}
let mut ip = "127.0.0.1"; // Default IP
let mut port = "7890"; // Default port
let mut i = 1;
while i < args.len() {
match args[i].as_str() {
"-p" | "--port" if i + 1 < args.len() => {
port = &args[i + 1];
i += 2; // skip the port argument
},
_ => {
ip = &args[i];
i += 1;
}
}
}
let mut stream = TcpStream::connect(format!("{}:{}", ip, port)).unwrap_or_else(|_| {
eprintln!("Failed to connect to {}:{}", ip, port);
process::exit(1);
});
println!("Connected to {}:{}", ip, port);
let stdin = io::stdin();
let handle = stdin.lock();
// Checking if there's piped input by peeking the buffer
let mut buffer = Vec::new();
let mut reader = BufReader::new(handle);
let bytes_available = reader.read_until(b'\n', &mut buffer).expect("Failed to read from input");
if bytes_available == 0 {
// No piped input, proceed to interactive mode
loop {
let mut input = String::new();
println!("Enter your message (or 'exit' to quit):");
io::stdin().read_line(&mut input).unwrap();
if input.trim().eq("exit") {
break;
}
send_message(&mut stream, input.trim());
}
} else {
// Handle piped input
send_message(&mut stream, std::str::from_utf8(&buffer).unwrap().trim());
for line in reader.lines() {
let line = line.unwrap();
send_message(&mut stream, &line);
}
}
}
fn send_message(stream: &mut TcpStream, message: &str) {
let datetime = Local::now();
let full_message = format!("{}: {}", datetime.format("%Y-%m-%d %H:%M:%S"), message);
if let Err(e) = stream.write_all(full_message.as_bytes()) {
eprintln!("Failed to send message: {:?}", e);
process::exit(1);
}
println!("Message sent!");
}