Skip to content

Commit

Permalink
chore: Last-minute cleanups
Browse files Browse the repository at this point in the history
Ranking is coming soon on another branch, so just stub a bunch of it for now so matchmaking works OK
  • Loading branch information
ashquarky committed Jul 1, 2024
1 parent b108eaf commit 5ac4fe4
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 99 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ All configuration options are handled via environment variables
| `PN_PUYOPUYOTETRIS_ACCOUNT_GRPC_HOST` | Host name for your account server gRPC service | Yes |
| `PN_PUYOPUYOTETRIS_ACCOUNT_GRPC_PORT` | Port for your account server gRPC service | Yes |
| `PN_PUYOPUYOTETRIS_ACCOUNT_GRPC_API_KEY` | API key for your account server gRPC service | No (Assumed to be an open gRPC API) |
| `PN_PUYOPUYOTETRIS_POSTGRES_URI` | Postgres connection for DataStore DB | Yes |
| `PN_PUYOPUYOTETRIS_CONFIG_S3_ENDPOINT` | URL for DataStore S3 storage | Yes |
| `PN_PUYOPUYOTETRIS_CONFIG_S3_ACCESS_KEY` | Access key for S3 | Yes |
| `PN_PUYOPUYOTETRIS_CONFIG_S3_SECRET` | Secret key for S3 | Yes |
| `PN_PUYOPUYOTETRIS_CONFIG_S3_BUCKET` | Bucket for DataStore storage | Yes |
21 changes: 0 additions & 21 deletions datastore/init_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,5 @@ func initPostgres() {
os.Exit(0)
}

//// * Unsure what like half of this is but the client sends it so we saves it
//_, err = Postgres.Exec(`CREATE TABLE IF NOT EXISTS datastore.object_ratings (
// data_id bigint,
// slot smallint,
// flag smallint,
// internal_flag smallint,
// lock_type smallint,
// initial_value bigint,
// range_min int,
// range_max int,
// period_hour smallint,
// period_duration int,
// total_value bigint,
// count int NOT NULL DEFAULT 0,
// PRIMARY KEY(data_id, slot)
//)`)
//if err != nil {
// globals.Logger.Critical(err.Error())
// os.Exit(0)
//}

