Skip to content

Commit

Permalink
Add a basic implementation of battlegrounds in preparation for cross-…
Browse files Browse the repository at this point in the history
…realm
  • Loading branch information
walkline committed Nov 6, 2024
1 parent 10ce877 commit 4d570d4
Show file tree
Hide file tree
Showing 84 changed files with 6,524 additions and 408 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ generate:
protoc --proto_path=api/proto/v1/mail --go-grpc_out=. --go_out=. mail.proto
protoc --proto_path=api/proto/v1/worldserver --go-grpc_out=. --go_out=. worldserver.proto
protoc --proto_path=api/proto/v1/group --go-grpc_out=. --go_out=. group.proto
protoc --proto_path=api/proto/v1/matchmaking --go-grpc_out=. --go_out=. matchmaking.proto

migrate-characters:
migrate -database "mysql://trinity:trinity@tcp(localhost:3306)/characters" -path sql/characters/mysql up
Expand Down Expand Up @@ -53,6 +54,9 @@ build-guildserver:
build-mailserver:
go build -o $(INSTALL_PATH)/mailserver apps/mailserver/cmd/mailserver/main.go

build-matchmakingserver:
go build -o $(INSTALL_PATH)/matchmakingserver apps/matchmakingserver/cmd/matchmakingserver/main.go

build-groupserver:
go build -o $(INSTALL_PATH)/groupserver apps/groupserver/cmd/groupserver/main.go

Expand Down Expand Up @@ -83,10 +87,13 @@ compose-rebuild-guidserver:
compose-rebuild-mailserver:
docker-compose up -d --build --no-deps mailserver

compose-rebuild-matchmakingserver:
docker-compose up -d --build --no-deps matchmakingserver

compose-rebuild-groupserver:
docker-compose up -d --build --no-deps groupserver

compose-rebuild-gameserver:
docker-compose up -d --build --no-deps gameserver

install: build-authserver build-charserver build-chatserver build-game-load-balancer build-servers-registry build-sidecar build-guidserver build-guildserver build-mailserver build-groupserver build-perun
install: build-authserver build-charserver build-chatserver build-game-load-balancer build-servers-registry build-sidecar build-guidserver build-guildserver build-mailserver build-groupserver build-perun build-matchmakingserver
119 changes: 119 additions & 0 deletions api/proto/v1/matchmaking/matchmaking.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
syntax = "proto3";
package v1;

option go_package = "gen/matchmaking/pb";

service MatchmakingService {
rpc EnqueueToBattleground(EnqueueToBattlegroundRequest) returns (EnqueueToBattlegroundResponse);

rpc BattlegroundQueueDataForPlayer(BattlegroundQueueDataForPlayerRequest) returns (BattlegroundQueueDataForPlayerResponse);

rpc PlayerLeftBattleground(PlayerLeftBattlegroundRequest) returns (PlayerLeftBattlegroundResponse);
rpc PlayerJoinedBattleground(PlayerJoinedBattlegroundRequest) returns (PlayerJoinedBattlegroundResponse);
rpc BattlegroundStatusChanged(BattlegroundStatusChangedRequest) returns (BattlegroundStatusChangedResponse);
}

enum PVPTeamID {
Any = 0;
Alliance = 1;
Horde = 2;
}

enum PlayerQueueStatus {
NotInQueue = 0;
InQueue = 1;
Invited = 2;
InProgress = 3;
}

message EnqueueToBattlegroundRequest {
string api = 1;
uint32 realmID = 2;

uint64 leaderGUID = 3;
repeated uint64 partyMembers = 4;

uint32 leadersLvl = 5;

uint32 bgTypeID = 6;
PVPTeamID teamID = 7;
}

message EnqueueToBattlegroundResponse {
string api = 1;
}

message BattlegroundQueueDataForPlayerRequest {
string api = 1;

uint32 realmID = 2;
uint64 playerGUID = 3;
}

message BattlegroundQueueDataForPlayerResponse {
string api = 1;

message AssignedBattlegroundData {
uint32 assignedBattlegroundInstanceID = 1;
uint32 mapID = 2;
uint32 battlegroupID = 3;
string gameserverAddress = 4;
string gameserverGRPCAddress = 5;
}

message QueueSlot {
uint32 bgTypeID = 1;
PlayerQueueStatus status = 2;
optional AssignedBattlegroundData assignedBattlegroundData = 3;
};

repeated QueueSlot slots = 2;
}

message PlayerLeftBattlegroundRequest {
string api = 1;

uint32 realmID = 2;
uint64 playerGUID = 3;
uint32 instanceID = 4;
bool isCrossRealm = 5;
}

message PlayerLeftBattlegroundResponse {
string api = 1;
}

message PlayerJoinedBattlegroundRequest {
string api = 1;

uint32 realmID = 2;
uint64 playerGUID = 3;
uint32 instanceID = 4;
bool isCrossRealm = 5;
}

message PlayerJoinedBattlegroundResponse {
string api = 1;
}

