RMuh
NOTICE: UnitedOperations has dropped support for ArmA 2. So as of now, this
project should be considered no longer maintained. Due to this tests are also
failing, so Travis CI has been disabled by renaming the .travis.yml
file to
.travis.yml.disabled
RMuh, a play on the name ArmA (Armed Assault), is a Ruby library for interacting with ArmA 2 servers (specifically tested against Operation Arrowhead servers).
LICENSE
RMuh is released under the
The MIT License. The full text of the
license can be found in the LICENSE
file. The summary can be found
here courtest of
tldrlegal.
In short, MIT is a permissive license and means you can pretty much do what you want with this code as long as the original copyright is included.
CONTRIBUTING
I know different communities may have slightly different RPT/Server log files. Want to contribute changes/additions to the project? Just for the project to your own repo, make your changes and write corresponding RSpec tests, and then submit a PR.
INSTALLATION
This is packaged on the RubyGems site and can be
installed via the gem
command:
$ gem install rmuh
If you have a Gemfile
or a Gemspec
file for your project you can add
these entires to these files and use bundle install
to install the gem:
Gemfile:
gem 'rmuh'
Gemspec:
Gem::Specification.new do |g|
# ...
g.add_runtime_dependency 'rmuh'
# ...
end
Note: If you want to do version pinning within your Gemfile
or Gemspec
file visit RubyGems :: RMuh to see the
specific versions available.
USAGE
This is just an overview of how to use the specific features of RMuh
. For
full documentation please view the README.md
files within the lib
dir,
look in the examples
dir, or visit the docs on
RubyDoc.
So here are some examples of how to use the different classes.
Log Fetching
There is a built in log fetcher that uses httparty
to pull the log files.
Here is an example of how to just fetch the full log and print it:
require 'rmuh/rpt/log/fetch'
URL = 'http://arma2.unitedoperations.net/dump/SRV1/SRV1_RPT.txt'
f = RMuh::RPT::Log::Fetch.new(URL)
puts f.log
In this case f.log
returns an Array
object which will be used by the
parsers to parse the log files.
If you want to specify a byte range:
f = RMuh::RPT::Log::Fetch.new(URL, byte_start: 100, byte_end: 200)
This can be used to pull the log in smaller sizes if you are doing incremental updates. To compound the byte range ability, you can get the log file size as well as update the byte range after initializing the object:
f.size # prints Fixnum
f.byte_start = 10 # Sets the first byte to 10
f.byte_end = 40 # Sets the last byte to 40
Log Parsing
Included with this module is a default log parser. The default parser does nothing but return each line as a Hash within an Array. There is no metadata extracted, it's a literal copy and paste of the provided log line. This default parser is primarily used as an example class to be used for subclassing of your own parser.
require 'rmuh/rpt/log/fetch'
require 'rmuh/rpt/parsers/base'
URL = 'http://arma2.unitedoperations.net/dump/SRV1/SRV1_RPT.txt'
f = RMuh::RPT::Log::Fetch.new(URL)
p = RMuh::RPT::Log::Parsers::Base.new
l = p.parse(f.log)
At this specific moment l
would contain an Array of Hashes corresponding to
the log lines.
Log Formatting
There are also built-in formatters that allow you to dump the events to a format similar to the original log lines. They were changed a bit to be more readable and relevant.
The formatters just take an event and return a String. Assuming event
is a
single valid event here:
require 'rmuh'
puts RMuh::PRT::Log::Formatters::UnitedOperationsRPT.format(event)
Server Stats
The RMuh
gem also wraps the
GamespyQuery Rubygem for pulling
live statistics from the server. This includes current map, mission, play list,
and others. Deep down this just uses the GameSpy protocol to get the
information directly from the server.
Future Functionality Note
As of ArmA 2: Operation Arrowhead version 1.63
this is no longer
working. This is due to GameSpy being shut down, and removed from ArmA 2 by
Bohemia Interactive as part of
ArmA 2:OA Update 1.63.
Beyond the Bohemia Interactive server list
there are no known alternatives to getting this information at the time of writing.
well fuck...
So, if you have an A2:OA server older than 1.63
(e.g., version 1.62
),
here is a quick overview of how to use this functionality:
require 'rmuh/serverstats/base'
UO_IP = '70.42.74.59'
s = RMuh::ServerStats::Base.new(host: UO_IP)
puts s.stats
By default the ServerStats::Base
class caches the information so you need to
explicitly update the cache. This is not done automatically as it is a blocking
operation, this allow you to block somewhere other than where you instantiate
the object.
If you want to avoid using the cache:
s = RMuh::ServerStats::Base.new(host: UO_IP, cache: false)
If you want to be able to pull each part of the returned data set using
dot-notation, you can use the Advanced
class:
require 'rmuh/serverstats/base'
s = RMuh::ServerStats::Advanced.new(host: UO_IP)
puts s.players
In this case, players
is an Array. If you specify a key that doesn't exist
you will get a NoMethodError exception.
SUPPORT
Having some problems understanding something? Just open an issue and I'll get back to you as soon as I can.