mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-05-06 05:26:33 -05:00
Database: Move Mario Kart Wii FriendInfo to new SAKE
This commit is contained in:
parent
0a5e354e61
commit
e4bc072e57
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"wwfc/common"
|
||||
|
||||
"github.com/jackc/pgx/v4"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
)
|
||||
|
||||
|
|
@ -133,3 +134,50 @@ func InsertMarioKartWiiGhostFile(pool *pgxpool.Pool, ctx context.Context, region
|
|||
|
||||
return err
|
||||
}
|
||||
|
||||
// Mario Kart Wii friend info functions for API compatibility
|
||||
|
||||
func GetMKWFriendInfo(pool *pgxpool.Pool, ctx context.Context, profileId uint32) string {
|
||||
records, err := GetSakeRecords(pool, ctx, 1687, []int32{int32(profileId)}, "FriendInfo", nil, []string{"info"}, "")
|
||||
if err != nil || len(records) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
infoField, ok := records[0].Fields["info"]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
return infoField.Value
|
||||
}
|
||||
|
||||
func UpdateMKWFriendInfo(pool *pgxpool.Pool, ctx context.Context, profileId uint32, info string) {
|
||||
records, err := GetSakeRecords(pool, ctx, 1687, []int32{int32(profileId)}, "FriendInfo", nil, []string{"info"}, "")
|
||||
if err == pgx.ErrNoRows || (err == nil && len(records) == 0) {
|
||||
// No existing record, insert new one
|
||||
record := SakeRecord{
|
||||
GameId: 1687,
|
||||
TableId: "FriendInfo",
|
||||
OwnerId: int32(profileId),
|
||||
Fields: map[string]SakeField{
|
||||
"info": {
|
||||
Type: SakeFieldTypeBinaryData,
|
||||
Value: info,
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err = InsertSakeRecord(pool, ctx, record)
|
||||
} else if err == nil {
|
||||
// Update existing record
|
||||
records[0].Fields["info"] = SakeField{
|
||||
Type: SakeFieldTypeBinaryData,
|
||||
Value: info,
|
||||
}
|
||||
err = UpdateSakeRecord(pool, ctx, records[0], int32(profileId))
|
||||
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,6 @@ const (
|
|||
UpdateUserLastIPAddress = `UPDATE users SET last_ip_address = $2, last_ingamesn = $3 WHERE profile_id = $1`
|
||||
UpdateUserBan = `UPDATE users SET has_ban = true, ban_issued = $2, ban_expires = $3, ban_reason = $4, ban_reason_hidden = $5, ban_moderator = $6, ban_tos = $7 WHERE profile_id = $1`
|
||||
DisableUserBan = `UPDATE users SET has_ban = false WHERE profile_id = $1`
|
||||
|
||||
GetMKWFriendInfoQuery = `SELECT mariokartwii_friend_info FROM users WHERE profile_id = $1`
|
||||
UpdateMKWFriendInfoQuery = `UPDATE users SET mariokartwii_friend_info = $2 WHERE profile_id = $1`
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
|
@ -163,20 +160,3 @@ func UnbanUser(pool *pgxpool.Pool, ctx context.Context, profileId uint32) bool {
|
|||
_, err := pool.Exec(ctx, DisableUserBan, profileId)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func GetMKWFriendInfo(pool *pgxpool.Pool, ctx context.Context, profileId uint32) string {
|
||||
var info string
|
||||
err := pool.QueryRow(ctx, GetMKWFriendInfoQuery, profileId).Scan(&info)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
func UpdateMKWFriendInfo(pool *pgxpool.Pool, ctx context.Context, profileId uint32, info string) {
|
||||
_, err := pool.Exec(ctx, UpdateMKWFriendInfoQuery, profileId, info)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,7 @@ CREATE TABLE IF NOT EXISTS public.users (
|
|||
email character varying NOT NULL,
|
||||
unique_nick character varying NOT NULL,
|
||||
firstname character varying,
|
||||
lastname character varying DEFAULT ''::character varying,
|
||||
mariokartwii_friend_info character varying
|
||||
lastname character varying DEFAULT ''::character varying
|
||||
);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user