Hi,
I implemented player rank and money listing in jpoker.plugins.tourneyDetails:
http://jpoker.aminche.com/hg/jpoker/rev/c4577bb022e0
Feel free to pull using:
hg pull http://jpoker.aminche.com/hg/jpoker/
And also reworked the server side code for PacketPokerTourneyManager
in order to use only the database, instead of relying on in-core data
structure to describe the tournaments; poker-network patch attached.
--
bou ^
Index: pokernetwork/pokerservice.py
===================================================================
--- pokernetwork/pokerservice.py (revision 4180)
+++ pokernetwork/pokerservice.py (working copy)
@@ -690,29 +690,44 @@
def tourneyManager(self, tourney_serial):
packet = PacketPokerTourneyManager()
packet.tourney_serial = tourney_serial
- if self.tourneys.has_key(tourney_serial):
- cursor = self.db.cursor(DictCursor)
- cursor.execute("SELECT user_serial, tourney_serial, table_serial, rank FROM user2tourney WHERE tourney_serial = %d" % tourney_serial)
- packet.user2tourney = cursor.fetchall()
- table2serials = {}
- for row in packet.user2tourney:
- table_serial = row['table_serial']
- if table_serial == None:
- continue
- if not table2serials.has_key(table_serial):
- table2serials[table_serial] = []
- table2serials[table_serial].append(row['user_serial'])
- packet.table2serials = table2serials
- packet.user2money = {}
- if len(table2serials) > 0:
- cursor.execute("SELECT user_serial, money FROM user2table WHERE table_serial IN ( " + ",".join(map(lambda x: str(x), table2serials.keys())) + " )")
- for row in cursor.fetchall():
- packet.user2money[row['user_serial']] = row['money']
- cursor.close()
- from pprint import pprint
- packet.tourney = copy.copy(self.tourneys[tourney_serial].__dict__)
- for key in [ 'cancel', 'create_game', 'destroy_game', 'game_filled', 'move_player', 'new_state', 'remove_player' ]:
- del packet.tourney['callback_' + key]
+ cursor = self.db.cursor(DictCursor)
+ cursor.execute("SELECT user_serial, table_serial, rank FROM user2tourney WHERE tourney_serial = %d" % tourney_serial)
+ user2tourney = cursor.fetchall()
+
+ table2serials = {}
+ for row in user2tourney:
+ table_serial = row['table_serial']
+ if table_serial == None:
+ continue
+ if not table2serials.has_key(table_serial):
+ table2serials[table_serial] = []
+ table2serials[table_serial].append(row['user_serial'])
+ packet.table2serials = table2serials
+ user2money = {}
+ if len(table2serials) > 0:
+ cursor.execute("SELECT user_serial, money FROM user2table WHERE table_serial IN ( " + ",".join(map(lambda x: str(x), table2serials.keys())) + " )")
+ for row in cursor.fetchall():
+ user2money[row['user_serial']] = row['money']
+
+ cursor.execute("SELECT user_serial, name FROM user2tourney, users WHERE user2tourney.tourney_serial = " + str(tourney_serial) + " AND user2tourney.user_serial = users.serial")
+ user2name = dict((entry["user_serial"], entry["name"]) for entry in cursor.fetchall())
+
+ cursor.execute("SELECT * FROM tourneys WHERE serial = " + str(tourney_serial));
+ packet.tourney = cursor.fetchone()
+ packet.tourney["registered"] = len(user2tourney)
+
+ cursor.close()
+
+ user2properties = {}
+ for row in user2tourney:
+ user_serial = row["user_serial"]
+ money = user2money.has_key(user_serial) and user2money[user_serial] or -1
+ user2properties[str(user_serial)] = {"name": user2name[user_serial],
+ "money": money,
+ "rank": row["rank"],
+ "table_serial": row["table_serial"]}
+ packet.user2properties = user2properties
+
return packet
def tourneyPlayersList(self, tourney_serial):
Index: tests/test-pokerservice.py.in
===================================================================
--- tests/test-pokerservice.py.in (revision 4180)
+++ tests/test-pokerservice.py.in (working copy)
@@ -736,31 +736,46 @@
class TourneyManagerTestCase(PokerServiceTestCaseBase):
- def test_ok(self):
- tourney_serial = 100
+ def test_no_rank(self):
self.service.startService()
self.createUsers()
user_serial = self.user1_serial
table_serial = 606
table_money = 140
- tourney = pokertournament.PokerTournament(serial = tourney_serial,
- dirs = ['/etc/poker-engine'])
- tourney.currency_serial = 1
- self.service.tourneys[tourney_serial] = tourney
+ tourney_serial, schedule = self.service.tourneys_schedule.items()[0]
+ self.service.spawnTourney(schedule)
self.service.tourneyRegister(PacketPokerTourneyRegister(serial = self.user1_serial,
game_id = tourney_serial))
self.service.db.db.query("INSERT INTO user2table VALUES (" + str(self.user1_serial) + ", " + str(table_serial) + ", " + str(table_money) + ", 0)")
self.service.db.db.query("UPDATE user2tourney SET table_serial = " + str(table_serial))
packet = self.service.tourneyManager(tourney_serial)
- self.assertEqual(({'rank': -1,
- 'table_serial': 606,
- 'tourney_serial': 100,
- 'user_serial': 4},), packet.user2tourney)
- self.assertEqual(True, packet.tourney.has_key('payouts'))
self.assertEqual(tourney_serial, packet.tourney['serial'])
- self.assertEqual(table_money, packet.user2money[self.user1_serial])
- Packet.JSON.encode(packet.__dict__)
+ self.assertEqual(1, packet.tourney['registered'])
+ self.assertEqual({'4' : {'rank': -1,
+ 'table_serial': table_serial,
+ 'name' : 'user1',
+ 'money': table_money}}, packet.user2properties)
+ print Packet.JSON.encode(packet.__dict__)
+ def test_no_money_no_table(self):
+ self.service.startService()
+ self.createUsers()
+ user_serial = self.user1_serial
+ table_serial = 606
+ table_money = 140
+ tourney_serial, schedule = self.service.tourneys_schedule.items()[0]
+ self.service.spawnTourney(schedule)
+ self.service.tourneyRegister(PacketPokerTourneyRegister(serial = self.user1_serial,
+ game_id = tourney_serial))
+ packet = self.service.tourneyManager(tourney_serial)
+ self.assertEqual(tourney_serial, packet.tourney['serial'])
+ self.assertEqual(1, packet.tourney['registered'])
+ self.assertEqual({'4' : {'rank': -1,
+ 'table_serial': None,
+ 'name' : 'user1',
+ 'money': -1}}, packet.user2properties)
+ print Packet.JSON.encode(packet.__dict__)
+
class TourneyMovePlayerTestCase(PokerServiceTestCaseBase):
tourney_serial = 10
_______________________________________________
Pokersource-users mailing list
[email protected]
https://mail.gna.org/listinfo/pokersource-users