nadybot/aolib
Composer 安装命令:
composer require nadybot/aolib
包简介
An amphp3-based client library for the Anarchy Online chat server
README 文档
README
This is a very basic library that provides AMP3-based async classes to deal with connections to the chat-server of Anarchy Online. It consists of
- a tokenizer to extract single packets out of an endless stream (files, sockets, …)
- a connection-handler that utilizes the tokenizer to parse these string-packets into binary packets
- a parser that parses these binary packets into AO-packets
- an MMDB database class to access builtin-strings
- a basic client that combines all this, and keeps track of known uid <=> name mappings, as well as make the ever important lookup of these available as if these calls were sync
You have to be familiar with the AMP way of dealing with things, otherwise, this is useless to you.
Basic usage
<?php declare(strict_types=1); use function Amp\Socket\connect; use Monolog\Handler\StreamHandler; use Monolog\Processor\PsrLogMessageProcessor; use Monolog\{Level, Logger}; require_once __DIR__ . "/../vendor/autoload.php"; $logger = new Logger('mylogger'); $logger->pushHandler(new StreamHandler("php://stdout", Level::Debug)); $logger->pushProcessor(new PsrLogMessageProcessor(null, true)); $socket = connect("chat.d1.funcom.com:7105"); $client = new \AO\Client\Basic( $logger, new \AO\Connection($logger, $socket, $socket); \AO\Parser::createDefault($logger) ); $client->login(username: "Myuser", password: "Mypassword", character: "Mychar"); while (($package = $client->read()) !== null) { // Process package }
This just scratches the surface of what the library can do. I don't expect anyone else to use this code, so please step forward if I'm mistaken.
Check the code for usage of the client. Whether you extend it, or wrap it, is up to you, but extending is the more elegant solution.
Lookups
Looking up names or UIDs is done like this
$uid = $client->lookupUid("Nady"); $character = $client->lookupCharacter(123456);
All the logic happens behind the scenes. You either receive an int/string, or null.
Sending packets
This is the most basic interface:
$client->write(new Out\Tell(charId: 1234, message: "Hello!"));
Multi character usage
<?php declare(strict_types=1); use AO\Client\{Multi, WorkerConfig}; require_once __DIR__ . "/../vendor/autoload.php"; $client = new Multi( mainCharacter: "Char1", workers: [ new WorkerConfig( dimension: 5, username: "login1", password: "password1", character: "Char1", ), new WorkerConfig( dimension: 5, username: "login2", password: "password2", character: "Char2", ), ] ); $client->login(); foreach ($client->getPackages() as $package) { // Do something } EventLoop::run();
Running tests
Make sure you installed the developer packages as well and run vendor/bin/phpunit -c phpunit.xml
Developing
The code has been written under VSCode using the following extensions:
- PHP Intelephense (bmewburn.vscode-intelephense-client)
- phpcs (shevaua.phpcs)
- phpstan (sanderronde.phpstan-vscode)
- PHPUnit Watcher (herisit.phpunit-watcher)
- Simple PHP CS Fixer 3 (phlak.simple-php-cs-fixer-3)
The shipped .vscode/settings.json-file should automatically configure them to work with this project.
nadybot/aolib 适用场景与选型建议
nadybot/aolib 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34.57k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nadybot/aolib 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nadybot/aolib 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 34.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2024-04-28