Class: MudServer
- Inherits:
-
Object
- Object
- MudServer
- Defined in:
- lib/mud_server.rb
Overview
The server class creates a single instance of a mud server.
Defined Under Namespace
Classes: AbstractController, DefaultController, Session
Instance Attribute Summary collapse
-
#connection_acceptor ⇒ Object
Returns the value of attribute connection_acceptor.
-
#connection_pool ⇒ Object
Returns the value of attribute connection_pool.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#port ⇒ Object
Returns the value of attribute port.
-
#tcp_socket ⇒ Object
Returns the value of attribute tcp_socket.
Instance Method Summary collapse
- #bootstrap_settings(ip, port, environment) ⇒ Object
-
#initialize(ip = "0.0.0.0", port = 4000, environment = 'development') ⇒ MudServer
constructor
A new instance of MudServer.
- #start ⇒ Object
-
#stop ⇒ Object
You probably won’t need this one in production, but it’s a must for testing.
Constructor Details
#initialize(ip = "0.0.0.0", port = 4000, environment = 'development') ⇒ MudServer
Returns a new instance of MudServer.
7 8 9 |
# File 'lib/mud_server.rb', line 7 def initialize(ip = "0.0.0.0", port = 4000, environment = 'development') bootstrap_settings(ip, port, environment) end |
Instance Attribute Details
#connection_acceptor ⇒ Object
Returns the value of attribute connection_acceptor.
4 5 6 |
# File 'lib/mud_server.rb', line 4 def connection_acceptor @connection_acceptor end |
#connection_pool ⇒ Object
Returns the value of attribute connection_pool.
4 5 6 |
# File 'lib/mud_server.rb', line 4 def connection_pool @connection_pool end |
#environment ⇒ Object
Returns the value of attribute environment.
4 5 6 |
# File 'lib/mud_server.rb', line 4 def environment @environment end |
#ip ⇒ Object
Returns the value of attribute ip.
4 5 6 |
# File 'lib/mud_server.rb', line 4 def ip @ip end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/mud_server.rb', line 4 def port @port end |
#tcp_socket ⇒ Object
Returns the value of attribute tcp_socket.
4 5 6 |
# File 'lib/mud_server.rb', line 4 def tcp_socket @tcp_socket end |
Instance Method Details
#bootstrap_settings(ip, port, environment) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/mud_server.rb', line 11 def bootstrap_settings(ip, port, environment) @port = port @ip = ip @environment = environment @connection_pool = [] # This is where we keep reference to all game # connections end |
#start ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/mud_server.rb', line 19 def start @tcp_socket = TCPServer.new @ip , @port @connection_acceptor = Thread.new do while connection = @tcp_socket.accept @connection_pool << MudServer::Session.new(connection) end end return true end |
#stop ⇒ Object
You probably won’t need this one in production, but it’s a must for testing.
30 31 32 33 34 35 |
# File 'lib/mud_server.rb', line 30 def stop @tcp_socket.close @connection_acceptor.kill @connection_acceptor = nil return true end |