nanoMMO

MMORPG guild ranks in C++ with a roster, officers and kicks

Our C++ MMORPG's guilds get a roster with who's playing, officers the leader makes, removing a player by rank and disbanding, each change locking the guild's row in MySQL first.

Watch on YouTube

Guild ranks for our MMORPG, in C++ and MySQL. The guild window gets a roster, the highest rank first, with each player's level and who's playing now, which MySQL and the world put together and the server reads at most once a tick for each guild. A right-click on a player opens a menu of what your rank lets you do to theirs: the leader makes officers, a higher rank removes a lower one, and the leader can disband the guild after a question. Each change locks the guild's row first with SELECT ... FOR UPDATE, then the player's, so a kick and a leave at the same moment from two instances of the world go one after the other without a deadlock, which a test runs on two MySQL connections. This is episode 67 of a series about building an MMORPG from scratch in C++, with the focus on the engineering around the game.

Topics: Databases, Testing, Gameplay

The code

Each step on screen is a tag in the game's repository. The code at the end of the episode is ep067/end.

  1. 2:35ep067/step-1The rosterBrowseChanges
  2. 11:31ep067/step-2OfficersBrowseChanges
  3. 21:34ep067/step-3Removing a playerBrowseChanges
  4. 29:07ep067/step-4DisbandingBrowseChanges

Transcript

Intro

0:00 Welcome back to episode sixty-seven, where our guilds get a roster of who's in them, and ranks that let the leader and the officers run them. Episode sixty-six's guilds could be founded, joined, talked to and left, and not much more, so today they get the parts a group of people needs to manage one. Two players can also change one guild at once, from two instances of the world, and I think that's the more interesting half of the episode. First, a quick look at what we'll have by the end.

0:29 By the end of the episode, the guild window lists who's in Iron Wolves, by rank, with their levels and who's playing now. A right-click on a player opens a menu of what the leader's rank allows, so gwen goes up to officer, and merlin, who's offline, is out of the guild.

0:50 The series' website has more on the project, with a link to the code on GitHub, which is open source, and a page for each episode, with its chapters and the code at each of its steps.

Last time

1:00 Last time, we gave the game guilds, so here's a quick reminder of how they work. A guild lives in MySQL, founded from a window on G, with a transaction for each change. An officer or the leader invites a player, and the invitation lasts a minute in Redis, and the guild's name sits under each member's, over their head. Slash g talks to the guild alone, and when the leader leaves, the guild goes to whoever's been in it longest.

Today

1:26 Here's the game at the end of last episode, where arthur leads Iron Wolves, with three more players in it. The guild's window has its name, arthur's rank, and a field to ask people in, and nothing about who's in it already, or who's playing. The one change a player can make to the guild is to leave it. So nobody can make an officer, though the rank has been in the database since last episode's first step. And a player who stopped playing stays in until they come back and leave, while the guild ends when its last player goes, and not before.

2:00 Today, then, our guilds get ranks that do something. First, a roster in the window, with who's in the guild and who's playing now, which MySQL and the world put together. Then officers, which the leader makes from a menu on the roster, removing a player, where your rank has to be above theirs, and disbanding, for the leader, after a question. Each of those changes locks the guild's row in MySQL first, and I'll show you why the guild comes before the player, with a diagram and a test that runs a kick and a leave at once. Right, let's start with the roster, which the menus later on are built on.

The roster

