Neo-Poseidon/main.rs

60 lines
1019 B
Rust
Raw Normal View History

#![feature(plugin)]
#![plugin(rocket_codegen)]
use std::str::FromStr;
extern crate rocket;
2018-10-09 22:40:12 +02:00
#[macro_use] extern crate rocket_contrib;
use rocket::http::RawStr;
use rocket_contrib::Json;
2018-10-09 22:40:12 +02:00
//extern crate serde_json;
//use serde_json::{Value, Error};
extern crate rand;
use rand::Rng;
extern crate base64;
fn main()
{
2018-10-09 22:40:12 +02:00
rocket::ignite().mount("/", routes![index,login,]).launch();
}
#[get("/")]
fn index() -> &'static str {
"Owo What's this\n
You probably shouldn't be here! :D"
}
#[get("/login/<username>/<password>")]
2018-10-09 22:40:12 +02:00
fn login(username: &RawStr, password: &RawStr) -> Json
{
let mut rng = rand::thread_rng();
let session: u64 = rng.gen();
2018-10-09 22:40:12 +02:00
let session = format!("{:x}", session);
Json(json!(session))
}
2018-10-09 22:40:12 +02:00
#[get("/game/<game_id>/<session_id>/get_stars")]
fn get_stars(game_id: &RawStr, session_id: &RawStr) -> Json
{
2018-10-09 22:40:12 +02:00
let player = Player {
name: "Daniel",
color: (0,255,255)
};
let star = Star {
id: 80085,
name: "Loli sanctuary",
coordinates: (50, 64),
resources: 50
};
Json(star)
}