refactor api

This commit is contained in:
41666 2022-11-27 18:18:41 -05:00
parent a8c4bc5756
commit 01471342b0
18 changed files with 873 additions and 1595 deletions

View file

@ -7,8 +7,7 @@ edition = "2021"
[dependencies]
redis = { version = "0.22.1", default_features = false, features = ["r2d2"] }
redis_ts = "0.4.2"
once_cell = "1.16.0"
lazy_static = "1.4.0"
tokio-tungstenite = { version = "0.17.2", features=["native-tls"] }
serde_json = "1.0.88"
serde = { version = "1.0.147", features = ["derive"] }

View file

@ -1,6 +1,6 @@
use futures::{pin_mut, FutureExt};
use futures_util::StreamExt;
use once_cell::sync::Lazy;
use lazy_static::lazy_static;
use redis::Commands;
use serde::Deserialize;
use serde_json::json;
@ -9,14 +9,17 @@ use tokio_tungstenite::{connect_async, tungstenite::Message};
mod translators;
pub static REDIS_CLIENT: Lazy<redis::Client> = Lazy::new(|| {
redis::Client::open(std::env::var("REDIS_ADDR").unwrap_or("redis://localhost:6379".to_string()))
.unwrap()
});
static PAIR: Lazy<String> = Lazy::new(|| env::var("PAIR").unwrap_or_default());
static ROLE: Lazy<String> = Lazy::new(|| env::var("ROLE").unwrap_or("primary".to_string()));
static WS_ADDR: Lazy<String> = Lazy::new(|| env::var("WS_ADDR").unwrap_or_default());
lazy_static! {
static ref REDIS_CLIENT: redis::Client = redis::Client::open(format!(
"redis://{}:{}",
std::env::var("REDIS_HOST").unwrap_or("localhost".to_string()),
std::env::var("REDIS_PORT").unwrap_or("6379".to_string()),
))
.unwrap();
static ref PAIR: String = env::var("PAIR").unwrap_or_default();
static ref ROLE: String = env::var("ROLE").unwrap_or("primary".to_string());
static ref WS_ADDR: String = env::var("WS_ADDR").unwrap_or_default();
}
async fn send_init(tx: futures::channel::mpsc::UnboundedSender<Message>) {
let worlds_raw = env::var("WORLDS").unwrap_or_default();

View file

@ -1,10 +1,10 @@
// GENERATED CODE -- Do not edit. Run `cargo run --bin codegen` to regenerate.
use once_cell::sync::Lazy;
use lazy_static::lazy_static;
use std::collections::HashMap;
static VEHICLE_TO_NAME: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
HashMap::from([
lazy_static! {
static ref VEHICLE_TO_NAME: HashMap<&'static str, &'static str> = HashMap::from([
("1", "flash"),
("2", "sunderer"),
("3", "lightning"),
@ -48,18 +48,8 @@ static VEHICLE_TO_NAME: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
("2136", "dervish"),
("2137", "chimera"),
("2142", "corsair"),
])
});
pub fn vehicle_to_name(vehicle_id: &str) -> String {
match VEHICLE_TO_NAME.get(&vehicle_id) {
Some(name) => name.to_string(),
None => "unknown".to_string(),
}
}
static LOADOUT_TO_CLASS: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
HashMap::from([
]);
static ref LOADOUT_TO_CLASS: HashMap<&'static str, &'static str> = HashMap::from([
("1", "infiltrator"),
("3", "light_assault"),
("4", "combat_medic"),
@ -84,8 +74,15 @@ static LOADOUT_TO_CLASS: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
("31", "engineer"),
("32", "heavy_assault"),
("45", "max"),
])
});
]);
}
pub fn vehicle_to_name(vehicle_id: &str) -> String {
match VEHICLE_TO_NAME.get(&vehicle_id) {
Some(name) => name.to_string(),
None => "unknown".to_string(),
}
}
pub fn loadout_to_class(loadout_id: &str) -> String {
match LOADOUT_TO_CLASS.get(&loadout_id) {