Skip to content

Commit 3196d7b

Browse files
committed
first version
1 parent f913218 commit 3196d7b

24 files changed

+4050
-1
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Auto detect text files and perform LF normalization
2-
* text=auto
2+
* text=auto eol=lf

backend/.prettierignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
lib
2+
dist
3+
doc
4+
coverage
5+
.yarn
6+
.pnp.js
7+
node_modules
8+
.nyc_output
9+
public
10+
**/*.md

backend/.prettierrc.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# .prettierrc or .prettierrc.yaml
2+
trailingComma: 'es5'
3+
tabWidth: 4
4+
semi: true
5+
singleQuote: true
6+
printWidth: 100
7+
useTabs: true
8+
overrides:
9+
- files: '**/*.yml'
10+
options:
11+
tabWidth: 2
12+
useTabs: false

backend/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Jens Forstmann
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

backend/nodemon.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"verbose": true,
3+
"exec": "ts-node src/index.ts",
4+
"watch": ["src"],
5+
"ext": "ts",
6+
"ignore": ["src/routes.ts"]
7+
}

backend/package.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "tmt2-backend",
3+
"version": "1.0.0",
4+
"main": "dist/index.js",
5+
"repository": "https://github.com/JensForstmann/tmt2",
6+
"author": "Jens Forstmann",
7+
"license": "MIT",
8+
"scripts": {
9+
"build": "tsc",
10+
"build2": "tsoa spec-and-routes && tsc",
11+
"dev": "concurrently \"nodemon\" \"nodemon -x tsoa spec-and-routes\"",
12+
"clean": "prettier --write .",
13+
"start": "node ./dist/index.js"
14+
},
15+
"dependencies": {
16+
"body-parser": "^1.19.0",
17+
"express": "^4.17.1",
18+
"rcon-client": "^4.2.2",
19+
"steamid": "^1.1.3",
20+
"tsoa": "^3.2.1"
21+
},
22+
"devDependencies": {
23+
"@types/body-parser": "^1.19.0",
24+
"@types/express": "^4.17.8",
25+
"@types/node": "^14.10.1",
26+
"@types/steamid": "^1.1.0",
27+
"axios": "^0.20.0",
28+
"concurrently": "^5.3.0",
29+
"nodemon": "^2.0.4",
30+
"prettier": "^2.1.1",
31+
"ts-node": "^9.0.0",
32+
"typescript": "^4.0.2"
33+
}
34+
}

backend/src/index.ts

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import express, { ErrorRequestHandler } from 'express';
2+
import bodyParser from 'body-parser';
3+
import { RegisterRoutes } from './routes';
4+
import { ValidateError } from 'tsoa';
5+
import axios from 'axios';
6+
7+
const app = express();
8+
9+
app.use((req, res, next) => {
10+
if (req.is('text/plain')) {
11+
req.body = { raw: '' };
12+
req.setEncoding('utf8');
13+
req.on('data', function (chunk) {
14+
req.body.raw += chunk;
15+
});
16+
req.on('end', next);
17+
} else {
18+
next();
19+
}
20+
});
21+
22+
app.use(
23+
bodyParser.urlencoded({
24+
extended: true,
25+
})
26+
);
27+
app.use(bodyParser.json());
28+
29+
RegisterRoutes(app);
30+
31+
const errorRequestHandler: ErrorRequestHandler = (err, req, res, next) => {
32+
if (req.url.startsWith('/api/')) {
33+
if (err instanceof ValidateError) {
34+
res.status(400).send(err);
35+
} else {
36+
console.log(`ERROR: ${req.method} ${req.url}:`, err);
37+
res.status(500).send(err + '');
38+
}
39+
} else {
40+
next(err);
41+
}
42+
};
43+
44+
app.use(errorRequestHandler);
45+
46+
const port = process.env.PORT || 8080;
47+
48+
app.listen(port, () => {
49+
console.log(`Example app listening at http://localhost:${port}`);
50+
if (process.env.DO_AXIOS) {
51+
console.log('init match');
52+
axios.post(`http://localhost:${port}/api/matches`, {
53+
id: '1',
54+
mapPool: ['de_dust2'],
55+
team1: {
56+
id: '1',
57+
name: 'team1',
58+
},
59+
team2: {
60+
id: '2',
61+
name: 'team2',
62+
},
63+
electionSteps: [
64+
{
65+
map: {
66+
mode: 'PICK',
67+
who: 'TEAM_1',
68+
},
69+
side: {
70+
mode: 'PICK',
71+
who: 'TEAM_1',
72+
},
73+
},
74+
],
75+
gameServer: {
76+
ip: 'localhost',
77+
port: 27016,
78+
rconPassword: 'blob',
79+
},
80+
rconInit: ['sv_password 123'],
81+
rconConfig: ['say config loaded'],
82+
rconEnd: ['thx for travelling with deutsche bahn'],
83+
}); //.then(data => console.log("data", data));
84+
}
85+
});

backend/src/match/commands.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
export enum ECommand {
2+
BAN = 'BAN',
3+
PICK = 'PICK',
4+
AGREE = 'AGREE',
5+
CT = 'CT',
6+
T = 'T',
7+
READY = 'READY',
8+
UNREADY = 'UNREADY',
9+
PAUSE = 'PAUSE',
10+
HELP = 'HELP',
11+
FULL_HELP = 'FULL_HELP',
12+
STAY = 'STAY',
13+
SWITCH = 'SWITCH',
14+
TEAM = 'TEAM',
15+
RESTART = 'RESTART', // knife
16+
}
17+
18+
export const commandMapping = new Map<string, ECommand>();
19+
20+
commandMapping.set('ban', ECommand.BAN);
21+
commandMapping.set('pick', ECommand.PICK);
22+
commandMapping.set('agree', ECommand.AGREE);
23+
commandMapping.set('map', ECommand.AGREE);
24+
commandMapping.set('ct', ECommand.CT);
25+
commandMapping.set('t', ECommand.T);
26+
commandMapping.set('ready', ECommand.READY);
27+
commandMapping.set('rdy', ECommand.READY);
28+
commandMapping.set('unpause', ECommand.READY);
29+
commandMapping.set('unready', ECommand.UNREADY);
30+
commandMapping.set('unrdy', ECommand.UNREADY);
31+
commandMapping.set('pause', ECommand.PAUSE);
32+
commandMapping.set('help', ECommand.HELP);
33+
commandMapping.set('fullhelp', ECommand.FULL_HELP);
34+
commandMapping.set('stay', ECommand.STAY);
35+
commandMapping.set('switch', ECommand.SWITCH);
36+
commandMapping.set('swap', ECommand.SWITCH);
37+
commandMapping.set('team', ECommand.TEAM);
38+
commandMapping.set('restart', ECommand.RESTART);
39+
40+
export function getCommands(internal: ECommand) {
41+
const commands: string[] = [];
42+
commandMapping.forEach((int, command) => {
43+
if (int === internal) {
44+
commands.push(command);
45+
}
46+
});
47+
return commands;
48+
}

0 commit comments

Comments
 (0)