2:35 Each episode's code gets a minor version of its own, so the top CMake file moves the project on to zero point sixty-seven. The roster starts in our proto file, as the server is the one that knows who's in a guild, and the client draws what it's sent. The guild each player is sent gets its members, field three, as a repeated field, which is protobuf's list. Over it, we write their order: the highest rank first, and then by name, so the client can draw them as they come. A guild member is one of the guild's players, as the roster lists them. It carries their character's id, which the roster's menus are going to send back to the server later on, their name, their rank, and their level. Online says whether they're playing in the world now, which is the one field MySQL can't fill in. In the guilds' header file, we bring in vector, for the list. Roster reads a guild's players from MySQL, the highest rank first, and by name, and MySQL can't tell it two things. Their levels are a few seconds behind the world's, as a player's progress reaches MySQL after the world has it. And none of them is online, as playing is something a world knows, and the database doesn't. In guilds, we bring in our levels header, for turning experience into a level. Roster is a single query with a join, so a guild of a hundred players costs one round trip to MySQL, where a query for each member would cost a hundred. It selects each member's id, name, grade and experience, as the client wants a level, and MySQL keeps the experience. It joins the guild's members to players for the name and the experience, keeps this guild's rows, and orders them by grade, highest first, and then by name. I'd sooner have MySQL sort them than the client, so each player gets the roster in one order, and the window can draw the rows as they come. If the query fails, Roster returns its error, as our other queries do. The roster is a vector, with room reserved for as many members as there are rows, so it doesn't grow a step at a time. For each row, simple a to i reads the id, the grade and the experience back from MySQL's text, and Rank is valid checks that the grade is a rank we know. If any of that fails, it's an internal error, as the table would hold something our code didn't write. Emplace back adds a member at the end, and hands us a reference to it, which we fill in: the id, the name, and the rank, cast from the grade. The level comes from Level for, which works out the level that goes with an amount of experience. Online stays false, its default, as Guilds can't tell who's playing. In the server's header file, Refresh guild sends each of the guild's players here its roster with the next guild news. And the server gets a Roster of its own, which takes MySQL's and adds what the world knows: who's playing here, and their level as it is now. In the server, a player in a guild who joins the world refreshes their guild, so the rest of it sees them online. As a player leaves, we find their membership in an if with an initialiser, which keeps member inside the if. We keep the guild's id before erasing the membership, then refresh the guild, so the others see them go grey. A player who joins a guild refreshes it, in place of news for them alone, so the roster grows for each of the guild's players here, the new one too. And leaving a guild refreshes the one that was left. Refresh guild goes through the members on this server, and puts each of that guild's into guild news. Guild news is a set, so a player refreshed twice in one tick still gets one message. Send guilds is where the roster goes out to the players. A roster is a query to MySQL, and a guild with forty players here, all refreshed in one tick, would read it forty times. So a map keeps each guild's roster for the tick, and each one is read once, for all its players who get news. For a player in a guild, we look for their guild's roster in the map, and when it isn't there yet, we read it with Roster and put it in. Then its members go into the message, from the vector's begin to its end. The server's Roster asks Guilds first, and keeps its answer, a status or, which holds the roster or the error. When MySQL fails, it logs the guild and the status for us, and returns an empty roster, so the news still goes out, with the guild's name and your rank. Then, for each member, World of gives the copy of the world they're playing in, if they're here. If they are, they're online, and their level comes from the experience the world has for them now, which can be a few seconds ahead of MySQL's. Last, we move the vector out of the status or, so it isn't copied.

7:12 On the client, the roster goes in the guild window, under your rank, which you can see working in the corner. We bring in algorithm, for counting who's online. The roster is one of ImGui's tables, called Roster, with three columns. Row background shades alternate rows, so your eye can follow a row across, and sizing stretch prop shares the width between the columns by how wide their contents are. It's as wide as the window's fields, and as tall as its rows. Over it, we write how it's ordered: the highest rank first, as the server sends it, with those playing in white. The columns are Name, Rank and Level, and Table headers row draws their names along the top. Then comes a row for each member, in the order they came. A member who isn't online gets their row drawn disabled, which is ImGui's grey for what can't be used, and suits a player who isn't here. Table next column moves along a cell at a time, for the name, the rank, by the name Rank name gives it, and the level, with percent u, as it's unsigned. End disabled closes each row's, and End table the table. ImGui wants End table called when Begin table returned true, and not otherwise, so it goes inside the if. Under the table, ranges count if counts the members who are online, with a lambda that says whether one is. Then a muted line says how many of the guild's players are playing now, out of all of them. Count if gives a difference type, so it's cast to an int, for percent d.

