Commit 32987f78 authored by 神楽坂玲奈's avatar 神楽坂玲奈

在线大厅修复

parent 4eb9f0fb
...@@ -99,7 +99,7 @@ end ...@@ -99,7 +99,7 @@ end
task :refresh_user_pass => :environment do task :refresh_user_pass => :environment do
require 'cgi' require 'cgi'
require 'open-uri' require 'open-uri'
servers = Server.all#where(:server_type => "ygopro") servers = Server.where(:name => :"ygopro-ocg")#all#where(:server_type => "ygopro")
users = [] users = []
User.all.each do |user| User.all.each do |user|
if user.password.nil? if user.password.nil?
...@@ -115,7 +115,7 @@ task :refresh_user_pass => :environment do ...@@ -115,7 +115,7 @@ task :refresh_user_pass => :environment do
out = "#{user.id} #{user.name} " out = "#{user.id} #{user.name} "
servers.each do |server| 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) 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 $! open(url, server.server_type=='ygopro' ? 'r:GBK' : 'r'){|f|out << "\t"+f.read.encode("UTF-8", :undef => :replace, :invalid => :replace)} rescue p $!
end end
print out+"\n" print out+"\n"
end end
......
...@@ -8,16 +8,21 @@ class RoomsController < ApplicationController ...@@ -8,16 +8,21 @@ class RoomsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.json do format.json do
Server.all.each_with_index do |server, index| if params[:server_id]
open("http://#{server.ip}:#{server.http_port}/?operation=getroomjson", 'r:GBK') do |file| servers = Server.where(id: params[:server_id])
JSON.parse(file.read.encode("UTF-8"))["rooms"].each do |r| else
room = {id: ('A'.ord+index).chr + r["roomid"], name: r["roomname"], status: r["istart"].to_sym, users: []} servers = Server.where(server_type: "ygopro")
end
servers.each_with_index do |server, index|
open("#{server.index}/?operation=getroomjsondelphi") do |file|
JSON.parse(file.read)["rooms"].each do |r|
room = {id: ('A'.ord+index).chr + r["roomid"], name: decode(r["roomname"]), status: r["istart"].to_sym, users: []}
r["users"].each do |u| r["users"].each do |u|
if u["id"] == "0" if u["id"] == "0"
user = {player: u["pos"].to_i%2+1, id: 0, name: u["name"], certified: false} user = {player: u["pos"].to_i%2+1, id: 0, name: decode(u["name"]), certified: false}
else else
user = User.find_by_name(u["name"]) user = User.find_by_name(u["name"])
user = {player: u["pos"].to_i%2+1, id: user ? user.id : 0, name: u["name"], certified: true} user = {player: u["pos"].to_i%2+1, id: user ? user.id : 0, name: decode(u["name"]), certified: true}
end end
room[:users] << user room[:users] << user
end end
...@@ -29,4 +34,9 @@ class RoomsController < ApplicationController ...@@ -29,4 +34,9 @@ class RoomsController < ApplicationController
end end
end end
end end
private
def decode(str)
[str].pack('H*').force_encoding("UTF-16BE").encode("UTF-8", :undef => :replace, :invalid => :replace)
end
end end
...@@ -2,7 +2,12 @@ class ServersController < ApplicationController ...@@ -2,7 +2,12 @@ class ServersController < ApplicationController
# GET /servers # GET /servers
# GET /servers.json # GET /servers.json
def index def index
if params[:server_type]
@servers = Server.where(server_type: params[:server_type])
else
@servers = Server.all @servers = Server.all
end
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
......
...@@ -70,7 +70,7 @@ class UsersController < ApplicationController ...@@ -70,7 +70,7 @@ class UsersController < ApplicationController
if !@user.errors.any? and @user.save if !@user.errors.any? and @user.save
remote_register(@user, @from) remote_register(@user, @from)
session[:user_id] = @user.id 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 : params[:continue].gsub(/\{name\}|\{password\}/, '{name}' => URI.encode_www_form_component(@user.name), '{password}' => URI.encode_www_form_component(@user.password)), :notice => '注册成功') }
format.xml { render :xml => @user, :status => :created, :location => @user } format.xml { render :xml => @user, :status => :created, :location => @user }
else else
format.html { render :action => "new" } format.html { render :action => "new" }
...@@ -139,7 +139,7 @@ class UsersController < ApplicationController ...@@ -139,7 +139,7 @@ class UsersController < ApplicationController
session[:user_id] = @user.id session[:user_id] = @user.id
@user.update_attribute(:lastloginip, request.remote_ip) @user.update_attribute(:lastloginip, request.remote_ip)
remote_register(@user) remote_register(@user)
format.html { redirect_to(params[:continue].blank? ? @user : URI.escape(params[:continue]), :notice => 'Login Successfully.') } format.html { redirect_to(params[:continue].blank? ? @user : params[:continue].gsub(/\{name\}|\{password\}/, '{name}' => URI.encode_www_form_component(@user.name), '{password}' => URI.encode_www_form_component(@user.password)), :notice => 'Login Successfully.') }
format.json { render json: @user } format.json { render json: @user }
else else
@user = User.new(params[:user]) @user = User.new(params[:user])
......
<style>
.topic {
float: left;
width: 190px;
margin: 2px;
}
.posttop {
height: 146px;
overflow: hidden;
}
.first {
height: 92px;
}
.last {
height: 54px;
}
.name {
//如何设置单行
}
#stat {
float: right;
clear: both;
}
.first {
overflow: hidden;
}
.topics {
overflow: hidden;
}
.avatar_small {
float: left;
}
</style>
<div id="wrap" class="wrap s_clear"> <div id="wrap" class="wrap s_clear">
<div class="itemtitle s_clear"> <div id="stat">
<p class="right boardcount"> <%= t 'datetime.today' %>: <em><%= Post.today.count %> </em>,
<%=t 'datetime.today' %>: <em><%= Post.today.count %> </em>, <%= t 'datetime.yesterday' %>: <em><%= Post.yesterday.count %></em>,
<%=t 'datetime.yesterday' %>: <em><%= Post.yesterday.count %></em>, <%= t 'stat.total' %>: <em><%= Post.count %></em>
<%=t 'stat.total' %>: <em><%= Post.count %></em> </div>
</p> <div>最新帖子</div>
<div id="stream">
<ul id="topics">
<% Post.group(:topic_id).order(:created_at).reverse_order.limit(5).includes(:topic).each do |post| %>
<li class="topic">
<% last_post = post.topic.posts.order(:id).last %>
<div class="post<%= ' first' if last_post != post %>">
<div class="posttop">
<%= image_tag post.user.avatar.url(:small), width: 48, height: 48, class: "avatar_small" %>
<div>
<span class="name"><%= link_to post.topic.name, post.topic %></span>
</div>
<div>
<span><%= link_to post.user.name, post.user %></span>
<span><%= distance_of_time_in_words_to_now post.created_at %> <%= t 'ago' %></span>
</div> </div>
<%= post.content %>
</div>
<div class="postbottom">
</div>
</div>
<% if last_post != post %>
<% post = last_post %>
<div class="post last">
<div class="posttop last">
<%= image_tag post.user.avatar.url(:small), width: 48, height: 48, class: "avatar_small" %>
<div>
<span><%= link_to post.user.name, post.user %></span>
<span><%= distance_of_time_in_words_to_now post.created_at %> <%= t 'ago' %></span>
</div>
<%= post.content %>
</div>
</div>
<% end %>
<span><%=link_to post.topic.category.name, post.topic.category %></span>
<span>回复:<%=post.topic.posts.count %> </span><span>查看:<%=post.topic.viewnum %></span>
</li>
<% end %>
</ul>
</div>
<div class="itemtitle s_clear"></div>
<%= render @boards %> <%= render @boards %>
<div class="mainbox list"> <div class="mainbox list">
<span class="headactions"><%= image_tag 'common/collapsed_no.gif' %></span> <span class="headactions"><%= image_tag 'common/collapsed_no.gif' %></span>
<h3><%=link_to t('forum.link'), links_path %></h3>
<h3><%= link_to t('forum.link'), links_path %></h3>
<div id="forumlinks"> <div id="forumlinks">
<!--<div class="forumlinks"> <!--<div class="forumlinks">
<ul class="s_clear"><li><div class="forumlogo"><img src="http://www.touhou.cc/logo.gif" border="0" alt="东方幻想乡"></div><div class="forumcontent"><h5><a href="http://www.touhou.cc/bbs" target="_blank">东方幻想乡</a></h5><p>这里是幻想乡,一片充满生机和幸福的乐土.</p></div></li></ul> <ul class="s_clear"><li><div class="forumlogo"><img src="http://www.touhou.cc/logo.gif" border="0" alt="东方幻想乡"></div><div class="forumcontent"><h5><a href="http://www.touhou.cc/bbs" target="_blank">东方幻想乡</a></h5><p>这里是幻想乡,一片充满生机和幸福的乐土.</p></div></li></ul>
......
...@@ -55,9 +55,6 @@ ...@@ -55,9 +55,6 @@
return false; return false;
} }
else{ else{
<% if @from == :"ygopro-ocg" %>
$("#continue").val("http://ygopro-ocg.com/mycard.php?username=" + $("#username").val() + "&password=" + $("#password").val());
<% end %>
return true; return true;
} }
} }
......
...@@ -398,3 +398,4 @@ zh-CN: ...@@ -398,3 +398,4 @@ zh-CN:
tournament: tournament:
location: location:
qun: "QQ群" qun: "QQ群"
ago: "前"
\ No newline at end of file
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