<commit_before><?php

class Player {
  public $name;
  public $password;
  public $host;
  public $super; 

  static function getSessionPlayer() { 
    if (!isset($_SESSION['username'])) { 
      return NULL;
    }
  
    return new Player($_SESSION['username']);
  } 

  static function checkPassword($username, $password) { 
    $db = Database::getConnection(); 
    $stmt = $db->prepare("SELECT password FROM players WHERE name = ?"); 
    $stmt->bind_param("s", $username); 
    $stmt->execute(); 
    $stmt->bind_result($srvpass); 
    if (!$stmt->fetch()) { 
      return false;
    } 
    $stmt->close(); 

    $hashpwd = hash('sha256', $_POST['password']);

    return strcmp($srvpass, $hashpwd) == 0;
  } 

  static function findByName($playername) { 
    $database = Database::getConnection(); 
    $stmt = $database->prepare("SELECT name FROM players WHERE name = ?"); 
    $stmt->bind_param("s", $playername); 
    $stmt->execute(); 
    $stmt->bind_result($resname); 
    $good = false; 
    if ($stmt->fetch()) { 
      $good = true; 
    } 
    $stmt->close(); 

    if ($good) { 
      return new Player($playername); 
    } else { 
      return NULL; 
    } 
  } 

  static function createByName($playername) { 
    $db = Database::getConnection(); 
    $stmt = $db->prepare("INSERT INTO players(name) VALUES(?)"); 
    $stmt->bind_param("s", $playername); 
    $stmt->execute();
    $stmt->close();
    return Player::findByName($playername); 
  } 

  static function findOrCreateByName($playername) { 
    $found = Player::findByName($playername); 
    if (is_null($found)) { 
      return Player::createByName($playername); 
    } 
  } 

  function __construct($name) { 
    $database = Database::getConnection();
    $stmt = $database->prepare("SELECT password, host, super FROM players WHERE name = ?");
    $stmt->bind_param("s", $name);
    $stmt->execute();
    $stmt->bind_result($this->password, $this->host, $this->super);
    if ($stmt->fetch() == NULL) { 
      throw new Exception('Player '. $name .' is not found.');
    } 
    $this->name = $name;
    $stmt->close();
  }

  function save() { 
    $db = Database::getConnection(); 
    $stmt = $database->prepare("UPDATE players SET password = ?, host = ?, super = ? WHERE name = ?"); 
    $stmt->bind_param("sdds", $this->password, $this->host, $this->super, $this->name); 
    $stmt->execute(); 
    $stmt->close(); 
  } 

  function isHost() { 
    return ($this->super == 1) || ($this->host == 1);
  } 

  function getHostedEvents() { 
    $db = Database::getConnection(); 
    $stmt = $db->prepare("SELECT name FROM events WHERE host = ? OR cohost = ?"); 
    $stmt->bind_param("ss", $this->name, $this->name); 
    $stmt->execute(); 
    $stmt->bind_result($evname); 

    $evnames = array(); 
    while ($stmt->fetch()) { 
      $evnames[] = $evname; 
    } 
    $stmt->close(); 
<commit_msg>fix bug with Player.php where new players could not register.<commit_after><?php

class Player {
  public $name;
  public $password;
  public $host;
  public $super; 

  static function getSessionPlayer() { 
    if (!isset($_SESSION['username'])) { 
      return NULL;
    }
  
    return new Player($_SESSION['username']);
  } 

  static function checkPassword($username, $password) { 
    $db = Database::getConnection(); 
    $stmt = $db->prepare("SELECT password FROM players WHERE name = ?"); 
    $stmt->bind_param("s", $username); 
    $stmt->execute(); 
    $stmt->bind_result($srvpass); 
    if (!$stmt->fetch()) { 
      return false;
    } 
    $stmt->close(); 

    $hashpwd = hash('sha256', $_POST['password']);

    return strcmp($srvpass, $hashpwd) == 0;
  } 

  static function findByName($playername) { 
    $database = Database::getConnection(); 
    $stmt = $database->prepare("SELECT name FROM players WHERE name = ?"); 
    $stmt->bind_param("s", $playername); 
    $stmt->execute(); 
    $stmt->bind_result($resname); 
    $good = false; 
    if ($stmt->fetch()) { 
      $good = true; 
    } 
    $stmt->close(); 

    if ($good) { 
      return new Player($playername); 
    } else { 
      return NULL; 
    } 
  } 

  static function createByName($playername) { 
    $db = Database::getConnection(); 
    $stmt = $db->prepare("INSERT INTO players(name) VALUES(?)"); 
    $stmt->bind_param("s", $playername); 
    $stmt->execute();
    $stmt->close();
    return Player::findByName($playername); 
  } 

  static function findOrCreateByName($playername) { 
    $found = Player::findByName($playername); 
    if (is_null($found)) { 
      return Player::createByName($playername); 
    }
   return $found; 
  } 

  function __construct($name) { 
    $database = Database::getConnection();
    $stmt = $database->prepare("SELECT password, host, super FROM players WHERE name = ?");
    $stmt->bind_param("s", $name);
    $stmt->execute();
    $stmt->bind_result($this->password, $this->host, $this->super);
    if ($stmt->fetch() == NULL) { 
      throw new Exception('Player '. $name .' is not found.');
    } 
    $this->name = $name;
    $stmt->close();
  }

  function save() { 
    $db = Database::getConnection(); 
    $stmt = $db->prepare("UPDATE players SET password = ?, host = ?, super = ? WHERE name = ?"); 
    $stmt->bind_param("sdds", $this->password, $this->host, $this->super, $this->name); 
    $stmt->execute(); 
    $stmt->close(); 
  } 

  function isHost() { 
    return ($this->super == 1) || ($this->host == 1);
  } 

  function getHostedEvents() { 
    $db = Database::getConnection(); 
    $stmt = $db->prepare("SELECT name FROM events WHERE host = ? OR cohost = ?"); 
    $stmt->bind_param("ss", $this->name, $this->name); 
    $stmt->execute(); 
    $stmt->bind_result($evname); 

    $evnames = array(); 
    while ($stmt->fetch()) { 
      $evnames[] = $evname; 
    } 
    $stmt->close(); 

{'fraction_non_alphanumeric': 0.18853021978021978, 'fraction_numerical': 0.0020604395604395605, 'mean_word_length': 2.9979409746053536, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4579808', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1790, 'n_words': 391}