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

View File

@ -90,11 +90,11 @@ export class CanvasUtils {
fontSize = 16,
padding = 4,
): { 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 lines = Array.isArray(text) ? text : [text];
const lineWidths = [];
const lineWidths: number[] = [];
let longestLine = 0;
// Measure the text bounds
@ -176,7 +176,7 @@ export class CanvasUtils {
public readPixelDataRGB(image: HTMLImageElement): number[] {
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.height = image.height;
ctx.drawImage(image, 0, 0, image.width, image.height);
@ -202,7 +202,7 @@ export class CanvasUtils {
scale: number,
): number[] {
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.height = 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._input.value = null;
this._input.value = '';
if (this._rehide) {
this.hide();
@ -69,7 +69,7 @@ export class Chat {
}
} else if (e.key === 'Escape') {
this._input.blur();
this._input.value = null;
this._input.value = '';
if (this._rehide) {
this.hide();

View File

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

View File

@ -54,7 +54,7 @@ export class PlayerEntity extends PonyEntity {
}
public addChat(message: string): void {
const lines = [];
const lines: string[] = [];
let truncated = message;
while (truncated.length > 80) {
@ -74,7 +74,7 @@ export class PlayerEntity extends PonyEntity {
});
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);
if (this._chats.length > 3) {
@ -122,13 +122,13 @@ export class PlayerEntity extends PonyEntity {
private setFromPacket(packet: FullStatePacket | PositionUpdatePacket) {
if ((packet as FullStatePacket).velocity) {
this.setVelocity(
new Vector3().fromArray((packet as FullStatePacket).velocity),
new Vector3().fromArray((packet as FullStatePacket).velocity!),
);
}
if ((packet as FullStatePacket).angular) {
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) {
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 = {
animState: this._targetFrame.animState,
position: this.container.position.toArray(),

View File

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

View File

@ -19,7 +19,9 @@ import { Game } from './game';
import { InterServerEvents, SocketData } from './types/socket';
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({
secret: config.server.sessionSecret,