Neo-Poseidon/main.rs

60 lines
1019 B
Rust

#![feature(plugin)]
#![plugin(rocket_codegen)]
use std::str::FromStr;
extern crate rocket;
#[macro_use] extern crate rocket_contrib;
use rocket::http::RawStr;
use rocket_contrib::Json;
//extern crate serde_json;
//use serde_json::{Value, Error};
extern crate rand;
use rand::Rng;
extern crate base64;
fn main()
{
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>")]
fn login(username: &RawStr, password: &RawStr) -> Json
{
let mut rng = rand::thread_rng();
let session: u64 = rng.gen();
let session = format!("{:x}", session);
Json(json!(session))
}
#[get("/game/<game_id>/<session_id>/get_stars")]
fn get_stars(game_id: &RawStr, session_id: &RawStr) -> Json
{
let player = Player {
name: "Daniel",
color: (0,255,255)
};
let star = Star {
id: 80085,
name: "Loli sanctuary",
coordinates: (50, 64),
resources: 50
};
Json(star)
}