8:44 In the game, arthur leads Iron Wolves, and of its other three players, gwen is the one playing now. arthur is at the top, as the leader, and the members follow by name. gwen's row is white, with her level from the world, while elaine and merlin are offline, in grey, with the levels MySQL has for them. As elaine joins the world, the server refreshes her guild, and her row turns white, with three of four playing now.

9:13 Now that we've seen it, let's pin the roster down with two tests, one against MySQL and one over the network. The guilds' test brings in vector, for the roster it gets back. In the first, the test makes a Guilds on the fixture's MySQL and Redis, and alice founds Iron Wolves. It keeps what Create returns, as it needs the guild's id further down, and asserts that the founding worked. Then dave joins, and then bob, each asked in by alice, and each accepting, with asserts that both steps worked. dave goes first on purpose, so the order they joined in isn't the order of their names, and a roster in the order of joining would fail. Roster reads the guild back by the id Create gave us, and the test asserts that worked, printing the status if it didn't, and that there are three players. alice comes first, as the leader, then bob, and then dave, by name, even though dave joined before bob. dave's level is one, as he has no experience yet, and he's offline, as Guilds doesn't know who's playing. In the server test, the second test plays it out over TLS, like two clients would, against the fixture's server, which runs a world named after the test. alice joins as a test player, with a login token the fixture issues for her, the way the login server would. Next, bob joins, and the test waits until both have had their first guild news, which is how it knows they're in the world. Then the guild comes together like in last episode's tests, with one input carrying each guild action in turn. Setting a field of a oneof clears the one set before, so the input that founds the guild can ask bob in next. alice founds Iron Wolves, and the test waits for her guild news, then she asks bob in by his name, and the test waits for his invitation, and bob says yes. The test runs until alice's roster has two players, and the second, bob, is online. Then bob leaves the world, as his connection closes, and over that, we note that alice's roster shows him offline. The test runs until it does, so the server has to refresh the guild as a player goes, as well as when they come.

11:16 We build the server's tests at this step, in Docker, and run the two roster tests against MySQL and Redis in Compose, with grep keeping the line each test ends on. The roster comes in rank and name order, bob shows as offline once he's gone, and both pass.

Officers

11:32 Next come officers, a rank that's been in our tables since the last episode. They can already ask players in, but nobody can make one. In our proto file, a guild action gets two more fields in its oneof, each pointing at the player it changes. The leader makes a member an officer, or an officer a member again, by an id that comes from the roster. So with promote and demote, the server doesn't look anyone up by name, and the player doesn't have to be online, which suits a leader who wants to make an officer of someone who's away. In the guilds' header file, Changed is what a change to another member did, for the news. It holds the guild's id and its name, and the name of the member it changed, as the server tells the guild who it was. They may not be playing anywhere the server can see, so it can't look the name up in its world. Set rank has the leader make a member an officer, or an officer a member again. Its errors are permission denied when the one asking doesn't lead, not found when the player isn't in their guild, and invalid argument for a rank they can't give. In guilds, two helpers come first, in the unnamed namespace, as each change to a guild from here on starts with the steps that leaving started with last time. Rank in gives a member's rank in a guild, with their row locked, or not found when they aren't in it. It's a free function that takes the database, so that Leave guild, which is free too, can start with these helpers, and the unnamed namespace keeps them to this file. It selects their grade for update, where both the player and the guild match, so a player who's in another guild by now doesn't count. No row is not found, in a player's words, a grade that isn't a rank is an internal error, and otherwise, we cast the grade to the rank. Nobody but our own code writes that column, so the internal error would mean a bug of ours, or a row someone wrote by hand. Lock for starts each change a player makes to their guild, and it takes two locks, in an order that each change keeps. Over it, we write that order: the guild's row first, as each change to a guild locks it, so changes to one guild happen one at a time. Then the player's own row, which someone may have changed before we got the guild's. So it reads the player's guild first, with a plain select, as we can't lock a guild's row before we know which one it is. A plain select doesn't wait for anyone's locks, and that's fine, as we're going to read the row again once we hold the guild's. No row, or an id that isn't a number, means they're in no guild. Then select for update locks the guild's row, and waits while another transaction holds it, for two seconds at most, as we set last time. With the guild locked, Rank in reads the player's row again, locked this time, and in this guild. Between the first select and the lock, a kick or a leave on another instance of the world could have taken them out, and this second read notices it. A guild that's gone, or a player who isn't in it any more, is not found, other errors go back as they are, and otherwise the membership gets the guild's name and the player's rank. So Lock for hands back the guild a player is in, as it is now, with both rows locked until the transaction ends. Set rank takes who's asking, the player and the rank to give them, and checks what it can before touching MySQL, as a check in memory costs nothing, while a transaction holds locks. Leader isn't a rank you can hand out, as a guild has one, and the leader can't change their own rank, so either is an invalid argument, with what the leader can do instead. The rest is a transaction, in a lambda that captures by reference and returns a status, like Create's. It starts with Lock for on the one who asks, which locks their guild's row, and then theirs. Anyone but the leader gets permission denied, in a player's words. We keep the guild, for the news, and Rank in locks the member's row, in the leader's guild, so a player from another guild comes back as not found. Their name comes from players, with a plain select, as they may not be playing, and it's empty if there's no row, which the foreign key rules out while their membership points at it. Last, the update sets their grade, which commits with the transaction. A failed transaction is Set rank's answer, and otherwise, what changed. Leave guild began with these steps written out, so it calls Lock for now, and its own copy of them goes. The guild and its name come from the membership, and the check for the leader reads the rank that Lock for found. In the server's header file, Set rank is the server's half of it. In the server, the switch sends promote to Set rank with an officer's rank, and demote with a member's, so one function does both, as they differ in the rank alone. Set rank asks Guilds, with the leader's id, the player's and the rank. When Guilds says no, Refuse tells the leader why, in the error's words, or with try again when it's MySQL. When the player is playing here, their membership takes the new rank, so their own window shows it, and Refresh guild sends the guild's players here the roster again. Then the guild hears it, with the conditional operator choosing the words: they're an officer now, or a member now.

