Skip to content

Commit

Permalink
Merge pull request #7 from LtHummus/chat
Browse files Browse the repository at this point in the history
chat, persisting, and some bug fixes
  • Loading branch information
LtHummus committed Jan 4, 2016
2 parents 3339fc7 + 16d152b commit e4a7942
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 149 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ You shouldn't have too much trouble running this locally if you'd like. Clone t
# TODO List

1. A not-terrible UI
2. Distinguish between "any" vs. "pick" for non-known maps
3. Some display bugs
4. Massive code cleanup
2. Some display bugs
3. Massive code cleanup
4. Ability to rejoin draft in progress

# Contact the author

Expand Down
36 changes: 36 additions & 0 deletions SpyPartyDraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,26 @@

import time
import random
import datetime
import uuid
from threading import Thread
from flask import Flask, render_template, session, request
from flask_socketio import SocketIO, emit, join_room, leave_room, \
close_room, rooms, disconnect
from room import Room
from draft.map import Map

import boto3

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('spypartydraft_test')

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, async_mode=async_mode)
thread = None
dynamo_db_table_name = "spypartydraft_test"


ROOM_LENGTH = 5

Expand Down Expand Up @@ -235,12 +243,29 @@ def ask_pick_order(room, msg):
}
emit('select_pick_order', data, room=room.id)

def persist_draft(room):
data = {
'picks': room.draft.picked_maps,
'bans': room.draft.banned_maps,
'player1': room.draft.player_one,
'player2': room.draft.player_two,
'time': int(time.mktime(datetime.datetime.now().timetuple())),
'first_pick': room.draft.start_player,
'first_spy': room.draft.first_spy,
'uuid': str(uuid.uuid4()),
'room_id': room.id
}

if table is not None:
table.put_item(Item=data)
print "persisted item for room: {}".format(room.id)

def dump_draft(room):
response_type = 'draft_info'
if room.draft.draft_complete():
# set draft over if it's over
response_type = 'draft_over'
persist_draft(room)

room.touch()
emit(response_type, room.serialize(), room=room.id)
Expand Down Expand Up @@ -362,6 +387,17 @@ def spectate_draft(message):
})
broadcast_to_spectator(request.sid, room.get_spectator_data())

@socketio.on('chat_message', namespace='/test')
def chat_message(message):
room = room_map[message['room_id']]
print 'got chat message ' + message['chat_text']
data = {
'room_id': room.id,
'talker': message['username'],
'text': message['chat_text']
}
emit('chat_event', data, room=room.id)


if __name__ == '__main__':
socketio.run(app)
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
boto3==1.2.3
botocore==1.3.15
docutils==0.12
eventlet==0.17.4
Flask==0.10.1
Flask-SocketIO==1.2
futures==3.0.3
greenlet==0.4.9
gunicorn==19.4.1
itsdangerous==0.24
Jinja2==2.8
jmespath==0.9.0
MarkupSafe==0.23
python-dateutil==2.4.2
python-engineio==0.8.4
python-socketio==0.8.1
six==1.10.0
Expand Down
Loading

0 comments on commit e4a7942

Please sign in to comment.