#!/usr/bin/ruby # Stockage/update de vue # Licence GPL - 2007 - par tyrollus 72681 (Yoann Guillot) def parsehttp(s, sep='&') s.to_s.split(sep).inject({}) { |h, a| k, v = a.split('=', 2).map { |s| s.gsub('+', ' ').gsub(/%(..)/) { $1.hex.chr } } h.update k => v } end def htmlesc(s) s.gsub('<', '<').gsub('>', '>').gsub('"', '"') end if ARGV.empty? str = $stdin.read postdata = parsehttp str else postdata = {'vue' => File.read(ARGV.first)} end if not vue = postdata['vue'] puts "location: ../jjvue.html\r\n\r\n" exit end XMIN = -600 XMAX = 600 YMIN = -600 YMAX = 600 NOMS = {} IO.foreach(File.join(File.dirname(__FILE__), '../demange/.mh_cache/file_Trolls2')) { |l| mat, nom, foo = l.split(';') NOMS[mat.to_i] = nom } # parse la vue vue_parsed = {} # id => [x, y, z] vue_view = {} # y => x => n => mat vue_history = {} # id => [date, x, y, z], ...] cat = :trolls vue.each_line { |l| case l when /^\s*Monstres\s/ cat = :monstres when /^\s*TROLLS\s/ cat = :trolls when /^\s*TR.*SORS\s/ break when /^\s*#DEBUT TROLLS/ cat = :sp_trolls when /^\s*#DEBUT MONSTRES/ cat = :sp_monstres when /^\s*#FIN MONSTRES/ break end case cat when :monstres # dist mat level(mz) nom x y z if l =~ /^\s*\d+\s+(\d+)\s+(?:-|\d+\s+)?(.*\])\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)/ mat, nom, x, y, z = $1.to_i, $2, $3.to_i, $4.to_i, $5.to_i NOMS[mat] = nom vue_parsed[mat] = [x, y, z] if not NOMS[mat] File.open(__FILE__, 'a') { |ffdd| ffdd.puts "#{mat} #{nom}" } end end when :trolls # dist mat nom lvl? race guilde x y z # if l =~ /^\s*\d+\s+(\d+)\s+(.*)\s+(?:-|\d+)?\s+(?:Durakuir|Kastar|Skrim|Tomawak)\s+.*\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)/ if l =~ /^\s*\d+\s+(\d+)\s+(.*)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)/ mat, nom, x, y, z = $1.to_i, $2, $3.to_i, $4.to_i, $5.to_i NOMS[mat] = nom vue_parsed[mat] = [x, y, z] end when :sp_monstres if l =~ /^\s*(\d+);(.*);(-?\d+);(-?\d+);(-?\d+)/ mat, nom, x, y, z = $1.to_i, $2, $3.to_i, $4.to_i, $5.to_i NOMS[mat] = nom vue_parsed[mat] = [x, y, z] end when :sp_trolls if l =~ /^\s*(\d+);(-?\d+);(-?\d+);(-?\d+)/ mat, x, y, z = $1.to_i, $2.to_i, $3.to_i, $4.to_i vue_parsed[mat] = [x, y, z] end end } # prend la main sur la DB if false fdlock = nil starttime = Time.now loop do break if (fdlock = File.open('../vue.lock', 'w')).flock(File::LOCK_EX | File::LOCK_NB) == 0 fdlock.close if Time.now - starttime > 5 # timeout.. puts "content-type: text/html\r\n" puts "Refresh: 10; url=../jjvue.html\r\n" puts "\r\n" puts "
La db est occupee... reessayez plus tard !
la vue
Y \\ X | " + (xs.min..xs.max).map { |x| "#{x} | " }.join + "
#{y} | " if vue_view.keys.find { |k| k[1] == y } (xs.min..xs.max).each { |x| fd.print ""
curz = nil
fd.print vue_view[[x, y]].to_a.sort.reverse.map { |z, mat|
" #{z}: " + disp_mat(mat) if z != 0
}.compact.join(' ') fd.puts " | "
}
end
fd.puts "
Y \\ X | " + (xs.min..xs.max).map { |x| "#{x} | " }.join + "
#{y} | " if vue_view.keys.find { |k| k[1] == y } (xs.min..xs.max).each { |x| fd.print ""
curz = nil
fd.print vue_view[[x, y]].to_a.sort.reverse.map { |z, mat|
disp_mat(mat) if z == 0
}.compact.join(' ') fd.puts " | "
}
end
fd.puts "