16:39 On the client, officers are made from a menu on the roster. In the guild window's header file, we bring in cstdint, as Build now takes you, by your character's id, so it can tell your row from the others. Its description keeps what it said, that it draws the question and the window, and returns what the player asks for. And a right-click on someone in the roster now opens a menu of what your rank lets you do to theirs. In guild window, Build takes your id as well. Before the rows, leader says whether you lead the guild. Each row pushes the member's id onto ImGui's ID stack. ImGui tells widgets apart by their labels, and each row's menu is going to be called Member, so without the id, the rows would share one menu. Begin disabled goes, as a disabled row doesn't take clicks, and the leader may well want to make an offline player an officer. So the colour is the theme's text colour for a player who's online, and its disabled colour otherwise, pushed for the name. Above it, we write why: grey for those who aren't playing, but not their menu. The name is a selectable now, which is ImGui's clickable line of text, and span all columns stretches it across the row, so a right-click anywhere on the row counts. Then comes the menu, which you can see open in the corner, on gwen's row. On someone else's row, and while you lead, Begin popup context item opens a popup called Member when the row is right-clicked. For a member, the menu has Make an officer, which sets promote to their id, and for an officer, Make a member, which sets demote. End popup ends the menu's contents, and it sits inside the if, as ImGui wants it called when Begin popup context item returned true. The colour is pushed again for the rank and the level, as we popped it before the menu, so the menu's words stay white on an offline player's row, and the row pops its id at the end. In the client's main, Build gets our id from the world the server sent us, as you.

18:41 To make an officer, we go back to Iron Wolves, which arthur leads, with gwen as a member who's playing. The roster looks as before, with gwen's row in white. A right-click on her row opens the menu, which has one choice for a member, and Make an officer sends the server her character's id. The transaction locks the guild's row, then arthur's, then hers, and sets her grade to an officer's. The guild hears that she's an officer now, and the roster that comes with the news has her under arthur.

