-
Notifications
You must be signed in to change notification settings - Fork 5
/
ffnodegame.rb
executable file
·62 lines (52 loc) · 1.19 KB
/
ffnodegame.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
# encoding: UTF-8
#Freifunk node highscore game
#Copyright (C) 2012 Anton Pirogov
#Licensed under The GPLv3
require 'json'
require 'sinatra'
require './settings'
require './scores'
log "---- APPLICATION STARTING ----"
get '/update' do
if params['pw'] == PWD
Scores.update
'Scores updated!'
else
'Wrong password!'
end
end
get '/reset' do
if params['pw'] == PWD
if Scores.reset && Scores.update
'Scores reset!'
else
'Reset failed!'
end
else
'Wrong password!'
end
end
#----
get '/' do
log 'Viewed by '+request.ip
@days = params.include?('days') ? params['days'].to_i : 1
@days = 1 if @days <= 0
@offset = params.include?('offset') ? params['offset'].to_i : 0
@offset = 0 if @offset < 0
@lastupdate = Scores.last_update.strftime('am %d.%m.%Y um %H:%M')
@scores = Scores.generate @days, @offset
erb :index
end
helpers do
def scores_for(days, offset)
if days == 1
return 'heute' if offset == 0
return 'gestern' if offset == 1
return 'vorgestern' if offset == 2
end
return 'letzte Woche' if offset == 7 && days == 7
return "#{days} Tage" if offset == 0
return "(benutzerdefiniert)"
end
end