func (s *sqlService) OnlineCount() int {
	database := s.connect(context.Background())
	stmt, err := database.QueryContext(context.Background(), "SELECT COUNT(id) FROM player WHERE loggedIn=TRUE")
	if err != nil {
		log.Info.Println("UsernameTaken: Could not query player profile information:", err)
		return -1
	}
	defer stmt.Close()
	if stmt.Next() {
		var online int
		stmt.Scan(&online)
		return online
	}
	return 0
}
OnlineCount Returns number of online players total.
package db
import (
	"context"
	"strconv"
	"strings"
	"time"
	"github.com/spkaeros/rscgo/pkg/definitions"
	"github.com/spkaeros/rscgo/pkg/game/entity"
	"github.com/spkaeros/rscgo/pkg/config"
	"github.com/spkaeros/rscgo/pkg/errors"
	"github.com/spkaeros/rscgo/pkg/game/world"
	"github.com/spkaeros/rscgo/pkg/log"
	"github.com/spkaeros/rscgo/pkg/strutil"
)
type PlayerService interface {
	PlayerCreate(string, string, string) bool
	PlayerNameExists(username string) bool
	PlayerHasRecoverys(uint64) bool
	PlayerValidLogin(uint64, string) bool
	PlayerChangePassword(uint64, string) bool
	PlayerLoadRecoverys(uint64) []string
	PlayerLoad(*world.Player) bool
	PlayerSave(*world.Player)
	OnlineCount() int
}
func NewPlayerServiceSql() PlayerService {
	s := newSqlService(config.PlayerDriver())
	s.sqlOpen(config.PlayerDB())
	return dbConn
}
var DefaultPlayerService PlayerService
func (s *sqlService) PlayerCreate(username, password, ip string) bool {
	db := s.connect(context.Background())
	tx, err := db.BeginTx(context.Background(), nil)
	if err != nil {
		log.Info.Println("SQLiteService Could not begin transaction:", err)
		return false
	}
	var playerID int
	if config.PlayerDriver() != "postgres" {
		stmt, err := tx.Exec("INSERT INTO player(username, userhash, password, x, y, group_id) VALUES($1, $2, $3, 220, 445, 0)", username, strutil.Base37.Encode(username), password)
		if err != nil {
			log.Info.Println("SQLiteService Could not insert new player profile information:", err)
			return false
		}
		pID, err := stmt.LastInsertId()
		if err != nil || playerID < 0 {
			tx.Rollback()
			log.Info.Printf("PlayerCreate(): Could not retrieve player database ID(%d):\n%v", playerID, err)
			return false
		}
		playerID = int(pID)
	} else {
		stmt := tx.QueryRow("INSERT INTO player(username, userhash, password, x, y, group_id) VALUES($1, $2, $3, 220, 445, 0) RETURNING id", username, strutil.Base37.Encode(username), password)
		err = stmt.Scan(&playerID)
		if err != nil || playerID < 0 {
			tx.Rollback()
			log.Info.Printf("PlayerCreate(): Could not retrieve player database ID(%d):\n%v", playerID, err)
			return false
		}
	}
	_, err = tx.Exec("INSERT INTO appearance VALUES($1, 2, 8, 14, 0, 1, 2)", playerID)
	if err != nil {
		log.Info.Println("PlayerCreate(): Could not insert new player profile information:", err)
		return false
	}
	_, err = tx.Exec("INSERT INTO player_attr VALUES($1, 'lastIP', $2)", playerID, "s"+ip)
	if err != nil {
		log.Info.Println("PlayerCreate(): Could not insert new player profile information:", err)
		return false
	}
	_, err = tx.Exec("INSERT INTO stats (playerid, num, cur, exp) VALUES ($1, 0, 1, 0), ($1, 1, 1, 0), "+
		"($1, 2, 1, 0), ($1, 3, 10, 1156), ($1, 4, 1, 0), ($1, 5, 1, 0), ($1, 6, 1, 0), ($1, 7, 1, 0), ($1, 8, 1, 0), "+
		"($1, 9, 1, 0), ($1, 10, 1, 0), ($1, 11, 1, 0), ($1, 12, 1, 0), ($1, 13, 1, 0), ($1, 14, 1, 0), ($1, 15, 1, 0), "+
		"($1, 16, 1, 0), ($1, 17, 1, 0)", playerID)
	if err != nil {
		log.Info.Println("PlayerCreate(): Could not insert new player profile information:", err)
		return false
	}
	_, err = tx.Exec("INSERT INTO bank (playerid, itemid, amount) VALUES ($1, 546, 96000), ($1, 373, 96000)", playerID)
	if err != nil {
		log.Info.Println("PlayerCreate(): Could not insert new player profile information:", err)
		return false
	}
	_, err = tx.Exec("INSERT INTO inventory (playerid, itemid, amount) VALUES ($1, 1263, 1), ($1, 77, 1), ($1, 71, 1), "+
		"($1, 6, 1), ($1, 7, 1), ($1, 8, 1), ($1, 9, 1), ($1, 316, 1), ($1, 198, 1), ($1, 185, 1), ($1, 184, 1), "+
		"($1, 187, 1), ($1, 35, 100), ($1, 33, 100), ($1, 36, 100), ($1, 188, 1), ($1, 189, 1), ($1, 11, 100)", playerID)
	if err != nil {
		log.Info.Println("PlayerCreate(): Could not insert new player profile information:", err)
		return false
	}
	if err := tx.Commit(); err != nil {
		log.Warning.Println("PlayerCreate(): Error committing transaction for new player:", err)
		return false
	}
	return true
}
func (s *sqlService) PlayerNameExists(username string) bool {
	database := s.connect(context.Background())
	stmt, err := database.QueryContext(context.Background(), "SELECT id FROM player WHERE userhash=$1", strutil.Base37.Encode(username))
	if err != nil {
		log.Info.Println("UsernameTaken: Could not query player profile information:", err)
		return true
	}
	defer stmt.Close()
	return stmt.Next()
}