six-updater-web 0.13.6 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'rake/testtask'
7
7
 
8
8
  spec = Gem::Specification.new do |s|
9
9
  s.name = 'six-updater-web'
10
- s.version = '0.13.6'
10
+ s.version = '0.14.1'
11
11
  s.has_rdoc = false
12
12
  #s.extra_rdoc_files = ['README', 'LICENSE']
13
13
  s.summary = 'Your summary here'
@@ -10,38 +10,35 @@ class LogviewsController < ApplicationController
10
10
  end
11
11
 
12
12
  def upd
13
- a = false
14
- session[:logentry] = 0 if session[:logentry]
15
-
16
-
17
- cached = Rails.cache.read('logs_last')
18
- s = 0
19
- if cached
20
- s = cached.to_i
21
- else
22
- #begin
23
- s = Log.find(:last)
24
- if s
25
- s = s.id
26
- end
27
- #rescue
28
- #end
29
- Rails.cache.write('logs_last', s)
30
- end
31
-
32
- logger.info "cached/new entry #{s}"
13
+ s = Log.find(:last, :select => "id")
14
+ s = s.id if s
15
+ logger.debug "Latest entry: #{s}"
16
+
17
+ #session[:logentry] = 0 unless session[:logentry]
18
+ # Cache'll loop :D
19
+ # cached = Rails.cache.read('logs_last')
20
+ # if cached
21
+ # s = cached.to_i
22
+ # logger.debug "cached entry #{s}"
23
+ # else
24
+ # Rails.cache.write('logs_last', s)
25
+ # end
33
26
 
27
+ a = false
34
28
  if session[:logentry]
35
- logger.info "session entry #{session[:logentry]}"
36
- if s != session[:logentry]
29
+ logger.debug "Session entry #{session[:logentry]}"
30
+ if s != session[:logentry]
37
31
  session[:logentry] = s
32
+ logger.debug "New session entry #{session[:logentry]}"
38
33
  a = true
39
34
  end
40
35
  else
41
36
  session[:logentry] = s
37
+ logger.debug "New session entry #{session[:logentry]}"
42
38
  a = true
43
39
  end
44
40
 
41
+ # TODO: Only refresh activescaffold instead?
45
42
  render :nothing => true unless a
46
43
  end
47
44
 
@@ -19,7 +19,8 @@ class MainController < ApplicationController
19
19
  if ok
20
20
  @msg << "Auto Synchronize: " + begin
21
21
  @system_setting.sync
22
- rescue
22
+ rescue => e
23
+ logger.debug "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}"
23
24
  "FAILURE: #{$!}"
24
25
  end + "<br />"
25
26
  end
@@ -108,7 +108,7 @@ class Mod < ActiveRecord::Base
108
108
  m = Mod.new :name => dir
109
109
  m.save
110
110
  end
111
- logger.info "#{m.inspect}"
111
+ logger.debug "#{m.inspect}"
112
112
  end
113
113
  end
114
114
  end
@@ -62,6 +62,7 @@ class Queryserver < ActiveRecord::Base
62
62
  end
63
63
 
64
64
  def convert(data)
65
+ r = Hash.new
65
66
  data.each_pair do |k, v|
66
67
  if !k.is_a? String
67
68
  logger.info "Key that is no string: #{k} #{v}!"
@@ -71,10 +72,15 @@ class Queryserver < ActiveRecord::Base
71
72
  logger.info "Key that is empty: #{k} #{v}!"
72
73
  next
73
74
  end
74
- self[k] = v if FIELDS.include?(k.to_sym)
75
- self[k] = v.split(";").reject{|e| e.empty?} if FIELDS2.include?(k.to_sym)
75
+ if FIELDS.include?(k.to_sym)
76
+ r[k] = v
77
+ end
78
+ if FIELDS2.include?(k.to_sym)
79
+ r[k] = v.split(";").reject{|e| e.empty?}
80
+ end
76
81
  end
77
82
  end
83
+ r
78
84
  end
79
85
 
80
86
 
@@ -137,31 +143,21 @@ class Queryserver < ActiveRecord::Base
137
143
  end
138
144
 
139
145
  def self.import(e)
146
+ return nil unless e[:gamedata]
140
147
  s = self.find_by_ip_and_port(e[:ip], e[:port])
