Skip to content

Commit

Permalink
Merge branch 'hosted' into server
Browse files Browse the repository at this point in the history
  • Loading branch information
SLiV9 committed Jul 12, 2021
2 parents beb8c22 + 7dbf0f5 commit 23e19ca
Show file tree
Hide file tree
Showing 12 changed files with 1,964 additions and 288 deletions.
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "epicinium"
version = "1.0.12"
version = "1.1.0"
authors = ["Sander in 't Veld <sanderintveld@hotmail.com>"]
edition = "2018"
publish = false
default-run = "server"

[dependencies]
epicinium_lib = { version = "1.0.12" }
epicinium_lib = { version = "1.1.0", path = "../epicinium_lib/" }
openssl = { version = "0.10", features = ["vendored"] }
rlimit = "*"
serde = "*"
Expand Down
4 changes: 2 additions & 2 deletions src/common/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ impl Version
{
Version {
major: 1,
minor: 0,
patch: 12,
minor: 1,
patch: 0,
release: 1,
}
}
Expand Down
67 changes: 43 additions & 24 deletions src/logic/challenge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde_derive::{Deserialize, Serialize};
#[derive(Debug)]
pub struct Challenge
{
pub id: ChallengeId,
pub key: String,
pub metadata: Metadata,
}
Expand All @@ -22,36 +23,54 @@ pub struct Metadata
panel_picture_name: String,
discord_image_key: String,
steam_short_key: String,
max_stars: i32,
}

pub fn current_id() -> ChallengeId
pub fn load_pool() -> Result<Vec<Challenge>, InterfaceError>
{
epicinium_lib::current_challenge_id()
let mut pool = Vec::new();
for id in epicinium_lib::challenge_pool()
{
let key = epicinium_lib::challenge_key(id);
let display_name = epicinium_lib::challenge_display_name(id)?;
let panel_picture_name =
epicinium_lib::challenge_panel_picture_name(id);
let discord_image_key = epicinium_lib::challenge_discord_image_key(id);
let steam_short_key = epicinium_lib::challenge_steam_short_key(id);

let briefing = load_briefing(id)?;
let max_stars = if briefing.0.get("3").is_some()
{
3
}
else if briefing.0.get("2").is_some()
{
2
}
else
{
1
};

let challenge = Challenge {
id,
key,
metadata: Metadata {
display_name,
panel_picture_name,
discord_image_key,
steam_short_key,
max_stars,
},
};
pool.push(challenge);
}
Ok(pool)
}

pub fn get_current_key() -> String
pub fn key(id: ChallengeId) -> String
{
epicinium_lib::challenge_key(epicinium_lib::current_challenge_id())
}

pub fn load_current() -> Result<Challenge, InterfaceError>
{
let id = epicinium_lib::current_challenge_id();
let key = epicinium_lib::challenge_key(id);
let display_name = epicinium_lib::challenge_display_name(id)?;
let panel_picture_name = epicinium_lib::challenge_panel_picture_name(id);
let discord_image_key = epicinium_lib::challenge_discord_image_key(id);
let steam_short_key = epicinium_lib::challenge_steam_short_key(id);

Ok(Challenge {
key,
metadata: Metadata {
display_name,
panel_picture_name,
discord_image_key,
steam_short_key,
},
})
epicinium_lib::challenge_key(id)
}

pub fn num_bots(id: ChallengeId) -> usize
Expand Down
75 changes: 33 additions & 42 deletions src/server/chat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* Server::Chat */