19:14 Let's test who may change a rank, starting with Guilds, against MySQL. Like the roster's test, it makes a Guilds of its own on the fixture's MySQL and Redis. The guild comes together the way players make one, with Create, Invite and Accept, and no rows written by hand, so the test goes through the code the server runs. alice founds Iron Wolves, and the test asserts that worked, as the rest needs the guild. Then bob and dave join it, in that order, each asked in by alice, and each accepting, with an assert on each step. When alice makes bob an officer, the test asserts it worked, printing the status if not. Changed has his name, which the fixture made from the test's name and a b, and Of agrees he's an officer. Then come the refusals, starting with bob, who as an officer can't make dave one, and above that check, we note that an officer asks people in, and changes nobody's rank. Making carol an officer is not found, as she's in another world, and in no guild, and leader isn't a rank alice can hand out. Last, alice makes bob a member again, which works. So the refusals above come from the rules, as a Set rank that refused everything would fail this last step. In the server test, alice and bob join over TLS, each with a token the fixture issues, and the test waits until both have had their first guild news, so it knows they're both in the world. Run until gives each wait like that five seconds at most, and returns false after that, so the assert stops a test that's stuck, instead of letting it hang. Then the guild comes together as in the roster's test. alice founds it, and the test waits for her guild news. She asks bob in by his name, and the test waits for his invitation, and bob accepts, and the test waits until his guild news has him in Iron Wolves. Then alice sends promote, with bob's id, like the menu would. The test runs until bob's own guild news says he's an officer, and alice's roster has him as one too. And bob hears the news, word for word, as the last notice he got, which is the line the chat showed in the game a moment ago.

21:21 We run the new tests at this step, and with them, last episode's three Guilds tests of leaving, as Leave guild starts with Lock for now. Leaving still hands the guild on, the leader alone changes ranks, and all five pass.

Removing a player

21:34 Next, taking a player out of the guild, which is where the ranks start deciding who may do what to whom. In our proto file, kick is one more id in the oneof, and over it, we write that it takes a player of a lower rank out of the guild, by their character's id. In the guilds' header file, Kick goes after Set rank, and returns a Changed too, for the news. It takes a player out of the guild of the one who asks. The rule is that the one who asks has to rank above them, so the leader removes officers and members, and officers remove members. Permission denied says they don't, and not found that the player isn't in their guild. In guilds, Kick first turns away a player who tries to remove themselves, with an error that points them at leaving, as leaving hands the guild on and a kick doesn't. The transaction starts like Set rank's, with Lock for on the one acting, which locks the guild's row and then theirs, and Rank in locks the other player's row, in that guild. The rule is then a comparison of the two ranks, as the enum goes up from member to leader, and anything short of a higher rank is refused, in a player's words. I like that the enum's order, which we picked last time so that a missing rank falls back to a member, makes this a single comparison. We keep the guild for the news, and read the player's name from players, like Set rank does, with a plain select, as the lock we need is on their membership, which Rank in already holds. Then the delete takes their row out of the guild. The guild's row stays locked until the transaction commits, so no other change to this guild can run in between. In the server's header file, Kick is the server's half, and in the server, the switch sends kick to it, with the id from the action, like promote. Kick asks Guilds with the two ids, and when Guilds says no, Refuse tells the player why, such as a member who tried to remove an officer, which a modified client could send. Erase returns how many it took out of the map, so one call tells us whether the player was playing here, and drops their membership. If they were, their guild news goes out, which says they're in none, and a notice tells them which guild they were removed from. So they lose the name over their head as well, as the next full world goes out without it. The guild's roster goes out again, and the guild hears who removed whom. A player removed while they play on another instance finds out when they next join, which is good enough for now, like a successor last time. In the guild window, where the corner plays a removal, the menu opens now on anyone of a lower rank than yours, so an officer gets one on members too. Making officers stays with the leader, so those two items check leader, and Remove from the guild goes at the bottom, for whoever gets the menu, and sets kick to the player's id. The client offers what the server's rule allows, so a player isn't shown a choice that gets refused, while the server still checks the ranks, as a modified client could send anything.