message BattlegroundStatusChangedRequest {
string api = 1;

uint32 realmID = 2;
uint32 instanceID = 3;
bool isCrossRealm = 4;

// Use the same statuses as in gameserver (AC/TC)
enum Status {
None = 0; // unused
WaitQueue = 1; // unused
WaitJoin = 2; // unused
InProgress = 3;
Ended = 4;
}
Status status = 5;
}

message BattlegroundStatusChangedResponse {
string api = 1;
}
31 changes: 19 additions & 12 deletions api/proto/v1/servers-registry/registry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ message RegisterGameServerRequest{
uint32 healthPort = 3;
uint32 grpcPort = 4;
uint32 realmID = 5;
string availableMaps = 6;
string preferredHostName = 7;
bool isCrossRealm = 6; // If true realm id should be 0
string availableMaps = 7;
string preferredHostName = 8;
}

message RegisterGameServerResponse{
Expand All @@ -44,6 +45,7 @@ message AvailableGameServersForMapAndRealmRequest{

uint32 realmID = 2;
uint32 mapID = 3;
bool isCrossRealm = 4; // Can't be used with realm id
}

message AvailableGameServersForMapAndRealmResponse{
Expand Down Expand Up @@ -74,6 +76,7 @@ message ListGameServersForRealmRequest {
string api = 1;

uint32 realmID = 2;
bool isCrossRealm = 3; // Can't be used with realm id
}

message GameServerDetailed {
Expand All @@ -85,14 +88,16 @@ message GameServerDetailed {
uint32 max = 5;
};

string address = 1;
string healthAddress = 2;
string grpcAddress = 3;
uint32 realmID = 4;
uint32 activeConnections = 5;
Diff diff = 6;
repeated uint32 availableMaps = 7;
repeated uint32 assignedMaps = 8;
string ID = 1;
string address = 2;
string healthAddress = 3;
string grpcAddress = 4;
uint32 realmID = 5;
bool isCrossRealm = 6;
uint32 activeConnections = 7;
Diff diff = 8;
repeated uint32 availableMaps = 9;
repeated uint32 assignedMaps = 10;
}

message ListGameServersForRealmResponse {
Expand Down Expand Up @@ -124,7 +129,8 @@ message RegisterLoadBalancerRequest{
uint32 gamePort = 2;
uint32 healthPort = 3;
uint32 realmID = 4;
string preferredHostName = 5;
bool isCrossRealm = 5; // Can't be used with realm id
string preferredHostName = 6;
}

message RegisterLoadBalancerResponse{
Expand Down Expand Up @@ -177,5 +183,6 @@ message ListLoadBalancersForRealmResponse {
message Server {
string address = 1;
uint32 realmID = 2;
string grpcAddress = 3;
bool isCrossRealm = 3;
string grpcAddress = 4;
}
57 changes: 57 additions & 0 deletions api/proto/v1/worldserver/worldserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ service WorldServerService {
// Interactions
rpc CanPlayerInteractWithNPC(CanPlayerInteractWithNPCRequest) returns (CanPlayerInteractWithNPCResponse);
rpc CanPlayerInteractWithGameObject(CanPlayerInteractWithGameObjectRequest) returns (CanPlayerInteractWithGameObjectResponse);

// Battlegrounds
rpc StartBattleground(StartBattlegroundRequest) returns (StartBattlegroundResponse);
rpc AddPlayersToBattleground(AddPlayersToBattlegroundRequest) returns (AddPlayersToBattlegroundResponse);
}

// GetPlayerItemsByGuids
Expand Down Expand Up @@ -148,3 +152,56 @@ message CanPlayerInteractWithGameObjectResponse {

bool canInteract = 2;
}

enum BattlegroundType {
None = 0;
AlteracValley = 1;
WarsongGulch = 2;
ArathiBasin = 3;
NagrandArena = 4;
BladesEdgeArena = 5;
AllArenas = 6;
EyeOfTheStorm = 7;
RuinsOfLordaeron = 8;
StrandOfTheAncients = 9;
DalaranSewers = 10;
RingOfValor = 11;
IsleOfConquest = 30;
RandomBattleground = 32;
}

// StartBattleground
message StartBattlegroundRequest {
string api = 1;

BattlegroundType battlegroundTypeID = 2;
uint32 arenaType = 3; // Arenas not supported yet.
bool isRated = 4; // Arenas not supported yet.
uint32 mapID = 5;
uint32 bracketLvl = 6;

repeated uint64 playersToAddAlliance = 7;
repeated uint64 playersToAddHorde = 8;
}

message StartBattlegroundResponse {
string api = 1;

uint32 instanceID = 2;
uint32 clientInstanceID = 3;
}

// AddPlayersToBattleground
message AddPlayersToBattlegroundRequest {
string api = 1;

BattlegroundType battlegroundTypeID = 2;
uint32 instanceID = 3;

repeated uint64 playersToAddAlliance = 4;
repeated uint64 playersToAddHorde = 5;
}

message AddPlayersToBattlegroundResponse {
string api = 1;
}
12 changes: 7 additions & 5 deletions apps/game-load-balancer/balancer.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package game_load_balancer

var RealmID uint32

var RetrievedBalancerID string

const (
Ver = "0.0.1"
SupportedCharServiceVer = "0.0.1"
SupportedServerRegistryVer = "0.0.1"
SupportedMailServiceVer = "0.0.1"
SupportedGroupServiceVer = "0.0.1"
Ver = "0.0.1"
SupportedCharServiceVer = "0.0.1"
SupportedServerRegistryVer = "0.0.1"
SupportedMailServiceVer = "0.0.1"
SupportedGroupServiceVer = "0.0.1"
SupportedMatchmakingServiceVer = "0.0.1"
)
24 changes: 23 additions & 1 deletion apps/game-load-balancer/cmd/game-load-balancer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import (
pbGroup "github.com/walkline/ToCloud9/gen/group/pb"
pbGuild "github.com/walkline/ToCloud9/gen/guilds/pb"
pbMail "github.com/walkline/ToCloud9/gen/mail/pb"
pbMM "github.com/walkline/ToCloud9/gen/matchmaking/pb"
pbServ "github.com/walkline/ToCloud9/gen/servers-registry/pb"
"github.com/walkline/ToCloud9/shared/events"
gameserverconn "github.com/walkline/ToCloud9/shared/gameserver/conn"
"github.com/walkline/ToCloud9/shared/healthandmetrics"
sharedRepo "github.com/walkline/ToCloud9/shared/repo"
//_ "net/http/pprof"
)

func main() {
Expand All @@ -37,6 +40,8 @@ func main() {
// fmt.Println(http.ListenAndServe(":8333", nil))
//}()

//runtime.SetBlockProfileRate(1)

conf, err := config.LoadConfig()
if err != nil {
panic(err)
Expand Down Expand Up @@ -69,6 +74,7 @@ func main() {
guildClient := guildService(conf)
mailClient := mailService(conf)
groupClient := groupService(conf)
matchmakingClient := matchmakingService(conf)

healthandmetrics.EnableActiveConnectionsMetrics()
healthCheckServer := healthandmetrics.NewServer(conf.HealthCheckPort, promhttp.Handler())
Expand Down Expand Up @@ -120,6 +126,12 @@ func main() {
log.Fatal().Err(err).Msg("can't listen to group events-broadcaster")
}

mmListener := service.NewMatchmakingNatsListener(nc, broadcaster)
err = mmListener.Listen()
if err != nil {
log.Fatal().Err(err).Msg("can't listen to matchmaking events-broadcaster")
}

producer := events.NewLoadBalancerProducerNatsJSON(nc, root.Ver, root.RealmID, root.RetrievedBalancerID)
charsUpdsBarrier := service.NewCharactersUpdatesBarrier(&log.Logger, producer, time.Second)
go charsUpdsBarrier.Run(context.TODO())
Expand All @@ -142,11 +154,12 @@ func main() {
ChatServiceClient: chatClient,
GuildsServiceClient: guildClient,
MailServiceClient: mailClient,
MatchmakingServiceClient: matchmakingClient,
GroupServiceClient: groupClient,
EventsProducer: producer,
EventsBroadcaster: broadcaster,
CharsUpdsBarrier: charsUpdsBarrier,
GameServerGRPCConnMgr: service.DefaultGameServerGRPCConnMgr,
GameServerGRPCConnMgr: gameserverconn.DefaultGameServerGRPCConnMgr,
PacketProcessTimeout: time.Second * time.Duration(conf.PacketProcessTimeoutSecs),
ShowGameserverConnChangeToClient: conf.ShowGameserverConnChangeToClient,
})
Expand All @@ -169,6 +182,15 @@ func charService(cnf *config.Config) pbChar.CharactersServiceClient {
return pbChar.NewCharactersServiceClient(conn)
}

func matchmakingService(cnf *config.Config) pbMM.MatchmakingServiceClient {
conn, err := grpc.Dial(cnf.MatchmakingServiceAddress, grpc.WithInsecure())
if err != nil {
log.Fatal().Err(err).Msg("can't connect to matchmaking service")
}

return pbMM.NewMatchmakingServiceClient(conn)
}

func servRegistryService(cnf *config.Config) pbServ.ServersRegistryServiceClient {
conn, err := grpc.Dial(cnf.ServersRegistryServiceAddress, grpc.WithInsecure())
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions apps/game-load-balancer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type Config struct {
// ChatServiceAddress is address of chat service
ChatServiceAddress string `yaml:"chatServiceAddress" env:"CHAT_SERVICE_ADDRESS" env-default:"localhost:8992"`

// MatchmakingServiceAddress is address of matchmaking service.
MatchmakingServiceAddress string `yaml:"matchmakingServiceAddress" env:"MATCHMAKING_SERVICE_ADDRESS" env-default:"localhost:8994"`

// GuildsServiceAddress is address of guilds service
GuildsServiceAddress string `yaml:"guildsServiceAddress" env:"GUILDS_SERVICE_ADDRESS" env-default:"localhost:8995"`

Expand Down
Loading

0 comments on commit 4d570d4

Please sign in to comment.