source_server 1.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 64

SourceSerer #

A library to connect to Source Dedicated Servers [CS:GO, CSS, TF2, ...] and support for Minecraft Query Protocol

Get started #

Import the library (make sure to check for the latest version).

depedencies:
    source_server: ^1.1.0

And call the SourceServer constructor.

It contains both RconServer and QueryServer instances, if you wish to use just one protocol you can still use one of those classes.

// The SourceServer constructor requires an InternetAddress and a port, if you wish to
// use the rcon connection as well you need to provide a password as well.
var server = SourceServer((await InternetAddress.lookup('hexah.net')).first, 27015);

The only required parameter is the first, password, the ip and port by default are: localhost:27015

To establish a connection to the server call the connect method. It will return a Future<void> that will be completed when the connection to the server is successfully established.

await server.connect();

Sending commands to the RCON #

Use

var reply = await server.send('status');

the method command will return a Future<String> what will return the command reply.

the SourceServer provides also a way to parse the status command.

var status = wait server.getStatus();

Example reply:

{
	server: 
	{   
		hostname: Server name, 
		version: 1.36.8.2/13682 886/7424 secure  [G:1:xxxxxxx], 
		udp/ip: xxx.xx.xxx.xx:27015  (public ip: xxx.xx.xxx.xx), 
		os: Linux, 
		type: community dedicated, 
		map: de_mirage, 
		players: 0 humans, 0 bots (16/0 max) (not hibernating)
	}, 
	//If the server is not empty it will return a list containing all the players in the server (and it's info)
	players: []
}

Sending commands using the query protocol #

Look in the API documentation for all the available methods, here is an example:

var info = server.getInfo();

Returns a Future<Map> holding all the (parsed) server info.

Example for Minecraft Implementation #

