CREATE YOUR WORLD
Multiplay
Removing a specific user from Room
4 min
you can kick certain users out of the room at runtime please create the server code index ts sandbox function definition kick(client sandboxplayer, reason? string) promise; it is a function to kick out the sandboxplayer after receiving the sandboxplayer with sessionid \ if you are kicked out, a pop up will appear informing you that you are kicked out, but the pop up is the ui of the zepeto app and cannot be checked by the editor 📘 please refer to the following guide \[ zepeto multiplay(server) api https //developer zepeto me/docs/multiplay server/classes/zepeto multiplay sandbox#kick ] first, to get user information, define schema types and roomstate as follows example of use use the data in userinfos to get the session id of the user who will be kicked out of the userid after importing the sandbox player with the session id, call the kick function i can tell you who was kicked out through broadcast import { sandbox, sandboxoptions, sandboxplayer } from 'zepeto multiplay'; import { datastorage, loaddatastorage } from 'zepeto multiplay datastorage'; import { userinfo } from 'zepeto multiplay schema'; export default class extends sandbox { oncreate(options sandboxoptions) { this onmessage("kick", (client sandboxplayer, message string) => { this trykick(client, message); }); } onjoin(client sandboxplayer) { const user = new userinfo(); user sessionid = client sessionid; user userid = client userid; this state userinfos set(client userid, user); } async trykick(client sandboxplayer, userid string) { let player sandboxplayer; if (userid == null) { player = client; } else { const kickplayersessionid string = this state userinfos get(userid) sessionid; player = this loadplayer(kickplayersessionid); } console log(`try kick ${player userid}`); await this kick(player); this broadcast("log", `kick ${player userid}`); } } 👍 by default, users who have been kicked out can enter the room again to prevent this, use the datastorage management function based on the userid to store the room information that was kicked out by the user you can implement it by calling a kick when you try to enter the room