tweaks, redis url

This commit is contained in:
Evert Prants 2022-11-27 16:38:51 +02:00
parent be12bb5e78
commit 8ed5d84762
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
7 changed files with 31 additions and 28 deletions

View File

@ -208,7 +208,7 @@ export class Game {
this.chat.addMessage( this.chat.addMessage(
`Welcome to Icy3D World Experiment, ${user.display_name}!`, `Welcome to Icy3D World Experiment, ${user.display_name}!`,
null, undefined,
{ {
color: '#fbff4e', color: '#fbff4e',
}, },
@ -243,7 +243,7 @@ export class Game {
const newplayer = PlayerEntity.fromUser(user, this.renderer.scene); const newplayer = PlayerEntity.fromUser(user, this.renderer.scene);
newplayer.setHeightSource(this.world); newplayer.setHeightSource(this.world);
this.chat.addMessage(`${user.display_name} has joined the game.`, null, { this.chat.addMessage(`${user.display_name} has joined the game.`, undefined, {
color: '#fbff4e', color: '#fbff4e',
}); });
this.players.push(newplayer); this.players.push(newplayer);
@ -252,7 +252,7 @@ export class Game {
this.socket.on('player.leave', (user) => { this.socket.on('player.leave', (user) => {
const findPlayer = this.players.find((item) => item.user.id === user.id); const findPlayer = this.players.find((item) => item.user.id === user.id);
if (findPlayer) { if (findPlayer) {
this.chat.addMessage(`${user.display_name} has left the game.`, null, { this.chat.addMessage(`${user.display_name} has left the game.`, undefined, {
color: '#fbff4e', color: '#fbff4e',
}); });
@ -262,21 +262,21 @@ export class Game {
} }
}); });
this.socket.on('player.list', (list: CompositePacket[]) => { this.socket.on('player.list', (list: Partial<CompositePacket>[]) => {
list.forEach((player) => { list?.forEach((player) => {
if (player.id === this.me.id) { if (player.id === this.me.id) {
return; return;
} }
const newplayer = PlayerEntity.fromUser(player, this.renderer.scene); const newplayer = PlayerEntity.fromUser(player as CompositePacket, this.renderer.scene);
newplayer.setHeightSource(this.world); newplayer.setHeightSource(this.world);
newplayer.addUncommittedChanges(player); newplayer.addUncommittedChanges(player);
this.players.push(newplayer); this.players.push(newplayer);
}); });
this.chat.addMessage( this.chat.addMessage(
`List of players: ${list.map((user) => user.display_name).join(', ')}`, `List of players: ${(list || []).map((user) => user.display_name).join(', ')}`,
null, undefined,
{ {
color: '#fbff4e', color: '#fbff4e',
}, },
@ -284,7 +284,8 @@ export class Game {
}); });
this.socket.on('player.update', (data) => { this.socket.on('player.update', (data) => {
data.forEach((item: PositionUpdatePacket) => { data.forEach((item?: PositionUpdatePacket) => {
if (!item) return;
const player = this.players.find( const player = this.players.find(
(player) => player.user.id === item.id, (player) => player.user.id === item.id,
); );
@ -327,7 +328,7 @@ export class Game {
this.socket.on('disconnect', () => { this.socket.on('disconnect', () => {
this.chat.addMessage( this.chat.addMessage(
`Disconnected from the server, reconnecting..`, `Disconnected from the server, reconnecting..`,
null, undefined,
{ {
color: '#ff0000', color: '#ff0000',
}, },
@ -402,9 +403,9 @@ export class Game {
} }
if ( if (
!( !(sender.display_name &&
sender.display_name === this.me.display_name || (sender.display_name === this.me.display_name ||
this.party.includes(sender.display_name) this.party.includes(sender.display_name))
) )
) { ) {
return; return;

View File

@ -90,11 +90,11 @@ export class CanvasUtils {
fontSize = 16, fontSize = 16,
padding = 4, padding = 4,
): { texture: CanvasTexture; width: number; height: number } { ): { texture: CanvasTexture; width: number; height: number } {
const ctx = document.createElement('canvas').getContext('2d'); const ctx = document.createElement('canvas').getContext('2d')!;
const font = `${fontSize}px${bold ? ' bold' : ''} sans`; const font = `${fontSize}px${bold ? ' bold' : ''} sans`;
const lines = Array.isArray(text) ? text : [text]; const lines = Array.isArray(text) ? text : [text];
const lineWidths = []; const lineWidths: number[] = [];
let longestLine = 0; let longestLine = 0;
// Measure the text bounds // Measure the text bounds
@ -176,7 +176,7 @@ export class CanvasUtils {
public readPixelDataRGB(image: HTMLImageElement): number[] { public readPixelDataRGB(image: HTMLImageElement): number[] {
const array = new Array(image.width * image.height); const array = new Array(image.width * image.height);
const ctx = document.createElement('canvas').getContext('2d'); const ctx = document.createElement('canvas').getContext('2d')!;
ctx.canvas.width = image.width; ctx.canvas.width = image.width;
ctx.canvas.height = image.height; ctx.canvas.height = image.height;
ctx.drawImage(image, 0, 0, image.width, image.height); ctx.drawImage(image, 0, 0, image.width, image.height);
@ -202,7 +202,7 @@ export class CanvasUtils {
scale: number, scale: number,
): number[] { ): number[] {
const array = new Array(image.width * image.height); const array = new Array(image.width * image.height);
const ctx = document.createElement('canvas').getContext('2d'); const ctx = document.createElement('canvas').getContext('2d')!;
ctx.canvas.width = image.width; ctx.canvas.width = image.width;
ctx.canvas.height = image.height; ctx.canvas.height = image.height;
ctx.drawImage(image, 0, 0, image.width, image.height); ctx.drawImage(image, 0, 0, image.width, image.height);

View File

@ -61,7 +61,7 @@ export class Chat {
this._sendFn(this._input.value); this._sendFn(this._input.value);
} }
this._input.value = null; this._input.value = '';
if (this._rehide) { if (this._rehide) {
this.hide(); this.hide();
@ -69,7 +69,7 @@ export class Chat {
} }
} else if (e.key === 'Escape') { } else if (e.key === 'Escape') {
this._input.blur(); this._input.blur();
this._input.value = null; this._input.value = '';
if (this._rehide) { if (this._rehide) {
this.hide(); this.hide();

View File

@ -88,7 +88,7 @@ export class Joystick {
} }
dispose() { dispose() {
this.element.parentElement.removeChild(this.element); this.element.parentElement?.removeChild(this.element);
} }
show() { show() {

View File

@ -54,7 +54,7 @@ export class PlayerEntity extends PonyEntity {
} }
public addChat(message: string): void { public addChat(message: string): void {
const lines = []; const lines: string[] = [];
let truncated = message; let truncated = message;
while (truncated.length > 80) { while (truncated.length > 80) {
@ -74,7 +74,7 @@ export class PlayerEntity extends PonyEntity {
}); });
this._chats.unshift(newChat); this._chats.unshift(newChat);
newChat.tag.position.set(0, 1.8 + this.nameTag.tag.scale.y + 0.15, 0.5); newChat.tag.position.set(0, 1.8 + this.nameTag!.tag.scale.y + 0.15, 0.5);
this.container.add(newChat.tag); this.container.add(newChat.tag);
if (this._chats.length > 3) { if (this._chats.length > 3) {
@ -122,13 +122,13 @@ export class PlayerEntity extends PonyEntity {
private setFromPacket(packet: FullStatePacket | PositionUpdatePacket) { private setFromPacket(packet: FullStatePacket | PositionUpdatePacket) {
if ((packet as FullStatePacket).velocity) { if ((packet as FullStatePacket).velocity) {
this.setVelocity( this.setVelocity(
new Vector3().fromArray((packet as FullStatePacket).velocity), new Vector3().fromArray((packet as FullStatePacket).velocity!),
); );
} }
if ((packet as FullStatePacket).angular) { if ((packet as FullStatePacket).angular) {
this.setAngularVelocity( this.setAngularVelocity(
new Vector3().fromArray((packet as FullStatePacket).angular), new Vector3().fromArray((packet as FullStatePacket).angular!),
); );
} }
@ -151,10 +151,10 @@ export class PlayerEntity extends PonyEntity {
} }
for (let i = 0; i < this._updateQueue.length; ++i) { for (let i = 0; i < this._updateQueue.length; ++i) {
this._updateQueue[i].time -= dt; this._updateQueue[i].time! -= dt;
} }
while (this._updateQueue.length > 0 && this._updateQueue[0].time <= 0.0) { while (this._updateQueue.length > 0 && this._updateQueue[0].time! <= 0.0) {
this._lastFrame = { this._lastFrame = {
animState: this._targetFrame.animState, animState: this._targetFrame.animState,
position: this.container.position.toArray(), position: this.container.position.toArray(),

View File

@ -9,7 +9,7 @@ import { IcyNetUser } from './user';
export interface ServerToClientEvents { export interface ServerToClientEvents {
'set.me': (player: CompositePacket | null) => void; 'set.me': (player: CompositePacket | null) => void;
'error.duplicate': () => void; 'error.duplicate': () => void;
'player.list': (players: Partial<CompositePacket[]>) => void; 'player.list': (players: Partial<CompositePacket>[]) => void;
'player.chat': (data: { 'player.chat': (data: {
sender: Partial<IcyNetUser>; sender: Partial<IcyNetUser>;
message: string; message: string;

View File

@ -19,7 +19,9 @@ import { Game } from './game';
import { InterServerEvents, SocketData } from './types/socket'; import { InterServerEvents, SocketData } from './types/socket';
const RedisStore = connectRedis(session); const RedisStore = connectRedis(session);
const redisClient = config.redis?.enabled ? redis.createClient() : undefined; const redisClient = config.redis?.enabled ? redis.createClient({
url: config.redis?.url || 'redis://localhost:6379',
}) : undefined;
const sessionMiddleware = session({ const sessionMiddleware = session({
secret: config.server.sessionSecret, secret: config.server.sessionSecret,