24:32 This time, gwen is the one to go, so keep an eye on her, a little way to arthur's left, and on the guild under her name. The roster has her as a member, in white, as she's playing. On a member's row, the leader's menu has two choices now, and Remove from the guild sends the server her id. The transaction deletes her row while it holds the guild's, and then she's told she was removed, the guild hears who removed her, and the next full world takes Iron Wolves from under her name. The roster is down to three, with one of them playing.

25:06 Removing a player can race with that player leaving, as the two can come from different instances of the world, on two connections to MySQL. Say the leader removes bob on one instance, while bob leaves the guild on another. Both transactions start with Lock for, so both ask for the guild's row first, and InnoDB gives it to one of them, while the other waits. The first deletes bob's row and commits, which lets go of the guild's row, and the second gets it, reads bob's row again, finds it gone, and returns not found. Both take their locks in one order, the guild and then the member, so neither can hold what the other is waiting for, and there's no deadlock.

25:45 Now, the tests, starting with who removes whom. The guilds' test brings in thread, the standard library's threads, as the race further down needs two things running at once. It tries the rule across all three ranks, so it needs a guild with one of each. Like the others, it makes its own Guilds on the fixture's MySQL and Redis, and alice founds Iron Wolves. Then bob and dave join, each asked in by alice, and each accepting, and alice makes bob an officer, so there's a leader, an officer and a member. dave, a member, can't remove bob, an officer, and bob can't remove alice, who leads. But bob can remove dave, a member, and Changed names him, and dave is in no guild afterwards. Last, alice removes bob, an officer, which the leader can. The second test is the race from the diagram. Above it, we write what it does: a kick and a leave at once, on two connections, as two instances would, where the guild's row makes one wait for the other, and neither deadlocks. alice founds the guild, and bob joins it, asked in by alice, so there's a member for the two to race over. Then the test opens a second connection to MySQL, and one to Redis, the way the fixture opens its own, for a second Guilds, called elsewhere, as if it were another instance's, and asserts that both connected. A connection runs one transaction at a time, so with one, the race couldn't happen at all. Two threads start, one where alice removes bob, through the first Guilds, and one where bob leaves, through elsewhere. Each lambda captures by reference, to write its status into the test's variables, and join waits for each thread to finish. Then the checks: one of the two worked and the other didn't, and if not, the message prints both statuses, since whichever went second found bob gone. The one that failed, whichever it was, failed with not found, as bob's row was gone by the time it looked. Our database class turns a deadlock into aborted, so this check would catch one too. And bob is in no guild, whichever of the two got there first. A race test like this can pass by luck, when one thread happens to finish before the other starts, so on its own it doesn't prove the locks right. It does catch a run where both succeed, or where either fails with anything but not found, such as a deadlock. In the server test, the new test is built like the officer's, from lines I've copied from test to test this episode. alice and bob join over TLS, and the test waits for their first guild news. Those lines could go in a helper on the fixture, and I'll likely make one if they keep spreading. For now, though, each test still reads from top to bottom without a trip to the fixture, and I'd keep it that way while it's this short. Then alice founds Iron Wolves, and the test waits until her guild news says so. She asks bob in by his name, and the test waits for his invitation to arrive, and bob accepts, and the test waits until his guild news says he's in Iron Wolves. Then alice sends kick, with bob's id, as the remove item would. The test runs until bob's guild news says he's in none, and alice's roster is down to her, and then until bob's last notice says which guild he was removed from.

28:53 We run the three new tests at this step, against MySQL and Redis in Compose, and the race among them runs on two connections, in two threads. The kick and the leave went one after the other, with the second finding bob gone, and all three pass.

Disbanding

