baseDir = rtrim( $baseDir, DIRECTORY_SEPARATOR ); $this->updateInterval = $updateInterval; $this->load_server_list(); } public function get_by_name( $name ) { return $this->serverList[ $name ] ?? FALSE; } public function load_server_list( $forceUpdate = FALSE, $url = NULL ){ $url = $url ?? 'https://info.partcp.org/serverlist'; $localCacheFile = $this->baseDir . DIRECTORY_SEPARATOR . 'serverlist.yaml'; if ( $forceUpdate || ! file_exists( $localCacheFile ) || time() - filemtime( $localCacheFile ) > $this->updateInterval ){ $data = file_get_contents( $url ); if ( $data ){ $data = yaml_parse( $data ); if ( ! empty( $data['Server-List'] ) ){ $keys = array_column( $data['Server-List'], 'name' ); $this->serverList = array_combine( $keys, $data['Server-List'] ); if ( ! is_dir( $this->baseDir ) ){ mkdir( $this->baseDir, 0755, TRUE ); } file_put_contents( $localCacheFile, yaml_emit( $this->serverList ) ); return TRUE; } } } $data = file_get_contents( $localCacheFile ); if ( ! $data ){ return FALSE; } $this->serverList = yaml_parse( $data ); return TRUE; } public function get_list() { $list = ParTCP_Key_Storage_Fs::list_pubkeys(); $result = []; foreach ( $list as $name ){ $shortCode = $this->serverList[ $name ]['short_code'] ?? ''; $server = new ParTCP_Public_Identity( $name ); $result[] = [ 'name' => $name, 'pubkey' => $server->pubKey, 'short_code'=> $shortCode ]; } return $result; } public function create( $name, $pubKey ) { return ParTCP_Key_Storage_Fs::store_pubkey( $name, $pubKey ); } public function update( $name, $pubKey ) { return ParTCP_Key_Storage_Fs::store_pubkey( $name, $pubKey ); } } // end of file pas_servers.class.php