3 Commits

Author SHA1 Message Date
MrYummy
0aad3bb71a Added choice of project, r/w perms, and fixed up some css 2017-07-04 22:27:07 +02:00
MrYummy
0f74795159 Added basic hexfile reading that respects r/w perms 2017-07-01 04:48:52 +02:00
MrYummy
3bfc74045f hi 2017-06-21 01:59:02 +02:00
22 changed files with 161 additions and 18 deletions

Binary file not shown.

View File

@@ -51,4 +51,4 @@ $(function(){
return time + " " + unit + tail;
}
});
});
});

View File

@@ -14,4 +14,5 @@
//= require app
//= require editor
//= require highlight
//= require jquery-textcomplete
//= require jquery-textcomplete
//= require memory

View File

@@ -89,4 +89,4 @@ $(function() {
debounce: 300
});
});
});

View File

@@ -0,0 +1,26 @@
$(function() {
$('td').focus(function() {
if (this.id.split("-")[0] == "memory") {
$(this).css("background-color", "lightblue")
}
});
var data = [];
$('td').keydown(function() {
data.push(this.id, $(this).html().substr(0, 2)); //position, value
})
$('td').blur(function() {
$(this).css("background", "none");
if ((id_i = data.indexOf(this.id) != -1) && data[id_i+1] != $(this).html().substr(0, 2)) {
$(this).css("color", "darkgreen");
var int_id = this.id.split("-")[1]
$.post("/memory/update_memory?project="+$(this).closest("table").data("project")+"&file="+Math.floor((int_id/2048)+1)+"&mem_id="+int_id%2048+"&value="+$(this).html().substr(0, 2));
data.splice(id_i, 2);
}
});
$('select').change(function() {
$.get("/memory/table?project="+$(this).data("project")+"&file="+$(this).find("option:selected").text()+".hex")
});
});

View File

@@ -1026,4 +1026,13 @@ nav.pagination {
padding: 0.1em 0.2em;
border-radius: 0.2em;
text-shadow: none;
}
}
.memory-table {
width: 980px;
margin: auto;
text-align: center;
th, td {
height: 20px;
border: 1px solid black;
}
}

View File

@@ -8,8 +8,16 @@ class BlogpostsController < ApplicationController
end
def show
@comment = Comment.new(blogpost: @post)
@comments = @post.comments.page(params[:page])
if @post
@comment = Comment.new(blogpost: @post)
@comments = @post.comments.page(params[:page])
respond_to do |format|
format.html
format.json {render json: @post.attributes.merge(replies: Comment.where(blogpost: @post).ids).to_json}
end
else
respond_to {|format| format.json {render json: Comment.find_by(id: params[:id][1..-1]).try(:attributes).to_json}}
end
end
def new
@@ -64,7 +72,9 @@ class BlogpostsController < ApplicationController
def set_post
if params[:id]
@post = Blogpost.find(params[:id])
unless action_name == "show" && params[:id][0].downcase == "c"
@post = Blogpost.find(params[:id])
end
end
end
@@ -75,4 +85,4 @@ class BlogpostsController < ApplicationController
end
end
end
end

View File

@@ -2,6 +2,12 @@ class CommentsController < ApplicationController
include MailerHelper
def show
respond_to do |format|
format.json {render json: @comment.attributes.to_json}
end
end
def edit
@comment = Comment.find(params[:id])
if mod? || @comment.author.is?(current_user)
@@ -72,4 +78,4 @@ class CommentsController < ApplicationController
def comment_params
params.require(:comment).permit(:content)
end
end
end

View File

