Skip to content

Commit c63b8bd

Browse files
committed
adds a readme, various corrections in NewNote struct and get_all_ckey(), debug mode in Admin
1 parent af30e7a commit c63b8bd

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# cm-api-rs
2+
3+
This is the backend to [cmdb](https://github.com/cmss13-devs/cmdb), to provide Admins with access to database-stored information from outside the game.
4+
5+
## Configuration
6+
7+
### Api.toml
8+
9+
```toml
10+
[host]
11+
base_url = "/foobar" // if your api is served on a different route
12+
13+
[topic]
14+
host = "play.cm-ss13.com:1400" // which game server should be pinged for status updates
15+
auth = "your-auth-token-here" // the comms key to contact the game server
16+
17+
[logging]
18+
webhook = "some discord webhook" // for actions impacting the database, a discord webhook
19+
```
20+
21+
### Rocket.toml
22+
23+
```toml
24+
[default]
25+
address = "0.0.0.0"
26+
port = 8080
27+
28+
[default.databases.cmdb]
29+
url = "mysql://root:[email protected]:3306/cmdb"
30+
```

src/admin.rs

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ impl<'r> FromRequest<'r> for Admin {
1818
type Error = AdminError;
1919

2020
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
21+
if cfg!(debug_assertions) {
22+
return request::Outcome::Success(Admin {
23+
username: "AdminBot".to_string(),
24+
});
25+
}
26+
2127
let username = match req.headers().get("X-Forwarded-Preferred-Username").next() {
2228
Some(username) => username,
2329
None => return request::Outcome::Error((Status::BadRequest, AdminError::Missing)),

src/player.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub async fn id(mut db: Connection<Cmdb>, id: i32) -> Option<Json<Player>> {
228228
pub struct NewNote {
229229
message: String,
230230
category: i32,
231-
confidential: i32,
231+
confidential: bool,
232232
}
233233

234234
#[post("/<id>/Note", data = "<input>")]
@@ -254,7 +254,7 @@ pub async fn new_note(
254254
id,
255255
admin_id,
256256
&input.message,
257-
input.confidential > 0,
257+
input.confidential,
258258
input.category,
259259
)
260260
.await

src/stickyban.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub async fn get_matched_ckey(
191191

192192
#[get("/Ckey?<ckey>")]
193193
pub async fn get_all_ckey(mut db: Connection<Cmdb>, ckey: String) -> Json<Vec<Stickyban>> {
194-
let query: Vec<StickybanMatchedCid> =
194+
let query: Vec<StickybanMatchedCkey> =
195195
match query_as("SELECT * FROM stickyban_matched_ckey WHERE ckey = ? AND whitelisted = 0")
196196
.bind(ckey)
197197
.fetch_all(&mut **db)

0 commit comments

Comments
 (0)