Skip to content

Commit 7286674

Browse files
Made it so you can send chats
I made sure you cant send empty chats and you can only chat if your logged in. I might make it so you can chat even if your not logged in but idk. If I do that then your name will just show up as "Guest" when you chat without being logged in.
1 parent 2acac94 commit 7286674

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/main.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ async fn main() {
436436
let upload_url: String = format!("{}upload-level.php", main_url).to_string();
437437
let login_url: String = format!("{}login.php", main_url);
438438
let get_chat_url: String = format!("{}get-chats.php", main_url);
439+
let send_chat_url: String = format!("{}send-chat.php", main_url);
439440

440441
println!("Defining important game variables..");
441442
let game_state: Shared<GameState> = Shared::<GameState>(Rc::new(Cell::new(GameState::Menu)));
@@ -638,6 +639,7 @@ async fn main() {
638639
let mut show_level_not_found: bool = false;
639640
let mut login_response: String = "".to_string();
640641
let mut level_upload_response: String = "".to_string();
642+
let mut send_chat_response: String = "".to_string();
641643

642644
let save_file: String = std::fs::read_to_string("./save-data/save.txt")
643645
.expect("Failed to load save file");
@@ -1593,7 +1595,19 @@ async fn main() {
15931595
game_state.0.set(GameState::Menu);
15941596
}
15951597

1596-
if send_chat_button.is_clicked() {
1598+
if send_chat_button.is_clicked()
1599+
&& chat_textbox.input.len() > 0
1600+
&& logged_in {
1601+
send_chat_response = ureq::post(&send_chat_url)
1602+
.send_form([
1603+
("user", username.clone()),
1604+
("msg", chat_textbox.input)
1605+
])
1606+
.unwrap()
1607+
.into_body()
1608+
.read_to_string()
1609+
.unwrap();
1610+
15971611
chat_textbox.input = "".to_string();
15981612
}
15991613

@@ -2402,6 +2416,17 @@ async fn main() {
24022416
send_chat_button.draw(false, None, 1.0, false, &font);
24032417
chat_textbox.draw(&font);
24042418

2419+
if debug_mode {
2420+
draw_text_pro(
2421+
&send_chat_response,
2422+
20.0,
2423+
105.0,
2424+
20,
2425+
GREEN,
2426+
&font
2427+
);
2428+
}
2429+
24052430
let lines: Vec<&str> = chats.split('\n').collect();
24062431
let font_size = 20;
24072432
let mut y = 150.0;

0 commit comments

Comments
 (0)