framecommon.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package frame
  2. import (
  3. "bet24.com/servers/user"
  4. )
  5. type GameSink interface {
  6. GetServerPort() int
  7. GetGameID() int
  8. GetGameName() string
  9. GetRoomName() string
  10. CreateTableSink(table Table, data string) TableSink
  11. GetOfflineSeconds() int64
  12. GetCertFile() string
  13. GetKeyFile() string
  14. GetServerAddr() string
  15. //机器人配置
  16. GetRobotCount() int
  17. GetRobotGoldLimit() (min, max int)
  18. GetRobotOnlineSec() int
  19. GetRoomDatas() []string
  20. // 获取最低房间数量,少于则创建机器人房间
  21. GetMinRoomCount(roomData string) int
  22. IsChipRoom() bool
  23. OnPlatformConfig(key string)
  24. IsPrivateRoom() bool
  25. // 获取椅子号,1可表示百人游戏
  26. GetChairCount() int
  27. GetRoomRobotCount(roomName string) int
  28. GetRoomRobotGoldLimit(roomName string) (min, max int)
  29. GetRoomLevel(data string) int
  30. GetVersionID() int
  31. }
  32. type GameSink_LadderRoom interface {
  33. IsLadderRoom() bool
  34. GetMinGold(roomName string) int
  35. GetMaxGold(roomName string) int
  36. GetAdditionalPercent(roomName string) int
  37. GetBaseScore(roomName string) int
  38. }
  39. type GameSink_FishRoom interface {
  40. IsTableCloseByLogic() bool
  41. IgnoreSameIP() bool
  42. EnterPlayingRoomFirst() bool
  43. }
  44. const (
  45. TableStatus_Free = iota
  46. TableStatus_Playing
  47. )
  48. const (
  49. MultiSetStatus_Free = iota
  50. MultiSetStatus_Playing
  51. )
  52. const (
  53. Param_Target = iota
  54. Param_UserCount
  55. Param_PlayTimeout
  56. Param_RoomType
  57. Param_Bet
  58. Param_Win
  59. )
  60. const (
  61. RoomType_normal = iota
  62. RoomType_private
  63. RoomType_match
  64. )
  65. type TableSink interface {
  66. OnGameMessage(userIndex int32, msg, data string) bool
  67. OnUserEnterTable(userIndex int32, chairId int)
  68. OnUserExitTable(userIndex int32, chairId int)
  69. OnUserOffline(chairId int)
  70. OnUserReplay(chairId int)
  71. OnUserReady(userIndex int32, chairId int)
  72. OnUserCancelReady(userIndex int32, chairId int)
  73. OnGetChairScene(chairId int, isPlayer bool) string
  74. OnGetChairCount() int
  75. Destroy()
  76. OnTimer(timerId int)
  77. DumpScene()
  78. GetGoldLimit() (min, max int)
  79. IsDual() bool
  80. OnBaseScoreChanged(baseScore int)
  81. IsAllRobot() bool
  82. }
  83. // 目前已知,后续可补充
  84. type RoomExtraData struct {
  85. UserId int
  86. Param int
  87. }
  88. type TableSink_PrivateRoom interface {
  89. SetPrivateRoomParam(param int, value string)
  90. OnPrivateRoomStatusChanged(oldStatus, newStatus int)
  91. OnPrivateRoomDismissed()
  92. OnGetPrivateRoomScene(chairId int) string
  93. }
  94. type Table interface {
  95. // 游戏准备好后,即可调用框架StartGame进行场景广播
  96. StartGame()
  97. // 游戏结算后,调用
  98. EndGame()
  99. // 多局开关
  100. MultiSetStart()
  101. MultiSetEnd()
  102. // 刷新场景 chairId == -1表示所有人
  103. NotifySceneChanged(chairId int)
  104. GetUserByChair(chairId int) *user.UserInfo
  105. KickUser(userIndex int32, force bool) bool
  106. KickUserByChair(chairId int, force bool) bool
  107. // 如果userIndex == -1 则表示广播给所有人
  108. SendGameData(userIndex int32, msg, data string)
  109. SendGameDataToChair(chairId int, msg, data string)
  110. BroadcastToWatcher(msg, data string)
  111. // 获取玩家,不算旁观的
  112. GetPlayer(userIndex int32) *user.UserInfo
  113. GetUserByUserId(userId int) *user.UserInfo
  114. GetPlayerByUserId(userId int) *user.UserInfo
  115. // 获取用户接口,返回是否player
  116. GetUser(userIndex int32) (*user.UserInfo, bool)
  117. SetUserReadyStatus(userIndex int32, isReady bool) bool
  118. // 写分并返回实际修改数量
  119. WriteUserMoneyWithModifyAmount(userId int, amount, tax int, status, scoreType int, sourceName string) int
  120. WriteUserMoney(userId int, amount, tax int, status, scoreType int, sourceName string) (bool, int)
  121. WriteBetRecord(userId int, betAmount int, winAmount int, winRate float64, betDesc string, resultDesc string, roomName string)
  122. WriteBetRecordWithPlayTime(userId int, betAmount int, winAmount int, winRate float64, betDesc string, resultDesc string, roomName string, secsBefore int)
  123. WriteBetRecordWithSetcount(userId int, betAmount int, winAmount int, winRate float64, betDesc string, resultDesc string, roomName string, setCount int)
  124. GetTableID() int
  125. // 用户转成旁观状态
  126. UserWatch(userIndex int32)
  127. IsPlaying() bool
  128. IsMultiSetPlaying() bool
  129. RequestADAward(userIndex int32, losingAmount int)
  130. LogWithTableId(format string, a ...interface{})
  131. // 玩家游戏已结束,设置成Sit状态可以离开
  132. SetUserEndGame(chairId int)
  133. // 框架定时器
  134. SetTimer(timerId int, delayMs int)
  135. KillTimer(timerId int)
  136. KillAllTimer()
  137. SendBroadcast(userId int, userName string, score int)
  138. Dismiss()
  139. FinishGame(userId int, baseScore, gameType, playerCount int)
  140. // 获取用户的金币或筹码,根据房间类型自动返回
  141. GetUserChipOrGold(userIndex int32) int
  142. GetUserChipOrGoldByUserId(userId int) int
  143. GetUserChipOrGoldByUser(usr *user.UserInfo) int
  144. IsPrivate() bool
  145. GetRoomNo() int
  146. GetOwner() int
  147. GetPlayerCount() int
  148. // 局间更新分数,
  149. UpdateGameScore(userId, scoreDelta int)
  150. // 协商解散房间
  151. DismissPrivateRoom()
  152. // 上报赢家
  153. PrivateRoomSetWinners(winners []int)
  154. // 增加经验值,返回实际增加数值
  155. AddExperience(userId, exp int) int
  156. GetUserList() []*user.UserInfo
  157. PrivateRoomGetRoomType() string
  158. PrivateRoomGetFeeAndPrize(userId int) (int, int)
  159. CloseTable()
  160. }