summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun Persaud <arun@nubati.net>2010-02-04 22:23:38 -0800
committerArun Persaud <arun@nubati.net>2010-02-04 22:23:38 -0800
commitf2217bfa18ba8a8ab17dd188b38777460ae0590d (patch)
tree141fa327006ab683b01bfe6b0d1b61ca11b322e9
parent2070b0fcc3a069ff88267b740317cca7363c4bb0 (diff)
parentb76cddb9313d8a67e5d7e1830503b5775666238f (diff)
downloade-DoKo-f2217bfa18ba8a8ab17dd188b38777460ae0590d.tar.gz
e-DoKo-f2217bfa18ba8a8ab17dd188b38777460ae0590d.tar.bz2
e-DoKo-f2217bfa18ba8a8ab17dd188b38777460ae0590d.zip
Merge branch 'master' of /home/arun/nubati.net/git/e-DoKo
-rw-r--r--INSTALL1
-rw-r--r--config.php_template2
-rw-r--r--css/standard023.css (renamed from css/standard022.css)6
-rw-r--r--include/db.php20
-rw-r--r--include/functions.php99
-rw-r--r--include/game.php43
-rw-r--r--include/output.php148
-rw-r--r--index.php6
-rw-r--r--rss.php101
9 files changed, 345 insertions, 81 deletions
diff --git a/INSTALL b/INSTALL
index 86b65d4..0fada71 100644
--- a/INSTALL
+++ b/INSTALL
@@ -26,6 +26,7 @@ Installation
$HOST: for example "http://localhost"
$INDEX: the absolute web path to your index.php file e.g. "/mypath/index.php"
$STATS: the absolute web path to your stats.php file e.g. "/mypath/stast.php"
+ $RSSS: the absolute web path to your rss.php file e.g. "/mypath/rss.php"
database info:
diff --git a/config.php_template b/config.php_template
index 93e951c..a3e9e54 100644
--- a/config.php_template
+++ b/config.php_template
@@ -33,6 +33,8 @@
*/
$INDEX = "/index.php";
$HOST = "http://www.example.com";
+ $STATS = "/stats.php";
+ $RSS = "/rss.php";
/* point this to a Wiki that explains the rules, etc (or use this one)*/
$WIKI = "http://wiki.nubati.net/index.php?title=EmailDoko";
diff --git a/css/standard022.css b/css/standard023.css
index 79dfeea..7c84507 100644
--- a/css/standard022.css
+++ b/css/standard023.css
@@ -649,4 +649,8 @@ div.table div img.gravatar, img.gravatar {
width: 4em;
height: 4em;
border: 3px solid #aaa;
-} \ No newline at end of file
+}
+
+.highcall {
+ background-color: #fc3;
+}
diff --git a/include/db.php b/include/db.php
index 882a1ad..55d97c9 100644
--- a/include/db.php
+++ b/include/db.php
@@ -498,6 +498,15 @@ function DB_update_game_timestamp($gameid)
return;
}
+function DB_get_game_timestamp($gameid)
+{
+ $r = DB_query_array("SELECT mod_date FROM Game WHERE id=".DB_quote_smart($gameid));
+
+ if($r)
+ return $r[0];
+ else
+ return NULL;
+}
function DB_update_user_timestamp($userid)
{
@@ -514,6 +523,17 @@ function DB_get_user_timestamp($userid)
else
return NULL;
}
+
+function DB_get_user_creation_date($userid)
+{
+ $r = DB_query_array("SELECT create_date FROM User WHERE id=".DB_quote_smart($userid));
+
+ if($r)
+ return $r[0];
+ else
+ return NULL;
+}
+
function DB_get_user_timezone($userid)
{
$r = DB_query_array("SELECT timezone FROM User WHERE id=".DB_quote_smart($userid));
diff --git a/include/functions.php b/include/functions.php
index 63216eb..33da9ef 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -708,19 +708,36 @@ function sort_comp_low_high($a,$b)
function can_call($what,$hash)
{
+ /* figure out if a person can make a call:
+ $what in 0,30,60,90,120 = points of the call
+ $hash = the hash of the person who wants to make the call
+
+ return values:
+ 0 can't make that call
+ 1 can make the call
+ 2 can make the call, but this is the last chance to do so...
+ */
+
global $RULES;
+ /* get some information
+ */
$gameid = DB_get_gameid_by_hash($hash);
$gametype = DB_get_gametype_by_gameid($gameid);
- $oldcall = DB_get_call_by_hash($hash);
- $pcall = DB_get_partner_call_by_hash($hash);
+ $oldcall = DB_get_call_by_hash($hash); /* did the person already made a call? */
+ $pcall = DB_get_partner_call_by_hash($hash); /* did the partner already made a call */
- if( ($pcall!=NULL && $what >= $pcall) ||
- ($oldcall!=NULL && $what >=$oldcall) )
+
+ /* you're call must be better than the one you or your partner already made
+ */
+ if( ($pcall!=NULL && ($what >= $pcall))
+ || ($oldcall!=NULL && ($what >=$oldcall)) )
{
return 0;
}
+ /* for some rules we need to know how many cards people have
+ */
$NRcards = count(DB_get_hand($hash));
$NRallcards = 0;
@@ -730,7 +747,8 @@ function can_call($what,$hash)
$NRallcards += count(DB_get_hand($user));
};
- /* in case of a wedding, everything will be delayed by an offset */
+ /* in case of a wedding, everything will be delayed by an offset
+ */
$offset = 0;
if($gametype=="wedding")
{
@@ -739,18 +757,34 @@ function can_call($what,$hash)
return 0;
};
+ /* now check if the call is allowed depending on the rule set
+ */
switch ($RULES["call"])
{
case "1st-own-card":
- if( 4-($what/30) >= 12 - ($NRcards + $offset))
+ /* calls can be made before/while you play your card...
+ * first card = 120, second card = 90, etc.
+ */
+ if( 4-($what/30) == 12 - ($NRcards + $offset))
+ return 2;
+ if( 4-($what/30) > 12 - ($NRcards + $offset))
return 1;
break;
case "5th-card":
- if( 27+4*($what/30) <= $NRallcards + $offset*4)
+ /* you can make the first call anytime during the first trick
+ */
+ if( 27+4*($what/30) == $NRallcards + $offset*4)
+ return 2;
+ if( 27+4*($what/30) < $NRallcards + $offset*4)
return 1;
break;
case "9-cards":
+ /* you can call 120 with 12 cards, 90 with 9 or more cards, 60 with 6 or more, etc.
+ * you can't skip a call though
+ */
+ /* figure out last call
+ */
if($oldcall!=NULL && $pcall!=NULL)
$mincall = ($oldcall>$pcall) ? $pcall : $oldcall;
else if($oldcall!=NULL)
@@ -760,26 +794,51 @@ function can_call($what,$hash)
else
$mincall = -1;
- if( 12 <= ($NRcards + $offset))
+
+ if( 12 == ($NRcards + $offset))
+ {
+ return 2;
+ }
+ else if( 12 < ($NRcards + $offset))
{
return 1;
}
- else if ( 9 <= ($NRcards + $offset))
+ else if ( 9 == ($NRcards + $offset))
+ {
+ if( ($mincall>=0 && $mincall==120) )
+ return 2;
+ }
+ else if ( 9 < ($NRcards + $offset))
{
if( ($mincall>=0 && $mincall==120) )
return 1;
}
- else if ( 6 <= ($NRcards + $offset))
+ else if ( 6 == ($NRcards + $offset))
+ {
+ if( ($mincall>=0 && $mincall<=90 && $what<=60 ) )
+ return 2;
+ }
+ else if ( 6 < ($NRcards + $offset))
{
if( ($mincall>=0 && $mincall<=90 && $what<=60 ) )
return 1;
}
- else if ( 3 <= ($NRcards + $offset))
+ else if ( 3 == ($NRcards + $offset))
+ {
+ if( ($mincall>=0 && $mincall<=60 && $what<=30 ) )
+ return 2;
+ }
+ else if ( 3 < ($NRcards + $offset))
{
if( ($mincall>=0 && $mincall<=60 && $what<=30 ) )
return 1;
}
- else if ( 0 <= ($NRcards + $offset))
+ else if ( 0 == ($NRcards + $offset))
+ {
+ if( ($mincall>=0 && $mincall<=30 && $what==0 ) )
+ return 2;
+ }
+ else if ( 0 < ($NRcards + $offset))
{
if( ($mincall>=0 && $mincall<=30 && $what==0 ) )
return 1;
@@ -822,7 +881,7 @@ function display_table ()
$call = $r[5];
$hash = $r[7];
$timezone = $r[8];
- $email = $r[9];
+ $email = $r[9];
$wins = DB_get_number_of_tricks($gameid,$pos);
date_default_timezone_set($defaulttimezone);
$lastlogin = strtotime($r[6]);
@@ -1325,4 +1384,18 @@ function cancel_game($why,$gameid)
return;
}
+function get_user_token($userid)
+{
+
+ $token = NULL;
+
+ $date = DB_get_user_creation_date($userid);
+ $name = DB_get_name('userid',$userid);
+
+ if($date && $name)
+ $token = md5("token".$name.$date);
+
+ return $token;
+}
+
?>
diff --git a/include/game.php b/include/game.php
index 30abe7d..e20ea9a 100644
--- a/include/game.php
+++ b/include/game.php
@@ -24,10 +24,6 @@ if(!$myid)
global $GAME,$RULES,$CARDS;
-/* the user has done something, update the timestamp */
-if(isset($_SESSION['id']))
- DB_update_user_timestamp($_SESSION['id']);
-
/* get some information from the DB */
$gameid = DB_get_gameid_by_hash($me);
$myname = DB_get_name('hash',$me);
@@ -288,6 +284,16 @@ display_table();
* play: game in progress
* gameover: are we revisiting a game
*/
+
+/* the user has done something, update the timestamp. Use $myid in
+ * active games and check for session-id in old games (myid might be wrong in that case)
+ */
+if($mystatus!='gameover')
+ DB_update_user_timestamp($myid);
+ else
+ if(isset($_SESSION['id']))
+ DB_update_user_timestamp($_SESSION['id']);
+
switch($mystatus)
{
case 'start':
@@ -1420,7 +1426,10 @@ switch($mystatus)
$play = DB_get_cards_by_trick($trickid);
$winner = get_winner($play,$gametype); /* returns the position */
- /* check if someone caught a fox */
+ /*
+ * check if someone caught a fox
+ *******************************/
+
/* first check if we should account for solos at all,
* since it doesn't make sense in some games
*/
@@ -1453,7 +1462,10 @@ switch($mystatus)
}
}
- /* check for karlchen (jack of clubs in the last trick)*/
+ /*
+ * check for karlchen (jack of clubs in the last trick)
+ ******************************************************/
+
/* same as for foxes, karlchen doesn't always make sense
* check what kind of game it is and set karlchen accordingly */
$ok = 1; /* default: karlchen should be accounted for */
@@ -1478,7 +1490,10 @@ switch($mystatus)
DB_query("INSERT INTO Score".
" VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')");
}
- /* check for doppelopf (>40 points)*/
+ /*
+ * check for doppelopf (>40 points)
+ ***********************************/
+
$points = 0;
foreach($play as $played)
{
@@ -1493,6 +1508,10 @@ switch($mystatus)
" VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'doko')");
}
+ /*
+ * set winner (for this trick)
+ */
+
if($winner>0)
DB_query("UPDATE Trick SET winner='$winner' WHERE id='$trickid'");
else
@@ -1943,7 +1962,15 @@ switch($mystatus)
{
$oldcards = DB_get_all_hand($me);
$oldcards = mysort($oldcards,$gametype);
- echo "Your cards were: <br />\n";
+
+ if(isset($_SESSION['id']) && $myid==$_SESSION['id'])
+ echo "Your cards were: <br />\n";
+ else
+ {
+ $name = DB_get_name('userid',$myid);
+ echo "$name's were: <br />\n";
+ }
+
foreach($oldcards as $card)
display_card($card,$PREF['cardset']);
diff --git a/include/output.php b/include/output.php
index 9e87de3..61fef60 100644
--- a/include/output.php
+++ b/include/output.php
@@ -247,30 +247,61 @@ function output_check_for_sickness($me,$mycards)
function output_form_calls($me,$myparty)
{
- if( can_call(120,$me) )
+ $highstart = "<span class=\"highcall\">";
+ $highend = "</span>";
+
+ $tmp = can_call(120,$me);
+ if( $tmp )
+ {
+ if($tmp==2) echo $highstart;
+ if($myparty=='re')
+ echo "re (120):";
+ else if ($myparty=='contra')
+ echo "contra (120):";
+ else
+ echo " re/contra (120):";
+ echo " <input type=\"radio\" name=\"call\" value=\"120\" />";
+ if($tmp==2) echo $highend;
+ echo "<br />\n";
+ }
+ $tmp = can_call(90,$me);
+ if( $tmp )
+ {
+ if($tmp==2) echo $highstart;
+ echo " 90:".
+ " <input type=\"radio\" name=\"call\" value=\"90\" />";
+ if($tmp==2) echo $highend;
+ echo "<br />\n";
+ }
+ $tmp = can_call(60,$me);
+ if( $tmp )
{
- if($myparty=='re')
- echo "re (120):";
- else if ($myparty=='contra')
- echo "contra (120):";
- else
- echo " re/contra (120):";
- echo " <input type=\"radio\" name=\"call\" value=\"120\" /> <br />";
+ if($tmp==2) echo $highstart;
+ echo " 60:".
+ " <input type=\"radio\" name=\"call\" value=\"60\" />";
+ if($tmp==2) echo $highend;
+ echo "<br />\n";
+ }
+ $tmp = can_call(30,$me);
+ if( $tmp )
+ {
+ if($tmp==2) echo $highstart;
+ echo " 30:".
+ " <input type=\"radio\" name=\"call\" value=\"30\" />";
+ if($tmp==2) echo $highend;
+ echo "<br />\n";
+ }
+ $tmp = can_call(0,$me);
+ if( $tmp )
+ {
+ if($tmp==2) echo $highstart;
+ echo " 0:".
+ " <input type=\"radio\" name=\"call\" value=\"0\" />";
+ if($tmp==2) echo $highend;
+ echo "<br />\n".
+ " no call:".
+ " <input type=\"radio\" name=\"call\" value=\"no\" /> <br />";
}
- if( can_call(90,$me) )
- echo " 90:".
- " <input type=\"radio\" name=\"call\" value=\"90\" /> <br />";
- if( can_call(60,$me) )
- echo " 60:".
- " <input type=\"radio\" name=\"call\" value=\"60\" /> <br />";
- if( can_call(30,$me) )
- echo " 30:".
- " <input type=\"radio\" name=\"call\" value=\"30\" /> <br />";
- if( can_call(0,$me) )
- echo " 0:".
- " <input type=\"radio\" name=\"call\" value=\"0\" /> <br />".
- " no call:".
- " <input type=\"radio\" name=\"call\" value=\"no\" /> <br />";
}
function output_check_want_to_play($me)
@@ -301,7 +332,7 @@ function output_header()
<title>e-Doko</title>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
<link rel="shortcut icon" type="image/x-icon" href="pics/edoko-favicon.png" />
- <link rel="stylesheet" type="text/css" href="css/standard022.css" />
+ <link rel="stylesheet" type="text/css" href="css/standard023.css" />
<script type="text/javascript" src="include/game.js"> </script>
<script type="text/javascript" src="include/jquery.js"> </script>
<script type="text/javascript" src="include/jquery.tablesorter.js"></script>
@@ -349,39 +380,44 @@ function output_footer()
function output_status()
{
- global $defaulttimezone,$INDEX,$WIKI;
- if(isset($_SESSION["name"]))
- {
- $name = $_SESSION["name"];
-
- /* logout info */
- echo "\n<div class=\"status\">\n";
- echo $name,"\n";
- echo " | <a href=\"".$INDEX."\"> mypage </a>\n";
- echo " | <a href=\"".$INDEX."?action=prefs\">settings</a>\n";
- echo " | <a href=\"".$INDEX."?action=new\">new game</a>\n";
- echo " | <a href=\"".$INDEX."?action=stats\">statistics</a>\n";
- echo " | <a href=\"".$WIKI."\">wiki</a>\n";
- echo " |&nbsp;&nbsp;&nbsp; <a href=\"".$INDEX."?action=logout\">logout</a>\n";
- echo "</div>\n";
-
- /* last logon time */
- $myid = DB_get_userid("name",$name);
- $zone = DB_get_user_timezone($myid);
-
- $time = DB_get_user_timestamp($myid);
- date_default_timezone_set($defaulttimezone);
- $unixtime = strtotime($time);
- date_default_timezone_set($zone);
-
- echo "<div class=\"lastlogin\"><span>last login: ".date("r",$unixtime)."</span></div>\n";
- }
- else
- {
- echo "\n<div class=\"status\">\n";
- echo "<a href=\"".$INDEX."\">login</a>\n";
- echo "</div>\n";
- }
+ global $defaulttimezone, $INDEX, $WIKI, $RSS;
+
+ if(isset($_SESSION["name"]))
+ {
+ $name = $_SESSION["name"];
+
+ /* last logon time */
+ $myid = DB_get_userid("name",$name);
+ $zone = DB_get_user_timezone($myid);
+
+ $time = DB_get_user_timestamp($myid);
+ date_default_timezone_set($defaulttimezone);
+ $unixtime = strtotime($time);
+ date_default_timezone_set($zone);
+
+ /* rss token */
+ $token = get_user_token($myid);
+
+ /* logout info */
+ echo "\n<div class=\"status\">\n";
+ echo $name,"\n";
+ echo " | <a href=\"".$INDEX."\"> mypage </a>\n";
+ echo " | <a href=\"".$INDEX."?action=prefs\">settings</a>\n";
+ echo " | <a href=\"".$INDEX."?action=new\">new game</a>\n";
+ echo " | <a href=\"".$INDEX."?action=stats\">statistics</a>\n";
+ echo " | <a href=\"".$WIKI."\">wiki</a>\n";
+ echo " | <a href=\"".$RSS."?uid=".$myid."&amp;token=".$token."\">rss</a>\n";
+ echo " |&nbsp;&nbsp;&nbsp; <a href=\"".$INDEX."?action=logout\">logout</a>\n";
+ echo "</div>\n";
+
+ echo "<div class=\"lastlogin\"><span>last login: ".date("r",$unixtime)."</span></div>\n";
+ }
+ else
+ {
+ echo "\n<div class=\"status\">\n";
+ echo "<a href=\"".$INDEX."\">login</a>\n";
+ echo "</div>\n";
+ }
return;
}
diff --git a/index.php b/index.php
index 9702800..d92f478 100644
--- a/index.php
+++ b/index.php
@@ -2,7 +2,7 @@
error_reporting(E_ALL);
/* start a session, if it is not already running.
- * This way people don't have to log in all the times.
+ * This way people don't have to log in all the times.
* The session variables can also be read out from different
* php scripts, so that the code can be easily split up across several files
*/
@@ -50,11 +50,11 @@ switch($action)
require './include/reminder.php';
break;
case 'logout':
- require './include/logout.php';
+ require './include/logout.php';
require './include/welcome.php';
break;
case 'login':
- require './include/login.php';
+ require './include/login.php';
require './include/user.php';
break;
case 'register':
diff --git a/rss.php b/rss.php
new file mode 100644
index 0000000..6dbb6e6
--- /dev/null
+++ b/rss.php
@@ -0,0 +1,101 @@
+<?php
+ /* get some information from the database */
+error_reporting(E_ALL);
+
+/* start a session, if it is not already running.
+ * This way people don't have to log in all the times.
+ * The session variables can also be read out from different
+ * php scripts, so that the code can be easily split up across several files
+ */
+
+include_once("config.php"); /* needs to be first in list, since other includes use this */
+include_once("./include/output.php"); /* html output only */
+include_once("./include/db.php"); /* database only */
+include_once("./include/functions.php"); /* the rest */
+
+/* make sure that user has set all variables in config.php */
+config_check();
+
+/* open the database */
+if(DB_open()<0)
+ {
+ output_header();
+ echo "Database error, can't connect... Please wait a while and try again. ".
+ "If the problem doesn't go away feel free to contact $ADMIN_NAME at $ADMIN_EMAIL.";
+ output_footer();
+ exit();
+ }
+
+$ok = 0;
+$id = 0;
+
+if(!myisset("uid","token"))
+ {
+ echo "error";
+ }
+else
+ {
+ $id = $_REQUEST['uid'];
+ $token = get_user_token($id);
+
+ if($token == $_REQUEST['token'])
+ $ok = 1;
+ }
+
+if(! $ok)
+ {
+ echo "No valid userid";
+ exit();
+ }
+
+header("Content-Type: text/xml");
+/* start the feed */
+?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+<title>E-DoKo Feed</title>
+<subtitle>Know when it is your turn</subtitle>
+<?php
+
+ global $WIKI,$INDEX, $HOST;
+
+ /* output last creation date */
+echo "<link href=\"$HOST/$INDEX\" />\n";
+echo "<link rel=\"self\" href=\"".$HOST.htmlentities($_SERVER['REQUEST_URI'])."\" />\n";
+$date = DB_query_array("Select create_date from User order by create_date ASC limit 1");
+$date = $date[0];
+$timestamp = strtotime($date);
+echo "<id>tag:".$_SERVER['SERVER_NAME'].",".date("Y-m-d",$timestamp).":$INDEX</id>\n";
+echo "<updated>".date(DATE_ATOM)."</updated>\n";
+echo "<author>\n";
+echo "<name>$ADMIN_NAME $date $timestamp</name>\n";
+echo "<email>$ADMIN_EMAIL</email>\n";
+echo "</author>\n\n";
+
+
+ /* output the entries */
+
+
+ $result = DB_query("SELECT Hand.hash,Hand.game_id,Game.player from Hand".
+ " LEFT JOIN Game On Hand.game_id=Game.id".
+ " WHERE Hand.user_id='$id'".
+ " AND ( Game.player='$id' OR ISNULL(Game.player) )".
+ " AND ( Game.status='pre' OR Game.status='play' )".
+ " ORDER BY Game.session" );
+
+ while( $r = DB_fetch_array($result))
+ {
+ echo "<entry>\n";
+ echo "<title>game ".DB_format_gameid($r[1])."</title>\n";
+ $url=$INDEX."?action=game&amp;me=".$r[0];
+ echo "<link href=\"".$HOST.$url."\" />\n";
+ $date = DB_get_game_timestamp($r[1]);
+ $timestamp = strtotime($date);
+ $date = date("Y-m-d",$timestamp);
+ echo "<id>tag:doko.nubati.net,$date:$url</id>\n";
+ echo "<updated>".date(DATE_ATOM,$timestamp)."</updated>\n";
+ echo "<summary>Please use the link to access the game.</summary>\n";
+ echo "</entry>\n\n";
+ }
+
+?>
+</feed> \ No newline at end of file