Module: SteamSocket
- Included in:
- GoldSrcSocket, MasterServerSocket, RCONSocket, SourceSocket
- Defined in:
- lib/steam/sockets/steam_socket.rb
Overview
Defines common methods for sockets used to connect to game and master servers.
Constant Summary collapse
- @@timeout =
1000
Class Method Summary collapse
-
.timeout=(timeout) ⇒ Object
Sets the timeout for socket operations.
Instance Method Summary collapse
- #finalize ⇒ Object
- #initialize(*args) ⇒ Object
- #receive_packet(buffer_length = 0) ⇒ Object
-
#reply ⇒ Object
Abstract
replymethod. - #send(data_packet) ⇒ Object
Class Method Details
.timeout=(timeout) ⇒ Object
Sets the timeout for socket operations. This usually only affects timeouts, i.e. when a server does not respond in time.
Due to the server-side implementation of the RCON protocol, each RCON request will also wait this amount of time after execution. So if you need RCON requests to execute fast, you should set this to a adequatly low value.
timeout The amount of milliseconds before a request times out
26 27 28 |
# File 'lib/steam/sockets/steam_socket.rb', line 26 def self.timeout=(timeout) @@timeout = timeout end |
Instance Method Details
#finalize ⇒ Object
65 66 67 |
# File 'lib/steam/sockets/steam_socket.rb', line 65 def finalize @channel.close end |
#initialize(*args) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/steam/sockets/steam_socket.rb', line 30 def initialize(*args) @channel = DatagramChannel.open @channel.connect(*args) @channel.configure_blocking false @remote_socket = Socket.getaddrinfo args[0].to_s, args[1] end |
#receive_packet(buffer_length = 0) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/steam/sockets/steam_socket.rb', line 43 def receive_packet(buffer_length = 0) raise TimeoutException if select([@channel.socket], nil, nil, @@timeout / 1000).nil? if buffer_length == 0 @buffer.rewind else @buffer = StringIO.allocate buffer_length end bytes_read = @channel.read @buffer @buffer.rewind bytes_read end |
#reply ⇒ Object
Abstract reply method
39 40 41 |
# File 'lib/steam/sockets/steam_socket.rb', line 39 def reply raise NotImplementedError end |
#send(data_packet) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/steam/sockets/steam_socket.rb', line 58 def send(data_packet) puts "Sending data packet of type \"#{data_packet.class.to_s}\"." if $DEBUG @buffer = StringIO.new data_packet.to_s @channel.write @buffer end |