forked from MTSR/mapserver
/api/minetest for player/game update
This commit is contained in:
parent
b42648f36e
commit
ecaa385fb0
@ -1,4 +1,4 @@
|
||||
package playerdb
|
||||
package player
|
||||
|
||||
type Player struct {
|
||||
X int `json:"x"`
|
||||
@ -6,9 +6,6 @@ type Player struct {
|
||||
Z int `json:"z"`
|
||||
Name string `json:"name"`
|
||||
HP int `json:"hp"`
|
||||
Breath int `json:"breath"`
|
||||
//TODO: stamina, skin, etc
|
||||
}
|
||||
|
||||
type DBAccessor interface {
|
||||
GetActivePlayers() ([]*Player, error)
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package playerdb
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"time"
|
||||
)
|
||||
|
||||
//https://stackoverflow.com/questions/46746862/list-files-in-a-directory-sorted-by-creation-time
|
||||
|
||||
type FilePlayerDB struct{}
|
||||
|
||||
func (this *FilePlayerDB) GetActivePlayers() ([]*Player, error) {
|
||||
files, err := ioutil.ReadDir("Players")
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
activeTime := now - 5
|
||||
result := make([]*Player, 0)
|
||||
|
||||
for _, file := range files {
|
||||
if file.ModTime().Unix() > activeTime {
|
||||
p := Player{}
|
||||
|
||||
//TODO: parse
|
||||
|
||||
result = append(result, &p)
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package playerdb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"mapserver/worldconfig"
|
||||
)
|
||||
|
||||
func Create(cfg *worldconfig.WorldConfig) (DBAccessor, error) {
|
||||
switch cfg.PlayerBackend {
|
||||
case worldconfig.BACKEND_FILES:
|
||||
return &FilePlayerDB{}, nil
|
||||
default:
|
||||
return nil, errors.New("player backend not supported: " + worldconfig.BACKEND_FILES)
|
||||
}
|
||||
}
|
17
server/web/minetest.go
Normal file
17
server/web/minetest.go
Normal file
@ -0,0 +1,17 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"mapserver/app"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Minetest struct {
|
||||
ctx *app.App
|
||||
}
|
||||
|
||||
func (t *Minetest) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Add("content-type", "application/json")
|
||||
json.NewEncoder(resp).Encode("stub")
|
||||
|
||||
}
|
@ -20,6 +20,7 @@ func Serve(ctx *app.App) {
|
||||
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
|
||||
mux.Handle("/api/tile/", &Tiles{ctx: ctx})
|
||||
mux.Handle("/api/config", &ConfigHandler{ctx: ctx})
|
||||
mux.Handle("/api/minetest", &Minetest{ctx: ctx})
|
||||
mux.Handle("/api/mapobjects/", &MapObjects{ctx: ctx})
|
||||
|
||||
ws := NewWS(ctx)
|
||||
|
Loading…
Reference in New Issue
Block a user