package game

import (
	"github.com/gorilla/websocket"
)

type Player struct {
	Conn    *websocket.Conn
	IsValid bool
	Room    *Room
}

func (player *Player) OnLoad() {
	player.IsValid = true
}

func (player *Player) OnDestroy() {
	player.IsValid = false
}

//监听函数-进入房间
func (player *Player) OnEnterRoom(room *Room) {
	player.Room = room
}

//可被客户端调用的接口
//申请进入房间
func (player *Player) RequestEnterRoom(enterKey string) {
	EnterRoom(player, enterKey)
}

//可被客户端调用的接口
//上传游戏数据，并广播给房间内的其他人
func (player *Player) UploadPKGameData(key string, str string) {
	if player.Room != nil {
		player.Room.BroadcastToOthers(player, "OnReceivePKGameData", key, str)
	}
}

//初始化-安全的远程调用
func InitSecureRemoteCall() {
	CheckServiceFuncMapBeforInvoke = true
	ServiceFuncMap["RequestEnterRoom"] = true
	ServiceFuncMap["UploadPKGameData"] = true
}
