1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- use GameClient;
- class ProgramMain {
- private static ?GameClient $client = null;
-
- private static function getClient(): GameClient {
- if (self::$client === null) {
- self::$client = new GameClient();
- echo "客户端初始化完成\n";
- }
- return self::$client;
- }
- public static function handleCommand(array $args): void {
- $client = self::getClient();
-
- if (count($args) < 2) {
- echo "使用方法: php client.php [命令] [参数...]\n";
- echo "可用命令:\n";
- echo " login [账号] [密码] - 登录游戏\n";
- echo " start - 启动客户端\n";
- return;
- }
- $command = $args[1];
- switch ($command) {
- case 'login':
- if (count($args) < 4) {
- echo "错误:login命令需要账号和密码参数\n";
- echo "示例: php client.php login myaccount mypassword\n";
- return;
- }
- $account = $args[2];
- $password = $args[3];
- $client->login($account, $password);
- break;
- case 'start':
- $client->start();
- break;
- default:
- echo "未知命令: $command\n";
- }
- }
- }
- // 命令行执行
- if (php_sapi_name() === 'cli') {
- ProgramMain::handleCommand($argv);
- }
|