29:07 Last, disbanding, for a leader who wants to end the guild altogether. In our proto file, disband is a bool in the oneof, like leave, as there's nothing to say but yes, and over it, we write that the leader ends the guild, for everyone in it. In the guilds' header file, Disband ends the leader's guild, so its name is free again. Permission denied says the one who asks doesn't lead it, and it returns the guild that ended, for the news. In guilds, Disband takes the one who asks and nothing else, as a leader can disband their own guild and no other. It's a transaction that starts with Lock for on the leader, which locks the guild's row and then theirs, and it turns away anyone but the leader, with permission denied. We keep the membership, for the guild's id and name, and delete the guild's row. Its members' rows go with it, as the foreign key from last episode, with on delete cascade, deletes their memberships for us, in that transaction, so a guild can't end with players still in it. Disbanding locks the guild's row first, like the other changes, so a player joining at that moment either gets in first, and goes with the guild, or finds it gone. In the server's header file, Disband is the server's half, and in the server, the switch sends disband to it, with the player's id alone, as the server finds their guild in MySQL. Disband asks Guilds, and Refuse says why when it can't, say to a member whose client sends disband anyway. The news is who disbanded which guild, and Tell guild sends it to the guild's players here while they're still in members. Then erase if, a function C++20 added for the standard containers, takes each of the guild's members out of the map, with a lambda that also puts them in guild news, so they're told they're in no guild. So everyone in it who's playing here is in no guild now. On the client, disbanding asks first, as it can't be undone. In the guild window's header file, we bring in string, and Build disband asks the leader whether to disband the guild, for everyone in it. Disbanding says whether the question is up, and starts out false. In guild window, we bring in string too. Under Leave the guild, the leader gets Disband the guild, as a plain button, which puts the question up and sends nothing yet. After the window, while the question's up and we're in a guild, Build disband draws it, with our guild's name, and its answer, if any, becomes the window's action. Build disband draws the question you can see in the corner. It takes the guild's name, for its line, and returns the answer, if there is one. Like the question to join a guild, it's centred across and can't be moved, and it sits a little over four tenths down, over the guild window. It's a panel titled Disband, with a question mark, and its line names the guild, and says it's for everyone in it, for good, which a leader should know before clicking. Disband, in the fire's colours, sets disband and closes the question. Keep it closes it too, and whatever closed it, disbanding follows open, so the question stays down until the button's clicked again.

32:12 Disbanding comes last, and gwen is still in the guild and playing, so watch the name over her head. The leader's window has Disband the guild, under Leave the guild, which asks first, naming the guild, with Disband and Keep it. Disband deletes the guild's row, and MySQL takes its members' rows with it. So the guild hears who disbanded it, the window goes back to founding a guild, and Iron Wolves goes from over gwen's head, and from arthur's frame.

32:42 Disbanding gets its tests too, one against MySQL and one over the network. In it, the test makes its Guilds, and alice founds Iron Wolves. Then bob joins as a member, asked in by alice, so there's a member whose row the disband has to take too. As a member, bob can't disband it, while alice can, and the test asserts that worked, printing the status if not. Disband returns the guild that ended, Iron Wolves. Afterwards, bob is in no guild, which shows the cascade took his row, and dave can found Iron Wolves in that world straight away, as the name went with the guild's row. In the server test, this one checks what the players are told, which the Guilds test can't see, as the news comes from the server. alice and bob join over TLS, as players the server sends its news to, and the test waits for their first guild news. The guild comes together as in the officer's test, with alice founding it, asking bob in, which puts his invitation in Redis for a minute, and bob accepting, with a wait after each. Accepting reads the invitation from Redis, and deletes it once he's in. Then alice sends disband, with nothing else in the action, as the server knows her guild. The test runs until both have guild news that says they're in none, and then until bob's last notice says that alice disbanded Iron Wolves.

34:03 To finish, we run all of Guilds' tests at this step, from last episode's to today's, with the server's test of disbanding, against MySQL and Redis in Compose. The leader alone disbands, the name is free straight after, and all sixteen pass.

Wrap-up

34:18 In this episode, the guild window got a roster from MySQL, with each server adding who's playing on it and their level now, read at most once a tick for each guild. The leader makes officers from a menu on it, a higher rank removes a lower one, and the leader can disband the guild, after a question. Each change locks the guild's row first, and then its players', so two changes to one guild go one after the other, without a deadlock.

Playing it

35:35 Let me know in the comments what you'd want a guild's officers to be able to do, or what else you'd like to see next. If you'd like to follow along with the series, subscribing to the channel helps a lot. I hope you find this useful, and thanks for watching.