player.go 951 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package game
  2. import (
  3. "github.com/gorilla/websocket"
  4. )
  5. type Player struct {
  6. Conn *websocket.Conn
  7. IsValid bool
  8. Room *Room
  9. }
  10. func (player *Player) OnLoad() {
  11. player.IsValid = true
  12. }
  13. func (player *Player) OnDestroy() {
  14. player.IsValid = false
  15. }
  16. //监听函数-进入房间
  17. func (player *Player) OnEnterRoom(room *Room) {
  18. player.Room = room
  19. }
  20. //可被客户端调用的接口
  21. //申请进入房间
  22. func (player *Player) RequestEnterRoom(enterKey string) {
  23. EnterRoom(player, enterKey)
  24. }
  25. //可被客户端调用的接口
  26. //上传游戏数据,并广播给房间内的其他人
  27. func (player *Player) UploadPKGameData(key string, str string) {
  28. if player.Room != nil {
  29. player.Room.BroadcastToOthers(player, "OnReceivePKGameData", key, str)
  30. }
  31. }
  32. //初始化-安全的远程调用
  33. func InitSecureRemoteCall() {
  34. CheckServiceFuncMapBeforInvoke = true
  35. ServiceFuncMap["RequestEnterRoom"] = true
  36. ServiceFuncMap["UploadPKGameData"] = true
  37. }