From f126a42e8aeb423e81043fdf07bb4a16350b4d37 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Tue, 26 Oct 2021 10:00:02 +0200
Subject: [PATCH] Update points in table Players after each (won) round

---
 rpsls.js  |  1 +
 server.py | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/rpsls.js b/rpsls.js
index bf5df63..77213ed 100644
--- a/rpsls.js
+++ b/rpsls.js
@@ -63,6 +63,7 @@ let Play = {
     Play.oppselect = Play.oppmove; //reveal opponent's move only now
     if (Win[Play.mymove].includes(Play.oppmove)) {
       if (++Play.mypoints == MAX_POINTS) Play.endGame(true);
+      socket.emit("inc_pts", {uid: getV("uid"), gid:Play.gid});
     }
     else if (Win[Play.oppmove].includes(Play.mymove)) {
       if (++Play.oppoints == MAX_POINTS) Play.endGame(false);
diff --git a/server.py b/server.py
index 61a01aa..94b3788 100644
--- a/server.py
+++ b/server.py
@@ -91,6 +91,16 @@ def move(sid, data):
     con.commit()
     con.close()
 
+@sio.event
+def inc_pts(sid, data):
+    """ Add a point to the player (who won last round) """
+    con = sqlite3.connect(DB_PATH)
+    cur = con.cursor()
+    cur.execute("update Players set points=points+1 where uid=? and gid=?",
+                (data["uid"],data["gid"]))
+    con.commit()
+    con.close()
+
 static_files = {
     '/': RPSLS_PATH + 'index.html',
     '/rpsls.js': RPSLS_PATH + 'rpsls.js',
-- 
2.44.0