Skip to content

Commit cf35c3e

Browse files
3kynox3kynox
authored andcommitted
feat(guildserver): guild bank storage and per-rank tab rights
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.
1 parent a5b5d0c commit cf35c3e

14 files changed

Lines changed: 5427 additions & 472 deletions

File tree

‎api/proto/v1/guilds/guilds.proto‎

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ service GuildService {
3131
rpc SendGuildMessage(SendGuildMessageParams) returns (SendGuildMessageResponse);
3232

3333
rpc CreateGuild(CreateGuildParams) returns (CreateGuildResponse);
34+
35+
// Guild bank. The guild service is the only writer of the bank state
36+
// (tabs, items placement, money, per-rank tab rights, withdrawal counters).
37+
// Items themselves live in item_instance and move between a player and the
38+
// bank through the worldserver items API, driven by the gateway.
39+
rpc GetBankState(GetBankStateParams) returns (GetBankStateResponse);
40+
rpc GetBankTab(GetBankTabParams) returns (GetBankTabResponse);
41+
rpc BankDepositMoney(BankMoneyParams) returns (BankMoneyResponse);
42+
rpc BankWithdrawMoney(BankMoneyParams) returns (BankMoneyResponse);
43+
rpc BankDepositItem(BankDepositItemParams) returns (BankDepositItemResponse);
44+
rpc BankWithdrawItem(BankWithdrawItemParams) returns (BankWithdrawItemResponse);
45+
rpc BankMoveItem(BankMoveItemParams) returns (BankMoveItemResponse);
46+
rpc BankBuyTab(BankBuyTabParams) returns (BankBuyTabResponse);
47+
rpc BankSetTabInfo(BankSetTabInfoParams) returns (BankSetTabInfoResponse);
48+
rpc BankSetTabText(BankSetTabTextParams) returns (BankSetTabTextResponse);
49+
rpc GetBankLog(GetBankLogParams) returns (GetBankLogResponse);
3450
}
3551

