Repository navigation
Conversation
Adds a CreateGuild RPC: the guild row, the five default 3.3.5 ranks and the
leader as guild master are inserted in one transaction, the guild id being
allocated as MAX(guildid)+1 with a retry on primary key conflicts (a
worldserver can still create guilds in-process concurrently). The created
guild is cached hydrated and a guild.created event is published.
Also implements the GuildByRealmAndID mysql repo method that was left as
panic("implement me") - the cache needs it to hydrate the new guild.
(cherry picked from commit 3608d5a3f14348c31ca54faafb07f27948919bfc)
…ild creation The world can disband guilds without going through the guild service (e.g. GM .guild delete handled in-process), leaving a stale positive membership in the in-memory cache. CreateGuild now rechecks a positive answer against the database and evicts the stale cache entry, instead of rejecting with 'already in guild' until the service restarts. Also treats a missing guild_member row as 'not in a guild' in the MySQL repo instead of surfacing sql.ErrNoRows. (cherry picked from commit 2c779169db1722cb20bfa58faf8674a482af09f1)
Guild creation is always driven by a live session of the leader, but in cluster mode the world doesn't flush the online flag to the characters table, so the hydration read the leader back as offline. This left the fresh guild with an empty online-members list: the roster showed the leader disconnected and guild events (e.g. MOTD updates) were broadcast to nobody until the leader relogged. (cherry picked from commit 7000ccaa6c9f19ce89c1f3884f355243a74628d9)
…ity) The core's CreateDefaultGuildRanks gives both Guild Master and Officer GR_RIGHT_ALL; the service only gave the Officer chat rights, so a freshly promoted officer had every guild action greyed out client-side (invite, promote, etc.). Match the core layout and assert it in the create test.
- CreateGuildParams gains signatoryGUIDs; members are inserted with the lowest rank in the same transaction, skipping characters that joined another guild since signing. - guild.created event now carries the added member guids so worldservers can populate the state for the new guild. - New worldserver RPC CanTurnInGuildPetition for the gateway to validate petitions on the worldserver side before calling CreateGuild.
The world can mutate guild_member without going through the service (petition turn-in, in-process invites, GM commands), leaving the cache blind to those members until restart. Guild reads now re-hydrate the guild from the repo, throttled to one refresh per guild every 3s. Online statuses are overlaid from a new gateway-events-driven online set that also tracks characters that aren't guild members yet, since characters.online isn't maintained for cluster sessions. (cherry picked from commit 4d9df78)
cb059d9 to
acdd506
Compare
There was a problem hiding this comment.
Pull request overview
Implements guild bank persistence and per-rank/per-tab rights enforcement in the guildserver, aligning storage with the stock AzerothCore schema so worldserver/tooling can continue reading the same tables.
Changes:
- Added guild bank storage repo (MySQL) plus a guild bank domain service enforcing tab/money rights, daily withdrawal caps, and emitting
guild.bank.*events. - Extended GuildService gRPC/proto APIs with guild creation + bank RPCs, and carried per-tab rights through roster/rank messages.
- Improved in-memory guild cache by re-hydrating rosters on reads (throttled) and tracking/recovering online state.
Reviewed changes
Copilot reviewed 20 out of 24 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| shared/events/producer-guild.go | Adds producer methods for guild-created and bank-related events |
| shared/events/mocks/GuildServiceProducer.go | Extends event producer mock for new events |
| shared/events/events-guild.go | Defines new guild/bank events, subjects, and payloads |
| gen/guilds/pb/guilds_grpc.pb.go | Regenerates gRPC stubs for new GuildService RPCs |
| apps/guildserver/service/guilds.go | Adds CreateGuild logic and guild name validation |
| apps/guildserver/service/guilds-create_test.go | Adds service-level tests for CreateGuild behavior |
| apps/guildserver/service/guilds-cache.go | Extends cache interface with online seeding + source membership lookup |
| apps/guildserver/service/guilds-cache_inmem.go | Adds roster refresh-from-source, online tracking, and cache-aware CreateGuild |
| apps/guildserver/service/guilds-cache_inmem_test.go | Adds tests for refresh behavior, online tracking, and cache CreateGuild |
| apps/guildserver/service/guilds_test.go | Updates tests to account for refresh throttling behavior |
| apps/guildserver/service/bank.go | Introduces GuildBankService enforcing rights and emitting bank events |
| apps/guildserver/service/bank_test.go | Adds unit tests for bank rights and core flows |
| apps/guildserver/server/guilds.go | Wires bank tab rights into roster + persists rank bank rights + CreateGuild RPC |
| apps/guildserver/server/guilds-logger_debug.go | Adds debug-middleware forwarding for new RPCs |
| apps/guildserver/server/bank.go | Implements bank RPC handlers and error-to-status mapping |
| apps/guildserver/repo/mocks/guilds-repo.go | Extends GuildsRepo mock with CreateGuild |
| apps/guildserver/repo/guilds.go | Adds GuildsRepo.CreateGuild contract + name-taken error |
| apps/guildserver/repo/guilds_mysql.go | Implements GuildByRealmAndID and CreateGuild in MySQL |
| apps/guildserver/repo/bank.go | Defines bank repo API, constants, and error types |
| apps/guildserver/repo/bank_mysql.go | Implements bank persistence and transactional operations in MySQL |
| apps/guildserver/config/config.go | Adds characters-service address config for online recovery |
| apps/guildserver/cmd/guildserver/main.go | Wires bank service + daily reset + online seeding |
| api/proto/v1/guilds/guilds.proto | Adds CreateGuild + bank RPCs and roster/rank bank-right fields |
Files not reviewed (3)
- apps/guildserver/repo/mocks/guilds-repo.go: Generated file
- gen/guilds/pb/guilds_grpc.pb.go: Generated file
- shared/events/mocks/GuildServiceProducer.go: Generated file
Comments suppressed due to low confidence (1)
apps/guildserver/repo/bank_mysql.go:215
- WithdrawMoney later casts amount to uint32 (for the daily counter and event log). If amount > 2^32-1, the cast truncates and can bypass the daily limit / corrupt logs. Add a guard before any uint32 conversion.
func (g *guildBankMySQLRepo) WithdrawMoney(ctx context.Context, realmID uint32, guildID, playerGUID, amount uint64, dailyLimit uint32) (uint64, error) {
tx, err := g.db.DBByRealm(realmID).BeginTx(ctx, nil)
if err != nil {
return 0, err
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| return service.NewGuildService(cache, events.NewGuildServiceProducerNatsJSON(natsCon, guildserver.Ver)) | ||
| seedOnlineChars(cfg, cache, 1) |
There was a problem hiding this comment.
Fixed in #56, where the line comes from: it now loops over the configured realms, like the withdrawal reset in this PR already does.
| func (g *guildBankMySQLRepo) DepositMoney(ctx context.Context, realmID uint32, guildID, playerGUID, amount uint64) (uint64, error) { | ||
| tx, err := g.db.DBByRealm(realmID).BeginTx(ctx, nil) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| defer tx.Rollback() | ||
|
|
||
| res, err := tx.ExecContext(ctx, | ||
| "UPDATE guild SET BankMoney = BankMoney + ? WHERE guildid = ? AND BankMoney <= ?", | ||
| amount, guildID, GuildBankMoneyLimit-amount) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| if n, _ := res.RowsAffected(); n == 0 { | ||
| return 0, ErrBankMoneyLimit | ||
| } | ||
|
|
||
| if err = g.insertLog(ctx, tx, guildID, GuildBankMoneyLogsDBTab, BankLogDepositMoney, playerGUID, uint32(amount), 0, 0); err != nil { | ||
| return 0, err | ||
| } | ||
|
|
There was a problem hiding this comment.
The underflow is real and is fixed — an amount above the cap is now rejected before the bound is computed.
The uint32 in the log is deliberate: guild_bank_eventlog.ItemOrMoney is int unsigned in the AzerothCore schema, and this PR keeps the stock schema so the core tooling still reads it. A single deposit cannot exceed that anyway, since the client sends the amount as a 32-bit value and a player cannot carry more.
| func (g *guildBankMySQLRepo) CreateTab(ctx context.Context, realmID uint32, guildID, playerGUID uint64, tabID uint8, cost uint64) error { | ||
| tx, err := g.db.DBByRealm(realmID).BeginTx(ctx, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer tx.Rollback() | ||
|
|
||
| var count uint8 | ||
| if err = tx.QueryRowContext(ctx, | ||
| "SELECT COUNT(*) FROM guild_bank_tab WHERE guildid = ? FOR UPDATE", guildID).Scan(&count); err != nil { | ||
| return err | ||
| } | ||
| if tabID != count || tabID >= GuildBankMaxTabs { | ||
| return ErrBankTabNotFound | ||
| } | ||
|
|
||
| _, err = tx.ExecContext(ctx, | ||
| "INSERT INTO guild_bank_tab (guildid, TabId, TabName, TabIcon, TabText) VALUES (?, ?, '', '', '')", | ||
| guildID, tabID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return tx.Commit() | ||
| } |
There was a problem hiding this comment.
Fixed: the purchase is now logged as BankLogBuySlot in the money log with the buyer and the cost, inside the same transaction as the tab insert.
| log.Warn().Err(err).Msg("guild bank operation failed with unexpected error") | ||
| return err |
There was a problem hiding this comment.
Fixed. It now returns codes.Internal with a generic message after logging, so nothing internal reaches the gateway.
| func (g *guildBankMySQLRepo) SetTabText(ctx context.Context, realmID uint32, guildID uint64, tabID uint8, text string) error { | ||
| _, err := g.db.DBByRealm(realmID).ExecContext(ctx, | ||
| "UPDATE guild_bank_tab SET TabText = ? WHERE guildid = ? AND TabId = ?", | ||
| text, guildID, tabID) | ||
| return err | ||
| } |
There was a problem hiding this comment.
Fixed, using the same pattern as SetTabInfo just above: on zero rows affected I check whether the tab exists and return ErrBankTabNotFound when it does not, since an unchanged text also reports zero rows.
acdd506 to
b4eb354
Compare
…rvice on startup Login events observed before the process started are gone, so members hydrated from the DB stay offline until they relog. On startup the online state is recovered from the characters service (GetOnlineCharacters) and overlaid on the cached rosters, including guilds created in-process. Best effort: disabled when the address is empty, degrades to stale statuses on failure.
b4eb354 to
cf35c3e
Compare
The guild bank was not implemented on the guild service side. This adds it on top of the stock AzerothCore schema (guild_bank_tab, guild_bank_item, guild_bank_right, guild_bank_eventlog, guild_member_withdraw, guild.BankMoney) so existing tooling and the worldserver keep reading the same data. - storage for tabs, items, rights and the money balance; - a service enforcing rights per rank and per tab with a guild master bypass, and daily withdrawal counters accounted inside the storage transactions so concurrent withdrawals cannot exceed the cap; - an event log capped at 25 entries per tab, like the core does; - guild.bank.* events so gateways can refresh open bank frames; - bank RPCs on GuildService, and per-tab rights carried by the roster and rank messages. The gateway side comes in a follow-up. The rights matrix is covered by tests.
cf35c3e to
2657d30
Compare
|
Superseded by #82, which regroups the guild bank work into a single PR as discussed. Same content, rebased on current master, with the review points from this PR already applied. |
Depends on #55 and #56 — the commits below those two are shown here because this branch sits on top of them. The gateway side is a follow-up PR.
The guild bank was not implemented on the guild service side. This adds it on top of the stock AzerothCore schema (
guild_bank_tab,guild_bank_item,guild_bank_right,guild_bank_eventlog,guild_member_withdraw,guild.BankMoney) so existing tooling and the worldserver keep reading the same data.guild.bank.*events so gateways can refresh open bank frames;GuildService, and per-tab rights carried by the roster and rank messages.One thing worth flagging for anyone reading the rights code: I could not reuse the usual
rights & righttest for the withdraw flags.RightWithdrawGoldandRightRepairdo not carry theRightEmptybit, so the comparison returns true for ranks that should not have them. The service uses a plain mask instead, and the rights matrix is covered by tests.