globals.Logger.Success("Postgres tables created")
}
74 changes: 37 additions & 37 deletions datastore/puyo_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func GetObjectInfoByPersistenceTargetWithPassword(_ *types.DataStorePersistenceT

// get own gamedata (among other things)
func GetObjectInfosByDataStoreSearchParam(param *types.DataStoreSearchParam, pid *nextypes.PID) ([]*types.DataStoreMetaInfo, uint32, *nex.Error) {
// TODO refactor this according to Jon's notes
// TODO refactor this according to Jon's notes, add enum values
if param.DataType.Value == 65535 && param.SearchTarget.Value == 10 {
// TODO "gamedata" hardcoded
objects, err := getObjects(selectByNameAndOwnerStmt, 1, "gamedata", pid.Value())
Expand Down Expand Up @@ -197,22 +197,22 @@ func UpdateObjectDataTypeByDataIDWithPassword(_ *nextypes.PrimitiveU64, _ *nexty
func initDatastore() {
const selectObject = `
SELECT
data_id,
owner,
size,
name,
data_type,
data_id,
owner,
size,
name,
data_type,
meta_binary,
permission,
permission_recipients,
delete_permission,
delete_permission_recipients,
flag,
period,
refer_data_id,
tags,
creation_date,
update_date
permission,
permission_recipients,
delete_permission,
delete_permission_recipients,
flag,
period,
refer_data_id,
tags,
creation_date,
update_date
FROM datastore.objects`

stmt, err := Postgres.Prepare(selectObject + ` WHERE name = $2 AND owner = $3 LIMIT $1`)
Expand All @@ -228,27 +228,27 @@ func initDatastore() {
selectByDataIdStmt = stmt

stmt, err = Postgres.Prepare(`INSERT INTO datastore.objects
(
owner,
size,
name,
data_type,
meta_binary,
permission,
permission_recipients,
delete_permission,
delete_permission_recipients,
flag,
period,
refer_data_id,
tags,
persistence_slot_id,
extra_data,
creation_date,
update_date
)
(
owner,
size,
name,
data_type,
meta_binary,
permission,
permission_recipients,
delete_permission,
delete_permission_recipients,
flag,
period,
refer_data_id,
tags,
persistence_slot_id,
extra_data,
creation_date,
update_date
)
VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17
) RETURNING data_id`)
if err != nil {
panic(err)
Expand All @@ -268,7 +268,7 @@ func initDatastore() {
updatePeriodStmt = stmt
}

// Helpers for nex types
// Helpers for nex types - these can go once the types refactor lands
func convertPIDList(list *nextypes.List[*nextypes.PID]) []uint64 {
result := make([]uint64, list.Length())

Expand Down
1 change: 0 additions & 1 deletion globals/util.go

This file was deleted.

51 changes: 22 additions & 29 deletions nex/register_common_secure_server_protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
commonsecure "github.com/PretendoNetwork/nex-protocols-common-go/v2/secure-connection"
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking"
rankingtypes "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types"
secure "github.com/PretendoNetwork/nex-protocols-go/v2/secure-connection"
puyodatastore "github.com/PretendoNetwork/puyo-puyo-tetris/datastore"
"github.com/PretendoNetwork/puyo-puyo-tetris/globals"
puyoranking "github.com/PretendoNetwork/puyo-puyo-tetris/ranking"
"os"

commonmatchmaking "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making"
Expand All @@ -24,8 +24,6 @@ import (
commonnattraversal "github.com/PretendoNetwork/nex-protocols-common-go/v2/nat-traversal"
nattraversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal"

matchmakingtypes "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"

commonglobals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
)

Expand Down Expand Up @@ -57,25 +55,31 @@ func MatchmakeExtensionCloseParticipation(err error, packet nex.PacketInterface,
return rmcResponse, nil
}

func CreateReportDBRecord(_ *types.PID, _ *types.PrimitiveU32, _ *types.QBuffer) error {
func stubCreateReportDBRecord(_ *types.PID, _ *types.PrimitiveU32, _ *types.QBuffer) error {
return nil
}

func stubGetRankingsAndCountByCategoryAndRankingOrderParam(_ *types.PrimitiveU32, _ *rankingtypes.RankingOrderParam) (*types.List[*rankingtypes.RankingRankData], uint32, error) {
return nil, 0, nil
}

func stubInsertRankingByPIDAndRankingScoreData(_ *types.PID, _ *rankingtypes.RankingScoreData, _ *types.PrimitiveU64) error {
return nil
}

// TO DO:
// How do clubs work?
// GetObjectInfoByDataID
// UpdateObjectPeriodByDataIDWithPassword
// UpdateObjectMetaBinaryByDataIDWithPassword
// UpdateObjectDataTypeByDataIDWithPassword
func stubUploadCommonData(_ *types.PID, _ *types.PrimitiveU64, _ *types.Buffer) error {
return nil
}

func registerCommonSecureServerProtocols() {
secureProtocol := secure.NewProtocol()
globals.SecureEndpoint.RegisterServiceProtocol(secureProtocol)
commonSecureProtocol := commonsecure.NewCommonProtocol(secureProtocol)

commonSecureProtocol.CreateReportDBRecord = CreateReportDBRecord
commonSecureProtocol.CreateReportDBRecord = stubCreateReportDBRecord

// Datastore - replays, user profiles (country, preferred character)
// Datastore - user profiles (country, preferred character)
// TODO Replay upload and search
datastoreProtocol := datastore.NewProtocol()
globals.SecureEndpoint.RegisterServiceProtocol(datastoreProtocol)
commonDatastoreProtocol := commondatastore.NewCommonProtocol(datastoreProtocol)
Expand All @@ -92,13 +96,15 @@ func registerCommonSecureServerProtocols() {
commonDatastoreProtocol.GetObjectInfoByDataIDWithPassword = puyodatastore.GetObjectInfoByDataIDWithPassword
commonDatastoreProtocol.GetObjectInfoByPersistenceTargetWithPassword = puyodatastore.GetObjectInfoByPersistenceTargetWithPassword

// Ranking - ??
// TODO Ranking - Stub implementation for now
rankingProtocol := ranking.NewProtocol()
globals.SecureEndpoint.RegisterServiceProtocol(rankingProtocol)
commonRankingProtocol := commonranking.NewCommonProtocol(rankingProtocol)
commonRankingProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam = puyoranking.GetRankingsAndCountByCategoryAndRankingOrderParam
commonRankingProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam = stubGetRankingsAndCountByCategoryAndRankingOrderParam
commonRankingProtocol.InsertRankingByPIDAndRankingScoreData = stubInsertRankingByPIDAndRankingScoreData
commonRankingProtocol.UploadCommonData = stubUploadCommonData

// Matchmaking stuff - National Puzzle League
// Matchmaking - National Puzzle League
natTraversalProtocol := nattraversal.NewProtocol()
globals.SecureEndpoint.RegisterServiceProtocol(natTraversalProtocol)
commonnattraversal.NewCommonProtocol(natTraversalProtocol)
Expand All @@ -113,20 +119,7 @@ func registerCommonSecureServerProtocols() {

matchmakeExtensionProtocol := matchmakeextension.NewProtocol()
globals.SecureEndpoint.RegisterServiceProtocol(matchmakeExtensionProtocol)
commonMatchmakeExtensionProtocol := commonmatchmakeextension.NewCommonProtocol(matchmakeExtensionProtocol)
commonmatchmakeextension.NewCommonProtocol(matchmakeExtensionProtocol)
// * Handle custom CloseParticipation behaviour
matchmakeExtensionProtocol.SetHandlerCloseParticipation(MatchmakeExtensionCloseParticipation)

commonMatchmakeExtensionProtocol.OnAfterAutoMatchmakeWithSearchCriteriaPostpone = func(packet nex.PacketInterface, lstSearchCriteria *types.List[*matchmakingtypes.MatchmakeSessionSearchCriteria], anyGathering *types.AnyDataHolder, strMessage *types.String) {
globals.Logger.Info("Matchmake search criteria:")
for _, criteria := range lstSearchCriteria.Slice() {
globals.Logger.Info(criteria.FormatToString(1))
}

globals.Logger.Info("Active matchmaking sessions:")
for _, session := range commonglobals.Sessions {
globals.Logger.Info(session.GameMatchmakeSession.FormatToString(1))
}
}

}
11 changes: 0 additions & 11 deletions ranking/puyo_ranking.go

This file was deleted.

0 comments on commit 5ac4fe4

Please sign in to comment.