3652
message GetInfoParams {
@@ -95,6 +111,10 @@ message GetRosterInfoResponse {
95111
uint32 id = 1;
96112
uint32 flags = 2;
97113
uint32 goldLimit = 3;
114+
// Per-bank-tab rights (GUILD_BANK_RIGHT_* bitmask) and item withdrawals
115+
// per day, indexed by tab id. Empty when the guild has no purchased tabs.
116+
repeated uint32 bankTabRights = 4;
117+
repeated uint32 bankTabSlotsPerDay = 5;
98118
}
99119

100120
message Guild {
@@ -214,6 +234,10 @@ message RankUpdateParams {
214234
string rankName = 5;
215235
uint32 rights = 6;
216236
uint32 moneyPerDay = 7;
237+
// Per-bank-tab rights and item withdrawals per day from CMSG_GUILD_RANK
238+
// (6 entries). Only entries for purchased tabs are persisted.
239+
repeated uint32 bankTabRights = 8;
240+
repeated uint32 bankTabSlotsPerDay = 9;
217241
}
218242

219243
message RankUpdateResponse {
@@ -280,3 +304,199 @@ message CreateGuildResponse {
280304

281305
uint64 guildID = 2;
282306
}
307+
308+
// GuildBankItem describes an item stored in the guild bank, with the
309+
// item_instance fields the client needs to render it in the bank list.
310+
message GuildBankItem {
311+
uint32 slot = 1;
312+
uint64 itemGuid = 2;
313+
uint32 entry = 3;
314+
uint32 count = 4;
315+
uint32 flags = 5;
316+
uint32 durability = 6;
317+
int32 randomPropertyID = 7;
318+
// Permanent enchant id (first entry of item_instance.enchantments).
319+
uint32 enchantmentID = 8;
320+
// Remaining charges of the first charged spell, absolute value.
321+
uint32 charges = 9;
322+
string text = 10;
323+
// Gem enchant ids by socket index (0 = empty socket).
324+
repeated uint32 socketEnchantIDs = 11;
325+
}
326+
327+
message GetBankStateParams {
328+
string api = 1;
329+
uint32 realmID = 2;
330+
uint64 guildID = 3;
331+
uint64 playerGUID = 4;
332+
}
333+
334+
message GetBankStateResponse {
335+
string api = 1;
336+
337+
uint64 money = 2;
338+
uint32 rankID = 3;
339+
uint32 rankRights = 4;
340+
// Gold withdrawal limit per day of the member's rank (0xFFFFFFFF = unlimited).
341+
uint32 moneyPerDay = 5;
342+
// Gold the member can still withdraw today (0xFFFFFFFF = unlimited).
343+
uint32 remainingMoney = 6;
344+
345+
message Tab {
346+
string name = 1;
347+
string icon = 2;
348+
string text = 3;
349+
// Member's rights on this tab (GUILD_BANK_RIGHT_* bitmask).
350+
uint32 rights = 4;
351+
// Item withdrawals the member has left today on this tab.
352+
uint32 remainingSlots = 5;
353+
}
354+
// Purchased tabs only, index = tab id.
355+
repeated Tab tabs = 7;
356+
357+
// Cost of the next purchasable tab in copper, 0 when all tabs are purchased.
358+
uint32 nextTabCost = 8;
359+
}
360+
361+
message GetBankTabParams {
362+
string api = 1;
363+
uint32 realmID = 2;
364+
uint64 guildID = 3;
365+
uint64 playerGUID = 4;
366+
uint32 tab = 5;
367+
}
368+
369+
message GetBankTabResponse {
370+
string api = 1;
371+
repeated GuildBankItem items = 2;
372+
}
373+
374+
message BankMoneyParams {
375+
string api = 1;
376+
uint32 realmID = 2;
377+
uint64 guildID = 3;
378+
uint64 playerGUID = 4;
379+
uint64 amount = 5;
380+
}
381+
382+
message BankMoneyResponse {
383+
string api = 1;
384+
uint64 newBankMoney = 2;
385+
uint32 remainingMoney = 3;
386+
}
387+
388+
message BankDepositItemParams {
389+
string api = 1;
390+
uint32 realmID = 2;
391+
uint64 guildID = 3;
392+
uint64 playerGUID = 4;
393+
uint32 tab = 5;
394+
// 255 = first free slot.
395+
uint32 slot = 6;
396+
GuildBankItem item = 7;
397+
// Compensation path (failed withdraw): skip the rights check.
398+
bool restore = 8;
399+
}
400+
401+
message BankDepositItemResponse {
402+
string api = 1;
403+
// Slot the item was placed in.
404+
uint32 slot = 2;
405+
}
406+
407+
message BankWithdrawItemParams {
408+
string api = 1;
409+
uint32 realmID = 2;
410+
uint64 guildID = 3;
411+
uint64 playerGUID = 4;
412+
uint32 tab = 5;
413+
uint32 slot = 6;
414+
}
415+
416+
message BankWithdrawItemResponse {
417+
string api = 1;
418+
GuildBankItem item = 2;
419+
uint32 remainingSlots = 3;
420+
}
421+
422+
message BankMoveItemParams {
423+
string api = 1;
424+
uint32 realmID = 2;
425+
uint64 guildID = 3;
426+
uint64 playerGUID = 4;
427+
uint32 srcTab = 5;
428+
uint32 srcSlot = 6;
429+
uint32 dstTab = 7;
430+
uint32 dstSlot = 8;
431+
// 0 = move/swap the whole stack. Splits are not supported yet.
432+
uint32 splitCount = 9;
433+
}
434+
435+
message BankMoveItemResponse {
436+
string api = 1;
437+
}
438+
439+
message BankBuyTabParams {
440+
string api = 1;
441+
uint32 realmID = 2;
442+
uint64 guildID = 3;
443+
uint64 playerGUID = 4;
444+
uint32 tab = 5;
445+
// Cost the gateway already took from the player, re-validated by the service.
446+
uint32 paidCost = 6;
447+
}
448+
449+
message BankBuyTabResponse {
450+
string api = 1;
451+
}
452+
453+
message BankSetTabInfoParams {
454+
string api = 1;
455+
uint32 realmID = 2;
456+
uint64 guildID = 3;
457+
uint64 playerGUID = 4;
458+
uint32 tab = 5;
459+
string name = 6;
460+
string icon = 7;
461+
}
462+
463+
message BankSetTabInfoResponse {
464+
string api = 1;
465+
}
466+
467+
message BankSetTabTextParams {
468+
string api = 1;
469+
uint32 realmID = 2;
470+
uint64 guildID = 3;
471+
uint64 playerGUID = 4;
472+
uint32 tab = 5;
473+
string text = 6;
474+
}
475+
476+
message BankSetTabTextResponse {
477+
string api = 1;
478+
}
479+
480+
message GetBankLogParams {
481+
string api = 1;
482+
uint32 realmID = 2;
483+
uint64 guildID = 3;
484+
uint64 playerGUID = 4;
485+
// 0-5 = item tab log, 6 = money log.
486+
uint32 tab = 5;
487+
}
488+
489+
message GetBankLogResponse {
490+
string api = 1;
491+
492+
message Entry {
493+
uint32 eventType = 1;
494+
uint64 playerGUID = 2;
495+
uint32 itemEntry = 3;
496+
uint32 count = 4;
497+
uint32 destTab = 5;
498+
uint64 money = 6;
499+
int64 timestamp = 7;
500+
}
501+
repeated Entry entries = 2;
502+
}

‎apps/guildserver/cmd/guildserver/main.go‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ func main() {
6262
}
6363

6464
grpcServer := grpc.NewServer()
65-
guildServer := server.NewGuildServer(createGuildService(cfg, nc))
65+
guildsService, bankService := createGuildService(cfg, nc)
66+
guildServer := server.NewGuildServer(guildsService, bankService)
6667
if cfg.LogLevel == zerolog.DebugLevel {
6768
guildServer = server.NewGuildsDebugLoggerMiddleware(guildServer, log.Logger)
6869
}
@@ -92,7 +93,7 @@ func main() {
9293
log.Info().Msg("👍 Server successfully stopped.")
9394
}
9495

95-
func createGuildService(cfg *config.Config, natsCon *nats.Conn) service.GuildService {
96+
func createGuildService(cfg *config.Config, natsCon *nats.Conn) (service.GuildService, service.GuildBankService) {
9697
charDB := shrepo.NewCharactersDB()
9798
for realmID, connStr := range cfg.CharDBConnection {
9899
cdb, err := sql.Open("mysql", connStr)
@@ -134,7 +135,36 @@ func createGuildService(cfg *config.Config, natsCon *nats.Conn) service.GuildSer
134135
seedOnlineChars(cfg, cache, realmID)
135136
}
136137

137-
return service.NewGuildService(cache, events.NewGuildServiceProducerNatsJSON(natsCon, guildserver.Ver))
138+
producer := events.NewGuildServiceProducerNatsJSON(natsCon, guildserver.Ver)
139+
140+
bankRepo := repo.NewGuildBankMySQLRepo(charDB)
141+
bankService := service.NewGuildBankService(bankRepo, cache, producer)
142+
startBankWithdrawalsReset(cfg, bankRepo)
143+
144+
return service.NewGuildService(cache, producer), bankService
145+
}
146+
147+
// startBankWithdrawalsReset zeroes the daily guild bank withdrawal counters
148+
// of every realm once a day at 06:00 UTC (AC "Guild Daily Cap reset").
149+
func startBankWithdrawalsReset(cfg *config.Config, bankRepo repo.GuildBankRepo) {
150+
go func() {
151+
for {
152+
now := time.Now().UTC()
153+
next := time.Date(now.Year(), now.Month(), now.Day(), 6, 0, 0, 0, time.UTC)
154+
if !next.After(now) {
155+
next = next.Add(24 * time.Hour)
156+
}
157+
time.Sleep(next.Sub(now))
158+
159+
for realmID := range cfg.CharDBConnection {
160+
if err := bankRepo.ResetDailyWithdrawals(context.Background(), realmID); err != nil {
161+
log.Error().Err(err).Uint32("realmID", realmID).Msg("can't reset guild bank withdrawals")
162+
} else {
163+
log.Info().Uint32("realmID", realmID).Msg("guild bank daily withdrawals reset")
164+
}
165+
}
166+
}
167+
}()
138168
}
139169

140170
// seedOnlineChars recovers the online state of characters from the characters

0 commit comments

Comments
 (0)