Commit 27403848 authored by 神楽坂玲奈's avatar 神楽坂玲奈

公测

parent a843e94a
...@@ -9,7 +9,7 @@ a:visited{ color: #ffcc66;} ...@@ -9,7 +9,7 @@ a:visited{ color: #ffcc66;}
a:hover { text-decoration:underline } a:hover { text-decoration:underline }
nav {width: 750px; font-size: 14px; padding-bottom: 10px; line-height: 40px; color: #ffcc66; text-align: left; margin-left: auto; margin-right: auto;} nav {width: 750px; font-size: 14px; padding-bottom: 10px; line-height: 40px; color: #ffcc66; text-align: left; margin-left: auto; margin-right: auto;}
nav a{color:#ffcc66} nav a{color:#ffcc66}
#footer {line-height: 50px; padding-top: 20px; padding-bottom: 10px; font-size: 12px; color: #0099FF; clear: both; text-align: center; margin-left: auto; margin-right: auto;} #footer {padding-top: 20px; padding-bottom: 10px; font-size: 12px; color: #0099FF; clear: both; text-align: center; margin-left: auto; margin-right: auto;}
#header{width:600px; margin-left: auto; margin-right: auto;} #header{width:600px; margin-left: auto; margin-right: auto;}
#title {width: 600px; font-size: 30px; padding-bottom: 20px; color: #ffcc66; text-align: right; padding-top: 150px;} #title {width: 600px; font-size: 30px; padding-bottom: 20px; color: #ffcc66; text-align: right; padding-top: 150px;}
#main {width:600px; margin-left: auto; margin-right: auto;; display: none;} #main {width:600px; margin-left: auto; margin-right: auto; display: none;}
\ No newline at end of file \ No newline at end of file
...@@ -23,7 +23,7 @@ class CardsController < ApplicationController ...@@ -23,7 +23,7 @@ class CardsController < ApplicationController
# GET /cards/1.json # GET /cards/1.json
def show def show
@card = Card.find(params[:id]) @card = Card.find(params[:id])
@actions = [{"YGO战网" => users_path}, {"YGO战网" => cards_path}, @card] @actions = [{"YGO战网" => users_path}, {"卡片列表" => cards_path}, @card]
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
format.json { render json: @card } format.json { render json: @card }
...@@ -31,6 +31,14 @@ class CardsController < ApplicationController ...@@ -31,6 +31,14 @@ class CardsController < ApplicationController
end end
end end
def search
@cards = Card.where(:name => params[:name].split(','))
respond_to do |format|
#format.html { render }
format.json { render json: @cards }
format.jsonp { render text: "#{params[:callback]}(#{@cards.to_json})" }
end
end
# GET /cards/new # GET /cards/new
# GET /cards/new.json # GET /cards/new.json
def new def new
......
...@@ -49,8 +49,35 @@ class DuelsController < ApplicationController ...@@ -49,8 +49,35 @@ class DuelsController < ApplicationController
# POST /duels # POST /duels
# POST /duels.json # POST /duels.json
def create def create
@duel = Duel.new(params[:duel]) @duel = Duel.new
@duel.winreason = params[:duel][:winreason]
@duel.replay = params[:duel][:replay]
@duel.version = params[:duel][:version]
@duel.user1 = User.find_by_name params[:duel][:user1_name] if params[:duel][:user1_name]
@duel.user2 = User.find_by_name params[:duel][:user2_name] if params[:duel][:user2_name]
[params[:duel][:user1_main], params[:duel][:user1_extra], params[:duel][:user2_main], params[:duel][:user2_extra]].each_with_index do |cards, index|
user = index / 2 == 0 ? @duel.user1 : @duel.user2
main = index % 2 == 0
cards.split(',').collect do |card_number|
card = Card.find_by_number(card_number)
card = Card.create(:id => card_number, :name => card_number, :number => card_number) if card.nil?
@duel.duel_user_cards << DuelUserCard.new(user: user, card: card, main: main)
end
end
@duel.winner = params[:duel][:winner_pos] == "true" ? @duel.user1 : @duel.user2
if params[:duel][:credits] == "true"
if @duel.winner == @duel.user1
@duel.user1_credits = 10
@duel.user2_credits = -10
else
@duel.user1_credits = -10
@duel.user2_credits = 10
end
else
@duel.user1_credits = 0
@duel.user2_credits = 0
end
@duel.created_at = Time.zone.parse params[:duel][:created_at]#.to_i
respond_to do |format| respond_to do |format|
if @duel.save if @duel.save
format.html { redirect_to @duel, notice: 'Duel was successfully created.' } format.html { redirect_to @duel, notice: 'Duel was successfully created.' }
......
...@@ -14,7 +14,7 @@ class MycardController < ApplicationController ...@@ -14,7 +14,7 @@ class MycardController < ApplicationController
end end
end end
def download def download
file = Dir.glob('public/mycard/mycard-*-win32.7z').last file = Dir.glob('public/mycard/mycard-*-win32.7z').max
if file if file
file = File.basename(file) file = File.basename(file)
respond_to do |format| respond_to do |format|
......
...@@ -12,7 +12,7 @@ class UsersController < ApplicationController ...@@ -12,7 +12,7 @@ class UsersController < ApplicationController
@actions = [{"YGO战网" => users_path}, "用户排行"] @actions = [{"YGO战网" => users_path}, "用户排行"]
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.xml { render :xml => @users } #format.xml { render :xml => @users }
end end
end end
...@@ -50,10 +50,12 @@ class UsersController < ApplicationController ...@@ -50,10 +50,12 @@ class UsersController < ApplicationController
@user = User.new(params[:user]) @user = User.new(params[:user])
#验证ygocore服务器是否可注册,true为成功,false为重名,nil为异常 #验证ygocore服务器是否可注册,true为成功,false为重名,nil为异常
success = open("http://140.113.242.66:7922/?userregist=NEW&username=#{CGI.escape @user.name}&password=#{CGI.escape @user.password}") do |file| reply = ""
success = begin
open("http://140.113.242.66:7922/?userregist=NEW&username=#{CGI.escape @user.name}&password=#{CGI.escape @user.password}") do |file|
file.set_encoding("GBK") file.set_encoding("GBK")
case file.read.encode("UTF-8") case reply = file.read.encode("UTF-8", :invalid=>:replace, :undef=>:replace )
when "注册成功" when /注册成功/
open("http://140.113.242.66:7922/?pass=zh99998&operation=saveuser"){} rescue nil open("http://140.113.242.66:7922/?pass=zh99998&operation=saveuser"){} rescue nil
true true
when "用户已存在" when "用户已存在"
...@@ -62,11 +64,16 @@ class UsersController < ApplicationController ...@@ -62,11 +64,16 @@ class UsersController < ApplicationController
else else
nil nil
end end
end rescue nil end
@user.errors.add :name, "注册失败,可能是服务器故障,请与管理员联系 Email/GT/QQ: zh99998@gmail.com" if success.nil? rescue Exception => exception
reply = ([exception] + exception.backtrace).join("\n")
nil
end
@user.errors.add :name, "注册失败,可能是服务器故障,请与管理员联系 Email/GT/QQ: zh99998@gmail.com 详情: #{reply}" if success.nil?
respond_to do |format| respond_to do |format|
if success and @user.save if success
if@user.save
session[:user_id] = @user.id session[:user_id] = @user.id
format.html { redirect_to(@user, :notice => '注册成功') } format.html { redirect_to(@user, :notice => '注册成功') }
format.xml { render :xml => @user, :status => :created, :location => @user } format.xml { render :xml => @user, :status => :created, :location => @user }
...@@ -74,6 +81,10 @@ class UsersController < ApplicationController ...@@ -74,6 +81,10 @@ class UsersController < ApplicationController
format.html { render :action => "new" } format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity } format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end end
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end end
end end
# PUT /users/1 # PUT /users/1
......
...@@ -12,6 +12,15 @@ class Duel < ActiveRecord::Base ...@@ -12,6 +12,15 @@ class Duel < ActiveRecord::Base
result = cards.where('user_id=? and main = ?', user, main) result = cards.where('user_id=? and main = ?', user, main)
result.order("field(card_type, #{(main ? main_order : extra_order).collect{|type|"'#{type}'"}.join(',')})", 'cards.id') result.order("field(card_type, #{(main ? main_order : extra_order).collect{|type|"'#{type}'"}.join(',')})", 'cards.id')
end end
def user1
super || User::Guest
end
def user2
super || User::Guest
end
def winner
super || User::Guest
end
def user1_main def user1_main
user_cards(user1, true) user_cards(user1, true)
end end
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<tr><td colspan="7"><%= will_paginate @duels %></td></tr> <tr><td colspan="7"><%= will_paginate @duels %></td></tr>
</tfoot> </tfoot>
<tbody> <tbody>
<% first_index = @user.duels.where("id<=?",@duels.to_enum.first.id).count if @user %><!--这里的效率很低,待优化--> <% first_index = @user.duels.where("id<=?",@duels.to_enum.first.id).count if @user and !@user.duels.empty? %><!--这里的效率很低,待优化-->
<% @duels.each_with_index do |duel, index| %> <% @duels.each_with_index do |duel, index| %>
<tr> <tr>
<% if @user %> <% if @user %>
......
...@@ -18,9 +18,11 @@ ...@@ -18,9 +18,11 @@
<nav id="actions"> <nav id="actions">
<%= render 'entries/action' %> <%= render 'entries/action' %>
</nav> </nav>
<div align="center"><!--不加这个的话 飞入效果会抽一下,直接加到下面那个div上不管用,style="text-align:center; float:center"也不管用-->
<div id="main"> <div id="main">
<%= yield %> <%= yield %>
</div> </div>
</div>
<footer id="footer"> <footer id="footer">
YGO DULE BATTLENET YGO DULE BATTLENET
</footer> </footer>
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<tbody> <tbody>
<% top_users = User.order(:credits).reverse_order.limit(10) %> <% top_users = User.order(:credits).reverse_order.limit(10) %>
<% if logged? && !top_users.include?(@current_user) %> <% if logged? && !top_users.include?(@current_user) %>
<% top_users += @current_user %> <% top_users << @current_user %>
<% my_index = User.where("credits>=?", @current_user.credits).count %> <% my_index = User.where("credits>=?", @current_user.credits).count %>
<% end %> <% end %>
<% top_users.each_with_index do |user, index| %> <% top_users.each_with_index do |user, index| %>
......
...@@ -3,3 +3,4 @@ ...@@ -3,3 +3,4 @@
# Add new mime types for use in respond_to blocks: # Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf # Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone # Mime::Type.register_alias "text/html", :iphone
Mime::Type.register "application/json-p", :jsonp
\ No newline at end of file
...@@ -11,6 +11,7 @@ MycardServerHttp::Application.routes.draw do ...@@ -11,6 +11,7 @@ MycardServerHttp::Application.routes.draw do
get 'user2_deck.:format' => "duels#user2_deck" get 'user2_deck.:format' => "duels#user2_deck"
end end
resources :cards resources :cards
get 'search/cards' => 'cards#search'
resources :users do resources :users do
resources :duels resources :duels
resources :cards resources :cards
......
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