Merge branch 'master' into develop

This commit is contained in:
Gregoire Parant 2021-07-28 12:37:14 +02:00
commit 4b4356e7ff
7 changed files with 66 additions and 27 deletions

View file

@ -104,6 +104,15 @@ export class GameRoom {
public getUserById(id: number): User | undefined { public getUserById(id: number): User | undefined {
return this.users.get(id); return this.users.get(id);
} }
public getUsersByUuid(uuid: string): User[] {
const userList: User[] = [];
for (const user of this.users.values()) {
if (user.uuid === uuid) {
userList.push(user);
}
}
return userList;
}
public join(socket: UserSocket, joinRoomMessage: JoinRoomMessage): User { public join(socket: UserSocket, joinRoomMessage: JoinRoomMessage): User {
const positionMessage = joinRoomMessage.getPositionmessage(); const positionMessage = joinRoomMessage.getPositionmessage();

View file

@ -701,8 +701,8 @@ export class SocketManager {
return; return;
} }
const recipient = room.getUserByUuid(recipientUuid); const recipients = room.getUsersByUuid(recipientUuid);
if (recipient === undefined) { if (recipients.length === 0) {
console.error( console.error(
"In sendAdminMessage, could not find user with id '" + "In sendAdminMessage, could not find user with id '" +
recipientUuid + recipientUuid +
@ -711,14 +711,16 @@ export class SocketManager {
return; return;
} }
const sendUserMessage = new SendUserMessage(); for (const recipient of recipients) {
sendUserMessage.setMessage(message); const sendUserMessage = new SendUserMessage();
sendUserMessage.setType("ban"); //todo: is the type correct? sendUserMessage.setMessage(message);
sendUserMessage.setType("ban"); //todo: is the type correct?
const serverToClientMessage = new ServerToClientMessage(); const serverToClientMessage = new ServerToClientMessage();
serverToClientMessage.setSendusermessage(sendUserMessage); serverToClientMessage.setSendusermessage(sendUserMessage);
recipient.socket.write(serverToClientMessage); recipient.socket.write(serverToClientMessage);
}
} }
public async banUser(roomId: string, recipientUuid: string, message: string): Promise<void> { public async banUser(roomId: string, recipientUuid: string, message: string): Promise<void> {
@ -732,8 +734,8 @@ export class SocketManager {
return; return;
} }
const recipient = room.getUserByUuid(recipientUuid); const recipients = room.getUsersByUuid(recipientUuid);
if (recipient === undefined) { if (recipients.length === 0) {
console.error( console.error(
"In banUser, could not find user with id '" + "In banUser, could not find user with id '" +
recipientUuid + recipientUuid +
@ -742,19 +744,21 @@ export class SocketManager {
return; return;
} }
// Let's leave the room now. for (const recipient of recipients) {
room.leave(recipient); // Let's leave the room now.
room.leave(recipient);
const banUserMessage = new BanUserMessage(); const banUserMessage = new BanUserMessage();
banUserMessage.setMessage(message); banUserMessage.setMessage(message);
banUserMessage.setType("banned"); banUserMessage.setType("banned");
const serverToClientMessage = new ServerToClientMessage(); const serverToClientMessage = new ServerToClientMessage();
serverToClientMessage.setBanusermessage(banUserMessage); serverToClientMessage.setBanusermessage(banUserMessage);
// Let's close the connection when the user is banned. // Let's close the connection when the user is banned.
recipient.socket.write(serverToClientMessage); recipient.socket.write(serverToClientMessage);
recipient.socket.end(); recipient.socket.end();
}
} }
async sendAdminRoomMessage(roomId: string, message: string) { async sendAdminRoomMessage(roomId: string, message: string) {

View file

@ -3,9 +3,12 @@
import { chatMessagesStore, chatVisibilityStore } from "../../Stores/ChatStore"; import { chatMessagesStore, chatVisibilityStore } from "../../Stores/ChatStore";
import ChatMessageForm from './ChatMessageForm.svelte'; import ChatMessageForm from './ChatMessageForm.svelte';
import ChatElement from './ChatElement.svelte'; import ChatElement from './ChatElement.svelte';
import { afterUpdate, beforeUpdate } from "svelte"; import {afterUpdate, beforeUpdate} from "svelte";
import {HtmlUtils} from "../../WebRtc/HtmlUtils";
let listDom: HTMLElement; let listDom: HTMLElement;
let chatWindowElement: HTMLElement;
let handleFormBlur: { blur():void };
let autoscroll: boolean; let autoscroll: boolean;
beforeUpdate(() => { beforeUpdate(() => {
@ -16,6 +19,12 @@
if (autoscroll) listDom.scrollTo(0, listDom.scrollHeight); if (autoscroll) listDom.scrollTo(0, listDom.scrollHeight);
}); });
function onClick(event: MouseEvent) {
if (HtmlUtils.isClickedOutside(event, chatWindowElement)) {
handleFormBlur.blur();
}
}
function closeChat() { function closeChat() {
chatVisibilityStore.set(false); chatVisibilityStore.set(false);
} }
@ -26,10 +35,10 @@
} }
</script> </script>
<svelte:window on:keydown={onKeyDown}/> <svelte:window on:keydown={onKeyDown} on:click={onClick}/>
<aside class="chatWindow" transition:fly="{{ x: -1000, duration: 500 }}"> <aside class="chatWindow" transition:fly="{{ x: -1000, duration: 500 }}" bind:this={chatWindowElement}>
<p class="close-icon" on:click={closeChat}>&times</p> <p class="close-icon" on:click={closeChat}>&times</p>
<section class="messagesList" bind:this={listDom}> <section class="messagesList" bind:this={listDom}>
<ul> <ul>
@ -40,7 +49,7 @@
</ul> </ul>
</section> </section>
<section class="messageForm"> <section class="messageForm">
<ChatMessageForm></ChatMessageForm> <ChatMessageForm bind:handleForm={handleFormBlur}></ChatMessageForm>
</section> </section>
</aside> </aside>

View file

@ -7,13 +7,14 @@
export let message: ChatMessage; export let message: ChatMessage;
export let line: number; export let line: number;
const chatStyleLink = "color: white; text-decoration: underline;";
$: author = message.author as PlayerInterface; $: author = message.author as PlayerInterface;
$: targets = message.targets || []; $: targets = message.targets || [];
$: texts = message.text || []; $: texts = message.text || [];
function urlifyText(text: string): string { function urlifyText(text: string): string {
return HtmlUtils.urlify(text) return HtmlUtils.urlify(text, chatStyleLink);
} }
function renderDate(date: Date) { function renderDate(date: Date) {
return date.toLocaleTimeString(navigator.language, { return date.toLocaleTimeString(navigator.language, {

View file

@ -1,6 +1,12 @@
<script lang="ts"> <script lang="ts">
import {chatMessagesStore, chatInputFocusStore} from "../../Stores/ChatStore"; import {chatMessagesStore, chatInputFocusStore} from "../../Stores/ChatStore";
export const handleForm = {
blur() {
inputElement.blur();
}
}
let inputElement: HTMLElement;
let newMessageText = ''; let newMessageText = '';
function onFocus() { function onFocus() {
@ -18,7 +24,7 @@
</script> </script>
<form on:submit|preventDefault={saveMessage}> <form on:submit|preventDefault={saveMessage}>
<input type="text" bind:value={newMessageText} placeholder="Enter your message..." on:focus={onFocus} on:blur={onBlur} > <input type="text" bind:value={newMessageText} placeholder="Enter your message..." on:focus={onFocus} on:blur={onBlur} bind:this={inputElement}>
<button type="submit"> <button type="submit">
<img src="/static/images/send.png" alt="Send" width="20"> <img src="/static/images/send.png" alt="Send" width="20">
</button> </button>

View file

@ -244,6 +244,7 @@ export class CustomizeScene extends AbstractCharacterScene {
update(time: number, delta: number): void { update(time: number, delta: number): void {
if (this.lazyloadingAttempt) { if (this.lazyloadingAttempt) {
this.moveLayers(); this.moveLayers();
this.doMoveCursorHorizontally(this.moveHorizontally);
this.lazyloadingAttempt = false; this.lazyloadingAttempt = false;
} }

View file

@ -31,7 +31,7 @@ export class HtmlUtils {
return p.innerHTML; return p.innerHTML;
} }
public static urlify(text: string): string { public static urlify(text: string, style: string = ""): string {
const urlRegex = /(https?:\/\/[^\s]+)/g; const urlRegex = /(https?:\/\/[^\s]+)/g;
text = HtmlUtils.escapeHtml(text); text = HtmlUtils.escapeHtml(text);
return text.replace(urlRegex, (url: string) => { return text.replace(urlRegex, (url: string) => {
@ -40,10 +40,19 @@ export class HtmlUtils {
link.target = "_blank"; link.target = "_blank";
const text = document.createTextNode(url); const text = document.createTextNode(url);
link.appendChild(text); link.appendChild(text);
link.setAttribute("style", style);
return link.outerHTML; return link.outerHTML;
}); });
} }
public static isClickedInside(event: MouseEvent, target: HTMLElement): boolean {
return !!event.composedPath().find((et) => et === target);
}
public static isClickedOutside(event: MouseEvent, target: HTMLElement): boolean {
return !this.isClickedInside(event, target);
}
private static isHtmlElement<T extends HTMLElement>(elem: HTMLElement | null): elem is T { private static isHtmlElement<T extends HTMLElement>(elem: HTMLElement | null): elem is T {
return elem !== null; return elem !== null;
} }