|
nanoMMO 0.97.8
Building an MMO: The Engineering Series
|
#include <players.h>
Public Member Functions | |
| Players (Database &database, Redis &redis) | |
| absl::StatusOr< Player > | Load (const std::string &world, uint32_t id) |
| absl::StatusOr< std::string > | Lease (const std::string &world, uint32_t id, const std::string &instance) |
| absl::StatusOr< std::set< uint32_t > > | Renew (const std::string &world, const std::map< uint32_t, std::string > &leases) |
| absl::Status | Release (const std::string &world, uint32_t id, const std::string &lease) |
| absl::StatusOr< std::set< uint32_t > > | Pass (const std::string &world, const std::map< uint32_t, std::string > &leases, const std::string &next) |
| absl::StatusOr< std::set< uint32_t > > | Save (const std::string &world, const std::map< uint32_t, Progress > &changed, const std::map< uint32_t, protocol::Inventory > &bags={}, const std::map< uint32_t, std::string > &leases={}, const std::optional< Traded > &traded=std::nullopt, const std::vector< WarKill > &kills={}) |
| absl::StatusOr< int > | Flush () |
| absl::StatusOr< int > | Unsaved () |
| absl::StatusOr< int > | Duplicates () |
Static Public Attributes | |
| static constexpr int | kBatch = 500 |
| static constexpr std::size_t | kItemRows = 1000 |
| The most rows of the bags that go in one statement. | |
| static constexpr std::chrono::milliseconds | kLease {10000} |
| How long a lease on a player lasts, unless its instance renews it. | |
| absl::StatusOr< int > nanommo::Players::Duplicates | ( | ) |
The serials that more than one item in MySQL has, as only a copy of an item can have another's.
Definition at line 913 of file players.cc.
| absl::StatusOr< int > nanommo::Players::Flush | ( | ) |
Takes the unsaved players of all the worlds from Redis to MySQL, a batch at a time, each in a transaction with the bags that changed, and returns how many it saved. The trades that are waiting go first, each in a batch with both its players, into the trades table, and the war kills, a row each, into the war_kills table. A batch stays in Redis, in a set of its own, until MySQL has it, so that one a flush took and didn't save, as its saver died, goes back with the unsaved players as the next flush starts. There's one saver at a time.
Definition at line 578 of file players.cc.
| absl::StatusOr< std::string > nanommo::Players::Lease | ( | const std::string & | world, |
| uint32_t | id, | ||
| const std::string & | instance ) |
Leases the character in the world to the instance, so that no other instance plays them until it's released or runs out, and returns the lease as Redis has it: the instance's id, and a fencing number, higher than any lease's before it. A lease handed to the instance in a handover is its already. FailedPrecondition, naming the instance, when another instance has it.
Definition at line 415 of file players.cc.
| absl::StatusOr< Player > nanommo::Players::Load | ( | const std::string & | world, |
| uint32_t | id ) |
The character, by its id, in the world, from MySQL, with what Redis has on top, as that's newer. A NotFound error says there's no such character in this world.
Definition at line 284 of file players.cc.
| absl::StatusOr< std::set< uint32_t > > nanommo::Players::Pass | ( | const std::string & | world, |
| const std::map< uint32_t, std::string > & | leases, | ||
| const std::string & | next ) |
Hands each of the leases, by player, that's still as given, to the next instance, with a new fencing number, all in one round trip. Returns the players whose leases it handed over.
Definition at line 462 of file players.cc.
| absl::Status nanommo::Players::Release | ( | const std::string & | world, |
| uint32_t | id, | ||
| const std::string & | lease ) |
Ends the player's lease, if it's still as given, so that they can play on another instance at once. One that another instance has since stays.
Definition at line 456 of file players.cc.
| absl::StatusOr< std::set< uint32_t > > nanommo::Players::Renew | ( | const std::string & | world, |
| const std::map< uint32_t, std::string > & | leases ) |
Keeps the leases, by player, for another kLease, all in one round trip: those that are still as given. Returns the players whose leases aren't.
Definition at line 435 of file players.cc.
| absl::StatusOr< std::set< uint32_t > > nanommo::Players::Save | ( | const std::string & | world, |
| const std::map< uint32_t, Progress > & | changed, | ||
| const std::map< uint32_t, protocol::Inventory > & | bags = {}, | ||
| const std::map< uint32_t, std::string > & | leases = {}, | ||
| const std::optional< Traded > & | traded = std::nullopt, | ||
| const std::vector< WarKill > & | kills = {} ) |
Into Redis, all of them in a single round trip, and marked unsaved, with the bags of those whose bags changed, which are marked unsaved apart. It's one transaction, so Redis keeps all of it or none: the two bags a trade changed are never saved one without the other. And only while each of the leases, by player, is as given, so that an instance that's lost a player to another can't write over what that one saves. Returns the players whose leases aren't, when it saved none of it. A trade's record goes into the trades stream with its two bags, for the saver to take to MySQL with them, and each war kill into the war_kills stream, for its war's score.
Definition at line 483 of file players.cc.
| absl::StatusOr< int > nanommo::Players::Unsaved | ( | ) |
How many players are marked unsaved in Redis, waiting for a flush, or in a batch that isn't in MySQL yet, or both, each once.
Definition at line 898 of file players.cc.
|
staticconstexpr |
|
staticconstexpr |