defs.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package proto
  2. import (
  3. db2 "bet24.com/servers/micros/privateroom/config"
  4. )
  5. const (
  6. RoomType_Normal = "PrivateRoom"
  7. RoomType_SimpleMatch = "Match"
  8. )
  9. const (
  10. PrivateRoomStatus_Invalid = iota
  11. PrivateRoomStatus_Free
  12. PrivateRoomStatus_Playing
  13. PrivateRoomStatus_Ended
  14. )
  15. type GameRoom struct {
  16. Status int `xorm:"INT(11)" ` //1代表空闲 2代表使用中
  17. Id int `xorm:"not null pk autoincr INT(11)" json:"id"`
  18. PlayerNum int `xorm:"INT(11)" ` //加入游戏房间人数
  19. GameEnd int `xorm:"INT(11)" ` //0未开始,1进行中,2已结束
  20. Mode int `xorm:"INT(11)" ` //游戏模式,1是经典,2是匹配
  21. Logo string `xorm:"VARCHAR(255)"` //游戏logo
  22. Type int `xorm:"INT(11)" ` //1是lodo,2 baloot
  23. TableId int `xorm:"INT(11)" ` //1是lodo,2 baloot
  24. }
  25. const (
  26. Method_Create = "privateroom.create"
  27. Method_Dismiss = "privateroom.onRoomDismiss"
  28. Method_StatucChanged = "privateroom.onRoomStatusChanged"
  29. Method_ForceEnter = "privateroom.forceEnter"
  30. )
  31. type Request_Create struct {
  32. MethodName string
  33. Creator int // 创建者
  34. GameRule string // 游戏规则
  35. Target int // 局数或分数
  36. UserCount int // 对局人数
  37. //Fee int // 门票费用
  38. PlayTimeout int
  39. }
  40. type Request_OnRoomDismiss struct {
  41. MethodName string
  42. RoomNo int
  43. }
  44. type Request_OnRoomStatusChanged struct {
  45. MethodName string
  46. RoomNo int
  47. OldStatus int
  48. NewStatus int
  49. }
  50. type Request_ForceEnter struct {
  51. MethodName string
  52. RoomNo int
  53. UserId int
  54. ChairId int
  55. }
  56. type RoomUser struct {
  57. UserId int
  58. NickName string
  59. ChairId int
  60. Score int
  61. // 可能还有其他信息
  62. FaceId int
  63. FaceUrl string
  64. BaseScore int
  65. SetCount int
  66. YyfUid int
  67. }
  68. type RoomUserBrief struct {
  69. UserId int
  70. NickName string
  71. ChairId int
  72. Score int
  73. BaseScore int
  74. SetCount int `json:",omitempty"`
  75. }
  76. func (ru *RoomUser) ToBrief() *RoomUserBrief {
  77. return &RoomUserBrief{
  78. UserId: ru.UserId,
  79. NickName: ru.NickName,
  80. ChairId: ru.ChairId,
  81. Score: ru.Score,
  82. BaseScore: ru.BaseScore,
  83. SetCount: ru.SetCount,
  84. }
  85. }
  86. type RoomInfo struct {
  87. RoomNo int
  88. GameId int
  89. ServerAddr string
  90. TableId int
  91. GameName string
  92. RuleName string
  93. UserCount int // 限制人数
  94. Fee int
  95. Status int
  96. Target int
  97. Prize int // 奖金
  98. IsPublic bool
  99. UserList []*RoomUser
  100. PlayTime int
  101. ExtraInfo string
  102. }
  103. type RoomInfoBrief struct {
  104. RoomNo int
  105. GameId int
  106. ServerAddr string
  107. TableId int
  108. RuleName string
  109. UserCount int // 限制人数
  110. Fee int `json:",omitempty"`
  111. Target int
  112. Prize int // 奖金
  113. IsPublic bool
  114. UserList []*RoomUserBrief
  115. }
  116. func (ru *RoomInfo) ToBrief() *RoomInfoBrief {
  117. ret := &RoomInfoBrief{
  118. RoomNo: ru.RoomNo,
  119. GameId: ru.GameId,
  120. ServerAddr: ru.ServerAddr,
  121. TableId: ru.TableId,
  122. RuleName: ru.RuleName,
  123. UserCount: ru.UserCount,
  124. Target: ru.Target,
  125. Prize: ru.Prize,
  126. IsPublic: ru.IsPublic,
  127. Fee: ru.Fee,
  128. }
  129. for i := 0; i < len(ru.UserList); i++ {
  130. ret.UserList = append(ret.UserList, ru.UserList[i].ToBrief())
  131. }
  132. return ret
  133. }
  134. func GetIdleRoom2(mode int,tableId int) *GameRoom {
  135. //lock5.Lock()
  136. //var idle = 0
  137. var gameRoom GameRoom = GameRoom{Status: 1}
  138. //var gameRoom
  139. has, _ := db2.Engine.Get(&gameRoom)
  140. //if mode ==1{
  141. if has {
  142. gameRoom.Status = 2
  143. //gameRoom = gameRooms[i]
  144. //gameRoom.MinNum = 2
  145. //gameRoom.AdmissionFee = adminfee
  146. //gameRoom.MaxNum = maxnum
  147. gameRoom.Mode = mode
  148. gameRoom.Type = 2
  149. gameRoom.TableId=tableId
  150. //gameRooms[i].RoomType = true
  151. //gameRoom.DataList = DataList
  152. //初始化构建玩家
  153. //var rankPlayer = map[int]*GamePlayer{}
  154. // var gzPlayer = []*GamePlayer{}
  155. // var player = map[int]*GamePlayer{}
  156. // var roomPlayer = map[string]*GamePlayer{}
  157. // gameRoom.RoomPlayers = roomPlayer
  158. // gameRoom.RankPlayers = rankPlayer
  159. // gameRoom.GzPlayers = gzPlayer
  160. // gameRoom.Players = player
  161. //gameRoom.PlayerNum = 0
  162. //gameRoom.RunnerNum = 0
  163. //gameRoom.ArrivalNum = 0
  164. //gameRoom.GameEnd = GameNotStarted
  165. db2.Engine.ID(gameRoom.Id).Update(gameRoom)
  166. } else {
  167. // RoomInit(len(gameRooms), len(gameRooms)+100)
  168. // lock5.Unlock()
  169. //fmt.Printf("私人房建房")
  170. gameRoom.TableId=tableId
  171. gameRoom.Status = 2
  172. gameRoom.Type = 2
  173. //gameRoom = gameRooms[i]
  174. // gameRoom.MinNum = 2
  175. // gameRoom.AdmissionFee = adminfee
  176. // gameRoom.MaxNum = maxnum
  177. gameRoom.Mode = mode
  178. //gameRooms[i].RoomType = true
  179. //gameRoom.DataList = DataList
  180. //初始化构建玩家
  181. //var rankPlayer = map[int]*GamePlayer{}
  182. // var gzPlayer = []*GamePlayer{}
  183. // var player = map[int]*GamePlayer{}
  184. // var roomPlayer = map[string]*GamePlayer{}
  185. //gameRoom.RoomPlayers = roomPlayer
  186. // gameRoom.RankPlayers = rankPlayer
  187. //gameRoom.GzPlayers = gzPlayer
  188. //gameRoom.Players = player
  189. gameRoom.PlayerNum = 0
  190. // gameRoom.RunnerNum = 0
  191. // gameRoom.ArrivalNum = 0
  192. // gameRoom.GameEnd = GameNotStarted
  193. db2.Engine.Insert(&gameRoom)
  194. }
  195. //}
  196. // lock5.Unlock()
  197. return &gameRoom
  198. /*if idle == 0 {
  199. }
  200. */
  201. }