remove guid, reduce latency (gets stuck sometimes tho)
This commit is contained in:
parent
6bc6a039bd
commit
7044ffda79
|
@ -1,56 +1,38 @@
|
||||||
import {useCallback, useState} from 'react';
|
|
||||||
import ClientScreen from './ClientScreen';
|
import ClientScreen from './ClientScreen';
|
||||||
import Controls from './Controls.tsx';
|
import Controls from './Controls.tsx';
|
||||||
import JoinForm from './JoinForm.tsx';
|
import JoinForm from './JoinForm.tsx';
|
||||||
import PlayerInfo from './PlayerInfo.tsx';
|
import PlayerInfo from './PlayerInfo.tsx';
|
||||||
import {useStoredObjectState} from './useStoredState.ts';
|
import Column from './components/Column.tsx';
|
||||||
import {NameId, postPlayer} from './serverCalls.tsx';
|
import Row from './components/Row.tsx';
|
||||||
import Column from "./components/Column.tsx";
|
import Scoreboard from './Scoreboard.tsx';
|
||||||
import Row from "./components/Row.tsx";
|
import Button from './components/Button.tsx';
|
||||||
import Scoreboard from "./Scoreboard.tsx";
|
|
||||||
import Button from "./components/Button.tsx";
|
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import {getRandomTheme, useStoredTheme} from "./theme.ts";
|
import {getRandomTheme, useStoredTheme} from './theme.ts';
|
||||||
import {EmptyGuid} from "./Guid.ts";
|
import {useState} from 'react';
|
||||||
|
|
||||||
const getNewNameId = () => ({
|
|
||||||
id: EmptyGuid,
|
|
||||||
name: ''
|
|
||||||
});
|
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [theme, setTheme] = useStoredTheme();
|
const [theme, setTheme] = useStoredTheme();
|
||||||
const [nameId, setNameId] = useStoredObjectState<NameId>('access', getNewNameId);
|
const [name, setName] = useState<string | null>(null);
|
||||||
|
|
||||||
const [isLoggedIn, setLoggedIn] = useState<boolean>(false);
|
return <Column className="flex-grow">
|
||||||
const logout = () => setLoggedIn(false);
|
|
||||||
|
|
||||||
useCallback(async () => {
|
<ClientScreen theme={theme} player={name}/>
|
||||||
if (isLoggedIn)
|
|
||||||
return;
|
|
||||||
const result = await postPlayer(nameId);
|
|
||||||
setLoggedIn(result.ok);
|
|
||||||
}, [nameId, isLoggedIn])();
|
|
||||||
|
|
||||||
return <Column className='flex-grow'>
|
|
||||||
|
|
||||||
<ClientScreen logout={logout} theme={theme} playerId={nameId.id}/>
|
|
||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<h1 className='flex-grow'>CCCB-Tanks!</h1>
|
<h1 className="flex-grow">CCCB-Tanks!</h1>
|
||||||
<Button text='change colors' onClick={() => setTheme(_ => getRandomTheme())}/>
|
<Button text="change colors" onClick={() => setTheme(_ => getRandomTheme())}/>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => window.open('https://github.com/kaesaecracker/cccb-tanks-cs', '_blank')?.focus()}
|
onClick={() => window.open('https://github.com/kaesaecracker/cccb-tanks-cs', '_blank')?.focus()}
|
||||||
text='GitHub'/>
|
text="GitHub"/>
|
||||||
{nameId.name !== '' &&
|
{name !== '' &&
|
||||||
<Button onClick={() => setNameId(getNewNameId)} text='logout'/>}
|
<Button onClick={() => setName(_ => '')} text="logout"/>}
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
{nameId.name === '' && <JoinForm setNameId={setNameId} clientId={nameId.id}/>}
|
{name || <JoinForm onDone={name => setName(_ => name)}/>}
|
||||||
|
|
||||||
<Row className='GadgetRows'>
|
<Row className="GadgetRows">
|
||||||
{isLoggedIn && <Controls playerId={nameId.id}/>}
|
{name && <Controls player={name}/>}
|
||||||
{isLoggedIn && <PlayerInfo playerId={nameId.id}/>}
|
{name && <PlayerInfo player={name}/>}
|
||||||
<Scoreboard/>
|
<Scoreboard/>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import useWebSocket from 'react-use-websocket';
|
||||||
import {useEffect, useRef} from 'react';
|
import {useEffect, useRef} from 'react';
|
||||||
import './ClientScreen.css';
|
import './ClientScreen.css';
|
||||||
import {hslToString, Theme} from "./theme.ts";
|
import {hslToString, Theme} from "./theme.ts";
|
||||||
import {Guid} from "./Guid.ts";
|
|
||||||
import {makeApiUrl} from './serverCalls.tsx';
|
import {makeApiUrl} from './serverCalls.tsx';
|
||||||
|
|
||||||
const pixelsPerRow = 352;
|
const pixelsPerRow = 352;
|
||||||
|
@ -98,23 +97,21 @@ function drawPixelsToCanvas(
|
||||||
context.putImageData(imageData, 0, 0);
|
context.putImageData(imageData, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ClientScreen({logout, theme, playerId}: {
|
export default function ClientScreen({theme, player}: {
|
||||||
logout: () => void,
|
|
||||||
theme: Theme,
|
theme: Theme,
|
||||||
playerId?: Guid
|
player: string | null
|
||||||
}) {
|
}) {
|
||||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
|
|
||||||
const url = makeApiUrl('/screen', 'ws');
|
const url = makeApiUrl('/screen', 'ws');
|
||||||
if (playerId)
|
if (player && player !== '')
|
||||||
url.searchParams.set('player', playerId);
|
url.searchParams.set('playerName', player);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
lastMessage,
|
lastMessage,
|
||||||
sendMessage,
|
sendMessage,
|
||||||
getWebSocket
|
getWebSocket
|
||||||
} = useWebSocket(url.toString(), {
|
} = useWebSocket(url.toString(), {
|
||||||
onError: logout,
|
|
||||||
shouldReconnect: () => true,
|
shouldReconnect: () => true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import './Controls.css';
|
import './Controls.css';
|
||||||
import useWebSocket, {ReadyState} from 'react-use-websocket';
|
import useWebSocket, {ReadyState} from 'react-use-websocket';
|
||||||
import {useEffect} from 'react';
|
import {useEffect} from 'react';
|
||||||
import {Guid} from "./Guid.ts";
|
|
||||||
import {makeApiUrl} from './serverCalls.tsx';
|
import {makeApiUrl} from './serverCalls.tsx';
|
||||||
|
|
||||||
export default function Controls({playerId}: { playerId: Guid }) {
|
export default function Controls({player}: { player: string }) {
|
||||||
const url = makeApiUrl('/controls', 'ws');
|
const url = makeApiUrl('/controls', 'ws');
|
||||||
url.searchParams.set('playerId', playerId);
|
url.searchParams.set('playerName', player);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
sendMessage,
|
sendMessage,
|
||||||
|
@ -62,17 +61,17 @@ export default function Controls({playerId}: { playerId: Guid }) {
|
||||||
}, [readyState]);
|
}, [readyState]);
|
||||||
|
|
||||||
return <div className="Controls flex-row">
|
return <div className="Controls flex-row">
|
||||||
<div className='flex-column Controls-Container'>
|
<div className="flex-column Controls-Container">
|
||||||
<h3>Move</h3>
|
<h3>Move</h3>
|
||||||
<kbd>▲</kbd>
|
<kbd>▲</kbd>
|
||||||
<div className='flex-row Controls-Container'>
|
<div className="flex-row Controls-Container">
|
||||||
<kbd>◄</kbd>
|
<kbd>◄</kbd>
|
||||||
<kbd>▼</kbd>
|
<kbd>▼</kbd>
|
||||||
<kbd>►</kbd>
|
<kbd>►</kbd>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='flex-column Controls-Container'>
|
<div className="flex-column Controls-Container">
|
||||||
<h3>Fire</h3>
|
<h3>Fire</h3>
|
||||||
<kbd className="space">Space</kbd>
|
<kbd className="space">Space</kbd>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
import {useEffect, useState} from 'react';
|
import {useEffect, useState} from 'react';
|
||||||
import './JoinForm.css';
|
import './JoinForm.css';
|
||||||
import {NameId, Player, postPlayer} from './serverCalls';
|
import {Player, postPlayer} from './serverCalls';
|
||||||
import {Guid} from './Guid.ts';
|
import Column from './components/Column.tsx';
|
||||||
import Column from "./components/Column.tsx";
|
import Button from './components/Button.tsx';
|
||||||
import Button from "./components/Button.tsx";
|
import TextInput from './components/TextInput.tsx';
|
||||||
import TextInput from "./components/TextInput.tsx";
|
|
||||||
|
|
||||||
export default function JoinForm({setNameId, clientId}: {
|
export default function JoinForm({onDone}: {
|
||||||
setNameId: (mutator: (oldState: NameId) => NameId) => void,
|
onDone: (name: string) => void;
|
||||||
clientId: Guid
|
|
||||||
}) {
|
}) {
|
||||||
const [clicked, setClicked] = useState(false);
|
const [clicked, setClicked] = useState(false);
|
||||||
const [data, setData] = useState<Player | null>(null);
|
const [data, setData] = useState<Player | null>(null);
|
||||||
|
@ -18,10 +16,9 @@ export default function JoinForm({setNameId, clientId}: {
|
||||||
if (!clicked || data)
|
if (!clicked || data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
postPlayer({name, id: clientId})
|
postPlayer(name).then(response => {
|
||||||
.then(response => {
|
|
||||||
if (response.ok && response.successResult) {
|
if (response.ok && response.successResult) {
|
||||||
setNameId(_ => response.successResult!);
|
onDone(response.successResult!.trim());
|
||||||
setErrorText(null);
|
setErrorText(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -33,13 +30,13 @@ export default function JoinForm({setNameId, clientId}: {
|
||||||
|
|
||||||
setClicked(false);
|
setClicked(false);
|
||||||
});
|
});
|
||||||
}, [clicked, setData, data, clientId, setClicked, setNameId, errorText]);
|
}, [clicked, setData, data, setClicked, onDone, errorText]);
|
||||||
|
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
const disableButtons = clicked || name.trim() === '';
|
const disableButtons = clicked || name.trim() === '';
|
||||||
const setClickedTrue = () => setClicked(true);
|
const setClickedTrue = () => setClicked(true);
|
||||||
|
|
||||||
return <Column className='JoinForm'>
|
return <Column className="JoinForm">
|
||||||
<h3> Enter your name to play </h3>
|
<h3> Enter your name to play </h3>
|
||||||
<TextInput
|
<TextInput
|
||||||
value={name}
|
value={name}
|
||||||
|
@ -50,7 +47,7 @@ export default function JoinForm({setNameId, clientId}: {
|
||||||
<Button
|
<Button
|
||||||
onClick={setClickedTrue}
|
onClick={setClickedTrue}
|
||||||
disabled={disableButtons}
|
disabled={disableButtons}
|
||||||
text='INSERT COIN'/>
|
text="INSERT COIN"/>
|
||||||
{errorText && <p>{errorText}</p>}
|
{errorText && <p>{errorText}</p>}
|
||||||
</Column>;
|
</Column>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import {makeApiUrl, Scores} from './serverCalls';
|
import {makeApiUrl, Scores} from './serverCalls';
|
||||||
import {Guid} from './Guid.ts';
|
|
||||||
import Column from './components/Column.tsx';
|
import Column from './components/Column.tsx';
|
||||||
import useWebSocket, {ReadyState} from 'react-use-websocket';
|
import useWebSocket, {ReadyState} from 'react-use-websocket';
|
||||||
import {useEffect, useState} from 'react';
|
import {useEffect, useState} from 'react';
|
||||||
|
@ -37,11 +36,11 @@ type PlayerInfoMessage = {
|
||||||
readonly tank?: TankInfo;
|
readonly tank?: TankInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PlayerInfo({playerId}: { playerId: Guid }) {
|
export default function PlayerInfo({player}: { player: string }) {
|
||||||
const [shouldSendMessage, setShouldSendMessage] = useState(false);
|
const [shouldSendMessage, setShouldSendMessage] = useState(false);
|
||||||
|
|
||||||
const url = makeApiUrl('/player');
|
const url = makeApiUrl('/player');
|
||||||
url.searchParams.set('id', playerId);
|
url.searchParams.set('name', player);
|
||||||
|
|
||||||
const {lastJsonMessage, readyState, sendMessage} = useWebSocket<PlayerInfoMessage>(url.toString(), {
|
const {lastJsonMessage, readyState, sendMessage} = useWebSocket<PlayerInfoMessage>(url.toString(), {
|
||||||
onMessage: () => setShouldSendMessage(true),
|
onMessage: () => setShouldSendMessage(true),
|
||||||
|
|
|
@ -54,8 +54,6 @@ export default function DataTable<T>({data, columns, className}: {
|
||||||
|
|
||||||
dataToDisplay.sort(actualSorter)
|
dataToDisplay.sort(actualSorter)
|
||||||
|
|
||||||
console.log('sorted', {dataToDisplay});
|
|
||||||
|
|
||||||
return <div className={'DataTable ' + (className ?? '')}>
|
return <div className={'DataTable ' + (className ?? '')}>
|
||||||
<table>
|
<table>
|
||||||
<thead className='DataTableHead'>
|
<thead className='DataTableHead'>
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import {Guid} from './Guid.ts';
|
|
||||||
|
|
||||||
export function makeApiUrl(path: string, protocol: 'http' | 'ws' = 'http') {
|
export function makeApiUrl(path: string, protocol: 'http' | 'ws' = 'http') {
|
||||||
return new URL(`${protocol}://${window.location.hostname}${path}`);
|
return new URL(`${protocol}://${window.location.hostname}${path}`);
|
||||||
}
|
}
|
||||||
|
@ -22,15 +20,9 @@ export type Scores = {
|
||||||
|
|
||||||
export type Player = {
|
export type Player = {
|
||||||
readonly name: string;
|
readonly name: string;
|
||||||
readonly id: Guid;
|
|
||||||
readonly scores: Scores;
|
readonly scores: Scores;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NameId = {
|
|
||||||
name: string,
|
|
||||||
id: Guid
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function fetchTyped<T>({url, method}: { url: URL; method: string; }): Promise<ServerResponse<T>> {
|
export async function fetchTyped<T>({url, method}: { url: URL; method: string; }): Promise<ServerResponse<T>> {
|
||||||
const response = await fetch(url, {method});
|
const response = await fetch(url, {method});
|
||||||
const result: ServerResponse<T> = {
|
const result: ServerResponse<T> = {
|
||||||
|
@ -46,10 +38,9 @@ export async function fetchTyped<T>({url, method}: { url: URL; method: string; }
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function postPlayer({name, id}: NameId) {
|
export function postPlayer(name: string) {
|
||||||
const url = makeApiUrl('/player');
|
const url = makeApiUrl('/player');
|
||||||
url.searchParams.set('name', name);
|
url.searchParams.set('name', name);
|
||||||
url.searchParams.set('id', id);
|
|
||||||
|
|
||||||
return fetchTyped<NameId>({url, method: 'POST'});
|
return fetchTyped<string>({url, method: 'POST'});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,85 +1,87 @@
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using TanksServer.GameLogic;
|
using TanksServer.GameLogic;
|
||||||
using TanksServer.Interactivity;
|
using TanksServer.Interactivity;
|
||||||
|
|
||||||
namespace TanksServer;
|
namespace TanksServer;
|
||||||
|
|
||||||
internal static class Endpoints
|
internal sealed class Endpoints(
|
||||||
|
ClientScreenServer clientScreenServer,
|
||||||
|
PlayerServer playerService,
|
||||||
|
ControlsServer controlsServer,
|
||||||
|
MapService mapService
|
||||||
|
)
|
||||||
{
|
{
|
||||||
public static void MapEndpoints(WebApplication app)
|
public void Map(WebApplication app)
|
||||||
{
|
{
|
||||||
var clientScreenServer = app.Services.GetRequiredService<ClientScreenServer>();
|
app.MapPost("/player", PostPlayer);
|
||||||
var playerService = app.Services.GetRequiredService<PlayerServer>();
|
app.MapGet("/player", GetPlayerAsync);
|
||||||
var controlsServer = app.Services.GetRequiredService<ControlsServer>();
|
app.MapGet("/scores", () => playerService.GetAll() as IEnumerable<Player>);
|
||||||
var mapService = app.Services.GetRequiredService<MapService>();
|
app.Map("/screen", ConnectScreenAsync);
|
||||||
|
app.Map("/controls", ConnectControlsAsync);
|
||||||
|
app.MapGet("/map", () => mapService.MapNames);
|
||||||
|
app.MapPost("/map", PostMap);
|
||||||
|
}
|
||||||
|
|
||||||
app.MapPost("/player", (string name, Guid? id) =>
|
private Results<BadRequest<string>, NotFound<string>, Ok> PostMap([FromQuery] string name)
|
||||||
{
|
{
|
||||||
name = name.Trim().ToUpperInvariant();
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
if (name == string.Empty)
|
return TypedResults.BadRequest("invalid map name");
|
||||||
return Results.BadRequest("name cannot be blank");
|
if (!mapService.TrySwitchTo(name))
|
||||||
if (name.Length > 12)
|
return TypedResults.NotFound("map with name not found");
|
||||||
return Results.BadRequest("name too long");
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
if (!id.HasValue || id.Value == Guid.Empty)
|
private async Task<Results<BadRequest, NotFound, EmptyHttpResult>> ConnectControlsAsync(HttpContext context,
|
||||||
id = Guid.NewGuid();
|
[FromQuery] string playerName)
|
||||||
|
|
||||||
var player = playerService.GetOrAdd(name, id.Value);
|
|
||||||
return player != null
|
|
||||||
? Results.Ok(new NameId(player.Name, player.Id))
|
|
||||||
: Results.Unauthorized();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/player", async (HttpContext context, [FromQuery] Guid id) =>
|
|
||||||
{
|
|
||||||
if (!playerService.TryGet(id, out var foundPlayer))
|
|
||||||
return Results.NotFound();
|
|
||||||
|
|
||||||
if (!context.WebSockets.IsWebSocketRequest)
|
|
||||||
return Results.Ok((object?)foundPlayer);
|
|
||||||
|
|
||||||
using var ws = await context.WebSockets.AcceptWebSocketAsync();
|
|
||||||
await playerService.HandleClientAsync(ws, foundPlayer);
|
|
||||||
return Results.Empty;
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/scores", () => playerService.GetAll());
|
|
||||||
|
|
||||||
app.Map("/screen", async (HttpContext context, [FromQuery] Guid? player) =>
|
|
||||||
{
|
{
|
||||||
if (!context.WebSockets.IsWebSocketRequest)
|
if (!context.WebSockets.IsWebSocketRequest)
|
||||||
return Results.BadRequest();
|
return TypedResults.BadRequest();
|
||||||
|
|
||||||
using var ws = await context.WebSockets.AcceptWebSocketAsync();
|
if (!playerService.TryGet(playerName, out var player))
|
||||||
await clientScreenServer.HandleClientAsync(ws, player);
|
return TypedResults.NotFound();
|
||||||
return Results.Empty;
|
|
||||||
});
|
|
||||||
|
|
||||||
app.Map("/controls", async (HttpContext context, [FromQuery] Guid playerId) =>
|
|
||||||
{
|
|
||||||
if (!context.WebSockets.IsWebSocketRequest)
|
|
||||||
return Results.BadRequest();
|
|
||||||
|
|
||||||
if (!playerService.TryGet(playerId, out var player))
|
|
||||||
return Results.NotFound();
|
|
||||||
|
|
||||||
using var ws = await context.WebSockets.AcceptWebSocketAsync();
|
using var ws = await context.WebSockets.AcceptWebSocketAsync();
|
||||||
await controlsServer.HandleClientAsync(ws, player);
|
await controlsServer.HandleClientAsync(ws, player);
|
||||||
return Results.Empty;
|
return TypedResults.Empty;
|
||||||
});
|
}
|
||||||
|
|
||||||
app.MapGet("/map", () => mapService.MapNames);
|
private async Task<Results<BadRequest, EmptyHttpResult>> ConnectScreenAsync(HttpContext context,
|
||||||
|
[FromQuery] string? playerName)
|
||||||
app.MapPost("/map", ([FromQuery] string name) =>
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(name))
|
if (!context.WebSockets.IsWebSocketRequest)
|
||||||
return Results.BadRequest("invalid map name");
|
return TypedResults.BadRequest();
|
||||||
if (!mapService.TrySwitchTo(name))
|
|
||||||
return Results.NotFound("map with name not found");
|
using var ws = await context.WebSockets.AcceptWebSocketAsync();
|
||||||
return Results.Ok();
|
await clientScreenServer.HandleClientAsync(ws, playerName);
|
||||||
});
|
return TypedResults.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<Results<NotFound, Ok<Player>, EmptyHttpResult>> GetPlayerAsync(HttpContext context,
|
||||||
|
[FromQuery] string name)
|
||||||
|
{
|
||||||
|
if (!playerService.TryGet(name, out var foundPlayer))
|
||||||
|
return TypedResults.NotFound();
|
||||||
|
|
||||||
|
if (!context.WebSockets.IsWebSocketRequest)
|
||||||
|
return TypedResults.Ok(foundPlayer);
|
||||||
|
|
||||||
|
using var ws = await context.WebSockets.AcceptWebSocketAsync();
|
||||||
|
await playerService.HandleClientAsync(ws, foundPlayer);
|
||||||
|
return TypedResults.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Results<BadRequest<string>, Ok<string>, UnauthorizedHttpResult> PostPlayer([FromQuery] string name)
|
||||||
|
{
|
||||||
|
name = name.Trim().ToUpperInvariant();
|
||||||
|
if (name == string.Empty) return TypedResults.BadRequest("name cannot be blank");
|
||||||
|
if (name.Length > 12) return TypedResults.BadRequest("name too long");
|
||||||
|
|
||||||
|
var player = playerService.GetOrAdd(name);
|
||||||
|
return player != null
|
||||||
|
? TypedResults.Ok(player.Name)
|
||||||
|
: TypedResults.Unauthorized();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ internal sealed class MapEntityManager(
|
||||||
Rotation = Random.Shared.NextDouble()
|
Rotation = Random.Shared.NextDouble()
|
||||||
};
|
};
|
||||||
_playerTanks[player] = tank;
|
_playerTanks[player] = tank;
|
||||||
logger.LogInformation("Tank added for player {}", player.Id);
|
logger.LogInformation("Tank added for player {}", player.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SpawnPowerUp() => _powerUps.Add(new PowerUp(ChooseSpawnPosition()));
|
public void SpawnPowerUp() => _powerUps.Add(new PowerUp(ChooseSpawnPosition()));
|
||||||
|
@ -44,7 +44,7 @@ internal sealed class MapEntityManager(
|
||||||
|
|
||||||
public void Remove(Tank tank)
|
public void Remove(Tank tank)
|
||||||
{
|
{
|
||||||
logger.LogInformation("Tank removed for player {}", tank.Owner.Id);
|
logger.LogInformation("Tank removed for player {}", tank.Owner.Name);
|
||||||
_playerTanks.Remove(tank.Owner);
|
_playerTanks.Remove(tank.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,27 +8,26 @@ internal sealed class GeneratePixelsTickStep(
|
||||||
IEnumerable<IFrameConsumer> consumers
|
IEnumerable<IFrameConsumer> consumers
|
||||||
) : ITickStep
|
) : ITickStep
|
||||||
{
|
{
|
||||||
|
private readonly GamePixelGrid _gamePixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
||||||
private readonly List<IDrawStep> _drawSteps = drawSteps.ToList();
|
private readonly List<IDrawStep> _drawSteps = drawSteps.ToList();
|
||||||
private readonly List<IFrameConsumer> _consumers = consumers.ToList();
|
private readonly List<IFrameConsumer> _consumers = consumers.ToList();
|
||||||
|
|
||||||
private readonly PixelGrid _observerPixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
|
||||||
private readonly GamePixelGrid _gamePixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
|
||||||
|
|
||||||
public async Task TickAsync(TimeSpan _)
|
public async Task TickAsync(TimeSpan _)
|
||||||
{
|
{
|
||||||
|
PixelGrid observerPixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
||||||
|
|
||||||
_gamePixelGrid.Clear();
|
_gamePixelGrid.Clear();
|
||||||
foreach (var step in _drawSteps)
|
foreach (var step in _drawSteps)
|
||||||
step.Draw(_gamePixelGrid);
|
step.Draw(_gamePixelGrid);
|
||||||
|
|
||||||
_observerPixelGrid.Clear();
|
|
||||||
for (var y = 0; y < MapService.PixelsPerColumn; y++)
|
for (var y = 0; y < MapService.PixelsPerColumn; y++)
|
||||||
for (var x = 0; x < MapService.PixelsPerRow; x++)
|
for (var x = 0; x < MapService.PixelsPerRow; x++)
|
||||||
{
|
{
|
||||||
if (_gamePixelGrid[x, y].EntityType.HasValue)
|
if (_gamePixelGrid[x, y].EntityType.HasValue)
|
||||||
_observerPixelGrid[(ushort)x, (ushort)y] = true;
|
observerPixelGrid[(ushort)x, (ushort)y] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var consumer in _consumers)
|
foreach (var consumer in _consumers)
|
||||||
await consumer.OnFrameDoneAsync(_gamePixelGrid, _observerPixelGrid);
|
await consumer.OnFrameDoneAsync(_gamePixelGrid, observerPixelGrid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,31 @@ internal sealed class ByteChannelWebSocket(WebSocket socket, ILogger logger, int
|
||||||
{
|
{
|
||||||
private readonly byte[] _buffer = new byte[messageSize];
|
private readonly byte[] _buffer = new byte[messageSize];
|
||||||
|
|
||||||
public ValueTask SendBinaryAsync(ReadOnlyMemory<byte> data, bool endOfMessage = true) =>
|
public async ValueTask SendBinaryAsync(ReadOnlyMemory<byte> data, bool endOfMessage = true)
|
||||||
socket.SendAsync(data, WebSocketMessageType.Binary, endOfMessage, CancellationToken.None);
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await socket.SendAsync(data, WebSocketMessageType.Binary, endOfMessage, CancellationToken.None);
|
||||||
|
}
|
||||||
|
catch (WebSocketException e)
|
||||||
|
{
|
||||||
|
logger.LogError(e, "could not send binary message");
|
||||||
|
await CloseAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ValueTask SendTextAsync(ReadOnlyMemory<byte> data, bool endOfMessage = true) =>
|
public async ValueTask SendTextAsync(ReadOnlyMemory<byte> data, bool endOfMessage = true)
|
||||||
socket.SendAsync(data, WebSocketMessageType.Text, endOfMessage, CancellationToken.None);
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await socket.SendAsync(data, WebSocketMessageType.Text, endOfMessage, CancellationToken.None);
|
||||||
|
}
|
||||||
|
catch (WebSocketException e)
|
||||||
|
{
|
||||||
|
logger.LogError(e, "could not send text message");
|
||||||
|
await CloseAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async IAsyncEnumerable<Memory<byte>> ReadAllAsync()
|
public async IAsyncEnumerable<Memory<byte>> ReadAllAsync()
|
||||||
{
|
{
|
||||||
|
@ -25,9 +45,12 @@ internal sealed class ByteChannelWebSocket(WebSocket socket, ILogger logger, int
|
||||||
Debugger.Break();
|
Debugger.Break();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task CloseWithErrorAsync(string error)
|
||||||
|
=> socket.CloseOutputAsync(WebSocketCloseStatus.InternalServerError, error, CancellationToken.None);
|
||||||
|
|
||||||
public async Task CloseAsync()
|
public async Task CloseAsync()
|
||||||
{
|
{
|
||||||
if (socket.State != WebSocketState.Open)
|
if (socket.State is not WebSocketState.Open and not WebSocketState.CloseReceived)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -6,20 +6,16 @@ namespace TanksServer.Interactivity;
|
||||||
|
|
||||||
internal sealed class ClientScreenServer(
|
internal sealed class ClientScreenServer(
|
||||||
ILogger<ClientScreenServer> logger,
|
ILogger<ClientScreenServer> logger,
|
||||||
ILoggerFactory loggerFactory,
|
ILoggerFactory loggerFactory
|
||||||
IOptions<HostConfiguration> hostConfig
|
|
||||||
) : WebsocketServer<ClientScreenServerConnection>(logger), IFrameConsumer
|
) : WebsocketServer<ClientScreenServerConnection>(logger), IFrameConsumer
|
||||||
{
|
{
|
||||||
private readonly TimeSpan _minFrameTime = TimeSpan.FromMilliseconds(hostConfig.Value.ClientDisplayMinFrameTimeMs);
|
public Task HandleClientAsync(WebSocket socket, string? player)
|
||||||
|
|
||||||
public Task HandleClientAsync(WebSocket socket, Guid? playerGuid)
|
|
||||||
=> base.HandleClientAsync(new(
|
=> base.HandleClientAsync(new(
|
||||||
socket,
|
socket,
|
||||||
loggerFactory.CreateLogger<ClientScreenServerConnection>(),
|
loggerFactory.CreateLogger<ClientScreenServerConnection>(),
|
||||||
_minFrameTime,
|
player
|
||||||
playerGuid
|
|
||||||
));
|
));
|
||||||
|
|
||||||
public Task OnFrameDoneAsync(GamePixelGrid gamePixelGrid, PixelGrid observerPixels)
|
public Task OnFrameDoneAsync(GamePixelGrid gamePixelGrid, PixelGrid observerPixels)
|
||||||
=> ParallelForEachConnectionAsync(c => c.SendAsync(observerPixels, gamePixelGrid));
|
=> ParallelForEachConnectionAsync(c => c.OnGameTickAsync(observerPixels, gamePixelGrid).AsTask());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using DisplayCommands;
|
using DisplayCommands;
|
||||||
using TanksServer.Graphics;
|
using TanksServer.Graphics;
|
||||||
|
@ -8,40 +7,88 @@ namespace TanksServer.Interactivity;
|
||||||
internal sealed class ClientScreenServerConnection(
|
internal sealed class ClientScreenServerConnection(
|
||||||
WebSocket webSocket,
|
WebSocket webSocket,
|
||||||
ILogger<ClientScreenServerConnection> logger,
|
ILogger<ClientScreenServerConnection> logger,
|
||||||
TimeSpan minFrameTime,
|
string? playerName = null
|
||||||
Guid? playerGuid = null
|
|
||||||
) : WebsocketServerConnection(logger, new ByteChannelWebSocket(webSocket, logger, 0)),
|
) : WebsocketServerConnection(logger, new ByteChannelWebSocket(webSocket, logger, 0)),
|
||||||
IDisposable
|
IDisposable
|
||||||
{
|
{
|
||||||
private readonly SemaphoreSlim _wantedFrames = new(1);
|
private readonly SemaphoreSlim _wantedFramesOnTick = new(0, 2);
|
||||||
private readonly PlayerScreenData? _playerScreenData = playerGuid.HasValue ? new PlayerScreenData(logger) : null;
|
private readonly SemaphoreSlim _mutex = new(1);
|
||||||
private DateTime _nextFrameAfter = DateTime.Now;
|
|
||||||
|
|
||||||
public void Dispose() => _wantedFrames.Dispose();
|
private PixelGrid? _lastSentPixels = null;
|
||||||
|
private PixelGrid? _nextPixels = null;
|
||||||
|
private readonly PlayerScreenData? _nextPlayerData = playerName != null ? new PlayerScreenData(logger) : null;
|
||||||
|
|
||||||
public async Task SendAsync(PixelGrid pixels, GamePixelGrid gamePixelGrid)
|
protected override async ValueTask HandleMessageAsync(Memory<byte> _)
|
||||||
{
|
{
|
||||||
if (_nextFrameAfter > DateTime.Now)
|
await _mutex.WaitAsync();
|
||||||
return;
|
try
|
||||||
|
|
||||||
if (!await _wantedFrames.WaitAsync(TimeSpan.Zero))
|
|
||||||
{
|
{
|
||||||
Logger.LogTrace("client does not want a frame yet");
|
if (_nextPixels == null)
|
||||||
|
{
|
||||||
|
_wantedFramesOnTick.Release();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_nextFrameAfter = DateTime.Today + minFrameTime;
|
_lastSentPixels = _nextPixels;
|
||||||
|
_nextPixels = null;
|
||||||
|
await SendNowAsync(_lastSentPixels);
|
||||||
|
}
|
||||||
|
catch (SemaphoreFullException)
|
||||||
|
{
|
||||||
|
logger.LogWarning("ignoring request for more frames");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_mutex.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (_playerScreenData != null)
|
public async ValueTask OnGameTickAsync(PixelGrid pixels, GamePixelGrid gamePixelGrid)
|
||||||
RefreshPlayerSpecificData(gamePixelGrid);
|
{
|
||||||
|
await _mutex.WaitAsync();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (pixels == _lastSentPixels)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_nextPlayerData != null)
|
||||||
|
{
|
||||||
|
_nextPlayerData.Clear();
|
||||||
|
foreach (var gamePixel in gamePixelGrid)
|
||||||
|
{
|
||||||
|
if (!gamePixel.EntityType.HasValue)
|
||||||
|
continue;
|
||||||
|
_nextPlayerData.Add(gamePixel.EntityType.Value, gamePixel.BelongsTo?.Name == playerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var sendImmediately = await _wantedFramesOnTick.WaitAsync(TimeSpan.Zero);
|
||||||
|
if (sendImmediately)
|
||||||
|
{
|
||||||
|
await SendNowAsync(pixels);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_wantedFramesOnTick.Release();
|
||||||
|
_nextPixels = pixels;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_mutex.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async ValueTask SendNowAsync(PixelGrid pixels)
|
||||||
|
{
|
||||||
Logger.LogTrace("sending");
|
Logger.LogTrace("sending");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Logger.LogTrace("sending {} bytes of pixel data", pixels.Data.Length);
|
Logger.LogTrace("sending {} bytes of pixel data", pixels.Data.Length);
|
||||||
await Socket.SendBinaryAsync(pixels.Data, _playerScreenData == null);
|
await Socket.SendBinaryAsync(pixels.Data, _nextPlayerData == null);
|
||||||
if (_playerScreenData != null)
|
if (_nextPlayerData != null)
|
||||||
await Socket.SendBinaryAsync(_playerScreenData.GetPacket());
|
{
|
||||||
|
await Socket.SendBinaryAsync(_nextPlayerData.GetPacket());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (WebSocketException ex)
|
catch (WebSocketException ex)
|
||||||
{
|
{
|
||||||
|
@ -49,21 +96,5 @@ internal sealed class ClientScreenServerConnection(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshPlayerSpecificData(GamePixelGrid gamePixelGrid)
|
public void Dispose() => _wantedFramesOnTick.Dispose();
|
||||||
{
|
|
||||||
Debug.Assert(_playerScreenData != null);
|
|
||||||
_playerScreenData.Clear();
|
|
||||||
foreach (var gamePixel in gamePixelGrid)
|
|
||||||
{
|
|
||||||
if (!gamePixel.EntityType.HasValue)
|
|
||||||
continue;
|
|
||||||
_playerScreenData.Add(gamePixel.EntityType.Value, gamePixel.BelongsTo?.Id == playerGuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override ValueTask HandleMessageAsync(Memory<byte> _)
|
|
||||||
{
|
|
||||||
_wantedFrames.Release();
|
|
||||||
return ValueTask.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ internal sealed class ControlsServer(
|
||||||
{
|
{
|
||||||
public Task HandleClientAsync(WebSocket ws, Player player)
|
public Task HandleClientAsync(WebSocket ws, Player player)
|
||||||
{
|
{
|
||||||
logger.LogDebug("control client connected {}", player.Id);
|
logger.LogDebug("control client connected {}", player.Name);
|
||||||
var clientLogger = loggerFactory.CreateLogger<ControlsServerConnection>();
|
var clientLogger = loggerFactory.CreateLogger<ControlsServerConnection>();
|
||||||
var sock = new ControlsServerConnection(ws, clientLogger, player);
|
var sock = new ControlsServerConnection(ws, clientLogger, player);
|
||||||
return HandleClientAsync(sock);
|
return HandleClientAsync(sock);
|
||||||
|
|
|
@ -28,7 +28,7 @@ internal sealed class ControlsServerConnection(
|
||||||
var type = (MessageType)buffer.Span[0];
|
var type = (MessageType)buffer.Span[0];
|
||||||
var control = (InputType)buffer.Span[1];
|
var control = (InputType)buffer.Span[1];
|
||||||
|
|
||||||
Logger.LogTrace("player input {} {} {}", player.Id, type, control);
|
Logger.LogTrace("player input {} {} {}", player.Name, type, control);
|
||||||
|
|
||||||
var isEnable = type switch
|
var isEnable = type switch
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,40 +11,58 @@ internal sealed class PlayerServer(
|
||||||
MapEntityManager entityManager
|
MapEntityManager entityManager
|
||||||
) : WebsocketServer<PlayerInfoConnection>(logger), ITickStep
|
) : WebsocketServer<PlayerInfoConnection>(logger), ITickStep
|
||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<string, Player> _players = new();
|
private readonly Dictionary<string, Player> _players = [];
|
||||||
|
private readonly SemaphoreSlim _mutex = new(1, 1);
|
||||||
|
|
||||||
public Player? GetOrAdd(string name, Guid id)
|
public Player? GetOrAdd(string name)
|
||||||
{
|
{
|
||||||
var existingOrAddedPlayer = _players.GetOrAdd(name, _ => AddAndSpawn());
|
_mutex.Wait();
|
||||||
if (existingOrAddedPlayer.Id != id)
|
try
|
||||||
return null;
|
|
||||||
|
|
||||||
logger.LogInformation("player {} (re)joined", existingOrAddedPlayer.Id);
|
|
||||||
return existingOrAddedPlayer;
|
|
||||||
|
|
||||||
Player AddAndSpawn()
|
|
||||||
{
|
{
|
||||||
var newPlayer = new Player(name, id);
|
if (_players.TryGetValue(name, out var existingPlayer))
|
||||||
|
{
|
||||||
|
logger.LogInformation("player {} rejoined", existingPlayer.Name);
|
||||||
|
return existingPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
var newPlayer = new Player { Name = name };
|
||||||
|
logger.LogInformation("player {} joined", newPlayer.Name);
|
||||||
|
_players.Add(name, newPlayer);
|
||||||
tankSpawnQueue.EnqueueForImmediateSpawn(newPlayer);
|
tankSpawnQueue.EnqueueForImmediateSpawn(newPlayer);
|
||||||
return newPlayer;
|
return newPlayer;
|
||||||
}
|
}
|
||||||
}
|
finally
|
||||||
|
|
||||||
public bool TryGet(Guid? playerId, [MaybeNullWhen(false)] out Player foundPlayer)
|
|
||||||
{
|
{
|
||||||
foreach (var player in _players.Values)
|
_mutex.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGet(string name, [MaybeNullWhen(false)] out Player foundPlayer)
|
||||||
{
|
{
|
||||||
if (player.Id != playerId)
|
_mutex.Wait();
|
||||||
continue;
|
try
|
||||||
foundPlayer = player;
|
{
|
||||||
return true;
|
foundPlayer = _players.Values.FirstOrDefault(player => player.Name == name);
|
||||||
|
return foundPlayer != null;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_mutex.Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foundPlayer = null;
|
public List<Player> GetAll()
|
||||||
return false;
|
{
|
||||||
|
_mutex.Wait();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _players.Values.ToList();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_mutex.Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Player> GetAll() => _players.Values;
|
|
||||||
|
|
||||||
public Task HandleClientAsync(WebSocket webSocket, Player player)
|
public Task HandleClientAsync(WebSocket webSocket, Player player)
|
||||||
=> HandleClientAsync(new PlayerInfoConnection(player, connectionLogger, webSocket, entityManager));
|
=> HandleClientAsync(new PlayerInfoConnection(player, connectionLogger, webSocket, entityManager));
|
||||||
|
|
|
@ -5,6 +5,4 @@ public class HostConfiguration
|
||||||
public bool EnableServicePointDisplay { get; set; } = true;
|
public bool EnableServicePointDisplay { get; set; } = true;
|
||||||
|
|
||||||
public int ServicePointDisplayMinFrameTimeMs { get; set; } = 25;
|
public int ServicePointDisplayMinFrameTimeMs { get; set; } = 25;
|
||||||
|
|
||||||
public int ClientDisplayMinFrameTimeMs { get; set; } = 25;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,23 @@ using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace TanksServer.Models;
|
namespace TanksServer.Models;
|
||||||
|
|
||||||
internal sealed class Player(string name, Guid id)
|
internal sealed class Player : IEquatable<Player>
|
||||||
{
|
{
|
||||||
public string Name => name;
|
public required string Name { get; init; }
|
||||||
|
|
||||||
[JsonIgnore] public Guid Id => id;
|
|
||||||
|
|
||||||
[JsonIgnore] public PlayerControls Controls { get; } = new();
|
[JsonIgnore] public PlayerControls Controls { get; } = new();
|
||||||
|
|
||||||
public Scores Scores { get; } = new();
|
public Scores Scores { get; } = new();
|
||||||
|
|
||||||
public DateTime LastInput { get; set; } = DateTime.Now;
|
public DateTime LastInput { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
|
public override bool Equals(object? obj) => obj is Player p && Equals(p);
|
||||||
|
|
||||||
|
public bool Equals(Player? other) => other?.Name == Name;
|
||||||
|
|
||||||
|
public override int GetHashCode() => Name.GetHashCode();
|
||||||
|
|
||||||
|
public static bool operator ==(Player? left, Player? right) => Equals(left, right);
|
||||||
|
|
||||||
|
public static bool operator !=(Player? left, Player? right) => !Equals(left, right);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,11 @@ public static class Program
|
||||||
var app = Configure(args);
|
var app = Configure(args);
|
||||||
|
|
||||||
var clientFileProvider = new PhysicalFileProvider(Path.Combine(app.Environment.ContentRootPath, "client"));
|
var clientFileProvider = new PhysicalFileProvider(Path.Combine(app.Environment.ContentRootPath, "client"));
|
||||||
|
|
||||||
app.UseDefaultFiles(new DefaultFilesOptions { FileProvider = clientFileProvider });
|
app.UseDefaultFiles(new DefaultFilesOptions { FileProvider = clientFileProvider });
|
||||||
app.UseStaticFiles(new StaticFileOptions { FileProvider = clientFileProvider });
|
app.UseStaticFiles(new StaticFileOptions { FileProvider = clientFileProvider });
|
||||||
|
|
||||||
Endpoints.MapEndpoints(app);
|
app.Services.GetRequiredService<Endpoints>().Map(app);
|
||||||
|
|
||||||
await app.RunAsync();
|
await app.RunAsync();
|
||||||
}
|
}
|
||||||
|
@ -63,6 +64,7 @@ public static class Program
|
||||||
builder.Services.AddSingleton<PlayerServer>();
|
builder.Services.AddSingleton<PlayerServer>();
|
||||||
builder.Services.AddSingleton<ClientScreenServer>();
|
builder.Services.AddSingleton<ClientScreenServer>();
|
||||||
builder.Services.AddSingleton<TankSpawnQueue>();
|
builder.Services.AddSingleton<TankSpawnQueue>();
|
||||||
|
builder.Services.AddSingleton<Endpoints>();
|
||||||
|
|
||||||
builder.Services.AddHostedService<GameTickWorker>();
|
builder.Services.AddHostedService<GameTickWorker>();
|
||||||
builder.Services.AddHostedService(sp => sp.GetRequiredService<ControlsServer>());
|
builder.Services.AddHostedService(sp => sp.GetRequiredService<ControlsServer>());
|
||||||
|
|
Loading…
Reference in a new issue