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

公测

parent a843e94a
......@@ -9,7 +9,7 @@ a:visited{ color: #ffcc66;}
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 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;}
#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;}
\ No newline at end of file
#main {width:600px; margin-left: auto; margin-right: auto; display: none;}
\ No newline at end of file
......@@ -23,14 +23,22 @@ class CardsController < ApplicationController
# GET /cards/1.json
def show
@card = Card.find(params[:id])
@actions = [{"YGO战网" => users_path}, {"YGO战网" => cards_path}, @card]
@actions = [{"YGO战网" => users_path}, {"卡片列表" => cards_path}, @card]
respond_to do |format|
format.html # show.html.erb
format.json { render json: @card }
format.png { redirect_to @card.image }
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.json
def new
......
......@@ -49,8 +49,35 @@ class DuelsController < ApplicationController
# POST /duels
# POST /duels.json
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|
if @duel.save
format.html { redirect_to @duel, notice: 'Duel was successfully created.' }
......
......@@ -14,7 +14,7 @@ class MycardController < ApplicationController
end
end
def download
file = Dir.glob('public/mycard/mycard-*-win32.7z').last
file = Dir.glob('public/mycard/mycard-*-win32.7z').max
if file
file = File.basename(file)
respond_to do |format|
......
......@@ -12,7 +12,7 @@ class UsersController < ApplicationController
@actions = [{"YGO战网" => users_path}, "用户排行"]
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
#format.xml { render :xml => @users }
end
end
......@@ -50,26 +50,37 @@ class UsersController < ApplicationController
@user = User.new(params[:user])
#验证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|
file.set_encoding("GBK")
case file.read.encode("UTF-8")
when "注册成功"
open("http://140.113.242.66:7922/?pass=zh99998&operation=saveuser"){} rescue nil
true
when "用户已存在"
@user.errors.add :name, "用户已存在"
false
else
nil
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")
case reply = file.read.encode("UTF-8", :invalid=>:replace, :undef=>:replace )
when /注册成功/
open("http://140.113.242.66:7922/?pass=zh99998&operation=saveuser"){} rescue nil
true
when "用户已存在"
@user.errors.add :name, "用户已存在"
false
else
nil
end
end
end rescue nil
@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|
if success and @user.save
session[:user_id] = @user.id
format.html { redirect_to(@user, :notice => '注册成功') }
format.xml { render :xml => @user, :status => :created, :location => @user }
if success
if@user.save
session[:user_id] = @user.id
format.html { redirect_to(@user, :notice => '注册成功') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
......
......@@ -12,6 +12,15 @@ class Duel < ActiveRecord::Base
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')
end
def user1
super || User::Guest
end
def user2
super || User::Guest
end
def winner
super || User::Guest
end
def user1_main
user_cards(user1, true)
end
......
......@@ -39,7 +39,7 @@
<tr><td colspan="7"><%= will_paginate @duels %></td></tr>
</tfoot>
<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| %>
<tr>
<% if @user %>
......
......@@ -18,11 +18,13 @@
<nav id="actions">
<%= render 'entries/action' %>
</nav>
<div id="main">
<%= yield %>
<div align="center"><!--不加这个的话 飞入效果会抽一下,直接加到下面那个div上不管用,style="text-align:center; float:center"也不管用-->
<div id="main">
<%= yield %>
</div>
</div>
<footer id="footer">
YGO DULE BATTLENET
</footer>
</body>
</html>
</html>
\ No newline at end of file
......@@ -24,7 +24,7 @@
<tbody>
<% top_users = User.order(:credits).reverse_order.limit(10) %>
<% if logged? && !top_users.include?(@current_user) %>
<% top_users += @current_user %>
<% top_users << @current_user %>
<% my_index = User.where("credits>=?", @current_user.credits).count %>
<% end %>
<% top_users.each_with_index do |user, index| %>
......
......@@ -3,3 +3,4 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# 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
get 'user2_deck.:format' => "duels#user2_deck"
end
resources :cards
get 'search/cards' => 'cards#search'
resources :users do
resources :duels
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