~starkingdoms/starkingdoms

ead5d25af55b7773fbe696ce9bd75c6b14353d62 — core 2 years ago 1b4d868
pull server list from the api
M Cargo.lock => Cargo.lock +16 -0
@@ 26,6 26,21 @@ dependencies = [
]

[[package]]
name = "actix-cors"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b340e9cfa5b08690aae90fb61beb44e9b06f44fe3d0f93781aaa58cfba86245e"
dependencies = [
 "actix-utils",
 "actix-web",
 "derive_more",
 "futures-util",
 "log",
 "once_cell",
 "smallvec",
]

[[package]]
name = "actix-files"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 3312,6 3327,7 @@ dependencies = [
name = "starkingdoms-api"
version = "0.1.0"
dependencies = [
 "actix-cors",
 "actix-files",
 "actix-request-identifier",
 "actix-web",

M api/Cargo.toml => api/Cargo.toml +1 -0
@@ 9,6 9,7 @@ edition = "2021"
actix-web = "4"                 # Web framework
actix-request-identifier = "4"  # Web framework
actix-files = "0.6"             # Web framework
actix-cors = "0.6.4"            # Web framework

serde = { version = "1", features = ["derive"] }    # Serialization and deserialization


M api/config.toml => api/config.toml +1 -0
@@ 2,6 2,7 @@ game = "localhost:5173"
internal_tokens = ["01GY803PVK7YJKXZYWFTK6DS1Y-01GY8040ZQY9SG29DXY4HZ4EPD"]
jwt_signing_secret = "544adbc8144d375d581a1622a4f0cbcf92f006a156ef8b9d4afac6410f51f73c"
base = "localhost:8080"
servers = ["http://localhost:3000"]

[server]
listen = "0.0.0.0:8080"

M api/src/config.rs => api/src/config.rs +1 -0
@@ 32,6 32,7 @@ pub struct StarkingdomsApiConfig {
    pub base: String,
    pub game: String,
    pub realms: HashMap<String, StarkingdomsApiConfigRealm>,
    pub servers: Vec<String>
}

#[derive(Serialize, Deserialize, Debug)]

M api/src/main.rs => api/src/main.rs +3 -0
@@ 9,6 9,7 @@ use sea_orm::{ConnectOptions, Database, DatabaseConnection};
use starkingdoms_api_migration::{Migrator, MigratorTrait};
use std::error::Error;
use std::time::Duration;
use actix_cors::Cors;
use tera::Tera;

pub mod config;


@@ 51,6 52,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

    HttpServer::new(move || {
        App::new()
            .wrap(Cors::permissive())
            .app_data(data.clone())
            .app_data(JsonConfig::default().error_handler(|err, _req| {
                let api_error: APIError = (&err).into();


@@ 69,6 71,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
            .service(routes::callback::callback)
            .service(routes::beamin::beam_in)
            .service(routes::beamout::beam_out)
            .service(routes::server_list::server_list)
            .service(actix_files::Files::new("/static", "static"))
    })
    .bind(CONFIG.server.bind)?

M api/src/routes/mod.rs => api/src/routes/mod.rs +1 -0
@@ 2,3 2,4 @@ pub mod beamin;
pub mod beamout;
pub mod callback;
pub mod select_realm;
pub mod server_list;
\ No newline at end of file

A api/src/routes/server_list.rs => api/src/routes/server_list.rs +16 -0
@@ 0,0 1,16 @@
use actix_web::{get};
use actix_web::web::Json;
use serde::Serialize;
use crate::config::CONFIG;

#[derive(Serialize)]
pub struct ServerListResponse {
    pub servers: Vec<String>
}

#[get("server-list")]
pub async fn server_list() -> Json<ServerListResponse> {
    Json(ServerListResponse {
        servers: CONFIG.servers.clone(),
    })
}
\ No newline at end of file

M assets/dist/spritesheet-125.json => assets/dist/spritesheet-125.json +2 -2
@@ 9,7 9,7 @@
      "pivot": { "x": 128, "y": 128 },
      "9slicedFrame": { "x": 0, "y": 0, "w": 256, "h": 256 }
    },
    "moon.png": {
    "earth.png": {
      "frame": { "x": 0, "y": 256, "w": 256, "h": 256 },
      "rotated": false,
      "trimmed": false,


@@ 18,7 18,7 @@
      "pivot": { "x": 128, "y": 128 },
      "9slicedFrame": { "x": 0, "y": 0, "w": 256, "h": 256 }
    },
    "earth.png": {
    "moon.png": {
      "frame": { "x": 0, "y": 512, "w": 256, "h": 256 },
      "rotated": false,
      "trimmed": false,

M assets/dist/spritesheet-125.png => assets/dist/spritesheet-125.png +0 -0
M assets/dist/spritesheet-375.json => assets/dist/spritesheet-375.json +2 -2
@@ 9,7 9,7 @@
      "pivot": { "x": 384, "y": 384 },
      "9slicedFrame": { "x": 0, "y": 0, "w": 768, "h": 768 }
    },
    "moon.png": {
    "earth.png": {
      "frame": { "x": 0, "y": 768, "w": 768, "h": 768 },
      "rotated": false,
      "trimmed": false,


@@ 18,7 18,7 @@
      "pivot": { "x": 384, "y": 384 },
      "9slicedFrame": { "x": 0, "y": 0, "w": 768, "h": 768 }
    },
    "earth.png": {
    "moon.png": {
      "frame": { "x": 0, "y": 1536, "w": 768, "h": 768 },
      "rotated": false,
      "trimmed": false,

M assets/dist/spritesheet-375.png => assets/dist/spritesheet-375.png +0 -0
M assets/dist/spritesheet-full.json => assets/dist/spritesheet-full.json +2 -2
@@ 9,7 9,7 @@
      "pivot": { "x": 1024, "y": 1024 },
      "9slicedFrame": { "x": 0, "y": 0, "w": 2048, "h": 2048 }
    },
    "moon.png": {
    "earth.png": {
      "frame": { "x": 0, "y": 2048, "w": 2048, "h": 2048 },
      "rotated": false,
      "trimmed": false,


@@ 18,7 18,7 @@
      "pivot": { "x": 1024, "y": 1024 },
      "9slicedFrame": { "x": 0, "y": 0, "w": 2048, "h": 2048 }
    },
    "earth.png": {
    "moon.png": {
      "frame": { "x": 0, "y": 4096, "w": 2048, "h": 2048 },
      "rotated": false,
      "trimmed": false,

M assets/dist/spritesheet-full.png => assets/dist/spritesheet-full.png +0 -0
M assets/final/125/moon.png => assets/final/125/moon.png +0 -0
M assets/final/375/moon.png => assets/final/375/moon.png +0 -0
M assets/final/full/moon.png => assets/final/full/moon.png +0 -0
M client/index.html => client/index.html +13 -5
@@ 38,10 38,11 @@

        <script type="module">
            let api_server = "http://localhost:8080";
            let servers = ["localhost:3000"];

            let servers = [];

            function server_url_to_ping_url(server) {
                return "http://" + server + "/ping"
                return server + "/ping"
            }

            function server_url_to_gateway_url(server) {


@@ 60,9 61,16 @@
                })
            }

            for (let i = 0; i < servers.length; i++) {
                load_server(servers[i]);
            }
            // load servers from the api
            fetch(`${api_server}/server-list`).then(response => {
                response.json().then(response => {
                    servers = response["servers"];

                    for (let i = 0; i < servers.length; i++) {
                        load_server(servers[i]);
                    }
                })
            })

            let query = new URLSearchParams(window.location.search);


M client/src/index.ts => client/src/index.ts +38 -34
@@ 273,54 273,58 @@ async function client_main(server: string, username: string, texture_quality: st
        }

        for (let i = 0; i < global.modules.length; i++) {
            let module = global.modules[i];
            // @ts-ignore
            let tex = global.spritesheet!["frames"][module_type_to_tex_id(module.moduleType)];
            if (global.me !== null) {
                let module = global.modules[i];
                // @ts-ignore
                let tex = global.spritesheet!["frames"][module_type_to_tex_id(module.moduleType)];

            global.context.save();
                global.context.save();

            // x_{screen} = x_{world} - player_{x_{world}}
            // x_{world} = x_{screen} + player_{x_{world}}
                // x_{screen} = x_{world} - player_{x_{world}}
                // x_{world} = x_{screen} + player_{x_{world}}

            global.context.translate(module.x - global.me!.x, module.y - global.me!.y);
                global.context.translate(module.x - global.me!.x, module.y - global.me!.y);

            global.context.rotate(module.rotation);
                global.context.rotate(module.rotation);

            global.context.drawImage(global.spritesheet_img!,
                                     tex.frame.x,
                                     tex.frame.y,
                                     tex.frame.w,
                                     tex.frame.h,
                                     -25,
                                     -25, 50, 50);

            global.context.restore();
                global.context.drawImage(global.spritesheet_img!,
                    tex.frame.x,
                    tex.frame.y,
                    tex.frame.w,
                    tex.frame.h,
                    -25,
                    -25, 50, 50);

                global.context.restore();
            }
        }

        for (let i = 0; i < global.players.length; i++) {
            let player = global.players[i];
            // @ts-ignore
            let tex = global.spritesheet!["frames"]["hearty.png"];
            if (global.me !== null) {
                let player = global.players[i];
                // @ts-ignore
                let tex = global.spritesheet!["frames"]["hearty.png"];

            global.context.save();
                global.context.save();

            global.context.translate(player.x - global.me!.x, player.y - global.me!.y);
                global.context.translate(player.x - global.me!.x, player.y - global.me!.y);

            global.context.textAlign = "center";
            global.context.font = "30px Segoe UI";
            global.context.fillStyle = "white";
            global.context.fillText(player.username, 0, -35);
                global.context.textAlign = "center";
                global.context.font = "30px Segoe UI";
                global.context.fillStyle = "white";
                global.context.fillText(player.username, 0, -35);

            global.context.rotate(player.rotation);
                global.context.rotate(player.rotation);

            global.context.drawImage(global.spritesheet_img!,
                tex.frame.x, // sx
                tex.frame.y, // sy
                tex.frame.w, // sw
                tex.frame.h, // sh
                -25, -25, 50, 50); // dh
                global.context.drawImage(global.spritesheet_img!,
                    tex.frame.x, // sx
                    tex.frame.y, // sy
                    tex.frame.w, // sw
                    tex.frame.h, // sh
                    -25, -25, 50, 50); // dh

            global.context.restore();
                global.context.restore();
            }
        }

        requestAnimationFrame(render);

M docker/config.jinja.toml => docker/config.jinja.toml +2 -0
@@ 7,6 7,8 @@ game = "{{ game_url }}"

jwt_signing_secret = "{{ jwt_signing_secret }}"

servers = ["{{ game_url }}"]

[realms.discord]
authorize_url = "https://api.e3t.cc/auth/discord/authorize.php"
public_key = "-----BEGIN PUBLIC KEY-----\nMIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHBcZsCM6ebFDCp3dFc+3EOzLw8B\n+fR+9Tx6S/lXOTghk49s7yaxza/zVRPxWaMqyjegfRCEepgV++jbWzBib7bhy91M\n+zlRbeZ9rf++N30Nf4R/XAnUAmhAHt8TzDC08DNQNYAFz37+r4EZlY7APHyND4qU\nd8w3qB95v/wMVB6nAgMBAAE=\n-----END PUBLIC KEY-----"

M spacetime_rs/src/commands/api.rs => spacetime_rs/src/commands/api.rs +2 -2
@@ 33,7 33,7 @@ pub fn run_api(args: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {

    exec(
        root.join("target/debug/starkingdoms-api").to_str().unwrap(),
        &root,
        &root.join("api"),
        args,
    )?;



@@ 51,7 51,7 @@ pub fn run_api_prod(args: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Erro
        root.join("target/release/starkingdoms-api")
            .to_str()
            .unwrap(),
        &root,
        &root.join("api"),
        args,
    )?;


M spacetime_rs/src/commands/docker.rs => spacetime_rs/src/commands/docker.rs +10 -4
@@ 9,12 9,13 @@ use std::process::Command;
use sedregex::find_and_replace;

fn _build(img: &str, channel: &str, root: &PathBuf) -> Result<(), Box<dyn Error>> {
    let mut patched = "".to_string();
    // compile the various thingies
    if img == "server" {
        build_server_prod(vec![], root.clone())?;
    } else if img == "api" {
        build_api_prod(vec![], root.clone())?;
    } else {
    } else if img == "web" {
        // we need to swap out the urls
        // TODO
        // for now i am just adding all three to all clients


@@ 31,13 32,14 @@ fn _build(img: &str, channel: &str, root: &PathBuf) -> Result<(), Box<dyn Error>

        let index_html_src = fs::read_to_string(&index_html_path)?;
        let index_html_patched = find_and_replace(&index_html_src, &[
            format!("s/let api_server = \"http:\\/\\/localhost:8080\";/let api_server = \"https:\\/\\/api.{}.{}\";/", a, b),
            format!("s/let servers = \\[\"http:\\/\\/localhost:3000\"\\];/let servers = [\"https:\\/\\/{}.{}\"];/", a, b)
            format!("s/let api_server = \"http:\\/\\/localhost:8080\";/let api_server = \"https:\\/\\/api.{}.{}\";/", a, b)
        ])?;

        fs::write(&index_html_path, index_html_patched.as_bytes())?;

        fs::write(root.clone().join("client/").join("index.html.orig"), index_html_src)?;
        fs::write(root.clone().join("client/").join("index.html.orig"), index_html_src.clone())?;

        patched = index_html_src.clone();

        build_client_prod(vec![], root.clone())?
    }


@@ 120,6 122,10 @@ fn _build(img: &str, channel: &str, root: &PathBuf) -> Result<(), Box<dyn Error>
        .collect(),
    )?;

    if img == "web" {
        fs::write(root.clone().join("client/").join("index.html"), patched)?;
    }

    Ok(())
}


M web/index.html => web/index.html +1 -1
@@ 33,7 33,7 @@

        <script>

            let servers = ["http://localhost:3000"];
            let servers = ["localhost:3000"];

            function server_url_to_ping_url(server) { return server + "/ping" }
            function server_url_to_gateway_url(server) { return "ws://" + server + "/ws" }