141
- if e[:gamedata]
142
- unless s
143
- s = self.new
144
- s.ip = e[:ip]
145
- s.port = e[:port]
146
- end
147
- #oldmod = s.mod ? s.mod.clone : nil
148
- s.name = e[:gamedata]["hostname"].split(",").join(", ") if e[:gamedata]["hostname"]
149
- #s.content = e[:gamedata]
150
- s.convert(e[:gamedata])
151
-
152
- if s.mod
153
- # TODO: Can't use the unless condition this until we can measure if there are any new Mod records too
154
- s.mods = s.mods_fetch2 # unless s.mod == oldmod
155
- end
156
- s.save
157
- else
158
- if s
159
- s.failures = 0 unless s.failures
160
- s.failures += 1
161
- s.save
162
- end
163
- # TODO: If more than 5 subsequent failures, only try em once an hour?
148
+ unless s
149
+ s = self.new(:ip => e[:ip], :port => e[:port])
150
+ #s.name = e[:gamedata]["hostname"].split(",").join(", ") if e[:gamedata]["hostname"]
151
+ # s.save # only when using 'update later'
164
152
  end
165
- s
153
+ s.name = e[:gamedata]["hostname"].split(",").join(", ") if e[:gamedata]["hostname"]
154
+ r = s.convert(e[:gamedata])
155
+ s.attributes = r
156
+
157
+ if s.mod
158
+ # TODO: Can't use the unless condition this until we can measure if there are any new Mod records too
159
+ s.mods = s.mods_fetch2 # unless s.mod == oldmod
160
+ end
161
+ return [s, r]
166
162
  end
167
163
  end
@@ -42,8 +42,8 @@ class SystemSetting < ActiveRecord::Base
42
42
  end
43
43
  rescue Timeout::Error
44
44
  logger.info "TIMEOUT while trying to synchronize!"
45
- rescue
46
- logger.info "ERROR: #{$!}"
45
+ rescue => e
46
+ logger.info "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}"
47
47
  end
48
48
  l
49
49
  end
@@ -41,8 +41,8 @@ begin
41
41
  ENV["OS_VERSION"] = ENV["VERSION"]
42
42
  ENV["VERSION"] = nil
43
43
  end
44
- rescue
45
- puts "ERROR: #{$!}"
44
+ rescue => e
45
+ puts "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}"
46
46
  end
47
47
 
48
48
  ENV["RAILS_ENV"] = "production"
@@ -1,28 +1,28 @@
1
- # Settings specified here will take precedence over those in config/environment.rb
2
-
3
- # The production environment is meant for finished, "live" apps.
4
- # Code is not reloaded between requests
5
- config.cache_classes = true
6
-
7
- # Full error reports are disabled and caching is turned on
8
- config.action_controller.consider_all_requests_local = false
9
- config.action_controller.perform_caching = true
10
- config.action_view.cache_template_loading = true
11
-
12
- # See everything in the log (default is :info)
13
- # config.log_level = :debug
14
-
15
- # Use a different logger for distributed setups
16
- # config.logger = SyslogLogger.new
17
-
18
- # Use a different cache store in production
19
- # config.cache_store = :mem_cache_store
20
-
21
- # Enable serving of images, stylesheets, and javascripts from an asset server
22
- # config.action_controller.asset_host = "http://assets.example.com"
23
-
24
- # Disable delivery errors, bad email addresses will be ignored
25
- # config.action_mailer.raise_delivery_errors = false
26
-
27
- # Enable threaded mode
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The production environment is meant for finished, "live" apps.
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.action_controller.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+ config.action_view.cache_template_loading = true
11
+
12
+ # See everything in the log (default is :info)
13
+ # config.log_level = :debug
14
+
15
+ # Use a different logger for distributed setups
16
+ # config.logger = SyslogLogger.new
17
+
18
+ # Use a different cache store in production
19
+ # config.cache_store = :mem_cache_store
20
+
21
+ # Enable serving of images, stylesheets, and javascripts from an asset server
22
+ # config.action_controller.asset_host = "http://assets.example.com"
23
+
24
+ # Disable delivery errors, bad email addresses will be ignored
25
+ # config.action_mailer.raise_delivery_errors = false
26
+
27
+ # Enable threaded mode
28
28
  # config.threadsafe!
@@ -19,7 +19,7 @@ case RUBY_VERSION
19
19
  end
20
20
 
21
21
  module SixUpdaterWeb
22
- VERSION = "0.13.6"
22
+ VERSION = "0.14.1"
23
23
  COMPONENT = "six-updater-web"
24
24
 
25
25
  DEFAULT_IP = "127.0.0.1" unless defined?(DEFAULT_IP)
@@ -120,6 +120,11 @@ module SixUpdaterWeb
120
120
  ActiveRecord::Base.logger
121
121
  end
122
122
 
123
+ def stamp(time)
124
+ (Time.now - time).to_s[/(.*\..?.?.?)/]
125
+ $1
126
+ end
127
+
123
128
  def initialize(config)
