Added better security for character loading, worked on zone joining and moving logic
This commit is contained in:
19
src/app/events/CharacterMove.ts
Normal file
19
src/app/events/CharacterMove.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Socket, Server } from "socket.io";
|
||||
import {TSocket} from "../utilities/Types";
|
||||
import CharacterRepository from "../repositories/CharacterRepository";
|
||||
import {Character} from "@prisma/client";
|
||||
|
||||
type SocketResponseT = {
|
||||
character_id: number
|
||||
}
|
||||
|
||||
export default function (socket: TSocket, io: Server) {
|
||||
socket.on('character:move', async (data: SocketResponseT) => {
|
||||
try {
|
||||
socket.character = await CharacterRepository.getById(data.character_id) as Character;
|
||||
socket.emit('character:connect', socket.character)
|
||||
} catch (error: any) {
|
||||
console.log('character:connect error', error);
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user