Skip to content

Commit

Permalink
去掉了msgpack
Browse files Browse the repository at this point in the history
  • Loading branch information
mailgyc-163 committed Apr 10, 2018
1 parent 874d9d8 commit b914de5
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
sudo: false
language: python
python:
- '3.6'
Expand All @@ -7,7 +6,8 @@ install:
- pip install codecov
- pip install -r requirements.txt

script: pytest
script:
- pytest

#after_success:
# - tox -e coverage-report
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

1.安装MySQL数据库, 执行:

mysql --user=root --password=123123 --database=ddz < schema.sql
mysql --user=root --password=your_password --database=ddz < schema.sql

2.安装Python3.6, 执行:

pip3 install tornado bcrypt pymysql msgpack-python
pip3 install -r requirements.txt

python3 main.py

浏览器访问即可,端口默认8080

在线体验 <http://ddz.ihouser.com/>
在线体验 <https://www.ihouser.com/>

运行截图

Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Tornado==4.5.1
bcrypt==3.1.3
pymysql==0.7.11
msgpack-python==0.4.8
Tornado==5.0.2
bcrypt==3.1.4
pymysql==0.8.0
pytest==3.5.0

Binary file modified screenshot/c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshot/d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/core/robot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import msgpack

from tornado.ioloop import IOLoop

from core import rule
Expand All @@ -17,7 +18,7 @@ def __init__(self, uid: int, username: str, player: Player):
self.room = player.room

def to_server(self, message):
packet = msgpack.packb(message)
packet = json.dumps(message)
IOLoop.current().add_callback(self.socket.on_message, packet)
logger.info('AI[%d] REQ: %s', self.uid, message)

Expand Down
4 changes: 2 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger('ddz')
logger.setLevel(logging.DEBUG)
logger = logging.getLogger()
logger.setLevel(logging.INFO)


define("host", default="localhost", help="DB host")
Expand Down
1 change: 0 additions & 1 deletion src/net/loopback.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import msgpack
from tornado.ioloop import IOLoop

from net.socket import SocketHandler
Expand Down
5 changes: 1 addition & 4 deletions src/net/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import logging

import msgpack
from tornado.escape import json_decode
from tornado.web import authenticated
from tornado.websocket import WebSocketHandler, WebSocketClosedError
Expand Down Expand Up @@ -57,8 +56,7 @@ def on_close(self):
logger.info('SOCKET[%s] CLOSE', self.player.uid)

def on_message(self, message):
packet = msgpack.unpackb(message, use_list=False)
# packet = json.loads(message)
packet = json.loads(message)
logger.info('REQ[%d]: %s', self.uid, packet)

code = packet[0]
Expand Down Expand Up @@ -136,7 +134,6 @@ def handle_cheat(self, uid):
def write_message(self, message, binary=False):
if self.ws_connection is None:
raise WebSocketClosedError()
# packet = msgpack.packb(message)
logger.info('RSP[%d]: %s', self.uid, message)
packet = json.dumps(message)
return self.ws_connection.write_message(packet, binary=binary)
Expand Down
2 changes: 0 additions & 2 deletions src/static/js/msgpack.min.js

This file was deleted.

4 changes: 1 addition & 3 deletions src/static/js/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ PG.Socket.connect = function(onopen, onmessage, onerror) {

this.websocket.onmessage = function(evt) {
console.log('RSP: ' + evt.data);
// onmessage(msgpack.decode(evt.data));
onmessage(JSON.parse(evt.data));
};
};

PG.Socket.send = function(msg) {
console.log('REQ: ' + msg);
this.websocket.send(msgpack.encode(msg));
// this.websocket.send(JSON.stringify(msg));
this.websocket.send(JSON.stringify(msg));
};
1 change: 0 additions & 1 deletion src/static/poker.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1, user-scalable=no;"/>
<title>斗地主</title>
<script type="text/javascript" src="{{static_url('js/msgpack.min.js')}}"></script>
<script type="text/javascript" src="{{static_url('js/phaser.min.js')}}"></script>
<script type="text/javascript" src="{{static_url('js/phaser-input.min.js')}}"></script>
<script type="text/javascript" src="{{static_url('js/boot.js')}}"></script>
Expand Down
Empty file removed src/tests/simple_test.py
Empty file.
24 changes: 24 additions & 0 deletions src/tests/test_101.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest


class TestStringMethods(unittest.TestCase):

def setUp(self):
pass

def tearDown(self):
pass

def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')

def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())

def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)

0 comments on commit b914de5

Please sign in to comment.