{"id":16404212,"url":"https://github.com/beheh/sulphur","last_synced_at":"2025-04-04T14:40:22.598Z","repository":{"id":17682880,"uuid":"20488751","full_name":"beheh/sulphur","owner":"beheh","description":"🔎 Parse and extract data from Clonk game references.","archived":false,"fork":false,"pushed_at":"2016-10-14T10:28:16.000Z","size":43,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T10:47:54.195Z","etag":null,"topics":["clonk","masterserver"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/beheh/sulphur","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beheh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-04T15:19:50.000Z","updated_at":"2018-09-06T11:20:05.000Z","dependencies_parsed_at":"2022-09-24T00:50:32.487Z","dependency_job_id":null,"html_url":"https://github.com/beheh/sulphur","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beheh%2Fsulphur","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beheh%2Fsulphur/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beheh%2Fsulphur/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beheh%2Fsulphur/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beheh","download_url":"https://codeload.github.com/beheh/sulphur/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198400,"owners_count":20900078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clonk","masterserver"],"created_at":"2024-10-11T05:51:45.761Z","updated_at":"2025-04-04T14:40:22.577Z","avatar_url":"https://github.com/beheh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sulphur\n\n[![Packagist](https://img.shields.io/packagist/v/beheh/sulphur.svg?style=flat-square)](https://packagist.org/packages/beheh/sulphur)\n[![License](https://img.shields.io/packagist/l/beheh/sulphur.svg?style=flat-square)](https://packagist.org/packages/beheh/sulphur)\n[![Travis](https://img.shields.io/travis/beheh/sulphur/master.svg?style=flat-square)](https://travis-ci.org/beheh/sulphur)\n\nA full library to parse and filter data from the Clonk masterserver protocol, as used in the games Clonk Rage (http://clonk.de) and OpenClonk (http://openclonk.org).\n\nThis library was created by Benedict Etzel (developer@beheh.de) and is licensed under the ISC license.\n\n## Installing\n\nInstall Sulphur by using [composer](https://getcomposer.org/).\n\n```ShellSession\n$ composer require beheh/sulphur\n```\n\n## Examples\n\n```php\n// fetch masterserver response\n$parser = new BehEh\\Sulphur\\Parser();\n$response = $parser-\u003eparse(file_get_contents('example.com:80'));\n\n// count all running games\necho count($response-\u003ewhere('State')-\u003eis('Running')).' game(s) are currently running';\n\n// iterate through all games currently in lobby\nforeach($response-\u003ewhere('State')-\u003eis('Lobby') as $reference) {\n    echo $reference-\u003eTitle.' is now open!';\n}\n\n// show comment of first game containing \"CMC\" (case insensitive)\n$references = $response-\u003ewhere('Title')-\u003econtains('cmc', true);\necho $references[0]-\u003eComment;\n\n// show title of first running league game\n$references = $response-\u003ewhere('State')-\u003eis('Running')\n                       -\u003ewhere('League')-\u003edoesNotExist();\necho $references[0]-\u003eTitle;\n\n// count games for Clonk Rage or OpenClonk\n$references = $response-\u003ewhere('Game')-\u003epasses(function($field, $value) { return $value === 'Clonk Rage' || $value === 'OpenClonk'; });\necho count($references).' Clonk Rage and OpenClonk games open';\n\n// print all player names in a reference\nforeach($reference-\u003efirst('PlayerInfos')-\u003eall('Client') as $client) {\n\tforeach($client-\u003eall('Player') as $player) {\n\t\techo $player-\u003eName;\n\t}\n}\n```\n\n## Basic usage\n\nYou can access the master data by using the parser and passing masterserver data.\n\n```php\nuse BehEh\\Sulphur\\Parser;\n\n$parser = new Parser();\n$response = $parser-\u003eparse($data);\n```\n\nIt's recommended to cache this data so the masterserver doesn't blacklist your server.\n\n## Game references\n\nGame sessions are tracked as game references. They can have a variety of fields which describe something about the game.\n\n### Access\n\nTo access references, simply call the corresponding functions in the reference object:\n\n```php\n$references = $response-\u003eall();\n$references = $response-\u003ewhere('Title')-\u003eis('Clepal');\n$reference = $response-\u003efirst('Reference'); // or $response-\u003efirst()\n```\n\nThe calls return an object which should handle like an array.\n\n### Filtering\n\nResponses can be filtered in multiple ways:\n\n```php\n$response-\u003ewhere('State')-\u003eis('Lobby');\n$response-\u003ewhere('League')-\u003eexists();\n$response-\u003ewhere('Comment')-\u003econtains('friendly');\n$response-\u003ewhere('Comment')-\u003econtains('friendly', true); // case insensitive\n$response-\u003ewhere('Version')-\u003ematches('/4(,[0-9]+){3}/');\n```\n\nInverse filtering is also available:\n\n```php\n$response-\u003ewhere('State')-\u003eisNot('Running');\n$response-\u003ewhere('League')-\u003edoesNotExist();\n$response-\u003ewhere('Comment')-\u003edoesNotContain('bad');\n$response-\u003ewhere('Comment')-\u003edoesNotContains('bad', true); // case insensitive\n$response-\u003ewhere('Version')-\u003edoesNotMatch('/5(,[0-9]+){3}/');\n```\n\nYou can also use custom callbacks (anything accepted by call_user_func):\n\n```php\n$response-\u003ewhere('Title')-\u003epasses(function($field, $value) { return strlen($value) \u003e 5; });\n$response-\u003ewhere('Title')-\u003edoesNotPass(function($field, $value) { return strlen($value) \u003c= 3; });\n```\n\n#### Chain filtering\n\nYou can filter multiple fields by repeating calls to `where`:\n\n```php\n$response-\u003ewhere('State')-\u003eis('Running')-\u003ewhere('League')-\u003eexists();\n$response-\u003ewhere('State')-\u003eis('Lobby')-\u003ewhere('Password')-\u003edoesNotExist();\n```\n\n### Fields\n\nFields are key-value pairs and can be read simply by accessing the corresponding (case-sensitive) local variables:\n\n```php\necho $reference-\u003eTitle;\necho $reference-\u003eGame;\n```\n\n#### Subsections\n\nTo access fields in a specific section you can use the `all` and `first` methods:\n\n```php\necho $reference-\u003efirst('PlayerInfos')-\u003efirst('Client')-\u003efirst('Player')-\u003eName;\nforeach($reference-\u003eall('Resource') as $resource) {\n\techo $resource-\u003eFilename;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeheh%2Fsulphur","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeheh%2Fsulphur","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeheh%2Fsulphur/lists"}