Commit 4eb9f0fb authored by 神楽坂玲奈's avatar 神楽坂玲奈

比赛 用户同步

parent 1d328f50
#!/usr/bin/env rake
#encoding: UTF-8
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require 'rake/dsl_definition'
require File.expand_path('../config/application', __FILE__)
MycardServerHttp::Application.load_tasks
if RUBY_PLATFORM["mswin"] or RUBY_PLATFORM["ming"]
STDOUT.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace
#STDERR.set_encoding "GBK", "UTF-8"
end
def connect_fh(db='1.accdb')
puts '连接数据库...'
require 'win32ole'
conn = WIN32OLE.new('ADODB.connection')
conn.Open('Provider = Microsoft.ACE.OlEDB.12.0;Data Source=1.accdb')
rs = WIN32OLE.new('ADODB.Recordset')
[conn, rs]
end
task :load_from_fh => :environment do
conn, rs = connect_fh
puts '读取决斗信息...'
rs.Open("select d.*, w.getcount as winner_credits, l.getcount as loser_credits
from duel d, duelcount w, duelcount l
where d.id*2-1 = w.id and d.id*2 = l.id
and d.id not in (#{Duel.all.collect{|duel|duel.id}.push(0).join(',')})", conn)
columns = [:id,:user1_id,:user2_id,:winner_id,:winreason,:replay,:user1_credits,:user2_credits]#,created_at,updated_at
values = []
while !rs.EOF
duel = [
rs.Fields["id"].value,
User.find_or_create_by_name(rs.Fields["dueluser1"].value).id,
User.find_or_create_by_name(rs.Fields["dueluser2"].value).id,
:winner_id,
rs.Fields["winreason"].value,
rs.Fields["duelname"].value,
:user1_credits,
:user2_credits#,
#time,
#time
]
if rs.Fields["winnerpos"].value == 0
duel[3] = duel[1]
duel[6] = rs.Fields["winner_credits"].value
duel[7] = rs.Fields["loser_credits"].value
else
duel[3] = duel[2]
duel[6] = rs.Fields["loser_credits"].value
duel[7] = rs.Fields["winner_credits"].value
end
puts "#{duel[0]}: #{rs.Fields["dueluser1"].value} - #{rs.Fields["dueluser2"].value}"
values << duel
rs.MoveNext
end
rs.Close
puts '导入决斗信息...'
Duel.import columns, values, :validate => false
puts '读取玩家卡组信息...'
rs.Open("select count(*) as _count from deck", conn)
count = rs.Fields["_count"].value
rs.Close
columns = [:id, :duel_id, :user_id, :card_id, :main]
values = []
rs.Open("select * from deck where id not in (#{DuelUserCard.all.collect{|duel_user_card|duel_user_card.id}.push(0).join(',')})", conn)
while !rs.EOF
duel = Duel.find_or_create_by_id(rs.Fields["duelid"].value)
card = Card.find_by_number(rs.Fields["decknumber"].value)
duel_user_card = [
rs.Fields["ID"].value,
duel.id,
:user_id,
card ? card.id : p(card = (Card.create :number => rs.Fields["decknumber"].value, :name => rs.Fields["decknumber"].value.to_s)),
rs.Fields["deckpos"].value % 2,
]
duel_user_card[2] = rs.Fields["deckpos"].value <= 2 ? duel.user1_id : duel.user2_id
values << duel_user_card
puts "(#{duel_user_card[0]}/#{count})#{duel_user_card[2] || 'unknown'} - #{card.name}"
rs.MoveNext
end
rs.Close
puts '导入玩家卡组信息...'
DuelUserCard.import columns, values, :validate => false
puts '运行完毕'
end
#"update users u, duels_users_cards duc, duels d set u.credits = SUM()"
#select
task :refresh_user_count => :environment do
count = User.maximum(:id)
User.find_each do |user|
user.update_attributes :credits => Duel.where(:user1_id => user.id).sum(:user1_credits) + Duel.where(:user2_id => user.id).sum(:user2_credits),
:win => user.wins.count,
:lost => user.losts.count
puts "(#{user.id}/#{count})#{user.name}"
end
end
task :refresh_user_pass => :environment do
require 'cgi'
require 'open-uri'
servers = Server.all
users = []
User.find_each do |user|
if user.password.nil?
print "#{user.id} #{user.name} ..无密码\n"
next
end
users << user
end
threads = []
100.times do |i|
threads << Thread.new do
while user = users.pop
out = "#{user.id} #{user.name} "
servers.each do |server|
open("http://#{server.ip}:#{server.http_port}/?pass=#{server.password}&operation=forceuserpass&username=#{CGI.escape user.name}&password=#{CGI.escape user.password}"){|f|out << f.read + " "} rescue out << $!.inspect.encode("UTF-8", :invalid => :replace, :undef => :replace)
end
print out+"\n"
end
end
end
threads.each{|thread|thread.join}
#!/usr/bin/env rake
#encoding: UTF-8
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require 'rake/dsl_definition'
require File.expand_path('../config/application', __FILE__)
MycardServerHttp::Application.load_tasks
def connect_fh(db='1.accdb')
puts '连接数据库...'
require 'win32ole'
conn = WIN32OLE.new('ADODB.connection')
conn.Open('Provider = Microsoft.ACE.OlEDB.12.0;Data Source=1.accdb')
rs = WIN32OLE.new('ADODB.Recordset')
[conn, rs]
end
task :load_from_fh => :environment do
conn, rs = connect_fh
puts '读取决斗信息...'
rs.Open("select d.*, w.getcount as winner_credits, l.getcount as loser_credits
from duel d, duelcount w, duelcount l
where d.id*2-1 = w.id and d.id*2 = l.id
and d.id not in (#{Duel.all.collect{|duel|duel.id}.push(0).join(',')})", conn)
columns = [:id,:user1_id,:user2_id,:winner_id,:winreason,:replay,:user1_credits,:user2_credits]#,created_at,updated_at
values = []
while !rs.EOF
duel = [
rs.Fields["id"].value,
User.find_or_create_by_name(rs.Fields["dueluser1"].value).id,
User.find_or_create_by_name(rs.Fields["dueluser2"].value).id,
:winner_id,
rs.Fields["winreason"].value,
rs.Fields["duelname"].value,
:user1_credits,
:user2_credits#,
#time,
#time
]
if rs.Fields["winnerpos"].value == 0
duel[3] = duel[1]
duel[6] = rs.Fields["winner_credits"].value
duel[7] = rs.Fields["loser_credits"].value
else
duel[3] = duel[2]
duel[6] = rs.Fields["loser_credits"].value
duel[7] = rs.Fields["winner_credits"].value
end
puts "#{duel[0]}: #{rs.Fields["dueluser1"].value} - #{rs.Fields["dueluser2"].value}"
values << duel
rs.MoveNext
end
rs.Close
puts '导入决斗信息...'
Duel.import columns, values, :validate => false
puts '读取玩家卡组信息...'
rs.Open("select count(*) as _count from deck", conn)
count = rs.Fields["_count"].value
rs.Close
columns = [:id, :duel_id, :user_id, :card_id, :main]
values = []
rs.Open("select * from deck where id not in (#{DuelUserCard.all.collect{|duel_user_card|duel_user_card.id}.push(0).join(',')})", conn)
while !rs.EOF
duel = Duel.find_or_create_by_id(rs.Fields["duelid"].value)
card = Card.find_by_number(rs.Fields["decknumber"].value)
duel_user_card = [
rs.Fields["ID"].value,
duel.id,
:user_id,
card ? card.id : p(card = (Card.create :number => rs.Fields["decknumber"].value, :name => rs.Fields["decknumber"].value.to_s)),
rs.Fields["deckpos"].value % 2,
]
duel_user_card[2] = rs.Fields["deckpos"].value <= 2 ? duel.user1_id : duel.user2_id
values << duel_user_card
puts "(#{duel_user_card[0]}/#{count})#{duel_user_card[2] || 'unknown'} - #{card.name}"
rs.MoveNext
end
rs.Close
puts '导入玩家卡组信息...'
DuelUserCard.import columns, values, :validate => false
puts '运行完毕'
end
#"update users u, duels_users_cards duc, duels d set u.credits = SUM()"
#select
task :refresh_user_count => :environment do
count = User.maximum(:id)
User.find_each do |user|
user.update_attributes :credits => Duel.where(:user1_id => user.id).sum(:user1_credits) + Duel.where(:user2_id => user.id).sum(:user2_credits),
:win => user.wins.count,
:lost => user.losts.count
puts "(#{user.id}/#{count})#{user.name}"
end
end
task :refresh_user_pass => :environment do
require 'cgi'
require 'open-uri'
servers = Server.all#where(:server_type => "ygopro")
users = []
User.all.each do |user|
if user.password.nil?
print "#{user.id} #{user.name} ..无密码\n"
next
end
users << user
end
threads = []
20.times do |i|
threads << Thread.new do
while user = users.pop
out = "#{user.id} #{user.name} "
servers.each do |server|
url = server.register.gsub /\{key\}|\{id\}|\{name\}|\{password\}|\{email\}/, '{key}' => URI.encode_www_form_component(server.key), '{id}' => URI.encode_www_form_component(user.id), '{name}' => URI.encode_www_form_component(user.name), '{password}' => URI.encode_www_form_component(user.password), '{email}' => URI.encode_www_form_component(user.email)
open(url){|f|out << "\t"+f.read} rescue p $!
end
print out+"\n"
end
end
end
threads.each{|thread|thread.join}
end
\ No newline at end of file
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
// Place all the styles related to the enrolls controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the referees controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
#encoding: UTF-8
class EnrollsController < ApplicationController
layout 'ygo'
# GET /enrolls
# GET /enrolls.json
def index
@enrolls = Enroll.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @enrolls }
end
end
# GET /enrolls/1
# GET /enrolls/1.json
def show
@enroll = Enroll.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @enroll }
end
end
# GET /enrolls/new
# GET /enrolls/new.json
def new
@actions = [{"YGO战网" => users_path}, "参加比赛"]
@enroll = Enroll.new
@enroll.name = @current_user.name if @current_user.id != 0
@enroll.tournament = Tournament.find params[:tournament_id] if params[:tournament_id]
respond_to do |format|
format.html # new.html.erb
format.json { render json: @enroll }
end
end
# GET /enrolls/1/edit
def edit
@enroll = Enroll.find(params[:id])
end
# POST /enrolls
# POST /enrolls.json
def create
file = params[:enroll][:deck]
params[:enroll][:deck] = nil
@enroll = Enroll.new(params[:enroll])
@enroll.score = -1
@enroll.user = @current_user
@enroll.tournament = Tournament.find params[:enroll][:tournament_id]
if @enroll.tournament.need_deck
if file
extname = File.extname file.original_filename
if [".ydk", ".txt", ".deck"].include?(extname)
@enroll.deck = Deck.parse(file.read, extname)
@enroll.deck.name = File.basename(file.original_filename, extname)
else
@enroll.errors.add(:deck, '无法识别的卡组,如果你的卡组格式正确依然报此问题,请联系zh99998@gmail.com')
end
else
@enroll.errors.add(:deck, '请上传卡组')
end
end
if @enroll.tournament.need_team and @enroll.team.blank?
@enroll.errors.add(:team, '不能为空')
end
if @enroll.tournament.need_user and @enroll.team.blank?
@enroll.errors[:base] << '只有注册用户才能参加这个比赛'
end
respond_to do |format|
if !@enroll.errors.any? and @enroll.save
format.html { redirect_to @enroll.tournament, notice: 'Enroll was successfully created.' }
format.json { render json: @enroll, status: :created, location: @enroll }
else
format.html { render action: "new" }
format.json { render json: @enroll.errors, status: :unprocessable_entity }
end
end
end
# PUT /enrolls/1
# PUT /enrolls/1.json
def update
@enroll = Enroll.find(params[:id])
@enroll.tournament = Tournament.find params[:enroll][:tournament_id]
respond_to do |format|
if @enroll.update_attributes(params[:enroll])
format.html { redirect_to @enroll, notice: 'Enroll was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @enroll.errors, status: :unprocessable_entity }
end
end
end
# DELETE /enrolls/1
# DELETE /enrolls/1.json
def destroy
@enroll = Enroll.find(params[:id])
@enroll.destroy
respond_to do |format|
format.html { redirect_to enrolls_url }
format.json { head :no_content }
end
end
end
class RefereesController < ApplicationController
layout 'ygo'
# GET /referees
# GET /referees.json
def index
@referees = Referee.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @referees }
end
end
# GET /referees/1
# GET /referees/1.json
def show
@referee = Referee.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @referee }
end
end
# GET /referees/new
# GET /referees/new.json
def new
@referee = Referee.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @referee }
end
end
# GET /referees/1/edit
def edit
@referee = Referee.find(params[:id])
end
# POST /referees
# POST /referees.json
def create
params[:referee][:user] = User.find_by_name(params[:referee][:user]) if params[:referee][:user].is_a? String
@referee = Referee.new(params[:referee])
respond_to do |format|
if @referee.save
format.html { redirect_to @referee.tournament, notice: 'Referee was successfully created.' }
format.json { render json: @referee, status: :created, location: @referee }
else
format.html { render action: "new" }
format.json { render json: @referee.errors, status: :unprocessable_entity }
end
end
end
# PUT /referees/1
# PUT /referees/1.json
def update
@referee = Referee.find(params[:id])
respond_to do |format|
if @referee.update_attributes(params[:referee])
format.html { redirect_to @referee, notice: 'Referee was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @referee.errors, status: :unprocessable_entity }
end
end
end
# DELETE /referees/1
# DELETE /referees/1.json
def destroy
@referee = Referee.find(params[:id])
@referee.destroy
respond_to do |format|
format.html { redirect_to @referee.tournament }
format.json { head :no_content }
end
end
end
......@@ -5,7 +5,7 @@ class TournamentsController < ApplicationController
# GET /tournaments.json
def index
@tournaments = Tournament.all
@actions = [{"YGO战网" => users_path}, "比赛"]
respond_to do |format|
format.html # index.html.erb
format.json { render json: @tournaments }
......@@ -26,8 +26,9 @@ class TournamentsController < ApplicationController
# GET /tournaments/new
# GET /tournaments/new.json
def new
return redirect_to(:controller => :users, :action => :login, :continue => new_tournament_path) if @current_user.id == 0
@tournament = Tournament.new
@actions = [{"YGO战网" => users_path}, "发起比赛"]
respond_to do |format|
format.html # new.html.erb
format.json { render json: @tournament }
......@@ -42,8 +43,10 @@ class TournamentsController < ApplicationController
# POST /tournaments
# POST /tournaments.json
def create
return redirect_to(login_path, continue: new_tournament_path) if @current_user.id == 0
@tournament = Tournament.new(params[:tournament])
@tournament.status = 0
@tournament.user = @current_user
respond_to do |format|
if @tournament.save
format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' }
......
......@@ -65,18 +65,12 @@ class UsersController < ApplicationController
#@user.password = params[:user][:password]
@actions = [User.human_attribute_name(:register)]
@continue = params[:continue]
@from = params[:from].to_s.to_sym
@from = params[:from]
respond_to do |format|
# open("http://ygopro-ocg.com/mycard.php?key=zh99998&username=#{CGI.escape @user.name}&password=#{CGI.escape @user.password}&email=#{CGI.escape @user.email}") do |f|
# result = f.read
# if result.to_i <= 0
# @user.errors[:base] << "发生系统错误 (#{result}) 请联系zh99998@gmail.com"
# end
# end rescue @user.errors[:base] << "发生系统错误 (#{$!.inspect}) 请联系zh99998@gmail.com"
if !@user.errors.any? and @user.save
boardcast_user(@user, :"ygopro-ocg")
remote_register(@user, @from)
session[:user_id] = @user.id
format.html { redirect_to(params[:continue].blank? ? @user : URI.escape(params[:continue]) , :notice => '注册成功') }
format.html { redirect_to(params[:continue].blank? ? @user : URI.escape(params[:continue]), :notice => '注册成功') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
......@@ -123,36 +117,34 @@ class UsersController < ApplicationController
def login
@actions = [User.human_attribute_name(:login)]
@continue = params[:continue]
return @user = User.new if params[:user].blank?
@actions = [User.human_attribute_name(:login)]
user = User.find_by_name(params[:user][:name])
if user and params[:user][:password] == user.password
name = params[:user][:name]
password = params[:user][:password]
user = User.find_by_name(name)
if user and user.password.blank? and remote_login(name, password)
#远程登录
@user = User.find_by_name(name)
@user.update_attribute(:password, password)
elsif user and user.password == password
#本地登录
@user = user
elsif user.nil? or user.password.nil?
username = params[:user][:name]
password = params[:user][:password]
Server.all.each do |server|
open("http://#{server.ip}:#{server.http_port}/?operation=passcheck&username=#{CGI.escape username}&pass=#{CGI.escape password}") do |file|
if file.read == "true"
user.password = password
@user = user
@user.save
break
end
end rescue nil
break if @user
end
end
respond_to do |format|
if @user
session[:user_id] = @user.id
@user.update_attribute(:lastloginip, request.remote_ip)
boardcast_user(@user)
remote_register(@user)
format.html { redirect_to(params[:continue].blank? ? @user : URI.escape(params[:continue]), :notice => 'Login Successfully.') }
format.json { render json: @user }
else
@user = User.new(params[:user])
format.html { render :text => 'incorrent_username_or_password' }
@user.errors[:base] << '用户名或密码错误'
format.html
format.json { head json: nil }
end
end
......@@ -167,7 +159,6 @@ class UsersController < ApplicationController
end
def theme
#p params[:theme], @site[:themes].has_key?(params[:theme])
if params[:theme].blank?
cookies[:theme] = nil
@current_user.update_attribute(:theme, nil)
......@@ -181,22 +172,24 @@ class UsersController < ApplicationController
end
end
def boardcast_user(user, from=nil)
Server.find_each do |server|
url = "http://#{server.ip}:#{server.http_port}/?pass=#{server.password}&operation=forceuserpass&username=#{CGI.escape user.name}&password=#{CGI.escape user.password}"
if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
open(url) {} rescue nil
else
Process.spawn('curl', url)
end
end
if from != :"ygopro-ocg"
url = "http://ygopro-ocg.com/mycard.php?key=zh99998&username=#{CGI.escape user.name}&password=#{CGI.escape user.password}&email=#{CGI.escape user.email}"
if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
def remote_register(user, from=nil)
Server.all.each do |server|
url = server.register.gsub /\{key\}|\{id\}|\{name\}|\{password\}|\{email\}/, '{key}' => URI.encode_www_form_component(server.key), '{id}' => URI.encode_www_form_component(user.id), '{name}' => URI.encode_www_form_component(user.name), '{password}' => URI.encode_www_form_component(user.password), '{email}' => URI.encode_www_form_component(user.email)
if from == server.name
open(url) {}
else
Process.spawn('curl', url)
Thread.new { open(url) {} }
end
end
end
def remote_login(name, password, from=nil)
servers = Server.where("login is not null")
servers = servers.where(name: from) if from
servers.each do |server|
url = server.login.gsub /\{key\}|\{name\}|\{password\}/, '{key}' => URI.encode_www_form_component(server.key), '{name}' => URI.encode_www_form_component(name), '{password}' => URI.encode_www_form_component(password)
open(url) { |f| return server if f.read == "true" }
end
nil
end
end
\ No newline at end of file
module EnrollsHelper
end
module RefereesHelper
end
class Deck < ActiveRecord::Base
#has_many :cards, :through =>
belongs_to :user
belongs_to :duel
belongs_to :library
belongs_to :origin, :polymorphic => true
has_and_belongs_to_many :cards
def self.parse(contents, extname)
side = false
card_ids = []
card_sides = []
case extname.downcase
when ".ydk"
card_numbers = []
contents.each_line do |line|
line.chomp!
next if line[0, 1] == "#"
next side = true if line == "!side"
number = line.to_i
next if number == 0
card_numbers << number
card_sides << side
end
sql = Card.where(number: card_numbers.uniq).select([:id, :number]).order(:id).group(:number).to_sql
card_number_id = {}
Deck.connection.execute(sql).each { |id, number| card_number_id[number] = id }
card_numbers.each do |number|
id = card_number_id[number]
if id.nil?
Card.create(id: number, name: number, number: number)
card_number_id[number] = number
end
card_ids << card_number_id[number]
end
when ".deck", ".txt"
card_names = []
contents.force_encoding("GBK").encode("UTF-8").each_line do |line|
line.chomp!
next side = true if line == "####"
next side = false if line == "===="
break if line == "$$$$"
line =~ /\[(.*)\]/
name = $1
card_names << name
card_sides << side
end
sql = Card.where(name: card_names.uniq).select([:id, :name]).order(:id).group(:name).to_sql
card_name_id = {}
Deck.connection.execute(sql).each { |id, name| card_name_id[name] = id }
card_names.each do |name|
card_ids << card_name_id[name]
end
end
result = Deck.create
deck_id = result.id
sql = "INSERT INTO decks_cards (deck_id, card_id, side) VALUES "
card_sides = card_sides.to_enum
card_ids.each do |card_id|
next card_sides.next if card_id.nil?
sql << "(#{deck_id}, #{card_id}, #{card_sides.next}),"
end
sql[-1, 1] = ';'
Deck.connection.execute(sql)
result
end
end
class Enroll < ActiveRecord::Base
attr_accessible :contact, :contact_type, :deck, :name, :team, :score, :tournament_id
belongs_to :tournament
belongs_to :user
has_one :deck, :as => :origin
validates :name, :presence => true
validates :contact, :presence => true
validates :contact_type, :presence => true
end
\ No newline at end of file
class Referee < ActiveRecord::Base
belongs_to :user
belongs_to :tournament
end
class Tournament < ActiveRecord::Base
attr_accessible :location, :location_type, :name, :note
attr_accessible :location, :location_type, :name, :note, :status, :report, :created_at, :need_deck, :need_team, :need_user
has_many :matches
has_many :enrolls
belongs_to :user
has_many :users, :through => :enrolls
has_many :referees
end
<%= form_for(@enroll) do |f| %>
<% if @enroll.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@enroll.errors.count, "error") %> prohibited this enroll from being saved:</h2>
<ul>
<% @enroll.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :tournament %>
<%= f.select :tournament_id, Tournament.where(:status => 1).collect { |tournament| [tournament.name, tournament.id] } %>
</div>
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<% if @enroll.tournament.need_team %>
<div class="field">
<%= f.label :team %>
<%= f.text_field :team %>
</div>
<% end %>
<div class="field">
<%= f.label :contact %>
<%= f.select :contact_type, [["QQ", "QQ"], ["邮箱", "email"]] %>
<%= f.text_field :contact %>
</div>
<% if @enroll.tournament.need_deck %>
<div class="field">
<%= f.label :deck %>
<%= f.file_field :deck %>
<br/>
比赛要求中途不得换卡组, 请在这里上传卡组
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<h1>Editing enroll</h1>
<%= render 'form' %>
<%= link_to 'Show', @enroll %> |
<%= link_to 'Back', enrolls_path %>
<h1>Listing enrolls</h1>
<table>
<tr>
<th>Tournament</th>
<th>Name</th>
<th>User</th>
<th>Contact type</th>
<th>Contact</th>
<th>Deck</th>
<th>Score</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @enrolls.each do |enroll| %>
<tr>
<td><%= enroll.tournament %></td>
<td><%= enroll.name %></td>
<td><%= enroll.user %></td>
<td><%= enroll.contact_type %></td>
<td><%= enroll.contact %></td>
<td><%= enroll.deck %></td>
<td><%= enroll.score %></td>
<td><%= link_to 'Show', enroll %></td>
<td><%= link_to 'Edit', edit_enroll_path(enroll) %></td>
<td><%= link_to 'Destroy', enroll, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Enroll', new_enroll_path %>
<h1>参加比赛</h1>
<%= render 'form' %>
<%= link_to 'Back', @enroll.tournament %>
<p id="notice"><%= notice %></p>
<p>
<b>比赛:</b>
<%=link_to @enroll.tournament.name, @enroll.tournament %>
</p>
<p>
<b>昵称:</b>
<%= @enroll.name %>
</p>
<p>
<b>联系方式:</b>
<%= @enroll.contact_type %>
<%= @enroll.contact %>
</p>
<%= link_to 'Edit', edit_enroll_path(@enroll) %> |
<%= link_to 'Back', enrolls_path %>
......@@ -12,7 +12,7 @@
<% end %>
<div class="field">
<%= f.label :player1_id %><br />
<%= f.label :player1 %><br />
<%= f.text_field :player1_id %>
</div>
<div class="field">
......@@ -20,7 +20,7 @@
<%= f.number_field :player1_score %>
</div>
<div class="field">
<%= f.label :player2_id %><br />
<%= f.label :player2 %><br />
<%= f.text_field :player2_id %>
</div>
<div class="field">
......
<%= form_for(@referee) do |f| %>
<% if @referee.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@referee.errors.count, "error") %> prohibited this referee from being saved:</h2>
<ul>
<% @referee.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :user %><br />
<%= f.text_field :user %>
</div>
<div class="field">
<%= f.label :tournament %><br />
<%= f.text_field :tournament %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<h1>Editing referee</h1>
<%= render 'form' %>
<%= link_to 'Show', @referee %> |
<%= link_to 'Back', referees_path %>
<h1>Listing referees</h1>
<table>
<tr>
<th>User</th>
<th>Tournament</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @referees.each do |referee| %>
<tr>
<td><%= referee.user %></td>
<td><%= referee.tournament %></td>
<td><%= link_to 'Show', referee %></td>
<td><%= link_to 'Edit', edit_referee_path(referee) %></td>
<td><%= link_to 'Destroy', referee, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Referee', new_referee_path %>
<h1>New referee</h1>
<%= render 'form' %>
<%= link_to 'Back', referees_path %>
<p id="notice"><%= notice %></p>
<p>
<b>User:</b>
<%= @referee.user %>
</p>
<p>
<b>Tournament:</b>
<%= @referee.tournament %>
</p>
<%= link_to 'Edit', edit_referee_path(@referee) %> |
<%= link_to 'Back', referees_path %>
<%= form_for(@tournament) do |f| %>
<% if @tournament.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tournament.errors.count, "error") %> prohibited this tournament from being saved:</h2>
<% if @tournament.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tournament.errors.count, "error") %> prohibited this tournament from being saved:</h2>
<ul>
<% @tournament.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<ul>
<% @tournament.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :location_type %><br />
<%= f.text_field :location_type %>
</div>
<div class="field">
<%= f.label :location %><br />
<%= f.text_field :location %>
</div>
<div class="field">
<%= f.label :note %><br />
<%= f.text_area :note %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<div class="field">
<%= f.label :name %>
<br/>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :location %>
<br/>
<%= f.select :location_type, [["QQ群", "qun"]] %>
<%= f.text_field :location %>
</div>
<div class="field">
<%= f.label :note %>
<br/>
<%= f.text_area :note %>
</div>
<div class="field">
<%= f.label :need_team %>
<%= f.check_box :need_team %>
</div>
<div class="field">
<%= f.label :need_deck %>
<%= f.check_box :need_deck %>
</div>
<div class="field">
<%= f.label :need_user %>
<%= f.check_box :need_user %>
</div>
<div class="field">
<%= f.label :created_at %>
<%= f.date_select :created_at, :start_year => Time.now.year %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
\ No newline at end of file
<h1>Editing tournament</h1>
<%= render 'form' %>
<%= link_to 'Show', @tournament %> |
<%= link_to 'Back', tournaments_path %>
<h1>Editing tournament</h1>
<%= render 'form' %>
<%= link_to '返回', @tournament %>
\ No newline at end of file
<h1>New tournament</h1>
<%= render 'form' %>
<%= link_to 'Back', tournaments_path %>
<h1>发起比赛</h1>
<%= render 'form' %>
<%= link_to 'Back', tournaments_path %>
<p id="notice"><%= notice %></p>
<h2>
<%= @tournament.name %>
</h2>
<p>
<b>联系地点:</b>
<%= t 'tournament.location.' + @tournament.location_type %>
<% case @tournament.location_type %>
<% when "qun" %>
<a target="_blank" href="http://qun.qq.com/#jointhegroup/gid/<%= @tournament.location %>" alt="点击这里加入此群" title="点击这里加入此群"><%= @tournament.location %></a>
<% else %>
<%= @tournament.location %>
<% end %>
</p>
<p>
<b>备注:</b>
<%= @tournament.note %>
</p>
<p>
<b>时间:</b>
<%=l @tournament.updated_at.to_date %>
</p>
<%= link_to 'Edit', edit_tournament_path(@tournament) %> |
<%= link_to 'Back', tournaments_path %>
<p id="notice"><%= notice %></p>
<h2>
<%= @tournament.name %>
</h2>
<p>
<b>联系地点:</b>
<%= t 'tournament.location.' + @tournament.location_type %>
<% case @tournament.location_type %>
<% when "qun" %>
<a target="_blank" href="http://qun.qq.com/#jointhegroup/gid/<%= @tournament.location %>" alt="点击这里加入此群" title="点击这里加入此群"><%= @tournament.location %></a>
<% else %>
<%= @tournament.location %>
<% end %>
</p>
<p>
<b>时间:</b>
<%= l @tournament.created_at.to_date %>
</p>
<p>
<%= @tournament.note %>
</p>
<% if logged? and (@tournament.referees | [@tournament.user]).include?(@current_user) %>
<div>
<% case @tournament.status %>
<% when 0 %>
<table>
<tr>
<th>裁判</th>
<th></th>
<th></th>
</tr>
<% @tournament.referees.each do |referee| %>
<tr>
<td><%= referee.user %></td>
<td><%= link_to '删除', referee, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>
<%= form_for(@referee = @tournament.referees.build) do |f| %>
<%= f.hidden_field :tournament_id %>
<%= f.text_field :user %>
<%= f.submit '添加裁判' %>
<% end %>
<%= link_to '修改比赛信息', edit_tournament_path(@tournament) %>
<%= form_for(@tournament) do |f| %>
<%= f.hidden_field :status, value: 1 %>
<%= f.submit '开始报名', confirm: '开始报名后将不能修改比赛及裁判信息 确定吗' %>
<% end %>
<% when 1 %>
<%= form_for(@tournament) do |f| %>
<%= f.text_area :report %>
<br/>
<%= f.submit '修改公告' %>
<% end %>
<%= form_for(@tournament) do |f| %>
<%= f.hidden_field :status, value: 2 %>
<%= f.submit '开始比赛', confirm: '开始比赛后将停止报名 确定么' %>
<% end %>
<% when 2 %>
<%= form_for(@tournament) do |f| %>
<%= f.text_area :report %>
<br/>
<%= f.submit '修改公告' %>
<% end %>
<% end %>
</div>
<% end %>
<div style="margin-top: 30px">
<% case @tournament.status %>
<% when 0 %>
报名尚未开始
<% when 1 %>
<div id="report">
<%= @tournament.report %>
</div>
<div style="margin-top: 30px">
<%= link_to '我要报名', controller: :enrolls, action: :new, tournament_id: @tournament.id %>
</div>
<table style="margin-top: 30px">
<tr>
<th>昵称</th>
<% if @tournament.need_team %>
<th>战队</th>
<% end %>
<th colspan="2">联系方式</th>
</tr>
<% @tournament.enrolls.each do |enroll| %>
<tr>
<td><%= enroll.name %></td>
<% if @tournament.need_team %>
<td><%= enroll.team %></td>
<% end %>
<td><%= enroll.contact_type %></td>
<td>
<% case enroll.contact_type.to_sym %>
<% when :QQ %>
<%= link_to enroll.contact, "tencent://message/?uin=#{enroll.contact}&Site=card.touhou.com&Menu=yes" %>
<% when :email %>
<%= link_to enroll.contact, "mailto:#{enroll.contact}" %>
<% end %></td>
</tr>
<% end %>
</table>
<% when 2 %>
<div id="report">
<%= @tournament.report %>
</div>
<% when 3 %>
<div id="report">
<%= @tournament.report %>
</div>
<% end %>
</div>
\ No newline at end of file
......@@ -19,6 +19,7 @@
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<input type="hidden" name="continue" id="continue" value="<%=@continue%>" />
<div class="actions">
<%= f.submit %>
</div>
......
......@@ -289,6 +289,27 @@ zh-CN:
post:
attachments: "附件"
content: "正文"
tournament:
name: "比赛名称"
location: "联系方式"
note: "备注"
created_at: "比赛时间"
need_team: "战队赛"
need_deck: "需要上传卡组"
need_user: "仅允许mycard注册用户参加"
enroll:
tournament: "比赛"
team: "战队"
name: "昵称"
contact: "联系方式"
deck: "卡组"
match:
player1: "玩家1"
player1_score: "玩家1得分"
player2: "玩家1"
player2_score: "玩家1得分"
round: "轮次"
mycard:
download: "立即下载"
battlenet: "YGO战网"
......@@ -373,4 +394,7 @@ zh-CN:
content: "正文"
submit: "提交"
private: "仅楼主可见"
anonymous: "匿名发帖"
\ No newline at end of file
anonymous: "匿名发帖"
tournament:
location:
qun: "QQ群"
\ No newline at end of file
MycardServerHttp::Application.routes.draw do
resources :referees
resources :enrolls
resources :matches
resources :tournaments
......
class CreateEnrolls < ActiveRecord::Migration
def change
create_table :enrolls do |t|
t.references :tournament
t.string :name
t.references :user
t.string :contact_type
t.string :contact
t.text :deck
t.integer :score
t.timestamps
end
add_index :enrolls, :tournament_id
add_index :enrolls, :user_id
end
end
class CreateReferees < ActiveRecord::Migration
def change
create_table :referees do |t|
t.references :user
t.references :tournament
t.timestamps
end
add_index :referees, :user_id
add_index :referees, :tournament_id
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120531032103) do
ActiveRecord::Schema.define(:version => 20120618064745) do
create_table "attachments", :force => true do |t|
t.string "data_file_name"
......@@ -107,6 +107,21 @@ ActiveRecord::Schema.define(:version => 20120531032103) do
add_index "duels_users_cards", ["duel_id"], :name => "index_duels_users_cards_on_duel_id"
add_index "duels_users_cards", ["user_id"], :name => "index_duels_users_cards_on_user_id"
create_table "enrolls", :force => true do |t|
t.integer "tournament_id"
t.string "name"
t.integer "user_id"
t.string "contact_type"
t.string "contact"
t.text "deck"
t.integer "score"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "enrolls", ["tournament_id"], :name => "index_enrolls_on_tournament_id"
add_index "enrolls", ["user_id"], :name => "index_enrolls_on_user_id"
create_table "libraries", :force => true do |t|
t.string "name"
t.text "contents"
......@@ -127,6 +142,63 @@ ActiveRecord::Schema.define(:version => 20120531032103) do
t.datetime "updated_at", :null => false
end
create_table "lm", :primary_key => "uid", :force => true do |t|
t.string "username", :limit => 15, :default => "", :null => false
t.string "password", :limit => 32, :default => "", :null => false
t.string "secques", :limit => 8, :default => "", :null => false
t.boolean "gender", :default => false, :null => false
t.boolean "adminid", :default => false, :null => false
t.integer "groupid", :limit => 2, :default => 0, :null => false
t.integer "groupexpiry", :default => 0, :null => false
t.string "extgroupids", :limit => 20, :default => "", :null => false
t.string "regip", :limit => 15, :default => "", :null => false
t.integer "regdate", :default => 0, :null => false
t.string "lastip", :limit => 15, :default => "", :null => false
t.integer "lastvisit", :default => 0, :null => false
t.integer "lastactivity", :default => 0, :null => false
t.integer "lastpost", :default => 0, :null => false
t.integer "posts", :limit => 3, :default => 0, :null => false
t.integer "threads", :limit => 3, :default => 0, :null => false
t.integer "digestposts", :limit => 2, :default => 0, :null => false
t.integer "oltime", :limit => 2, :default => 0, :null => false
t.integer "pageviews", :limit => 3, :default => 0, :null => false
t.integer "credits", :default => 0, :null => false
t.integer "extcredits1", :default => 0, :null => false
t.integer "extcredits2", :default => 0, :null => false
t.integer "extcredits3", :default => 0, :null => false
t.integer "extcredits4", :default => 0, :null => false
t.integer "extcredits5", :default => 0, :null => false
t.integer "extcredits6", :default => 0, :null => false
t.integer "extcredits7", :default => 0, :null => false
t.integer "extcredits8", :default => 0, :null => false
t.string "email", :limit => 40, :default => "", :null => false
t.date "bday", :null => false
t.boolean "sigstatus", :default => false, :null => false
t.integer "tpp", :limit => 1, :default => 0, :null => false
t.integer "ppp", :limit => 1, :default => 0, :null => false
t.integer "styleid", :limit => 2, :default => 0, :null => false
t.boolean "dateformat", :default => false, :null => false
t.boolean "timeformat", :default => false, :null => false
t.boolean "pmsound", :default => false, :null => false
t.boolean "showemail", :default => false, :null => false
t.boolean "newsletter", :default => false, :null => false
t.boolean "invisible", :default => false, :null => false
t.string "timeoffset", :limit => 4, :default => "", :null => false
t.boolean "prompt", :default => false, :null => false
t.boolean "accessmasks", :default => false, :null => false
t.boolean "editormode", :default => false, :null => false
t.boolean "customshow", :default => false, :null => false
t.boolean "xspacestatus", :default => false, :null => false
t.boolean "customaddfeed", :default => false, :null => false
t.integer "newbietaskid", :limit => 2, :default => 0, :null => false
t.boolean "conisbind", :default => false, :null => false
end
add_index "lm", ["conisbind"], :name => "conisbind"
add_index "lm", ["email"], :name => "email"
add_index "lm", ["groupid"], :name => "groupid"
add_index "lm", ["username"], :name => "username", :unique => true
create_table "matches", :force => true do |t|
t.integer "player1_id"
t.integer "player1_score"
......@@ -209,6 +281,16 @@ ActiveRecord::Schema.define(:version => 20120531032103) do
t.datetime "updated_at", :null => false
end
create_table "referees", :force => true do |t|
t.integer "user_id"
t.integer "tournament_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "referees", ["tournament_id"], :name => "index_referees_on_tournament_id"
add_index "referees", ["user_id"], :name => "index_referees_on_user_id"
create_table "roles", :force => true do |t|
t.string "name", :null => false
t.boolean "topic_delete", :default => false, :null => false
......@@ -220,13 +302,16 @@ ActiveRecord::Schema.define(:version => 20120531032103) do
end
create_table "servers", :force => true do |t|
t.string "server_type", :default => "ygopro", :null => false
t.string "name"
t.string "password"
t.string "key"
t.string "ip"
t.integer "port"
t.integer "http_port"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "register", :null => false
t.string "login"
t.string "index", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "settings", :primary_key => "name", :force => true do |t|
......@@ -254,9 +339,13 @@ ActiveRecord::Schema.define(:version => 20120531032103) do
create_table "tournaments", :force => true do |t|
t.string "name"
t.integer "user_id", :null => false
t.string "location_type"
t.string "location"
t.text "note"
t.integer "status", :null => false
t.boolean "authentic", :null => false
t.boolean "team", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
......@@ -303,8 +392,6 @@ ActiveRecord::Schema.define(:version => 20120531032103) do
t.string "last_sign_in_ip"
end
add_index "users", ["email"], :name => "index_users_on_email"
add_index "users", ["name"], :name => "index_users_on_name"
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
tournament:
name: MyString
user:
contact_type: MyString
contact: MyString
deck: MyText
score: 1
two:
tournament:
name: MyString
user:
contact_type: MyString
contact: MyString
deck: MyText
score: 1
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
user:
tournament:
two:
user:
tournament:
require 'test_helper'
class EnrollsControllerTest < ActionController::TestCase
setup do
@enroll = enrolls(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:enrolls)
end
test "should get new" do
get :new
assert_response :success
end
test "should create enroll" do
assert_difference('Enroll.count') do
post :create, enroll: { contact: @enroll.contact, contact_type: @enroll.contact_type, deck: @enroll.deck, name: @enroll.name, score: @enroll.score }
end
assert_redirected_to enroll_path(assigns(:enroll))
end
test "should show enroll" do
get :show, id: @enroll
assert_response :success
end
test "should get edit" do
get :edit, id: @enroll
assert_response :success
end
test "should update enroll" do
put :update, id: @enroll, enroll: { contact: @enroll.contact, contact_type: @enroll.contact_type, deck: @enroll.deck, name: @enroll.name, score: @enroll.score }
assert_redirected_to enroll_path(assigns(:enroll))
end
test "should destroy enroll" do
assert_difference('Enroll.count', -1) do
delete :destroy, id: @enroll
end
assert_redirected_to enrolls_path
end
end
require 'test_helper'
class RefereesControllerTest < ActionController::TestCase
setup do
@referee = referees(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:referees)
end
test "should get new" do
get :new
assert_response :success
end
test "should create referee" do
assert_difference('Referee.count') do
post :create, referee: { }
end
assert_redirected_to referee_path(assigns(:referee))
end
test "should show referee" do
get :show, id: @referee
assert_response :success
end
test "should get edit" do
get :edit, id: @referee
assert_response :success
end
test "should update referee" do
put :update, id: @referee, referee: { }
assert_redirected_to referee_path(assigns(:referee))
end
test "should destroy referee" do
assert_difference('Referee.count', -1) do
delete :destroy, id: @referee
end
assert_redirected_to referees_path
end
end
require 'test_helper'
class EnrollTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class EnrollsHelperTest < ActionView::TestCase
end
require 'test_helper'
class RefereesHelperTest < ActionView::TestCase
end
require 'test_helper'
class RefereeTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment