Skip to content

Commit

Permalink
Merge commit '30016871a0c7915cb70dcf8ec931778a0f4d4974'
Browse files Browse the repository at this point in the history
  • Loading branch information
mailgyc-163 committed Jul 6, 2017
2 parents 290f927 + 3001687 commit b7a5a60
Show file tree
Hide file tree
Showing 9 changed files with 769 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ docs/_build/

# PyBuilder
target/
.vs
6 changes: 6 additions & 0 deletions src/core/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,11 @@ def join_table(self, t):
self.ready = True
self.table = t

def leave_table(self):
self.ready = False
if self.table:
self.table.remove(self)
logger.info('Player[%d] leave Table[%d]', self.uid, self.table.uid)

def __str__(self):
return self.uid + '-' + self.name
5 changes: 5 additions & 0 deletions src/core/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ def calc_coin(self, winner):
coins.append(-coin - tax)
return coins

def handle_chat(self, player, msg):
response = [Pt.RSP_CHAT, player.uid, msg]
for p in self.players:
p.send(response)

def add(self, player):
for i, p in enumerate(self.players):
if not p:
Expand Down
3 changes: 3 additions & 0 deletions src/net/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ class Protocol(IntEnum):

REQ_GAME_OVER = 41
RSP_GAME_OVER = 42

REQ_CHAT = 43
RSP_CHAT = 44
11 changes: 8 additions & 3 deletions src/net/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def on_message(self, message):

elif code == Pt.REQ_SHOT_POKER:
self.handle_shot_poker(packet)
elif code == Pt.REQ_CHAT:
self.handle_chat(packet)
else:
logger.info('UNKNOWN PACKET: %s', code)

Expand All @@ -110,6 +112,10 @@ def find_table(self, table_id):
return self.room.first_waiting_table()
return self.room.find_waiting_table(table_id)

def handle_chat(self, packet):
if self.player and self.player.table:
self.player.table.handle_chat(self.player, packet[1])

def write_message(self, message, binary=False):
if self.ws_connection is None:
raise WebSocketClosedError()
Expand All @@ -121,9 +127,8 @@ def write_message(self, message, binary=False):
def on_close(self):
# self.session.get(self.uid).socket = None
logger.info('socket[%s] close', self.player.uid)
# if self.player.table and self.player.table.remove(self.player):
# logger.info('Table[%d] close', self.player.table.pid)
# SocketHandler.tableList.remove(self.player.table)
if self.player:
self.player.leave_table()

def send_updates(cls, chat):
logger.info('sending message to %d waiters', len(cls.waiters))
Expand Down
15 changes: 15 additions & 0 deletions src/static/js/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ PG.MainMenu.prototype = {
var setting = this.add.button(this.world.width/2, this.world.height * 3/4, 'btn', this.gotoSetting, this, 'setting.png', 'setting.png', 'setting.png');
setting.anchor.set(0.5);
this.world.add(setting);

this.game.add.plugin(PhaserInput.Plugin);
var input = this.add.inputField(100, 90, {
font: '18px Arial',
fill: '#ff0000',
fontWeight: 'bold',
width: 150,
padding: 8,
borderWidth: 1,
borderColor: '#000',
borderRadius: 6,
placeHolder: 'Password',
type: PhaserInput.InputType.password
});
input.setText("My custom text");
},

startGame: function () {
Expand Down
Loading

0 comments on commit b7a5a60

Please sign in to comment.