use crate::common::keycode::*;
use crate::logic::ai;
use crate::logic::challenge;
use crate::server::client;
use crate::server::lobby;
Expand All @@ -27,7 +26,8 @@ pub enum Update
client_id: Keycode,
username: String,
unlocks: EnumSet<Unlock>,
rating_data: watch::Receiver<rating::Data>,
rating_data: rating::Data,
rating_and_stars: watch::Receiver<rating::RatingAndStars>,
handle: client::Handle,
},
RatingAndStars
Expand Down Expand Up @@ -99,7 +99,7 @@ pub enum Update
pub async fn run(
mut updates: mpsc::Receiver<Update>,
canary: mpsc::Sender<()>,
current_challenge: challenge::Challenge,
challenge_pool: &[challenge::Challenge],
)
{
let mut clients: Vec<Client> = Vec::new();
Expand All @@ -115,7 +115,7 @@ pub async fn run(
&mut ghostbusters,
&mut lobbies,
&mut bots,
&current_challenge,
challenge_pool,
);

let removed = clients
Expand All @@ -134,7 +134,7 @@ fn handle_update(
ghostbusters: &mut HashMap<Keycode, Ghostbuster>,
lobbies: &mut Vec<Lobby>,
listed_bots: &mut Vec<lobby::ConnectedAi>,
current_challenge: &challenge::Challenge,
challenge_pool: &[challenge::Challenge],
)
{
match update
Expand All @@ -144,18 +144,20 @@ fn handle_update(
username,
unlocks,
rating_data,
rating_and_stars,
handle,
} => handle_join(
client_id,
username,
unlocks,
rating_data,
rating_and_stars,
handle,
clients,
ghostbusters,
lobbies,
listed_bots,
current_challenge,
challenge_pool,
),
Update::RatingAndStars { client_id } =>
{
Expand Down Expand Up @@ -262,7 +264,7 @@ struct Client
username: String,
join_metadata: JoinMetadataOrTagMetadata,
handle: client::Handle,
rating_data: watch::Receiver<rating::Data>,
rating_and_stars: watch::Receiver<rating::RatingAndStars>,
availability_status: AvailabilityStatus,
hidden: bool,
}
Expand Down Expand Up @@ -334,13 +336,14 @@ fn handle_join(
id: Keycode,
username: String,
unlocks: EnumSet<Unlock>,
rating_data: watch::Receiver<rating::Data>,
rating_data: rating::Data,
rating_and_stars: watch::Receiver<rating::RatingAndStars>,
handle: client::Handle,
clients: &mut Vec<Client>,
ghostbusters: &mut HashMap<Keycode, Ghostbuster>,
lobbies: &Vec<Lobby>,
listed_bots: &mut Vec<lobby::ConnectedAi>,
current_challenge: &challenge::Challenge,
challenge_pool: &[challenge::Challenge],
)
{
// Prevent a user being online with multiple connections simultaneously.
Expand Down Expand Up @@ -383,7 +386,7 @@ fn handle_join(
username,
join_metadata,
handle,
rating_data,
rating_and_stars,
availability_status: AvailabilityStatus::Available,
hidden: hidden,
};
Expand Down Expand Up @@ -415,14 +418,12 @@ fn handle_join(
clients,
lobbies,
listed_bots,
current_challenge,
challenge_pool,
);

// Tell everyone the rating and stars of the newcomer.
// Let the newcomer know how many stars they have for the current challenge.
if !newcomer.hidden
{
let rating_data: rating::Data = *newcomer.rating_data.borrow();
let message = Message::RatingAndStars {
username: newcomer.username.clone(),
rating: rating_data.rating,
Expand All @@ -433,9 +434,14 @@ fn handle_join(
other.handle.send(message.clone());
}
newcomer.handle.send(message);
}

// Let the newcomer know how many stars they have for the current challenge.
for (challenge_key, stars) in rating_data.stars_per_challenge
{
let message = Message::RecentStars {
stars: rating_data.recent_stars,
challenge_key,
stars,
};
newcomer.handle.send(message);
}
Expand Down Expand Up @@ -487,29 +493,10 @@ fn do_init(
handle: &mut client::Handle,
clients: &Vec<Client>,
lobbies: &Vec<Lobby>,
listed_bots: &mut Vec<lobby::ConnectedAi>,
current_challenge: &challenge::Challenge,
_listed_bots: &mut Vec<lobby::ConnectedAi>,
challenge_pool: &[challenge::Challenge],
)
{
// This is a stupid hack that is necessary because clients <1.0.8
// do not handle LIST_AI messages sent after the lobby is created.
for name in ai::load_pool()
{
handle.send(Message::ListAi {
ai_name: name.clone(),
metadata: None,
});
}
for ai in listed_bots
{
handle.send(Message::ListAi {
ai_name: ai.ai_name.clone(),
metadata: Some(BotAuthorsMetadata {
authors: ai.authors.clone(),
}),
});
}

// Let the client know which lobbies there are.
for lobby in lobbies.iter()
{
Expand All @@ -533,7 +520,8 @@ fn do_init(
metadata: client.join_metadata.clone(),
});

let rating_data: rating::Data = *client.rating_data.borrow();
let rating_data: rating::RatingAndStars =
*client.rating_and_stars.borrow();
let message = Message::RatingAndStars {
username: client.username.clone(),
rating: rating_data.rating,
Expand Down Expand Up @@ -575,10 +563,13 @@ fn do_init(
}

// Let the client know what the current challenge is called.
handle.send(Message::ListChallenge {
key: current_challenge.key.clone(),
metadata: current_challenge.metadata.clone(),
});
for challenge in challenge_pool
{
handle.send(Message::ListChallenge {
key: challenge.key.clone(),
metadata: challenge.metadata.clone(),
});
}

// Let the client know we are done initializing.
handle.send(Message::Init)
Expand All @@ -595,7 +586,7 @@ fn handle_rating_and_stars(client_id: Keycode, clients: &mut Vec<Client>)
return;
}
};
let rating_data: rating::Data = *client.rating_data.borrow();
let rating_data: rating::RatingAndStars = *client.rating_and_stars.borrow();
let message = Message::RatingAndStars {
username: client.username.clone(),
rating: rating_data.rating,
Expand Down Expand Up @@ -634,7 +625,7 @@ fn handle_removed(
username,
join_metadata: _,
mut handle,
rating_data: _,
rating_and_stars: _,
availability_status: _,
hidden,
} = removed_client;
Expand Down
Loading

0 comments on commit 23e19ca

Please sign in to comment.