2018-10-08 23:03:19 +02:00
|
|
|
#![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;
|
2018-10-08 23:03:19 +02:00
|
|
|
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};
|
|
|
|
|
2018-10-08 23:03:19 +02:00
|
|
|
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();
|
2018-10-08 23:03:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
2018-10-08 23:03:19 +02:00
|
|
|
{
|
|
|
|
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-08 23:03:19 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 22:40:12 +02:00
|
|
|
#[get("/game/<game_id>/<session_id>/get_stars")]
|
2018-10-08 23:03:19 +02:00
|
|
|
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)
|
|
|
|
}
|