Giter VIP home page Giter VIP logo

mud's Introduction

Ruby Mud

A microframework for building Telnet-based text adventure games using Ruby. Started as a curiosity, now it's an actual ruby gem.

It's got:

  • Sockets
  • Threads
  • ?????
  • 0 external runtime dependencies (pure Ruby, yo.)

Installation

  • gem install ruby-mud
  • require 'ruby_mud'
  • Follow the tutorial.

A Word of Caution Before Starting...

Telnet is insecure by default. All network traffic to the game is sent in the clear. Advise users against using real passwords when running this codebase. This ain't SSH!

Quick Tutorial

require 'ruby_mud'

# Controllers define the action for a menu / sub-game. Eg: Login screen, 
# main game, map screen, etc.. By default, the server will start new connections
# in MudServer::DefaultController.
class MudServer::DefaultController
  # on_start will always be called when the user enters a controller.
  # You don't need to use it, but it's there.
  def on_start
    # Send messages via send_text.
    send_text "Welcome! Here's a list of available commands"
    send_text "TIME  : See the current time."
    send_text "SAY   : Talk."
    send_text "SECRET: Go somewhere super secret."
    send_text "QUIT  : Disconnect from the server."
  end
  # For security, you must explicitly whitelist any commands that you want to
  # give players access to. Otherwise they will not be accessible by users.
  def allowed_methods
    super + ['time', 'secret', 'say'] # Quit is available by default via `super`
                                      # No need to implement it yourself.
  end
  # User input after a command is provided via `params`.
  def say
   send_text "You just said: #{params}"
  end

  def time
    send_text "The time is now #{Time.now}"
  end
  #Transfer people to a different menu / area using `transfer_to`
  def secret
    transfer_to PokerRoom # Define the PokerRoom as a controller.
  end
end

# An example of another controller / sub-game / menu.
class PokerRoom < MudServer::AbstractController # controllers are inherited.
  def on_start
    send_text 'You found the secret poker room!'
    send_text 'Type DEAL to get a hand of cards.'
  end

  def allowed_methods
    ['quit', 'deal']
  end

  def deal
    send_text 'Did I say poker? I meant dice.'
    send_text "You rolled a #{rand(5)+1}."
  end

end

server = MudServer.new '0.0.0.0', '4321' # Run server on all IPs on port 4321.
                                         # Defaults to 0.0.0.0:4000 if none set.
server.start # Accept connections

puts 'Press enter to exit.'

server.stop if gets.chomp

mud's People

Contributors

rickcarlino avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.