module MimudServer # The following is a list of commands, it is pretty simple # right now with no allowance for level requirements. @@command_table['chat'] = :cmd_chat @@command_table['who'] = :cmd_who @@command_table['quit'] = :cmd_quit # Adding a command is pretty straight forward. All you do # is a define a new method, I use cmd_* just because it's # easy to understand, but you may use any method naming # scheme you like. The scope of a command is inside a socket # which has a @player object attached to it. If you want to # access another player from inside a command you will have # to write some methods to locate the player by name or socket # and bring it back in. Once you have written the method for # your new command, just add it into the command_table. It # is just a hash and the key is the text that should be recognized # as a command, the value is a symbol with the same name as your # method. def cmd_chat(args) send_to_player("&cYou &wchat&c, '&w#{args}&c'.") send_to_all_but("&c#{@player.name} &wchats&c, '&w#{args}&c'.") end def cmd_who(args) buf = '' buf << "====Players================\r\n" @@client_list.each do |c| player = c.get_player next unless player.level == 0 buf << "#{player.name} the #{player.title}\r\n" end buf << "\r\n" buf << "====Gods===================\r\n" @@client_list.each do |c| player = c.get_player next unless player.level == 1 buf << "#{player.name} the God of #{player.title}\r\n" end buf << "\r\n" buf << "====Admin==================\r\n" @@client_list.each do |c| player = c.get_player next unless player.level == 2 buf << "#{player.name} the Administrator\r\n" end send_to_player(buf) end def cmd_quit(args) send_to_player("Goodbye!") send_to_all_but("#{@player.name} has quit.") close_connection end end