|
|
@@ -1,7 +1,7 @@
|
|
|
require 'socket'
|
|
|
require 'yaml/store'
|
|
|
|
|
|
-config = YAML::Store.new "config.store"
|
|
|
+config = YAML::Store.new "../config.store"
|
|
|
config.transaction do
|
|
|
$name = config["name"]
|
|
|
$password = config["password"]
|
|
|
@@ -12,38 +12,59 @@ end
|
|
|
|
|
|
def connect(host,port)
|
|
|
$sock = TCPSocket.new(host,port)
|
|
|
- msg = sock.read()
|
|
|
- puts msg
|
|
|
- parse(msg)
|
|
|
+ #join($name,$password)
|
|
|
+ while line = $sock.gets
|
|
|
+ puts line
|
|
|
+ parse(line)
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
def join(name,password)
|
|
|
-
|
|
|
+ send("join",name,password)
|
|
|
end
|
|
|
|
|
|
def parse(message)
|
|
|
parts = message.split('|')
|
|
|
case parts[0]
|
|
|
when "error"
|
|
|
+ puts "error occured " + parts[1]
|
|
|
|
|
|
when "game"
|
|
|
+ $gameW = parts[1]
|
|
|
+ $gameH = parts[2]
|
|
|
+ $id = parts[3]
|
|
|
+
|
|
|
when "pos"
|
|
|
when "tick"
|
|
|
+ decide()
|
|
|
when "die"
|
|
|
+
|
|
|
when "message"
|
|
|
|
|
|
when "win", "lose"
|
|
|
-
|
|
|
-
|
|
|
+ reset()
|
|
|
+ when "motd"
|
|
|
+ join($name,$password)
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
def decide()
|
|
|
-
|
|
|
+ send("up")
|
|
|
end
|
|
|
|
|
|
def chat(message)
|
|
|
|
|
|
end
|
|
|
|
|
|
+def reset()
|
|
|
+end
|
|
|
+
|
|
|
+def send(msg,*param)
|
|
|
+
|
|
|
+ snd = "#{msg}|#{param.join("|")}"
|
|
|
+ $sock.puts(snd)
|
|
|
+ puts(snd)
|
|
|
+end
|
|
|
+
|
|
|
connect($host,$port)
|
|
|
|