Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

new hunt server skeleton in RUBY

  • Loading branch information...
commit 201edea032d61212151f4182950145c3e762e31d 1 parent 2ff2bba
Sean Moon authored

Showing 1 changed file with 56 additions and 0 deletions. Show diff stats Hide diff stats

  1. +56 0 huntd.rb
56 huntd.rb
... ... @@ -0,0 +1,56 @@
  1 +#!/usr/bin/env ruby
  2 +
  3 +require 'socket'
  4 +
  5 +class HuntServer
  6 +
  7 + def initialize(port)
  8 + @port = port
  9 + @clients = []
  10 + end
  11 +
  12 + def generate_map
  13 + end
  14 +
  15 + def send_map(clientaddr)
  16 + map = generate_map
  17 + #TODO: writeme
  18 + end
  19 +
  20 + def getclientaddr(packet)
  21 + #TODO: writeme
  22 + "127.0.0.1"
  23 + end
  24 +
  25 + def process(packet)
  26 +
  27 + # parse packet
  28 + cmd = packet[0]
  29 + clientaddr = getclientaddr(packet)
  30 +
  31 + # do something with the command
  32 + case cmd
  33 + when "STARTGAME"
  34 + puts "Registering a new client @ #{clientaddr}"
  35 + @clients.push(clientaddr)
  36 + when "GETMAP"
  37 + puts "Sending a map to #{clientaddr}"
  38 + send_map(clientaddr)
  39 + else
  40 + puts "Unknown command #{cmd}"
  41 + end
  42 + end
  43 +
  44 + def start
  45 + @socket = UDPSocket.new
  46 + @socket.bind('localhost', @port)
  47 + while true
  48 + packet = @socket.recvfrom(1024) # max bytes to recieve
  49 + self.process(packet)
  50 + end
  51 + end
  52 +end
  53 +
  54 +server = HuntServer.new(31337)
  55 +server.start
  56 +

0 comments on commit 201edea

Please sign in to comment.
Something went wrong with that request. Please try again.