login method

Future<StatusResult?> login(
  1. String username,
  2. String password, {
  3. int timeout = 5,
})
inherited

登录指令

Implementation

Future<StatusResult?> login(String username, String password,
    {int timeout = 5}) async {
  var status = null;
  if (p2pConnectState != ClientConnectState.CONNECT_STATUS_ONLINE) {
    return status;
  }

  AppP2PApi().clientLogin(clientPtr!, username, password);
  bool ret = await AppP2PApi().clientLogin(clientPtr!, username, password);
  if (ret == true) {
    CommandResult result = await waitCommandResult((int cmd, Uint8List data) {
      if (cmd == 24577) return true;
      if (cmd == 24785) {
        CommandResult cmdResult = CommandResult(true, cmd, data);
        var map = cmdResult.getMap();
        if (map == null) return false;
        if (map.containsKey("result") && map.keys.length == 1) return true;
        if (map.containsKey("result") &&
            map.containsKey("current_users") &&
            map.containsKey("max_support_users")) return true;
      }
      return false;
    }, timeout);
    if (result.isSuccess) {
      statusResult = StatusResult.form(result);
      status = statusResult;
    }
  }

  return status;
}