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)
There was a problem hiding this comment.
Pull request overview
This PR adds end-to-end guild bank support in cluster mode by moving guild bank state/rights into the guild service, routing client bank opcodes through the gateway, and using worldserver RPCs for item/money mutations so the in-world guild bank handlers are never relied on.
Changes:
- Introduces guild bank storage + business logic in
guildserver(tabs, items placement, money, rights, logs, daily withdrawal counters) and exposes it via new gRPC endpoints/events. - Extends the worldserver sidecar API with
GetPlayerItemByPosandSetPlayerGuildFieldsto support bank deposit flows and live guild UI refresh. - Updates the gateway to intercept guild bank opcodes, translate them into guild/world RPCs, and push live bank refreshes from
guild.bank.*events.
Reviewed changes
Copilot reviewed 52 out of 55 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| shared/events/producer-guild.go | Adds producer methods for guild-created and guild bank events. |
| shared/events/mocks/GuildServiceProducer.go | Updates mock producer with new event methods. |
| shared/events/events-guild.go | Adds new guild/bank event enums, subjects, and payload types. |
| gen/worldserver/pb/worldserver_grpc.pb.go | Regenerates gRPC stubs with new worldserver RPCs. |
| gen/worldserver/pb/mocks/WorldServerServiceClient.go | Updates worldserver client mock with new RPCs. |
| gen/guilds/pb/guilds_grpc.pb.go | Regenerates guildservice gRPC stubs with guild bank + CreateGuild RPCs. |
| game-server/libsidecar/player-items-api.h | Adds C API surface for GetPlayerItemByPos. |
| game-server/libsidecar/player-items-api.go | Wires Go exports + handler wrapper for GetPlayerItemByPos. |
| game-server/libsidecar/player-items-api.c | Adds C trampoline for GetPlayerItemByPos handler. |
| game-server/libsidecar/player-guild-api.h | Adds C API surface for SetPlayerGuildFields. |
| game-server/libsidecar/player-guild-api.go | Adds Go export + wrapper for SetPlayerGuildFields. |
| game-server/libsidecar/player-guild-api.c | Adds C trampoline for SetPlayerGuildFields handler. |
| game-server/libsidecar/grpcapi/server-items.go | Implements gRPC endpoint GetPlayerItemByPos on sidecar. |
| game-server/libsidecar/grpcapi/server-guild.go | Implements gRPC endpoint SetPlayerGuildFields on sidecar. |
| game-server/libsidecar/grpcapi/cpp-bindings.go | Extends bindings struct with new item/guild-field handlers. |
| game-server/libsidecar/grpc-api.go | Registers new bindings in GRPC service setup. |
| game-server/libsidecar-cpp/src/grpc/worldserver_service.h | Extends native sidecar gRPC service interface. |
| game-server/libsidecar-cpp/src/grpc/worldserver_service.cpp | Implements native gRPC handlers for new RPCs. |
| game-server/libsidecar-cpp/src/compat_api.cpp | Adds compatibility surface (warns bridging not implemented). |
| game-server/libsidecar-cpp/src/api.cpp | Registers new handler bridges into native bindings. |
| game-server/libsidecar-cpp/include/player-items-api.h | Adds public C header for GetPlayerItemByPos. |
| game-server/libsidecar-cpp/include/player-guild-api.h | Adds public C header for SetPlayerGuildFields. |
| game-server/libsidecar-cpp/include/libsidecar/tc9_types.h | Adds TC9 types for new RPCs/handlers. |
| game-server/libsidecar-cpp/include/libsidecar.h | Exposes new headers + registration functions. |
| apps/guildserver/service/guilds.go | Adds CreateGuild service flow + publishes GuildCreated event. |
| apps/guildserver/service/guilds-create_test.go | Adds unit tests for CreateGuild behavior. |
| apps/guildserver/service/guilds-cache.go | Extends cache interface (seed online chars + source membership). |
| apps/guildserver/service/guilds-cache_inmem.go | Adds source-refresh + online overlay + membership source methods. |
| apps/guildserver/service/guilds-cache_inmem_test.go | Adds tests for refresh/throttle/online overlay/eviction paths. |
| apps/guildserver/service/guilds_test.go | Adjusts existing tests for new cache refresh bookkeeping. |
| apps/guildserver/service/bank.go | Implements guild bank business logic and event publishing. |
| apps/guildserver/service/bank_test.go | Adds unit tests for bank rights, restore, and costs behavior. |
| apps/guildserver/server/guilds.go | Adds bank rights into roster and persists bank rights on UpdateRank; adds CreateGuild RPC. |
| apps/guildserver/server/guilds-logger_debug.go | Pass-through logging for new bank RPCs + CreateGuild. |
| apps/guildserver/server/bank.go | Implements gRPC handlers and status mapping for bank RPCs. |
| apps/guildserver/repo/mocks/guilds-repo.go | Adds CreateGuild to repo mock. |
| apps/guildserver/repo/guilds.go | Adds CreateGuild to repo interface + ErrGuildNameTaken. |
| apps/guildserver/repo/guilds_mysql.go | Implements GuildByRealmAndID + CreateGuild transaction logic. |
| apps/guildserver/repo/bank.go | Defines bank repo interface, constants, models, and errors. |
| apps/guildserver/repo/bank_mysql.go | Implements MySQL storage for bank state, rights, logs, and counters. |
| apps/guildserver/config/config.go | Adds characters service address for online-state recovery. |
| apps/guildserver/cmd/guildserver/main.go | Wires bank repo/service, daily reset, and online-state seeding. |
| apps/gateway/session/session.go | Tracks “bank open” state for live refresh behavior. |
| apps/gateway/session/handler.go | Registers handlers for guild bank opcodes. |
| apps/gateway/session/handler-events.go | Registers handlers for guild bank NATS-driven events. |
| apps/gateway/session/guild.go | Plumbs bank rights into roster/permissions and reads rank bank rights from CMSG_GUILD_RANK. |
| apps/gateway/session/guild-bank.go | Implements guild bank opcode handling + item/money flows via RPCs and live updates. |
| apps/gateway/session/guild_test.go | Updates test mock to satisfy new GetBankState usage. |
| apps/gateway/service/listener-guild.go | Subscribes to new guild.bank.* NATS subjects. |
| apps/gateway/events-broadcaster/mocks/Broadcaster.go | Updates broadcaster mock with new guild bank events. |
| apps/gateway/events-broadcaster/broadcaster.go | Adds new event types + fanout for guild bank events. |
| api/proto/v1/worldserver/worldserver.proto | Adds new RPCs/messages for item-by-position and guild field refresh. |
| api/proto/v1/guilds/guilds.proto | Adds CreateGuild + full guild bank RPC/messages and rank/roster extensions. |
Files not reviewed (2)
- apps/gateway/events-broadcaster/mocks/Broadcaster.go: Generated file
- apps/guildserver/repo/mocks/guilds-repo.go: Generated file
Comments suppressed due to low confidence (1)
apps/gateway/session/guild-bank.go:320
BankWithdrawMoneymaps allFailedPreconditionerrors toERR_GUILD_NOT_ENOUGH_MONEY, but the service also usesFailedPreconditionfor the daily withdrawal limit. This causes the client to show the wrong error when the player hits their cap; distinguish the specific condition (at least by message) and returnERR_GUILD_WITHDRAW_LIMIT.
if err != nil {
switch status.Code(err) {
case codes.PermissionDenied:
s.sendGuildCommandResult(guildCommandMoveItem, "", guildErrPermissions)
case codes.FailedPrecondition:
s.sendGuildCommandResult(guildCommandMoveItem, "", guildErrNotEnoughMoney)
}
return nil
💡 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.
Right, and the line predates this PR — it comes from #56, which is in this stack. I fixed it there rather than here: it now loops over the configured realms like the withdrawal reset does.
| if err != nil { | ||
| // Refund the debit. | ||
| _, _ = s.gameServerGRPCClient.ModifyMoneyForPlayer(ctx, &pbGameServ.ModifyMoneyForPlayerRequest{ | ||
| Api: root.Ver, | ||
| PlayerGuid: s.character.GUID, | ||
| Value: int32(amount), | ||
| }) | ||
| s.sendGuildCommandResult(guildCommandMoveItem, "", guildErrBankFull) | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Fixed. It now maps PermissionDenied to ERR_GUILD_PERMISSIONS and keeps bank-full for the rest, which matches what the withdraw path already does. The bank money cap is the only other business failure the service can return here.
| res, err := tx.ExecContext(ctx, | ||
| "UPDATE guild SET BankMoney = BankMoney + ? WHERE guildid = ? AND BankMoney <= ?", | ||
| amount, guildID, GuildBankMoneyLimit-amount) |
There was a problem hiding this comment.
Good catch, the guard was indeed ineffective — the subtraction wraps around and the BankMoney <= ? bound becomes huge. Fixed in #77 (where the file lives) by rejecting an amount above the cap before computing the bound. Not reachable from the client today, since a deposit is capped by the money a player can carry, but the check was there to be a check.
8cb6235 to
37df3a8
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.
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.
37df3a8 to
4ef94de
Compare
Two RPCs the cluster side needs on a live player object, exposed by both sidecars (the Go c-shared one and the native libsidecar-cpp): - GetPlayerItemByPos resolves the item at a given (bag, slot) into the same Item shape the other item RPCs return. Packets like CMSG_GUILD_BANK_SWAP_ITEMS carry an inventory position instead of the item guid, and the gateway has no view of the player's inventory. - SetPlayerGuildFields refreshes PLAYER_GUILDID / PLAYER_GUILDRANK on the live player object. In cluster mode guild membership is owned by the guild service, so those unit fields stay stale until the player relogs, and the 3.3.5 client gates its guild control buttons on them rather than on the roster. Both return whether the player was found on this worldserver, so callers can degrade cleanly. The AzerothCore-side handlers are a companion PR.
Intercepts the guild bank opcodes so the guild code inside the worldserver is never reached in cluster mode, where it has no Guild object to work with and answers nothing. Items move between the player and the bank through the worldserver item RPCs: a deposit detaches the item first and restores it if the bank refuses it, a failed withdraw gives it back. Money is debited first for the same reason. Per-tab rights ride on SMSG_GUILD_BANK_LIST, MSG_GUILD_PERMISSIONS and the roster rank block, and CMSG_GUILD_RANK carries the six tab right/slot pairs the client sends. Open bank frames are refreshed from the guild.bank.* events, with a partial slot update on deposit/withdraw/move so emptied slots disappear without reopening the frame.
4ef94de to
a6fdeca
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 #77 (guild service side) and #75 (worldserver item RPC) — the commits from both are shown here because this branch sits on top of them.
Intercepts the guild bank opcodes so the guild code inside the worldserver is never reached in cluster mode, where it has no
Guildobject to work with and simply answers nothing — the bank frame stays empty and the client gets no error.Items move between the player and the bank through the worldserver item RPCs: a deposit detaches the item first and puts it back if the bank refuses it, a failed withdraw gives it back. Money is debited first for the same reason. Per-tab rights ride on
SMSG_GUILD_BANK_LIST,MSG_GUILD_PERMISSIONSand the roster rank block, andCMSG_GUILD_RANKreads the six tab right/slot pairs the client sends.Open bank frames are refreshed from the
guild.bank.*events, with a partial slot update on deposit/withdraw/move so emptied slots disappear without reopening the frame — the full update only lists occupied slots, so an emptied one would otherwise stay on screen.Two details that cost me some time and are worth knowing:
CMSG_GUILD_BANK_SWAP_ITEMScarries(bag, slot, entry)for a deposit, not the item guid. That is whatGetPlayerItemByPosin feat(worldserver): item-by-position and guild-field player RPCs #75 is for.SMSG_GUILD_BANK_LIST, the byte that tells the client a full update is coming also decides whether the tab-info block is present. Deriving the two from separate conditions makes the client read item bytes as tab names, so both come from the same flag here.Known gaps in this first version, all answered with a proper client message rather than silently dropped: stack splits, swapping directly onto an occupied slot, withdrawing to a chosen slot (it auto-stores), and item repairs. Enchantments are lost on withdraw, same as the mail and auction paths do today.