-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcarssender.py
More file actions
320 lines (273 loc) · 11.3 KB
/
Copy pathcarssender.py
File metadata and controls
320 lines (273 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#! -*- coding:utf-8 -*-
# Author: qianyong
# Created: 2016.06.21 21.56
from freetime.entity.msg import MsgPack
from poker.entity.game.tables.table_sender import TYTableSender
from poker.protocol import router
from cars.entity import const
from cars.entity import carsconf
from cars.entity.util import UtilFunc
from cars.gameplays.kingday import KingDay
from cars.gameplays.kingweek import KingWeek
class Sender(TYTableSender):
def __init__(self, table):
super(Sender, self).__init__(table)
def sendQuickStartRes(self, userId, clientId, result):
'''quickstart的响应消息'''
mpSitRes = self.createMsgPackRes("quick_start")
mpSitRes.updateResult(result)
router.sendToUser(mpSitRes, userId)
@classmethod
def sendUserErrorMsg(self, userId, action, error):
'''发送错误消息'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', action)
mo.setResult('error', error)
router.sendToUser(mo, userId)
def sendInfoMsg(self, user, clientId, history, openFruitsPeriod, lotteryTimeLeft, uchip, poolChip, rejoin, betsInfo, issueNum, now):
'''玩家进入牌桌时, 推送该消息, 包含客户端要用的配置, 金币等初始化消息'''
mo = self.createMsgPackRes('table_call', 'cars_info')
mo.setResult('conf', carsconf.getClientConf())
mo.setResult('fruitHistory', history)
mo.setResult('openFruitsPeriod', Sender._convertFruitsOpenTimeLeft(openFruitsPeriod))
mo.setResult('lotteryTimeLeft', lotteryTimeLeft)
mo.setResult('uchip', uchip)
mo.setResult('poolchip', poolChip)
mo.setResult('product', UtilFunc.getProductsGroup(user.userId, clientId, carsconf.getProductsConf())) # 充值用的product
mo.setResult('ranklist', KingDay.getTodayGameRanks(now)),
mo.setResult('myWinChips', user.getDayWinChips())
mo.setResult('weekKingList', KingWeek.buildDataForClient())
mo.setResult('kingReward', KingWeek.getUserClaimStatus(user.userId))
mo.setResult('rejoin', rejoin)
mo.setResult('issueNum', issueNum)
if betsInfo is not None: # 仅在rejoin时有效
mo.setResult('bets', betsInfo)
router.sendToUser(mo, user.userId)
def sendLeaveMsg(self, userId):
'''玩家发送离开请求时的响应消息'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_leave')
mo.setResult('isOK', True)
router.sendToUser(mo, userId)
@classmethod
def sendBetMsg(cls, userId, uchip, fruitBettingChips):
'''发送押注响应消息'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_bet')
mo.setResult('uchip', uchip)
mo.setResult('fruitBettingChips', fruitBettingChips)
router.sendToUser(mo, userId)
def sendClaimKingRewardMsg(self, userId, uchip):
'''发送领取水果王奖励的响应消息'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_claim_king_reward')
mo.setResult('uchip', uchip)
router.sendToUser(mo, userId)
@classmethod
def sendLotteryMsg(cls,
userId,
uchip,
poolchip,
fruitsOpenTimeLeft,
openIds,
luckType,
triggeredPool,
triggeredPoolTotal,
maxWinPoolList,
lotteryTimeLeft,
dayWinChips,
winBetChip,
winPoolChip,
weekKingList,
myKingReward,
top,
nextIssueNum,
now):
'''发送开奖消息'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_lottery')
if uchip > 0:
mo.setResult('uchip', uchip)
mo.setResult('nextIssueNum', nextIssueNum)
mo.setResult('openFruitsPeriod', cls._convertFruitsOpenTimeLeft(fruitsOpenTimeLeft))
mo.setResult('poolchip', poolchip)
again = const.AGAIN_ID in openIds
mo.setResult('lottery', {"openIds": openIds, "luckType": luckType, "isBonus": triggeredPool, "again":again})
mo.setResult('triggeredPoolTotal', triggeredPoolTotal)
mo.setResult('maxWinPoolList', maxWinPoolList)
mo.setResult('lotteryTimeLeft', lotteryTimeLeft)
mo.setResult('top', top)
mo.setResult('ranklist', KingDay.getTodayGameRanks(now))
mo.setResult('winBetChip', winBetChip)
mo.setResult('winPoolChip', winPoolChip)
mo.setResult('myWinChips', dayWinChips)
if weekKingList is not None:
mo.setResult('weekKingList', weekKingList)
if myKingReward is not None:
mo.setResult('kingReward', myKingReward)
router.sendToUser(mo, userId)
@classmethod
def sendFireBuyMsg(cls, userId, uchip, fireIndex):
'''发送购买礼花的响应'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_fire_buy')
mo.setResult('uchip', uchip)
mo.setResult('index', fireIndex)
router.sendToUser(mo, userId)
@classmethod
def sendFireRewardMsg(cls, userId, fireId, timeout, name, fireIndex):
'''发送获得礼花奖励的响应'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_fire_reward')
mo.setResult('fireId', fireId)
mo.setResult('timeout', timeout)
mo.setResult('name', name)
mo.setResult('index', fireIndex)
router.sendToUser(mo, userId)
@classmethod
def sendClaimFireRewardMsg(cls, userId, fireId, buyerName, reward, uchip):
'''发送领取礼花奖励的响应'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_claim_firework_prize')
mo.setResult('gameId', const.GAME_ID)
mo.setResult('buyerName', buyerName)
mo.setResult('userId', userId)
mo.setResult('fireId', fireId)
mo.setResult('fireReward', reward)
mo.setResult('chip', uchip)
router.sendToUser(mo, userId)
@classmethod
def sendPoolListMsg(cls, userId, poolList):
'''发送彩池中奖名单的响应'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_pool_list')
mo.setResult('poolList', poolList)
router.sendToUser(mo, userId)
@classmethod
def sendClickMoreGameMsg(self, userId):
'''用户点击"更多游戏"时,发送该消息,用于记录BI'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'click_more_game')
mo.setResult('isOK', True)
mo.setResult('reason', 0)
router.sendToUser(mo, userId)
@classmethod
def sendSwitchGameMsg(cls, userId):
'''用户点击切换游戏时,发送该消息,用于记录BI'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'switch_game')
mo.setResult('isOK', True)
mo.setResult('reason', 0)
router.sendToUser(mo, userId)
@classmethod
def sendHistoryDetail(cls, userId, historyDetail):
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_history_detail')
mo.setResult('gameId', const.GAME_ID)
mo.setResult('historyDetail', historyDetail)
router.sendToUser(mo, userId)
@classmethod
def sendDebugMsg(cls, userId, action, text):
'''发送debug响应消息'''
mo = MsgPack()
mo.setCmd('debug')
mo.setResult('action', action)
mo.setResult('text', text)
router.sendToUser(mo, userId)
@classmethod
def buildChatMsg(cls, userId, userName, vipLevel, type, chatMsg, lableType):
'''构造聊天消息'''
mo = MsgPack()
mo.setCmd('new_table_chat')
mo.setResult('gameId', const.GAME_ID)
mo.setResult('type', type)
mo.setResult('userId', userId)
mo.setResult('vipLevel', vipLevel)
mo.setResult('msg', chatMsg)
mo.setResult('name', userName)
mo.setResult('lableType', lableType)
return mo
@classmethod
def directlySendMsg(cls, userId, mo):
'''直接发送裸消息'''
router.sendToUser(mo, userId)
@classmethod
def buildLotteryObserverMsg(cls,
poolchip,
fruitsOpenTimeLeft,
openIds,
luckType,
triggeredPool,
triggeredPoolTotal,
maxWinPoolList,
lotteryTimeLeft,
dayWinChips,
weekKingList,
myKingReward,
top,
nextIssueNum,
now):
'''构建发给观察者的开奖消息'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_lottery')
mo.setResult('poolchip', poolchip)
mo.setResult('openFruitsPeriod', cls._convertFruitsOpenTimeLeft(fruitsOpenTimeLeft))
again = const.AGAIN_ID in openIds
mo.setResult('lottery', {"openIds": openIds, "luckType": luckType, "isBonus": triggeredPool, "again": again})
mo.setResult('triggeredPoolTotal', triggeredPoolTotal)
mo.setResult('maxWinPoolList', maxWinPoolList)
mo.setResult('lotteryTimeLeft', lotteryTimeLeft)
mo.setResult('myWinChips', dayWinChips)
mo.setResult('top', top)
mo.setResult('nextIssueNum', nextIssueNum)
mo.setResult('ranklist', KingDay.getTodayGameRanks(now))
if weekKingList is not None:
mo.setResult('weekKingList', weekKingList)
if myKingReward is not None:
mo.setResult('kingReward', myKingReward)
return mo
@classmethod
def buildFruitBettingMsg(cls, fruitBetting):
'''构建水果总注的广播消息'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_betting_chips')
mo.setResult('fruitBettingChips', fruitBetting)
return mo
@classmethod
def buildFireNotifyMsg(cls, name, fireIndex):
'''构建放礼花的通知消息'''
mo = MsgPack()
mo.setCmd('table_call')
mo.setResult('action', 'cars_fire_notify')
mo.setResult('name', name)
mo.setResult('index', fireIndex)
return mo
@classmethod
def _convertFruitsOpenTimeLeft(cls, fruitsOpenTimeLeft):
'''转化格式'''
m = fruitsOpenTimeLeft.copy()
for fruit, t in m.iteritems():
if t == -1:
m[fruit] = u'暂未开奖'
else:
if t < const.ONE_HOUR_SEC:
m[fruit] = u'{MIN}分前'.format(MIN=t / const.ONE_MINIUTE_SEC)
else:
hour = t / const.ONE_HOUR_SEC
miniute = (t % const.ONE_HOUR_SEC) / const.ONE_MINIUTE_SEC
m[fruit] = u'{HOUR}时{MIN}分前'.format(HOUR=hour, MIN=miniute)
return m