add lib, partition both application files, c-line input

This commit is contained in:
David Westgate 2023-11-19 19:03:59 -08:00
parent 27e13d6a90
commit 144453c692
5 changed files with 62 additions and 2 deletions

7
Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "rust-irc"
version = "0.1.0"

4
src/client.rs Normal file
View File

@ -0,0 +1,4 @@
pub fn start() {
println!("Starting the IRC client");
todo!();
}

19
src/lib.rs Normal file
View File

@ -0,0 +1,19 @@
pub mod codes {
pub mod client {
pub const JOIN_ROOM: u8 = 0x01;
pub const JOIN_SERVER: u8 = 0x02;
pub const LEAVE_ROOM: u8 = 0x03;
pub const LIST_ROOMS: u8 = 0x04;
pub const SEND_MESSAGE: u8 = 0x05;
}
pub const KEEP_ALIVE: u8 = 0x0C;
pub const RESPONSE: u8 = 0x0D;
pub const RESPONSE_OK: u8 = 0x0E;
pub const ERROR: u8 = 0x0F;
pub const QUIT: u8 = 0x0B;
pub mod error {
pub const INVALID_ROOM: u8 = 0x10;
pub const NICKNAME_COLLISION: u8 = 0x11;
pub const SERVER_FULL: u8 = 0x12;
}
}

View File

@ -1,3 +1,29 @@
fn main() { use std::env;
println!("Hello, world!");
mod client;
mod server;
fn parsechar(s: &str) -> char {
s.parse().unwrap_or_else(|_| info())
}
fn info() -> ! {
println!("Start client: cargro run c\nStart server: cargo run s");
std::process::exit(1)
}
fn main() {
let args: Vec<String> = env::args().skip(1).collect();
if args.len() == 1 {
let input: char = parsechar(&args[0]);
if input == 'c' {
client::start();
} else if input == 's' {
server::start();
} else {
info();
}
} else {
info();
}
} }

4
src/server.rs Normal file
View File

@ -0,0 +1,4 @@
pub fn start() {
println!("Starting the IRC Server");
todo!();
}