124
129
  if defined?(OLDLOCATION)
125
130
  config.log_path = File.join(DATA_PATH, 'logs', 'six-updater-web.log')
@@ -154,8 +159,8 @@ module SixUpdaterWeb
154
159
  #begin
155
160
  shell = WIN32OLE.new('Shell.Application')
156
161
  shell.ShellExecute(file_to_use, arguments, directory, operation, show)
157
- #rescue
158
- #logger.warn "Unable to open browser: #{$!}"
162
+ #rescue => e
163
+ #logger.warn "Unable to open browser: ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}"
159
164
  #end
160
165
  =end
161
166
  end
@@ -7,26 +7,74 @@ namespace :sync do
7
7
  task :gamespy => :environment do
8
8
  puts "Fetching server info..."
9
9
  geo = ENV['NOGEO'] ? "" : nil
10
+ #geo = ""
10
11
  puts "Pings and Countries: #{geo.nil?}"
11
- puts
12
+ puts ""
12
13
 
13
14
  q = Six::Query::GamespyMaster.new(geo)
14
15
  h = q.process
15
16
 
16
- puts
17
+ puts ""
17
18
  puts "Received #{h.size} servers"
18
19
 
19
- puts
20
+ puts ""
20
21
  puts "Updating database..."
21
22
 
23
+ i, saved = 0, 0
24
+ ids = []
25
+ #hasj = Hash.new
26
+ timestart = Time.now
22
27
  h.each_pair do |key, e|
23
- Queryserver.import(e)
28
+ i += 1
29
+ time = Time.now
30
+ r = Queryserver.import(e)
31
+ next unless r
32
+ if r[0].changed?
33
+ #hasj[r[0].id] = r[1]
34
+ saved += 1
35
+ r[0].save
36
+ else
37
+ ids << r[0].id
38
+ end
39
+ print "#{i} / #{h.keys.size}, took #{SixUpdaterWeb::stamp(time)}s\r"
40
+ end
41
+ puts "Saved: #{saved}, Unchanged: #{h.keys.size - saved}. Took: #{SixUpdaterWeb::stamp(timestart)}s"
42
+
43
+ =begin
44
+ timestart = Time.now
45
+ puts "Updating #{hasj.keys.size} records..."
46
+ begin
47
+ Queryserver.update(hasj.keys, hasj.values) unless hasj.keys.empty?
48
+ rescue => e
49
+ puts "#{e.class}: #{e.message} #{e.backtrace.join("\n")}"
50
+ sleep 3
51
+ ensure
52
+ puts "Took: #{SixUpdaterWeb::stamp(timestart)}s"
53
+ end
54
+ =end
55
+
56
+ timestart = Time.now
57
+ puts "Tagging... #{ids.size} records"
58
+ begin
59
+ Queryserver.update_all("updated_at = '#{Time.now}'", ["id in (?)",ids]) unless ids.empty?
60
+ rescue => e
61
+ puts "#{e.class}: #{e.message} #{e.backtrace.join("\n")}"
62
+ ensure
63
+ puts "Took: #{SixUpdaterWeb::stamp(timestart)}s"
24
64
  end
25
65
 
26
66
  puts "Pruning database..."
67
+ timestart = Time.now
27
68
  Queryserver.prune
69
+ puts "Took: #{SixUpdaterWeb::stamp(timestart)}s"
70
+
28
71
  puts "Cleaning database..."
72
+ timestart = Time.now
29
73
  Queryserver.clean
74
+ puts "Took: #{SixUpdaterWeb::stamp(timestart)}s"
75
+ puts ""
76
+ puts "Done!"
77
+ sleep 3
30
78
  end
31
79
 
32
80
  task :system => :environment do
@@ -67,7 +67,7 @@ module Six
67
67
  end
68
68
 
69
69
  path = "/#{self.to_s.pluralize.downcase}/exp/1.json"
70
- logger.info "Path: #{path}"
70
+ logger.debug "Path: #{path}"
71
71
  res = Six::Network::Panel.get(path)
72
72
  h = ActiveSupport::JSON.decode res.body
73
73
  k = []
@@ -96,11 +96,13 @@ module Six
96
96
  end
97
97
  end
98
98
  n = nil
99
+ previous = nil
99
100
  if h["id"]
100
101
  id = h["id"]
101
102
  h.delete "id"
102
- r = self.find(:first, :conditions => "id = \"#{id}\"")
103
+ r = self.find(id)
103
104
  if r
105
+ previous = r.inspect
104
106
  r.attributes = h
105
107
  n = r
106
108
  else