(Currently it's only supported the RconProtocol)

  var server = MinecraftServer(InternetAddress('127.0.0.1'), 27015, 'mypassword');
  await server.connect();
  print(await server.send('say hello'));
  server.close();

TODO #

Check the issues page on github

1.0.0 #

  • Initial version, created by Stagehand

1.0.7 #

  • Throw exception when writing to null

1.1.0 #

  • Add support for MinecraftServer.
  var server = MinecraftServer(InternetAddress('127.0.0.1'), 27015, 'mypassword');
  await server.connect();
  print(await server.send('say hello'));
  server.close();
  • Add skipFirst parameter for RconSocket to skip the first optionally packet.

1.1.1 #

  • Random port for UDP socket

1.1.2 #

  • Fix random port

example/example.dart

import 'dart:io';

import 'package:source_server/source_server.dart';

Future<void> main() async {
  var server = SourceServer(InternetAddress('127.0.0.1'), 27015, 'mypassword');
  await server.connect();
  print(await server.getStatus());
  server.close();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  source_server: ^1.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:source_server/source_server.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
31
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Feb 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Format lib/src/exceptions.dart.

Run dartfmt to format lib/src/exceptions.dart.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

exitCode: 255 stdout: parsing /tmp/pub-dartlang-dartdocRDEVDE/pkg/lib/source_server.dart... parsing /tmp/pub-dartlang-dartdocRDEVDE/pkg/lib/minecraft_server.dart... parsing /dart-sdk/lib/async/async.dart... parsing /dart-sdk/lib/collection/collection.dart... parsing /dart-sdk/lib/internal/internal.dart... parsing /dart-sdk/lib/convert/convert.dart... parsing /dart-sdk/lib/typed_data/typed_data.dart... parsing /dart-sdk/lib/core/core.dart... parsing /dart-sdk/lib/math/math.dart... parsing /dart-sdk/lib/io/io.dart... parsing /dart-sdk/lib/developer/developer.dart... parsing /dart-sdk/lib/isolate/isolate.dart... parsing /dart-sdk/lib/_http/http.dart... parsing /tmp/pub-cache-dirDFQJES/hosted/pub.dartlang.org/logging-0.11.4/lib/logging.dart... parsing /tmp/pub-cache-dirDFQJES/hosted/pub.dartlang.org/logging-0.11.4/lib/src/log_record.dart... parsing /tmp/pub-cache-dirDFQJES/hosted/pub.dartlang.org/logging-0.11.4/lib/src/level.dart... parsing /tmp/pub-cache-dirDFQJES/hosted/pub.dartlang.org/logging-0.11.4/lib/src/logger.dart... parsing /tmp/pub-cache-dirDFQJES/hosted/pub.dartlang.org/pedantic-1.9.0/lib/pedantic.dart... parsing /tmp/pub-dartlang-dartdocRDEVDE/pkg/lib/src/exceptions.dart... parsing /tmp/pub-dartlang-dartdocRDEVDE/pkg/lib/src/query_socket.dart... [...] parsing /dart-sdk/lib/js_util/dart2js/js_util_dart2js.dart... parsing /dart-sdk/lib/html/html_common/metadata.dart... parsing /dart-sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart... parsing /dart-sdk/lib/svg/dart2js/svg_dart2js.dart... parsing /dart-sdk/lib/web_audio/dart2js/web_audio_dart2js.dart... parsing /dart-sdk/lib/web_sql/dart2js/web_sql_dart2js.dart... parsing /dart-sdk/lib/js/dart2js/js_dart2js.dart... parsing /dart-sdk/lib/js/_js.dart... parsing /dart-sdk/lib/mirrors/mirrors.dart... parsing /dart-sdk/lib/html/dartium/nativewrappers.dart... parsing /dart-sdk/lib/cli/cli.dart... parsing /dart-sdk/lib/wasm/wasm.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/js_primitives.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/shared/async_await_error_codes.dart... Initialized dartdoc with 47 libraries in 30.2 seconds documenting source_server Generating docs for library source_server from package:source_server/source_server.dart... Generating docs for library source_server from package:source_server/minecraft_server.dart... Validating docs... Documented 2 public libraries in 2.3 seconds stderr: Documenting source_server... warning: ambiguous reexport of exceptions.RconException, canonicalization candidates: (source_server, source_server) -> source_server (confidence 0.000) from exceptions.RconException: (file:///tmp/pub-dartlang-dartdocRDEVDE/pkg/lib/src/exceptions.dart:7:7) source_server: 0.2100 - name is long (+0.01000), element location shares parts with name (+0.2000) source_server: 0.2100 - name is long (+0.01000), element location shares parts with name (+0.2000) Use {@canonicalFor exceptions.RconException} in the desired library's documentation to resolve the ambiguity and/or override dartdoc's decision, or structure your package so the reexport is less ambiguous. The symbol will still be referenced in all candidates -- this only controls the location where it will be written and which library will be displayed in navigation for the relevant pages. The flag --ambiguous-reexport-scorer-min-confidence allows you to set the threshold at which this warning will appear. warning: ambiguous reexport of source_server.rcon.RconSocket, canonicalization candidates: (source_server, source_server) -> source_server (confidence 0.000) from source_server.rcon.RconSocket: (file:///tmp/pub-dartlang-dartdocRDEVDE/pkg/lib/src/rcon_socket.dart:14:7) source_server: 0.2100 - name is long (+0.01000), element location shares parts with name (+0.2000) source_server: 0.2100 - name is long (+0.01000), element location shares parts with name (+0.2000) warning: ambiguous reexport of exceptions.RconError, canonicalization candidates: (source_server, source_server) -> source_server (confidence 0.000) from exceptions.RconError: (file:///tmp/pub-dartlang-dartdocRDEVDE/pkg/lib/src/exceptions.dart:1:6) source_server: 0.2100 - name is long (+0.01000), element location shares parts with name (+0.2000) source_server: 0.2100 - name is long (+0.01000), element location shares parts with name (+0.2000) warning: no canonical library found for source_server.QuerySocket.hashCode, not linking, from source_server.QuerySocket.hashCode: (file:///dart-sdk/lib/core/object.dart:94:20) warning: no canonical library found for source_server.QuerySocket.runtimeType, not linking, from source_server.QuerySocket.runtimeType: (file:///dart-sdk/lib/core/object.dart:116:21) warning: no canonical library found for source_server.QuerySocket.noSuchMethod, not linking, from source_server.QuerySocket.noSuchMethod: (file:///dart-sdk/lib/core/object.dart:111:20) warning: no canonical library found for source_server.QuerySocket.toString, not linking, from source_server.QuerySocket.toString: (file:///dart-sdk/lib/core/object.dart:99:19) warning: no canonical library found for source_server.QuerySocket.==, not linking, from source_server.QuerySocket.==: (file:///dart-sdk/lib/core/object.dart:62:26) warning: unresolved doc reference [ref link], from source_server.SourceServer.getInfo: (file:///tmp/pub-dartlang-dartdocRDEVDE/pkg/lib/source_server.dart:115:32) error: failed to write file at: source_server/source_server-library.html for symbol source_server: (file:///tmp/pub-dartlang-dartdocRDEVDE/pkg/lib/minecraft_server.dart:6:9) conflicting with file already generated by source_server: (file:///tmp/pub-dartlang-dartdocRDEVDE/pkg/lib/source_server.dart:6:9) Dartdoc generates a path and filename to write to for each symbol. source_server conflicts with another symbol in the generated path, and therefore can not be written out. Changing the name, library name, or class name (if appropriate) of one of the conflicting items can resolve the conflict. Alternatively, use the @nodoc tag in one symbol's documentation comments to hide it. warning: dartdoc generated a broken link to: source_server/QuerySocket-class.html (from index.json) warning: dartdoc generated a broken link to: source_server/QuerySocket/QuerySocket.html (from index.json) warning: dartdoc generated a broken link to: source_server/QuerySocket/address.html (from index.json) warning: dartdoc generated a broken link to: source_server/QuerySocket/close.html (from index.json) warning: dartdoc generated a broken link to: source_server/QuerySocket/connect.html (from index.json) warning: dartdoc generated a broken link to: source_server/QuerySocket/onInfo.html (from index.json) warning: dartdoc generated a broken link to: source_server/QuerySocket/onPlayers.html (from index.json) warning: dartdoc generated a broken link to: source_server/QuerySocket/port.html (from index.json) warning: dartdoc generated a broken link to: source_server/QuerySocket/updateInfo.html (from index.json) warning: dartdoc generated a broken link to: source_server/QuerySocket/updatePlayers.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer-class.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/SourceServer.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/address.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/close.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/connect.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/getInfo.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/getPlayers.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/getStatus.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/password.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/port.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/query.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/rcon.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/rconAuthenticate.html (from index.json) warning: dartdoc generated a broken link to: source_server/SourceServer/send.html (from index.json) found 33 warnings and 1 error Unhandled exception: dartdoc encountered 1 errors while processing. #0 Dartdoc.generateDocs (package:dartdoc/dartdoc.dart:202:7)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
logging ^0.11.3+2 0.11.4
pedantic ^1.5.0 1.9.0