Match_kick not doing anything

I’m trying to implement a timeout function that kicks inactive players if they haven’t submitted a certain action in a certain amount of time. After correctly registering presences in the match state, using the function match_kick(presence) in said presences doesn’t do anything, as shown in the following screenshot:

The code that kicks the players is:

-- M.match_check_timeout(dispatcher,state)
-- ...
for _, id in ipairs(state.players) do
  if state.formation[id] == nil then
    dispatcher.match_kick(state.presences[id])
    print("kicked player "..state.presences[id].username)
  end
end
-- ...

And the code that tracks the presences before and after the kick:

-- match_loop
print("presences before timeout: ")
for k,v in pairs(state.presences) do
    print(state.presences[k].username)
end
M.match_check_timeout(dispatcher,state)
print("presences after timeout: ")
for k,v in pairs(state.presences) do
    print(state.presences[k].username)
end

Am I doing something wrong? Is that the correct usage of match_kick?
Please help! Thanks in advance!

As the docs show, dispatcher.match_kick takes a table (Lua’s list-like structure) of presences to kick. You’re giving it a single presence.

Try dispatcher.match_kick({state.presences[id]}) instead.

Side note - the before/after timeout check won’t show any difference if you don’t update the state’s list of presences when you kick a presence. That list is maintained by your code, in your match state, and is not automatically updated by dispatcher functions.

1 Like