Implement autodeletion of players on logout

This commit is contained in:
2024-03-04 16:33:23 -05:00
parent c2a94b5332
commit 044bb89edf
4 changed files with 84 additions and 11 deletions

View File

@@ -150,6 +150,12 @@ Tangible *World::tangible_make(const LuaCoreStack &LS0, LuaSlot database, int64_
assert (t == nullptr);
t.reset(new Tangible(this, id));
// Set the login flags.
t->can_be_controlled_ = false;
t->is_controlled_ = false;
t->force_disconnect_ = false;
t->delete_on_disconnect_ = false;
// AnimQueue initializes itself to a valid default state.
AnimState state;
state.add_defaults(nullptr);
@@ -246,28 +252,51 @@ World::Redirects World::fetch_redirects() {
return result;
}
int64_t World::create_login_actor(bool initialize) {
int64_t World::create_login_actor() {
assert(stack_is_clear());
int64_t id = id_global_pool_.get_one();
{
LuaVar database, classtab, mt, func;
LuaExtStack LS(state(), database, classtab, mt, func);
Tangible *tan = tangible_make(LS, database, id);
// Set the login flags.
if (is_authoritative()) {
tan->can_be_controlled_ = true;
tan->is_controlled_ = true;
tan->force_disconnect_ = false;
tan->delete_on_disconnect_ = true;
}
LS.makeclass(classtab, "login");
LS.getmetatable(mt, database);
LS.rawset(mt, "__index", classtab);
tan->configure_id_pool_for_actor();
tan->print_buffer_.clear();
if (initialize) {
if (is_authoritative()) {
LS.rawget(func, classtab, "initialize");
spawn(LS, id, id, func, true, 0, false);
}
}
run_scheduled_threads();
if (is_authoritative()) {
run_scheduled_threads();
}
return id;
}
void World::disconnected(int64_t actor_id) {
Tangible *tan = tangible_get(actor_id);
assert(tan != nullptr);
assert(tan->is_controlled_);
tan->is_controlled_ = false;
tan->force_disconnect_ = false;
if (tan->delete_on_disconnect_) {
util::dprintf("Deleted actor: %lld\n", actor_id);
tangible_delete(actor_id);
}
}
eng::string World::probe_lua(int64_t actor_id, std::string_view lua) {
assert(stack_is_clear());
lua_State *L = state();