redirect code in place
This commit is contained in:
@@ -89,7 +89,29 @@ public:
|
||||
sb->overwrite_int32(tw_1, tw_2 - tw_1);
|
||||
}
|
||||
|
||||
void redirect(int64_t id1, int64_t id2) {
|
||||
for (auto &client : clients_) {
|
||||
if (client->actor_id_ == id1) {
|
||||
bool ok = world_->redirected(id1, id2);
|
||||
if (!ok) delete_client(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Redirection is touchy: almost any world->invoke could
|
||||
// call tangible.redirect. After that point, the world is
|
||||
// relying on us not to control the wrong character.
|
||||
void process_redirects() {
|
||||
if (world_->have_redirects()) {
|
||||
World::Redirects redirects = world_->fetch_redirects();
|
||||
for (const auto &pair : redirects) {
|
||||
redirect(pair.first, pair.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool handle_invocation(UniqueClient &client) {
|
||||
if (client == nullptr) return false;
|
||||
StreamBuffer *sb = client->channel_->in();
|
||||
if (sb->empty()) return false;
|
||||
int64_t tr_before = sb->total_reads();
|
||||
@@ -131,6 +153,7 @@ public:
|
||||
//
|
||||
if (inv.actor() == client->actor_id_) {
|
||||
world_->invoke(inv);
|
||||
process_redirects();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -183,8 +206,9 @@ public:
|
||||
// Get the clock.
|
||||
double clock = get_clock();
|
||||
|
||||
// Execute any queued invocations.
|
||||
// We just feed these directly into the master model.
|
||||
// Execute any delayed invocations. These always
|
||||
// come from the local command line. We just feed
|
||||
// these directly into the master model.
|
||||
for (const Invocation &inv : delayed_invocations_) {
|
||||
world_->invoke(inv);
|
||||
}
|
||||
@@ -225,6 +249,11 @@ public:
|
||||
if (next_tick_ < clock + 0.3) next_tick_ = clock + 0.3;
|
||||
}
|
||||
|
||||
// This handles any redirects triggered from the server command
|
||||
// line or by the tick function.
|
||||
process_redirects();
|
||||
util::remove_nullptrs(clients_);
|
||||
|
||||
// Traverse all existing channels, process any communication.
|
||||
for (UniqueClient &client : clients_) {
|
||||
if (client->channel_->closed()) {
|
||||
|
||||
Reference in New Issue
Block a user