diff --git a/.env.template b/.env.template index a83bd171..a54df82e 100644 --- a/.env.template +++ b/.env.template @@ -10,3 +10,6 @@ START_ROOM_URL=/_/global/maps.workadventure.localhost/Floor0/floor0.json # If you are using Coturn, this is the value of the "static-auth-secret" parameter in your coturn config file. # Keep empty if you are sharing hard coded / clear text credentials. TURN_STATIC_AUTH_SECRET= + +# The email address used by Let's encrypt to send renewal warnings (compulsory) +ACME_EMAIL= diff --git a/README.md b/README.md index a8c186b6..c6facad3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![](https://github.com/thecodingmachine/workadventure/workflows/Continuous%20Integration/badge.svg) +![](https://github.com/thecodingmachine/workadventure/workflows/Continuous%20Integration/badge.svg) [![Discord](https://img.shields.io/discord/821338762134290432?label=Discord)](https://discord.gg/YGtngdh9gt) ![WorkAdventure landscape image](README-INTRO.jpg) @@ -25,13 +25,14 @@ docker-compose up The environment will start. -You should now be able to browse to http://workadventure.localhost/ and see the application. +You should now be able to browse to http://play.workadventure.localhost/ and see the application. +You can view the dashboard at http://workadventure.localhost:8080/ Note: on some OSes, you will need to add this line to your `/etc/hosts` file: **/etc/hosts** ``` -workadventure.localhost 127.0.0.1 +127.0.0.1 workadventure.localhost ``` ### MacOS developers, your environment with Vagrant diff --git a/back/src/RoomManager.ts b/back/src/RoomManager.ts index 256c904e..60e90d82 100644 --- a/back/src/RoomManager.ts +++ b/back/src/RoomManager.ts @@ -2,7 +2,7 @@ import {IRoomManagerServer} from "./Messages/generated/messages_grpc_pb"; import { AdminGlobalMessage, AdminMessage, - AdminPusherToBackMessage, + AdminPusherToBackMessage, AdminRoomMessage, BanMessage, EmptyMessage, @@ -15,7 +15,7 @@ import { ServerToClientMessage, SilentMessage, UserMovesMessage, - WebRtcSignalToServerMessage, + WebRtcSignalToServerMessage, WorldFullWarningToRoomMessage, ZoneMessage } from "./Messages/generated/messages_pb"; import {sendUnaryData, ServerDuplexStream, ServerUnaryCall, ServerWritableStream} from "grpc"; @@ -43,8 +43,13 @@ const roomManager: IRoomManagerServer = { if (room === null || user === null) { if (message.hasJoinroommessage()) { socketManager.handleJoinRoom(call, message.getJoinroommessage() as JoinRoomMessage).then(({room: gameRoom, user: myUser}) => { - room = gameRoom; - user = myUser; + if (call.writable) { + room = gameRoom; + user = myUser; + } else { + //Connexion may have been closed before the init was finished, so we have to manually disconnect the user. + socketManager.leaveRoom(gameRoom, myUser); + } }); } else { throw new Error('The first message sent MUST be of type JoinRoomMessage'); @@ -184,6 +189,10 @@ const roomManager: IRoomManagerServer = { socketManager.sendAdminRoomMessage(call.request.getRoomid(), call.request.getMessage()); callback(null, new EmptyMessage()); }, + sendWorldFullWarningToRoom(call: ServerUnaryCall, callback: sendUnaryData): void { + socketManager.dispatchWorlFullWarning(call.request.getRoomid()); + callback(null, new EmptyMessage()); + }, }; export {roomManager}; diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index 6317a46d..c03f4773 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -24,6 +24,7 @@ import { UserJoinedZoneMessage, GroupUpdateZoneMessage, GroupLeftZoneMessage, + WorldFullWarningMessage, UserLeftZoneMessage, BanUserMessage, } from "../Messages/generated/messages_pb"; @@ -58,6 +59,7 @@ function emitZoneMessage(subMessage: SubToPusherMessage, socket: ZoneSocket): vo // TODO: should we batch those every 100ms? const batchMessage = new BatchToPusherMessage(); batchMessage.addPayload(subMessage); + socket.write(batchMessage); } @@ -75,10 +77,17 @@ export class SocketManager { } public async handleJoinRoom(socket: UserSocket, joinRoomMessage: JoinRoomMessage): Promise<{ room: GameRoom; user: User }> { - + //join new previous room const {room, user} = await this.joinRoom(socket, joinRoomMessage); - + + if (!socket.writable) { + console.warn('Socket was aborted'); + return { + room, + user + }; + } const roomJoinedMessage = new RoomJoinedMessage(); roomJoinedMessage.setTagList(joinRoomMessage.getTagList()); @@ -94,7 +103,6 @@ export class SocketManager { const serverToClientMessage = new ServerToClientMessage(); serverToClientMessage.setRoomjoinedmessage(roomJoinedMessage); - console.log('SENDING MESSAGE roomJoinedMessage'); socket.write(serverToClientMessage); return { @@ -262,8 +270,6 @@ export class SocketManager { debug('Room is empty. Deleting room "%s"', room.roomId); } } finally { - //delete Client.roomId; - //this.sockets.delete(Client.userId); clientEventsEmitter.emitClientLeave(user.uuid, room.roomId); console.log('A user left'); } @@ -298,20 +304,14 @@ export class SocketManager { const roomId = joinRoomMessage.getRoomid(); - const world = await socketManager.getOrCreateRoom(roomId); - - // Dispatch groups position to newly connected user - /*world.getGroups().forEach((group: Group) => { - this.emitCreateUpdateGroupEvent(socket, group); - });*/ + const room = await socketManager.getOrCreateRoom(roomId); //join world - const user = world.join(socket, joinRoomMessage); + const user = room.join(socket, joinRoomMessage); clientEventsEmitter.emitClientJoin(user.uuid, roomId); - //console.log(new Date().toISOString() + ' A user joined (', this.sockets.size, ' connected users)'); console.log(new Date().toISOString() + ' A user joined'); - return {room: world, user}; + return {room, user}; } private onZoneEnter(thing: Movable, fromZone: Zone|null, listener: ZoneSocket) { @@ -419,10 +419,6 @@ export class SocketManager { } private joinWebRtcRoom(user: User, group: Group) { - /*const roomId: string = "webrtcroom"+group.getId(); - if (user.socket.webRtcRoomId === roomId) { - return; - }*/ for (const otherUser of group.getUsers()) { if (user === otherUser) { @@ -758,6 +754,24 @@ export class SocketManager { recipient.socket.write(clientMessage); }); } + + dispatchWorlFullWarning(roomId: string,): void { + const room = this.rooms.get(roomId); + if (!room) { + //todo: this should cause the http call to return a 500 + console.error("In sendAdminRoomMessage, could not find room with id '" + roomId + "'. Maybe the room was closed a few milliseconds ago and there was a race condition?"); + return; + } + + room.getUsers().forEach((recipient) => { + const worldFullMessage = new WorldFullWarningMessage(); + + const clientMessage = new ServerToClientMessage(); + clientMessage.setWorldfullwarningmessage(worldFullMessage); + + recipient.socket.write(clientMessage); + }); + } } export const socketManager = new SocketManager(); diff --git a/contrib/docker/docker-compose.prod.yaml b/contrib/docker/docker-compose.prod.yaml index 22860748..c726ba84 100644 --- a/contrib/docker/docker-compose.prod.yaml +++ b/contrib/docker/docker-compose.prod.yaml @@ -10,7 +10,7 @@ services: - --entrypoints.web.http.redirections.entryPoint.to=websecure - --entrypoints.web.http.redirections.entryPoint.scheme=https - --entryPoints.websecure.address=:443 - - --certificatesresolvers.myresolver.acme.email=d.negrier@thecodingmachine.com + - --certificatesresolvers.myresolver.acme.email=${ACME_EMAIL} - --certificatesresolvers.myresolver.acme.storage=/acme.json # used during the challenge - --certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web diff --git a/docker-compose.yaml b/docker-compose.yaml index 22b807a7..9ea637a3 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -53,10 +53,8 @@ services: pusher: image: thecodingmachine/nodejs:12 command: yarn dev - #command: yarn run prod - #command: yarn run profile environment: - DEBUG: "*" + DEBUG: "socket:*" STARTUP_COMMAND_1: yarn install SECRET_JITSI_KEY: "$SECRET_JITSI_KEY" SECRET_KEY: yourSecretKey diff --git a/front/dist/.gitignore b/front/dist/.gitignore index a60c53be..785f2eb9 100644 --- a/front/dist/.gitignore +++ b/front/dist/.gitignore @@ -1,3 +1,4 @@ index.html index.tmpl.html.tmp /js/ +style.*.css diff --git a/front/dist/index.tmpl.html b/front/dist/index.tmpl.html index ecf2c671..88efa80d 100644 --- a/front/dist/index.tmpl.html +++ b/front/dist/index.tmpl.html @@ -31,8 +31,6 @@ - - WorkAdventure @@ -70,98 +68,54 @@ + +
- +
- -
- -
- -
- - + +