@@ -0,0 +1,54 @@
class MemoryController < ApplicationController
before_filter :logged_in
def index
current_uuid = current_user.uuid.gsub("-", "")
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/players/#{current_uuid}")
psjson = JSON.parse(File.read("projects.json"))
@projects = psjson["owns"] + psjson["read"] + psjson["write"]
@project_names = @projects.collect{|p| (data = JSON.parse(File.read(File.expand_path("../..")+"/projects/#{p}/project.json")))["name"] + " | #{"own" if data["owner"] == current_uuid}#{"write" if data["write"].include? current_uuid}#{"read" if data["read"].include? current_uuid}"}
end
def list
render :index
end
def table
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/projects/#{params[:project].gsub(/[^a-zA-Z0-9-]/,"")[0..35]}")
@data = []
Dir.glob('*').reverse.each do |f|
File.open(Dir.pwd+"/#{f}") do |file|
@data.concat(file.read.unpack("C*").map{|h| h.to_s(16)})
unless (parse = JSON.parse((jf = File.open(Dir.pwd+"/project.json")).read))["read"].include? current_user.uuid.gsub("-","")
@can_edit = true
end
@name = parse["name"]
jf.close
end
end
end
def update_memory
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/projects/#{params[:project].gsub(/[^a-zA-Z0-9-]/,"")[0..35]}")
unless params[:mem_id].to_i > JSON.parse(File.read("project.json"))["size"] || (/[^A-Fa-f0-9]/.match params[:value])
new_text = ""
File.open("#{params[:file]}.hex"){|f| new_text = f.read.unpack("C*").collect{|h| h.to_s(16)}}
new_text[params[:mem_id].to_i] = params[:value]
File.open("#{params[:file]}.hex", "w") do |f|
f.write((new_text.collect{|h| h.to_s.to_i(16)}).pack("C*").force_encoding("UTF-8"))
end
render nothing: true
end
end
private
def logged_in
unless current_user
flash[:alert] = "Please log in before viewing memory files."
redirect_to home_statics_path
end
end
end

View File

@@ -30,6 +30,10 @@ class UsersController < ApplicationController
end
def show
respond_to do |format|
format.html
format.json {render json: @user.attributes.slice("id", "uuid", "ign", "name", "about", "donor", "confirmed", "last_seen", "created_at").to_json}
end
end
# SIGNUP

View File

@@ -0,0 +1,2 @@
module MemoryHelper
end

View File

@@ -173,4 +173,4 @@ class User < ActiveRecord::Base
def set_email_token
self.email_token ||= SecureRandom.hex(16)
end
end
end

View File

@@ -51,4 +51,4 @@
</div>
<% end %>
<%= paginate @threads %>
</div>
</div>

View File

@@ -25,4 +25,4 @@
</div>
<%= render partial: "/layouts/footer" %>
</body>
</html>
</html>

View File

@@ -0,0 +1,5 @@
<%= form_tag url_for(controller: "memory", action: "table"), method: :get do %>
<%= select_tag "project", options_for_select(@projects.collect.with_index{|p, i| [@project_names[i], p]}) %>
<br><br>
<%= submit_tag "Load table", name: nil, class: "btn blue" %>
<% end %>

View File

@@ -0,0 +1,17 @@
<h1 style="text-align:center"><%= title @name + (" (read-only)" if !@can_edit).to_s %></h1>
<table class="memory-table", data-project="<%=params[:project]%>">
<tr>
<% ["Address","0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"].each do |i| %>
<th><b><%=i%></b></th>
<% end %>
</tr>
<% @data.in_groups_of(16).each_with_index do |row, rindex| %>
<tr>
<td><b><%=(rindex*16).to_s(16).upcase.rjust(6, "0")%></b></td>
<% row.each_with_index do |hex, hindex| %>
<td contenteditable="<%=!!@can_edit%>" id="memory-<%=(16*rindex)+hindex%>"><%=hex.to_s.upcase.rjust(2, "0")%></td>
<% end %>
</tr>
<% end %>
</table>
<br>

View File

@@ -30,4 +30,4 @@
<span>for those who just want to mine some ore</span>
<span>and we have a freebuild world for large projects.</span>
</p>
<p>Join us now!</p>
<p>Join us now!</p>

View File

@@ -19,4 +19,4 @@
</div>
<% end %>
<%= paginate @users %>
</div>
</div>

View File

@@ -10,7 +10,7 @@ default: &default
development:
<<: *default
database: redstoner-web
username: root
username: web
production:
<<: *default
@@ -24,4 +24,4 @@ test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
timeout: 5000

View File

@@ -43,4 +43,4 @@ Redstoner::Application.configure do
password: ENV["GMAIL_PASSWORD"],
}
end
end

View File

@@ -29,6 +29,15 @@ Redstoner::Application.routes.draw do
end
end
resources :memory do
collection do
get 'list'
get 'table'
post 'update_memory'
end
end
resources :forumgroups, path: '/forums/groups'
resources :forums, path: '/forums'
resources :forumthreads, path: '/forums/threads' do

View File

@@ -38,4 +38,4 @@ User.create!(
password: "123456789", # high seructity!
password_confirmation: "123456789",
role: Role.get(:superadmin)
)
)