Working on redirect/connect/etc

This commit is contained in:
2026-06-05 17:52:46 -04:00
parent 8a46788512
commit 8d88c88fa0
5 changed files with 117 additions and 106 deletions

View File

@@ -293,36 +293,9 @@ LuaDefine(tangible_delete, "tan",
luaL_error(L, "Not a tangible.");
return 0;
}
if (tan->can_be_controlled_) {
luaL_error(L, "Cannot delete a player using tangible.delete, use tangible.deleteactor instead.");
return 0;
}
w->tangible_delete(tan->id());
return LS.result();
}
LuaDefine(tangible_deleteactor, "tan",
"|Delete an actor tangible, or mark it for deletion on logout."
"|"
"|This function is used to delete an actor tangible."
"|"
"|If the actor is not currently logged in, then the tangible is"
"|immediately deleted. If the actor is logged in, then the tangible"
"|is marked as delete_on_disconnect, and the force_disconnect flag"
"|is set. This will cause the actor to cleanly disconnect, and then"
"|the deletion will take place."
"|") {
LuaArg tanobj;
LuaDefStack LS(L, tanobj);
World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj, true);
if ((tan == nullptr) || (!tan->can_be_controlled_)) {
luaL_error(L, "Tangible is not an actor.");
return 0;
}
if (tan->is_controlled_) {
tan->delete_on_disconnect_ = true;
tan->force_disconnect_ = true;
w->connection_redirect(tan, nullptr);
} else {
w->tangible_delete(tan->id());
}
@@ -351,7 +324,7 @@ LuaDefine(tangible_keepactor, "tan",
LuaDefStack LS(L, tanobj);
World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj, true);
if ((tan == nullptr) || (!tan->can_be_controlled_)) {
if ((tan == nullptr) || (!tan->is_controlled_)) {
luaL_error(L, "Tangible is not an actor.");
return 0;
}
@@ -368,16 +341,18 @@ LuaDefine(tangible_redirect, "actor1, actor2",
"|client types his name and password, tangible.redirect is used "
"|to tell the client to control the real actor."
"|"
"|Actor1 must be currently logged in. Actor2 must be a valid actor "
"|tangible that is not curretly logged in."
"|If actor1 is not logged in, an error will be reported."
"|"
"|If actor2 is already logged in, they will be booted in order to "
"|enable actor1 to take control."
"|"
"|") {
LuaArg lactor1, lactor2;
LuaDefStack LS(L, lactor1, lactor2);
World *w = World::fetch_global_pointer(L);
Tangible *actor1 = w->tangible_get(LS, lactor1, true);
Tangible *actor2 = w->tangible_get(LS, lactor2, true);
int64_t client_id = w->connection_get_client(actor1->id());
eng::string error = w->connection_redirect(client_id, actor2->id());
eng::string error = w->connection_redirect(actor1, actor2);
if (!error.empty()) {
eng::ostringstream oss;
oss << "redirect from " << actor1->id() << " to " << actor2->id() << " failed: " << error;
@@ -387,6 +362,29 @@ LuaDefine(tangible_redirect, "actor1, actor2",
return LS.result();
}
LuaDefine(tangible_forcedisconnect, "actor",
"|Cause the client controlling actor to be disconnected"
"|"
"|This is a no-op if nobody is logged in to the specified actor."
"|") {
LuaArg lactor1, lactor2;
LuaDefStack LS(L, lactor1, lactor2);
World *w = World::fetch_global_pointer(L);
Tangible *actor = w->tangible_get(LS, lactor1, true);
if (actor->is_controlled_) {
eng::string error = w->connection_redirect(actor, nullptr);
if (!error.empty()) {
eng::ostringstream oss;
oss << "forcedisconnect of " << actor->id() << " failed: " << error;
luaL_error(L, "%s", oss.str().c_str());
return LS.result();
}
}
return LS.result();
}
LuaDefine(tangible_build, "config",
"|Build a new tangible object."
"|"