summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMrYummy <elemental428@gmail.com>2017-07-01 04:48:52 +0200
committerMrYummy <elemental428@gmail.com>2017-07-01 04:48:52 +0200
commit0f74795159ba65432aa1a6a25367dfdcffd4bb12 (patch)
treeded77479274a99d6f9f5668b911229c1eabb4087
parent3bfc74045fa61e7646754a1563c8813ed0952f14 (diff)
Added basic hexfile reading that respects r/w perms
-rw-r--r--app/assets/javascripts/app.js2
-rw-r--r--app/assets/javascripts/application.js3
-rw-r--r--app/assets/javascripts/editor.js2
-rw-r--r--app/assets/javascripts/memory.js19
-rw-r--r--app/assets/stylesheets/style.css.scss9
-rw-r--r--app/controllers/.memory_controller.rb.swpbin0 -> 12288 bytes
-rw-r--r--app/controllers/memory_controller.rb53
-rw-r--r--app/helpers/memory_helper.rb2
-rw-r--r--app/models/user.rb2
-rw-r--r--app/views/forums/show.html.erb2
-rw-r--r--app/views/layouts/application.html.erb2
-rw-r--r--app/views/memory/index.html.erb4
-rw-r--r--app/views/memory/table.html.erb16
-rw-r--r--app/views/statics/home.html.erb2
-rw-r--r--app/views/users/index.html.erb2
-rw-r--r--config/routes.rb9
16 files changed, 120 insertions, 9 deletions
diff --git a/app/assets/javascripts/app.js b/app/assets/javascripts/app.js
index dd7f08f..6f0ac24 100644
--- a/app/assets/javascripts/app.js
+++ b/app/assets/javascripts/app.js
@@ -51,4 +51,4 @@ $(function(){
return time + " " + unit + tail;
}
});
-}); \ No newline at end of file
+});
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 3b1499f..193617b 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -14,4 +14,5 @@
//= require app
//= require editor
//= require highlight
-//= require jquery-textcomplete \ No newline at end of file
+//= require jquery-textcomplete
+//= require memory
diff --git a/app/assets/javascripts/editor.js b/app/assets/javascripts/editor.js
index 4b35aea..4a42de5 100644
--- a/app/assets/javascripts/editor.js
+++ b/app/assets/javascripts/editor.js
@@ -89,4 +89,4 @@ $(function() {
debounce: 300
});
-}); \ No newline at end of file
+});
diff --git a/app/assets/javascripts/memory.js b/app/assets/javascripts/memory.js
new file mode 100644
index 0000000..4dac5a0
--- /dev/null
+++ b/app/assets/javascripts/memory.js
@@ -0,0 +1,19 @@
+$(function() {
+ var data = [];
+ $('td').keydown(function() {
+ data.push(this.id, $(this).html().substr(0, 2)); //position, value
+ })
+ $('td').blur(function() {
+ if ((id_i = data.indexOf(this.id) != -1) && data[id_i+1] != $(this).html().substr(0, 2)) {
+ 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")
+ });
+});
+
+
+
diff --git a/app/assets/stylesheets/style.css.scss b/app/assets/stylesheets/style.css.scss
index 6de5aa2..e8f06ab 100644
--- a/app/assets/stylesheets/style.css.scss
+++ b/app/assets/stylesheets/style.css.scss
@@ -1026,4 +1026,11 @@ nav.pagination {
padding: 0.1em 0.2em;
border-radius: 0.2em;
text-shadow: none;
-} \ No newline at end of file
+}
+.memory-table {
+ width: 870px;
+ margin: auto;
+ th, td {
+ border: 1px solid black;
+ }
+}
diff --git a/app/controllers/.memory_controller.rb.swp b/app/controllers/.memory_controller.rb.swp
new file mode 100644
index 0000000..18f0137
--- /dev/null
+++ b/app/controllers/.memory_controller.rb.swp
Binary files differ
diff --git a/app/controllers/memory_controller.rb b/app/controllers/memory_controller.rb
new file mode 100644
index 0000000..6d5947e
--- /dev/null
+++ b/app/controllers/memory_controller.rb
@@ -0,0 +1,53 @@
+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]}")
+ @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)})
+ if JSON.parse((jf = File.open(Dir.pwd+"/project.json")).read)["read"].include? current_user.uuid.gsub("-","")
+ @can_edit = false
+ else
+ @can_edit = true
+ end
+ jf.close
+ end
+ end
+ end
+
+ def update_memory
+ Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/projects/#{params[:project]}")
+ 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
+
+ private
+
+ def logged_in
+ unless current_user
+ flash[:alert] = "Please log in before viewing memory files."
+ redirect_to home_statics_path
+ end
+ end
+end
diff --git a/app/helpers/memory_helper.rb b/app/helpers/memory_helper.rb
new file mode 100644
index 0000000..cba154d
--- /dev/null
+++ b/app/helpers/memory_helper.rb
@@ -0,0 +1,2 @@
+module MemoryHelper
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index c422e28..9ddd4f0 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -173,4 +173,4 @@ class User < ActiveRecord::Base
def set_email_token
self.email_token ||= SecureRandom.hex(16)
end
-end \ No newline at end of file
+end
diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb
index 60f3185..6e8ea2f 100644
--- a/app/views/forums/show.html.erb
+++ b/app/views/forums/show.html.erb
@@ -51,4 +51,4 @@
</div>
<% end %>
<%= paginate @threads %>
-</div> \ No newline at end of file
+</div>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index a0a5f83..26d6c67 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -25,4 +25,4 @@
</div>
<%= render partial: "/layouts/footer" %>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/app/views/memory/index.html.erb b/app/views/memory/index.html.erb
new file mode 100644
index 0000000..9348db0
--- /dev/null
+++ b/app/views/memory/index.html.erb
@@ -0,0 +1,4 @@
+<%= form_tag "memory/table", method: :get do %>
+ <%= select_tag "project", options_for_select(@projects.collect.with_index{|p, i| [@project_names[i], p]}) %>
+ <%= submit_tag "View Table", name: nil %>
+<% end %>
diff --git a/app/views/memory/table.html.erb b/app/views/memory/table.html.erb
new file mode 100644
index 0000000..03f1ef2
--- /dev/null
+++ b/app/views/memory/table.html.erb
@@ -0,0 +1,16 @@
+<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>
diff --git a/app/views/statics/home.html.erb b/app/views/statics/home.html.erb
index a5f3242..6a51abd 100644
--- a/app/views/statics/home.html.erb
+++ b/app/views/statics/home.html.erb
@@ -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> \ No newline at end of file
+<p>Join us now!</p>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb
index 883ffb0..4f1d12d 100644
--- a/app/views/users/index.html.erb
+++ b/app/views/users/index.html.erb
@@ -19,4 +19,4 @@
</div>
<% end %>
<%= paginate @users %>
-</div> \ No newline at end of file
+</div>
diff --git a/config/routes.rb b/config/routes.rb
index 584c94f..a200838 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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