From: Hendrik B. <nh...@us...> - 2010-09-29 20:42:18
|
Update of /cvsroot/arianne/stendhal_website/scripts In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv15927/scripts Modified Files: account.php Log Message: moved functions related to login logging into the class PlayerLogEntry Index: account.php =================================================================== RCS file: /cvsroot/arianne/stendhal_website/scripts/account.php,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** account.php 29 Sep 2010 20:29:32 -0000 1.35 --- account.php 29 Sep 2010 20:42:08 -0000 1.36 *************** *** 47,51 **** /* Here we log the login attempt, with username, IP and whether failed or successful */ ! logUserLogin($$username, $_SERVER['REMOTE_ADDR'], $result == 0); return $result; --- 47,51 ---- /* Here we log the login attempt, with username, IP and whether failed or successful */ ! PlayerLoginEntry::logUserLogin($$username, $_SERVER['REMOTE_ADDR'], $result == 0); return $result; *************** *** 167,216 **** $row = mysql_fetch_assoc($result); - return $row['id']; } - // log password changes for user from ip - // returns boolean successfully logged - function logUserPasswordChange($user, $ip, $oldpass, $result) { - $userid = getUserID($user); - - if ( $userid === false) { - return false; - } - - $q = "INSERT INTO passwordChange (player_id, address, oldpassword, service, result)". - " values (".$userid.", '".mysql_real_escape_string($ip)."', '".mysql_real_escape_string($oldpass)."', 'website',".mysql_real_escape_string($result).")"; - - $result = mysql_query($q, getGameDB()); - - return $result !== false; - } - - // log logins for user from ip - // returns boolean successfully logged - function logUserLogin($user, $ip, $success) { - $userid = getUserID($user); - - if ( $userid === false ) { - return false; - } - - $q = "INSERT INTO loginEvent (player_id,address,result,service) values ". - "(".$userid.",'".mysql_real_escape_string($ip)."',".($success ? '1' : '0').",'website')"; - - $result = mysql_query($q, getGameDB()); - - return $result !== false; - } - - function logAccountMerge($character, $oldAccountId, $oldUsername, $newUsername) { - $q = "INSERT INTO gameEvents (source, event, param1, param2) values ". - "('".mysql_real_escape_string($character)."', 'accountmerge', '".mysql_real_escape_string($oldAccountId)."', '" - .mysql_real_escape_string($oldUsername). "-->". mysql_real_escape_string($newUsername) ."')"; - $result = mysql_query($q, getGameDB()); - return $result !== false; - } --- 167,174 ---- *************** *** 255,259 **** $result = mysql_query("SELECT charname FROM characters WHERE player_id='".mysql_real_escape_string($oldAccountId)."'", getGameDB()); while($row = mysql_fetch_assoc($result)) { ! logAccountMerge($row['charname'], $oldAccountId, $oldUsername, $newUsername); } mysql_free_result($result); --- 213,217 ---- $result = mysql_query("SELECT charname FROM characters WHERE player_id='".mysql_real_escape_string($oldAccountId)."'", getGameDB()); while($row = mysql_fetch_assoc($result)) { ! PlayerLoginEntry::logAccountMerge($row['charname'], $oldAccountId, $oldUsername, $newUsername); } mysql_free_result($result); *************** *** 285,313 **** /** - * gets a list of recent login events for that player - */ - function getLoginHistory($playerId) { - $sql = "SELECT address, timedate, service, event, result FROM " - . "(SELECT address, timedate, service, 'login' As event, result FROM loginEvent " - . "WHERE player_id=".mysql_real_escape_string($playerId)." AND timedate > DATE_SUB(CURDATE(),INTERVAL 7 DAY) " - . "UNION SELECT address, timedate, service, 'password change' As event, result FROM passwordChange " - . "WHERE player_id=".mysql_real_escape_string($playerId)." AND timedate > DATE_SUB(CURDATE(),INTERVAL 7 DAY)) As data " - . "ORDER BY timedate DESC LIMIT 25;"; - - $result = mysql_query($sql, getGameDB()); - $list=array(); - - while($row = mysql_fetch_assoc($result)) { - $list[] = new PlayerLoginEntry($row['timedate'], - $row['address'], $row['service'], $row['event'],$row['result']); - } - - mysql_free_result($result); - - return $list; - } - - - /** * A class that represent a player history entry */ --- 243,246 ---- *************** *** 331,334 **** --- 264,335 ---- $this->success = $success; } + + + /** + * gets a list of recent login events for that player + */ + public static function getLoginHistory($playerId) { + $sql = "SELECT address, timedate, service, event, result FROM " + . "(SELECT address, timedate, service, 'login' As event, result FROM loginEvent " + . "WHERE player_id=".mysql_real_escape_string($playerId)." AND timedate > DATE_SUB(CURDATE(),INTERVAL 7 DAY) " + . "UNION SELECT address, timedate, service, 'password change' As event, result FROM passwordChange " + . "WHERE player_id=".mysql_real_escape_string($playerId)." AND timedate > DATE_SUB(CURDATE(),INTERVAL 7 DAY)) As data " + . "ORDER BY timedate DESC LIMIT 25;"; + + $result = mysql_query($sql, getGameDB()); + $list=array(); + + while($row = mysql_fetch_assoc($result)) { + $list[] = new PlayerLoginEntry($row['timedate'], + $row['address'], $row['service'], $row['event'],$row['result']); + } + + mysql_free_result($result); + return $list; + } + + /** + * log password changes for user from ip + * returns boolean successfully logged + */ + public static function logUserPasswordChange($user, $ip, $oldpass, $result) { + $userid = getUserID($user); + + if ( $userid === false) { + return false; + } + + $q = "INSERT INTO passwordChange (player_id, address, oldpassword, service, result)". + " values (".$userid.", '".mysql_real_escape_string($ip)."', '".mysql_real_escape_string($oldpass)."', 'website',".mysql_real_escape_string($result).")"; + + $result = mysql_query($q, getGameDB()); + return $result !== false; + } + + /** + * log logins for user from ip + * returns boolean successfully logged + */ + public static function logUserLogin($user, $ip, $success) { + $userid = getUserID($user); + + if ( $userid === false ) { + return false; + } + + $q = "INSERT INTO loginEvent (player_id,address,result,service) values ". + "(".$userid.",'".mysql_real_escape_string($ip)."',".($success ? '1' : '0').",'website')"; + + $result = mysql_query($q, getGameDB()); + return $result !== false; + } + + public static function logAccountMerge($character, $oldAccountId, $oldUsername, $newUsername) { + $q = "INSERT INTO gameEvents (source, event, param1, param2) values ". + "('".mysql_real_escape_string($character)."', 'accountmerge', '".mysql_real_escape_string($oldAccountId)."', '" + .mysql_real_escape_string($oldUsername). "-->". mysql_real_escape_string($newUsername) ."')"; + $result = mysql_query($q, getGameDB()); + return $result !== false; + } } |