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

在线大厅修复

parent 4eb9f0fb
......@@ -99,7 +99,7 @@ end
task :refresh_user_pass => :environment do
require 'cgi'
require 'open-uri'
servers = Server.all#where(:server_type => "ygopro")
servers = Server.where(:name => :"ygopro-ocg")#all#where(:server_type => "ygopro")
users = []
User.all.each do |user|
if user.password.nil?
......@@ -115,7 +115,7 @@ task :refresh_user_pass => :environment do
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 $!
open(url, server.server_type=='ygopro' ? 'r:GBK' : 'r'){|f|out << "\t"+f.read.encode("UTF-8", :undef => :replace, :invalid => :replace)} rescue p $!
end
print out+"\n"
end
......
#encoding: UTF-8
class RoomsController < ApplicationController
require 'open-uri'
layout 'losses'
def index
@rooms = []
@actions = ["在线大厅"]
respond_to do |format|
format.html # index.html.erb
format.json do
Server.all.each_with_index do |server, index|
open("http://#{server.ip}:#{server.http_port}/?operation=getroomjson", 'r:GBK') do |file|
JSON.parse(file.read.encode("UTF-8"))["rooms"].each do |r|
room = {id: ('A'.ord+index).chr + r["roomid"], name: r["roomname"], status: r["istart"].to_sym, users: []}
r["users"].each do |u|
if u["id"] == "0"
user = {player: u["pos"].to_i%2+1, id: 0, name: u["name"], certified: false}
else
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}
end
room[:users] << user
end
@rooms << room
end
end
end
render json: @rooms
end
end
end
end
#encoding: UTF-8
class RoomsController < ApplicationController
require 'open-uri'
layout 'losses'
def index
@rooms = []
@actions = ["在线大厅"]
respond_to do |format|
format.html # index.html.erb
format.json do
if params[:server_id]
servers = Server.where(id: params[:server_id])
else
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|
if u["id"] == "0"
user = {player: u["pos"].to_i%2+1, id: 0, name: decode(u["name"]), certified: false}
else
user = User.find_by_name(u["name"])
user = {player: u["pos"].to_i%2+1, id: user ? user.id : 0, name: decode(u["name"]), certified: true}
end
room[:users] << user
end
@rooms << room
end
end
end
render json: @rooms
end
end
end
private
def decode(str)
[str].pack('H*').force_encoding("UTF-16BE").encode("UTF-8", :undef => :replace, :invalid => :replace)
end
end
......@@ -2,7 +2,12 @@ class ServersController < ApplicationController
# GET /servers
# GET /servers.json
def index
@servers = Server.all
if params[:server_type]
@servers = Server.where(server_type: params[:server_type])
else
@servers = Server.all
end
respond_to do |format|
format.html # index.html.erb
......
......@@ -70,7 +70,7 @@ class UsersController < ApplicationController
if !@user.errors.any? and @user.save
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 : 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 }
else
format.html { render :action => "new" }
......@@ -139,7 +139,7 @@ class UsersController < ApplicationController
session[:user_id] = @user.id
@user.update_attribute(:lastloginip, request.remote_ip)
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 }
else
@user = User.new(params[:user])
......
<div id="wrap" class="wrap s_clear">
<div class="itemtitle s_clear">
<p class="right boardcount">
<%=t 'datetime.today' %>: <em><%= Post.today.count %> </em>,
<%=t 'datetime.yesterday' %>: <em><%= Post.yesterday.count %></em>,
<%=t 'stat.total' %>: <em><%= Post.count %></em>
</p>
</div>
<%= render @boards %>
<div class="mainbox list">
<span class="headactions"><%= image_tag 'common/collapsed_no.gif' %></span>
<h3><%=link_to t('forum.link'), links_path %></h3>
<div id="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>
</div>--> <!--详细-->
<div class="forumimglink">
<%= render @links %>
</div>
<!--<div class="forumtxtlink">
<ul class="s_clear">
<li><a href="http://www.sakuracountry.cn/" target="_blank" title="樱之国度">樱之国度</a></li><li><a href="http://www.awawh.com/bbs/" target="_blank" title="聚合网">聚合网</a></li><li><a href="http://www.thactclub.cn/bbs" target="_blank" title="TAC触手乡">TAC触手乡</a></li><li><a href="http://www.bilibili.us/" target="_blank" title="哔哩哔哩">哔哩哔哩</a></li><li><a href="http://www.moeloli.cn" target="_blank" title="萝莉学园">萝莉学园</a></li><li><a href="http://www.0ymt.net/" target="_blank" title="零乐漫坛">零乐漫坛</a></li><li><a href="http://www.fulifuli.org/" target="_blank" title="炮姐大逃杀">炮姐大逃杀</a></li><li><a href="http://www.hgacg.com/" target="_blank" title="后宫动漫论坛">后宫动漫论坛</a></li><li><a href="http://www.lv8n.com" target="_blank" title="中国本土同人联盟">中国本土同人联盟</a></li><li><a href="http://bbs.u17.com/" target="_blank" title="有妖气漫画论坛">有妖气漫画论坛</a></li><li><a href="http://www.touhou.cc/bbs/plugin.php?id=xh_forumlinks:forumlinks" target="_blank" title="点击申请">点击申请</a></li></ul>
</div>--><!--文字-->
</div>
</div>
<div class="mainbox list" id="online">
<span class="headactions"><a href="index.php?showoldetails=yes#online" class="nobdr"><%= image_tag 'common/collapsed_yes.gif' %></a></span>
<h3>
<%= render 'entries/onlineuser' %>
</h3>
</div>
</div>
<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="stat">
<%= t 'datetime.today' %>: <em><%= Post.today.count %> </em>,
<%= t 'datetime.yesterday' %>: <em><%= Post.yesterday.count %></em>,
<%= t 'stat.total' %>: <em><%= Post.count %></em>
</div>
<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>
<%= 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 %>
<div class="mainbox list">
<span class="headactions"><%= image_tag 'common/collapsed_no.gif' %></span>
<h3><%= link_to t('forum.link'), links_path %></h3>
<div id="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>
</div>--> <!--详细-->
<div class="forumimglink">
<%= render @links %>
</div>
<!--<div class="forumtxtlink">
<ul class="s_clear">
<li><a href="http://www.sakuracountry.cn/" target="_blank" title="樱之国度">樱之国度</a></li><li><a href="http://www.awawh.com/bbs/" target="_blank" title="聚合网">聚合网</a></li><li><a href="http://www.thactclub.cn/bbs" target="_blank" title="TAC触手乡">TAC触手乡</a></li><li><a href="http://www.bilibili.us/" target="_blank" title="哔哩哔哩">哔哩哔哩</a></li><li><a href="http://www.moeloli.cn" target="_blank" title="萝莉学园">萝莉学园</a></li><li><a href="http://www.0ymt.net/" target="_blank" title="零乐漫坛">零乐漫坛</a></li><li><a href="http://www.fulifuli.org/" target="_blank" title="炮姐大逃杀">炮姐大逃杀</a></li><li><a href="http://www.hgacg.com/" target="_blank" title="后宫动漫论坛">后宫动漫论坛</a></li><li><a href="http://www.lv8n.com" target="_blank" title="中国本土同人联盟">中国本土同人联盟</a></li><li><a href="http://bbs.u17.com/" target="_blank" title="有妖气漫画论坛">有妖气漫画论坛</a></li><li><a href="http://www.touhou.cc/bbs/plugin.php?id=xh_forumlinks:forumlinks" target="_blank" title="点击申请">点击申请</a></li></ul>
</div>--><!--文字-->
</div>
</div>
<div class="mainbox list" id="online">
<span class="headactions"><a href="index.php?showoldetails=yes#online" class="nobdr"><%= image_tag 'common/collapsed_yes.gif' %></a></span>
<h3>
<%= render 'entries/onlineuser' %>
</h3>
</div>
</div>
This diff is collapsed.
......@@ -397,4 +397,5 @@ zh-CN:
anonymous: "匿名发帖"
tournament:
location:
qun: "QQ群"
\ No newline at end of file
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