@@ -110,7 +112,8 @@ module Six
110
112
  else
111
113
  n = self.new h
112
114
  end
113
- n.save
115
+ logger.debug "#{n.class} #{n.id} #{n.changed?}: #{"#{n.inspect} - #{previous}" if n.changed?}"
116
+ n.save if n.changed?# || n.new?
114
117
  n
115
118
  end
116
119
 
@@ -58,10 +58,10 @@ module Six
58
58
  # {'login[user]'=>'admin', 'login[password]'=>'admin', 'authenticity_token' => auth, 'commit'=>'Login'})
59
59
 
60
60
  # Output on the screen -> we should get either a 302 redirect (after a successful login) or an error page
61
- logger.debug 'Code = ' + resp.code
62
- logger.debug 'Message = ' + resp.message
61
+ #logger.debug 'Code = ' + resp.code
62
+ #logger.debug 'Message = ' + resp.message
63
63
  # resp.each {|key, val| puts key + ' = ' + val}
64
- logger.debug data
64
+ #logger.debug data
65
65
  end
66
66
 
67
67
  def Panel.get(path)
@@ -94,8 +94,8 @@ module Sixsense
94
94
  else
95
95
  logger.info "WARNING: Found goldberguser by cookie, but hash mismatch!"
96
96
  end
97
- rescue
98
- logger.info "WARNING: Something went wrong during login_goldberg: #{$!}"
97
+ rescue => e
98
+ logger.info "WARNING: Something went wrong during login_goldberg: ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}"
99
99
  end
100
100
  end
101
101
 
@@ -104,8 +104,8 @@ module Sixsense
104
104
  forumuser = nil
105
105
  begin
106
106
  forumuser = Remote::Vbulletin::User.find(cookies[:bbuserid])
107
- rescue
108
- logger.info "WARNING: Something went wrong during login_vb: #{$!}"
107
+ rescue => e
108
+ logger.info "WARNING: Something went wrong during login_vb: ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}"
109
109
  end
110
110
  return unless forumuser
111
111
  if forumuser.banned?
@@ -156,8 +156,8 @@ module Sixsense
156
156
  }
157
157
  end
158
158
  end
159
- rescue
160
- logger.info "WARNING: Something went wrong during save_vb_cookie: #{$!}"
159
+ rescue => e
160
+ logger.info "WARNING: Something went wrong during save_vb_cookie: ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}"
161
161
  end
162
162
  end
163
163
  end
@@ -4,15 +4,25 @@ module Six
4
4
  PARAMS = [:hostname, :gamever, :gametype, :gamemode, :numplayers, :maxplayers, :password, :equalModRequired, :mission, :mapname,
5
5
  :mod, :signatures, :verifysignatures, :gamestate, :dedicated, :platform, :sv_battleeye, :language, :difficulty]
6
6
 
7
- LINUX, WIN = "\\\\", "\\" # TODO: Autodetect?
8
- GEOIP_PATH = File.join(RAILS_ROOT, "config")
7
+ DELIMIT = case RUBY_PLATFORM
8
+ when /-mingw32$/, /-mswin32$/
9
+ "\\"
10
+ else
11
+ "\\\\"
12
+ end
13
+ GEOIP_PATH = case RUBY_PLATFORM
14
+ when /-mingw32$/, /-mswin32$/
15
+ File.join(RAILS_ROOT, "config").gsub("/", "\\")
16
+ else
17
+ File.join(RAILS_ROOT, "config")
18
+ end
9
19
 
10
20
  def initialize(geo = nil)
11
- @list = Hash.new
12
21
  @geo = geo
13
22
  end
14
23
 
15
24
  def process
25
+ @list = Hash.new
16
26
  self.to_hash(self.read)
17
27
  end
18
28
 
@@ -23,7 +33,7 @@ module Six
23
33
  puts "Warning: GeoIP.dat database missing. Can't parse countries. #{GEOIP_PATH}"
24
34
  geo = nil
25
35
  end
26
- reply = %x[gslist -p "#{GEOIP_PATH.gsub("/", "\\")}" -n arma2pc #{geo}-X #{PARAMS.clone.map{|e| "#{WIN}#{e}"}.join("")}]
36
+ reply = %x[gslist -p "#{GEOIP_PATH}" -n arma2pc #{geo}-X #{PARAMS.clone.map{|e| "#{DELIMIT}#{e}"}.join("")}]
27
37
  reply.gsub!("\\\\\\", "") if geo
28
38
  reply.split("\n")
29
39
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 13
8
- - 6
9
- version: 0.13.6
7
+ - 14
8
+ - 1
9
+ version: 0.14.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sickboy