Skip to content

Commit

Permalink
Add back friend list packet handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li committed Apr 29, 2024
1 parent 3069aa9 commit b257bfe
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ impl ChatBuilder<PlainRemote<Vec<ChatMessage>>, Rc<RefCell<FontLoader>>> {
Chat {
messages,
font_loader,
stamp: true,
state: Default::default(),
}
}
Expand Down
3 changes: 1 addition & 2 deletions korangar/src/interface/elements/miscellanious/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ use crate::ChatMessage;
pub struct Chat {
messages: PlainRemote<Vec<ChatMessage>>,
font_loader: Rc<RefCell<FontLoader>>,
// TODO: make this Remote
stamp: bool,
state: ElementState<InterfaceSettings>,
}

Expand Down Expand Up @@ -111,6 +109,7 @@ impl Element<InterfaceSettings> for Chat {
korangar_networking::MessageColor::Broadcast => theme.chat.broadcast_color.get(),
korangar_networking::MessageColor::Server => theme.chat.server_color.get(),
korangar_networking::MessageColor::Error => theme.chat.broadcast_color.get(),
korangar_networking::MessageColor::Information => theme.chat.information_color.get(),
};

// NOTE: Dividing by the scaling is done to counteract the scaling being applied
Expand Down
7 changes: 7 additions & 0 deletions korangar/src/interface/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ pub struct ChatTheme {
pub broadcast_color: Mutable<Color, Render>,
pub server_color: Mutable<Color, Render>,
pub error_color: Mutable<Color, Render>,
pub information_color: Mutable<Color, Render>,
}

impl ThemeDefault<DefaultMenu> for ChatTheme {
Expand All @@ -863,6 +864,7 @@ impl ThemeDefault<DefaultMenu> for ChatTheme {
broadcast_color: Mutable::new(Color::rgb_u8(210, 210, 210)),
server_color: Mutable::new(Color::rgb_u8(255, 255, 210)),
error_color: Mutable::new(Color::rgb_u8(255, 150, 150)),
information_color: Mutable::new(Color::rgb_u8(200, 255, 200)),
}
}
}
Expand All @@ -875,6 +877,7 @@ impl ThemeDefault<DefaultMain> for ChatTheme {
broadcast_color: Mutable::new(Color::rgb_u8(210, 210, 210)),
server_color: Mutable::new(Color::rgb_u8(255, 255, 210)),
error_color: Mutable::new(Color::rgb_u8(255, 150, 150)),
information_color: Mutable::new(Color::rgb_u8(200, 255, 200)),
}
}
}
Expand All @@ -899,6 +902,10 @@ impl korangar_interface::theme::ChatTheme<InterfaceSettings> for ChatTheme {
fn error_color(&self) -> Color {
self.error_color.get()
}

fn information_color(&self) -> Color {
self.information_color.get()
}
}

#[derive(Serialize, Deserialize, PrototypeElement)]
Expand Down
163 changes: 93 additions & 70 deletions korangar/src/main.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions korangar_interface/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ where
fn broadcast_color(&self) -> App::Color;
fn server_color(&self) -> App::Color;
fn error_color(&self) -> App::Color;
fn information_color(&self) -> App::Color;
}

pub trait CursorTheme<App>
Expand Down
51 changes: 18 additions & 33 deletions korangar_networking/examples/ollama-chat-bot.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::io::Write;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::thread::sleep;
use std::time::Duration;
Expand Down Expand Up @@ -68,6 +67,7 @@ async fn main() {
const OLLAMA_MODEL: &str = "llama2:13b";
const USERNAME: &str = "chatbot";
const PASSWORD: &str = "chatbot";
const CHARACTER_NAME: &str = "ChatbotBoy";

// Create the networking system and HTTP client.
let mut networking_system = NetworkingSystem::<()>::new();
Expand All @@ -76,7 +76,6 @@ async fn main() {
// Persistent data.
let mut saved_login_data = None;
let mut message_history = MessageHistory { hash_map: HashMap::new() };
let mut character_name = String::new();

// Kick of the bot by connecting to the login server.
networking_system.connect_to_login_server(SOCKET_ADDR, USERNAME.to_owned(), PASSWORD.to_owned());
Expand All @@ -93,8 +92,8 @@ async fn main() {
networking_system.connect_to_character_server(&login_data, character_servers[0].clone());
saved_login_data = Some(login_data);
}
NetworkEvent::LoginServerConnectionFailed { reason } => {
panic!("Failed to connect to login server: {}", reason);
NetworkEvent::LoginServerConnectionFailed { message, .. } => {
panic!("Failed to connect to login server: {}", message);
}
NetworkEvent::LoginServerDisconnected => {
panic!("Login server disconnected");
Expand All @@ -104,40 +103,26 @@ async fn main() {

networking_system.request_character_list();
}
NetworkEvent::CharacterServerConnectionFailed { reason } => {
panic!("Failed to connect to character server: {}", reason);
NetworkEvent::CharacterServerConnectionFailed { message, .. } => {
panic!("Failed to connect to character server: {}", message);
}
NetworkEvent::CharacterServerDisconnected => {
panic!("Character server disconnected");
}
NetworkEvent::CharacterSelectionFailed { reason } => {
panic!("Failed to select character: {}", reason);
NetworkEvent::CharacterSelectionFailed { message, .. } => {
panic!("Failed to select character: {}", message);
}
NetworkEvent::MapServerDisconnected => {
panic!("Map server disconnected");
}
NetworkEvent::CharacterInformation { characters } => {
for character in &characters {
println!(
"[{}] On slot {}: {}",
"Characters".magenta(),
character.character_number.green(),
character.name.magenta()
);
}

print!("[{}] Character to use: ", "Characters".magenta());
std::io::stdout().flush().unwrap();

let mut buffer = String::new();
let stdin = std::io::stdin();
stdin.read_line(&mut buffer).expect("Failed to receive input");

let character_slot = buffer.trim().parse::<usize>().expect("Failed to parse slot");
let character_name = characters
.into_iter()
.find(|character| character.character_number as usize == character_slot)
.expect("No player in that slot")
.name;
let character_slot = characters
.iter()
.find(|character| character.name == CHARACTER_NAME)
.expect(&format!("Character with name \"{}\" not found for this user", CHARACTER_NAME))
.character_number as usize;

print!("[{}] Using character: {}", "Characters".magenta(), character_name.green());
println!("[{}] Using character in slot: {}", "Setup".green(), character_slot.green());

networking_system.select_character(character_slot)
}
Expand All @@ -147,7 +132,7 @@ async fn main() {
networking_system.map_loaded();
}
NetworkEvent::ChatMessage { text, .. } => {
if text.starts_with(&character_name) {
if text.starts_with(CHARACTER_NAME) {
continue;
}

Expand Down Expand Up @@ -189,7 +174,7 @@ async fn main() {
content: response.content.to_owned(),
});

networking_system.send_chat_message(&character_name, &response.content);
networking_system.send_chat_message(CHARACTER_NAME, &response.content);
}
}
_ => {}
Expand Down
Loading

0 comments on commit b257bfe

Please sign in to comment.