mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-03-21 17:44:58 -05:00
Blob hashes are now stored in the database under the `hashes` table. They are stored internally as a map of packIDs to a map of versions to a map of regions to the hash. On login, a pack ID, version, and hash are required or the login attempt is rejected. Hashes can be updated using the `/api/hash` endpoint. The schema has been updated accordingly.
44 lines
704 B
Go
44 lines
704 B
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"wwfc/common"
|
|
"wwfc/database"
|
|
|
|
"github.com/jackc/pgx/v4/pgxpool"
|
|
)
|
|
|
|
var (
|
|
ctx = context.Background()
|
|
pool *pgxpool.Pool
|
|
apiSecret string
|
|
)
|
|
|
|
func StartServer(reload bool) {
|
|
// Get config
|
|
config := common.GetConfig()
|
|
|
|
apiSecret = config.APISecret
|
|
|
|
// Start SQL
|
|
dbString := fmt.Sprintf("postgres://%s:%s@%s/%s", config.Username, config.Password, config.DatabaseAddress, config.DatabaseName)
|
|
dbConf, err := pgxpool.ParseConfig(dbString)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
pool, err = pgxpool.ConnectConfig(ctx, dbConf)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
err = database.HashInit(pool, ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func Shutdown() {
|
|
}
|