This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TheeIntrepidGamer's profile picture

Voting System 2.0 (Updated)

Started by TheeIntrepidGamer, 11 August 2013 - 02:56 AM
TheeIntrepidGamer #1
Posted 11 August 2013 - 04:56 AM
I made this program so you are able to setup a booth/server where people can vote inside of your computercraft supported servers.
It is very easy to setup. Watch the v1.0 video to see how to setup the system. Then watch the v2.0 video to see what I added to the system.

V 1.0 (Highly Obsolete):
SpoilerVideo:

[media]http://www.youtube.com/watch?v=bYuLqXgFKKw&feature=share&list=UUh4b37kOnTC7oZtI0SQu4eQ[/media]

Server Code:
http://pastebin.com/EG1HQ7Xk
Booth Code:
http://pastebin.com/BiFwkiVp

Voting Server Code:

Spoiler

--[[Voting System Program]]-- Coded By:Firestorm002
---------------------------------------------------
--				 [Side Note]
-- Do not touch any of the code which isn't labeled
--"change this!", you might mess up the program.
--You can change it if you know what you are doing.
--Just maked sure to give me credit. - Fire
---------------------------------------------------
--Peripherals--
lmon = peripheral.wrap("left")
rmon = peripheral.wrap("right")
---------------------------------------------
--Startup Scripts--
if fs.exists("votingdata") == false then
  fs.makeDir("votingdata")
  a = fs.open("votingdata/filea","w")
  a.write("0")
  b = fs.open("votingdata/fileb","w")
  b.write("0")
  c = fs.open("votingdata/titlea","w")
  c.write("title1")
  c.close()
  c = fs.open("votingdata/titlea","r")
  d = fs.open("votingdata/titleb","w")
  d.write("title2")
  d.close()
  d = fs.open("votingdata/titleb","r")
  a.close()
  b.close()
else
  c = fs.open("votingdata/titlea","r")
  d = fs.open("votingdata/titleb","r")
end
if fs.exists("votinguserdata") == false then
  fs.makeDir("votinguserdata")
end
--------------------------------------------
--Variables--
filename1 = "votingdata/filea"
filename2 = "votingdata/fileb"
w,h = term.getSize()
wml,hml = lmon.getSize()
wmr,hmr = rmon.getSize()
title = c.readAll()
title2 = d.readAll()
--------------------------------------------|
--[Change this pass to whatever you like]---|
overridepass = "baconbits"
--------------------------------------------|
txtscale = 2
version = "1.0"
modemside = "top" --(top,left,bottom,right,back)
h = fs.open(filename1,"r")
t = fs.open(filename2,"r")
msga1 = h.readAll()
msga2 = t.readAll()
--Closes fs.open()'s--
h.close()
t.close()
--
---------------------------------------------
--[[Functions]]--
--Monitor Functions--
function clear()
  lmon.clear()
  rmon.clear()
  rmon.setCursorPos(1,1)
  lmon.setCursorPos(1,1)
end
function fillScrs()
  lmon.setTextScale(txtscale)
  rmon.setTextScale(txtscale)
  lmon.write("		   ")
  lmon.setCursorPos(1,2)
  lmon.write("		   ")
  lmon.setCursorPos(1,3)
  lmon.write("		   ")
  lmon.setCursorPos(1,4)
  lmon.write("		   ")
  lmon.setCursorPos(1,5)
  lmon.write("		   ")
  lmon.setCursorPos(1,6)
  lmon.write("		   ")
--------------------------
  rmon.write("		   ")
  rmon.setCursorPos(1,2)
  rmon.write("		   ")
  rmon.setCursorPos(1,3)
  rmon.write("		   ")
  rmon.setCursorPos(1,4)
  rmon.write("		   ")
  rmon.setCursorPos(1,5)
  rmon.write("		   ")
  rmon.setCursorPos(1,6)
  rmon.write("		   ")
end
function mUpdate()
clear()
--Titles--
rmon.setCursorPos(2,1)
rmon.write(title2)
lmon.setCursorPos(2,1)
lmon.write(title)
--Dividing Lines--
rmon.setCursorPos(1,2)
rmon.write(string.rep("-",w))
lmon.setCursorPos(1,2)
lmon.write(string.rep("-",w))
--Voting Data--
rmon.setCursorPos(2,4)
lmon.setCursorPos(2,4)
lmon.write(msg)
rmon.write(msg2)
end
----------------------
--Terminal Functions--
function tClear()
  term.clear()
end
function tWrite(str,xpos,ypos)
  term.setCursorPos(xpos,ypos)
  term.write(str)
end
function tCenter(str,ypos)
  term.setCursorPos(w/2 - #str/2,ypos)
  term.write(str)
end
function header(str)
  tCenter(string.rep("-",w),1)
  tCenter(str,3)
  tCenter(string.rep("-",w),5)
end
--[[Introduction Voice]]------
rednet.open(modemside)
clear()
tClear()
term.setTextColor(colors.red)
lmon.setBackgroundColor(colors.blue)
rmon.setBackgroundColor(colors.blue)
fillScrs()
term.setTextColor(colors.cyan)
tCenter("<coded by:="" firestorm002="">",2)
tCenter("<version 1.0="">",4)
term.setTextColor(colors.white)
tCenter("<loading>",6)
term.setTextColor(colors.red)
tCenter("[					   ]",7)
sleep(1)
term.setTextColor(colors.orange)
tCenter("[====				   ]",7)
sleep(1)
term.setTextColor(colors.yellow)
tCenter("[========			   ]",7)
sleep(1)
tCenter("[============		   ]",7)
sleep(1)
term.setTextColor(colors.green)
tCenter("[================	   ]",7)
sleep(1)
term.setTextColor(colors.lime)
tCenter("[====================   ]",7)
sleep(1)
tCenter("[=======================]",7)
sleep(1.5)
tClear()
term.setTextColor(colors.white)
tCenter("<loading complete="">",6)
term.setTextColor(colors.lime)
tCenter("[=======================]",7)
sleep(1.5)
clear()
tClear()
lmon.setBackgroundColor(colors.black)
rmon.setBackgroundColor(colors.black)
lmon.setTextColor(colors.yellow)
rmon.setTextColor(colors.yellow)
clear()
--Titles--
rmon.setCursorPos(2,1)
rmon.write(title2)
lmon.setCursorPos(2,1)
lmon.write(title)
--Dividing Lines--
rmon.setCursorPos(1,2)
rmon.write(string.rep("-",w))
lmon.setCursorPos(1,2)
lmon.write(string.rep("-",w))
--Voting Data--
rmon.setCursorPos(2,4)
lmon.setCursorPos(2,4)
lmon.write(msga1)
rmon.write(msga2)
------------------------------
--Core Mechanics-[DO NOT TOUCH UNLESS EXPERIENCED]-
while true do
  term.setTextColor(colors.yellow)
  header("<voting software="" 1.0="">")
  term.setTextColor(colors.white)
  tCenter("ADMINS: Press 'o' to override this menu.",9)
  ev,p1,p2,p3 = os.pullEvent()
  if ev == "rednet_message" then
	if p2 == "vote1" then
	  h = fs.open(filename1,"r")
	  msg = h.readAll()
	  msg = msg + 1
	  h.close()
	  h = fs.open(filename1,"w")
	  h.write(msg)
	  h.close()
	  t = fs.open(filename2,"r")
	  msg2 = t.readAll()
	  t.close()
	  clear()
	  mUpdate()
	elseif p2 == "vote2" then
	  h = fs.open(filename2,"r")
	  msg2 = h.readAll()
	  msg2 = msg2 + 1
	  h.close()
	  h = fs.open(filename2,"w")
	  h.write(msg2)
	  h.close()
	  t = fs.open(filename1,"r")
	  msg = t.readAll()
	  t.close()
	  clear()
	  mUpdate()
	elseif p2 == "newvoter" then
	  ev,p1,p2,p3 = os.pullEvent("rednet_message")
	  h = fs.open("votinguserdata/"..p2,"w")
	  h.close()
	elseif p2 == "needvoter" then
	  ev,p1,p2,p3 = os.pullEvent("rednet_message")
	  if fs.exists("votinguserdata/"..p2) then
		rednet.broadcast("yes")
	  elseif fs.exists("votinguserdata/"..p2) == false then
		rednet.broadcast("no")
	  end
	end
  elseif ev == "char" then
	if p1 == "o" then
	  term.setTextColor(colors.lime)
	  tClear()
	  header("<override initiated="">")
	  term.setTextColor(colors.white)
	  tWrite("PASSWORD: ",2,8)
	  userinput = read("*")
	  if userinput == overridepass then
		while true do
		  term.setTextColor(colors.lime)
		  tClear()
		  header("<control panel="">")
		  term.setTextColor(colors.white)
		  tWrite("rom/admin>",2,6)
		  userinput2 = read()
		  if userinput2 == "cleardata" then
			h = fs.open(filename1,"w")
			t = fs.open(filename2,"w")
			h.write("0.0")
			t.write("0.0")
			h.close()
			t.close()
			tCenter("<all voting="" data="" cleared="">",9)
			sleep(2)
		  elseif userinput2 == "exit" then
			tClear()
			term.setTextColor(colors.lime)
			header("<exiting>")
			sleep(1.5)
			tClear()
			break
		  elseif userinput2 == "renametitles" then
			term.setTextColor(colors.lime)
			header("<rename titles="">")
			term.setTextColor(colors.white)
			tCenter("<press '1'="" or="" '2'="" to="" rename="" them="">",9)
			ev,p1,p2,p3 = os.pullEvent("char")
			if p1 == "1" then
			  tClear()
			  term.setTextColor(colors.lime)
			  header("<rename title="" #1="">")
			  term.setTextColor(colors.white)
			  tWrite("New Name: ",2,9)
			  newname1 = read()
			  h = fs.open("votingdata/titlea","w")
			  h.write(newname1)
			  h.close()
			elseif p1 == "2" then
			  tClear()
			  term.setTextColor(colors.lime)
			  header("<rename title="" #2="">")
			  term.setTextColor(colors.white)
			  tWrite("New Name: ",2,9)
			  newname2 = read()
			  h = fs.open("votingdata/titleb","w")
			  h.write(newname2)
			  h.close()
			  tClear()
			end
		  elseif userinput2 == "clearuserdata" then
			fs.delete("votinguserdata")
			tCenter("<all user="" data="" cleared="">",9)
			sleep(2)
		  else
			shell.run(userinput2)
		  end
		end
	  else
		tClear()
		term.setTextColor(colors.red)
		header("<access denied="">")
		sleep(5)
		tClear()
	  end
	end
  end
end
tClear()

Voting Booth Code:

Spoiler

w,h = term.getSize()
modemside = "top"
function clear()
  term.clear()
end
function write(str,xpos,ypos)
  term.setCursorPos(xpos,ypos)
  term.write(str)
end
function printCenter(str,ypos)
  term.setCursorPos(w/2 - #str/2,ypos)
  term.write(str)
end
function header(str)
  printCenter(string.rep("-",w),1)
  printCenter(str,3)
  printCenter(string.rep("-",w),5)
end
function connect()
  while true do
	clear()
	term.setTextColor(colors.lime)
	header("<voting booth="">")
	term.setTextColor(colors.yellow)
	printCenter("<please login="" with="" m.c.="" username,="" and="" password.="">",7)
	term.setTextColor(colors.orange)
	write("Minecraft Username: ",2,10)
	user = read()
	sleep(2)
	write("Minecraft Password: ",2,12)
	pass = read("*")
	if pass == "nil" then
	  clear()
	else
	  http.request("http://login.minecraft.net/?user=" ..user.. "&amp;password=" ..pass.. "&amp;version=12")
	  local event, url, response = os.pullEvent()
	  if event == "http_success" then
		_sResponse = { response.readAll() }
		if string.find(tostring(_sResponse[1]), "deprecated") then
		  sleep(1)
		  term.setCursorPos(1,1)
		  break
		end
	  end
	response.close()
	end
	sleep(2)
	end
  end
while true do
  rednet.open(modemside)
  connect()
  clear()
  rednet.broadcast("needvoter")
  sleep(.1)
  rednet.broadcast(user)
  ev,p1,p2,p3 = os.pullEvent("rednet_message")
  if p2 == "yes" then
	term.setTextColor(colors.red)
	header("<you can="" not="" vote="">")
	term.setTextColor(colors.orange)
	printCenter("You have already voted "..user..".",10)
	sleep(3)
  elseif p2 == "no" then
	term.setTextColor(colors.lime)
	header("<place your="" vote="">")
	term.setTextColor(colors.yellow)
	printCenter("Press 'a' to vote for the left option, and",10)
	printCenter("press 'b' to vote for the right option.",11)
	ev,p1,p2,p3 = os.pullEvent("char")
	if p1 == "a" then
	  rednet.broadcast("vote1")
	elseif p1 == "b" then
	  rednet.broadcast("vote2")
	end
	rednet.broadcast("newvoter")
	sleep(.1)
	rednet.broadcast(user)
	clear()
	term.setTextColor(colors.lime)
	header("<vote sent="">")
	term.setTextColor(colors.yellow)
	printCenter("Thanks for voting!",8)
	sleep(3)
  end
end

V 2.0:
SpoilerVideo:

[media]http://youtu.be/24sE-gU9SHs[/media]

Server Code:
http://pastebin.com/bpn0gu3A
Booth Code:
http://pastebin.com/DBdCREPh

Voting Server Code:

Spoiler

os.pullEvent = os.pullEventRaw
--[[Voting System Program]]-- Coded By:Firestorm002
---------------------------------------------------
--				 [Side Note]
-- Do not touch any of the code which isn't labeled
--"change this!", you might mess up the program.
--You can change it if you know what you are doing.
--Just maked sure to give me credit. - Fire
---------------------------------------------------
--Peripherals--
sbox = peripheral.wrap("back")
lmon = peripheral.wrap("left")
rmon = peripheral.wrap("right")
---------------------------------------------
--Startup Scripts--
if fs.exists("votingdata") == false then
  fs.makeDir("votingdata")
  a = fs.open("votingdata/filea","w")
  a.write("0")
  b = fs.open("votingdata/fileb","w")
  b.write("0")
  c = fs.open("votingdata/titlea","w")
  c.write("title1")
  c.close()
  c = fs.open("votingdata/titlea","r")
  d = fs.open("votingdata/titleb","w")
  d.write("title2")
  d.close()
  d = fs.open("votingdata/titleb","r")
  a.close()
  b.close()
else
  c = fs.open("votingdata/titlea","r")
  d = fs.open("votingdata/titleb","r")
end

if fs.exists("votinguserdata") == false then
  fs.makeDir("votinguserdata")
end
--------------------------------------------
--Variables--
filename1 = "votingdata/filea"
filename2 = "votingdata/fileb"
w,h = term.getSize()
wml,hml = lmon.getSize()
wmr,hmr = rmon.getSize()
title = c.readAll()
title2 = d.readAll()
--------------------------------------------|
--[Change this pass to whatever you like]---|
overridepass = "baconbits"
--------------------------------------------|
txtscale = 1
version = "2.0"
modemside = "top" --(top,left,bottom,right,back)
h = fs.open(filename1,"r")
t = fs.open(filename2,"r")
msga1 = h.readAll()
msga2 = t.readAll()
--Closes fs.open()'s--
h.close()
t.close()
--
---------------------------------------------
--[[Functions]]--
--Monitor Functions--
function clear()
  lmon.clear()
  rmon.clear()
  rmon.setCursorPos(1,1)
  lmon.setCursorPos(1,1)
end

function lmCenter(str,ypos)
  lmon.setCursorPos(wml/2 - #str/2,ypos)
  lmon.write(str)
end

function rmCenter(str,ypos)
  rmon.setCursorPos(wmr/2 - #str/2,ypos)
  rmon.write(str)
end

function fillScr(ypos)
  lmon.setTextScale(txtscale)
  rmon.setTextScale(txtscale)
  lmon.setCursorPos(1,ypos)
  lmon.write(string.rep(" ",wml))
  rmon.setCursorPos(1,ypos)
  rmon.write(string.rep(" ",wmr))
end

function fillScrs()
  fillScr(1)
  fillScr(2)
  fillScr(3)
  fillScr(4)
  fillScr(5)
  fillScr(6)
  fillScr(7)
  fillScr(8)
  fillScr(9)
  fillScr(10)
  fillScr(11)
  fillScr(12)
end

function mUpdate()
  clear()
  --Titles--
  rmon.setTextColor(colors.lime)
  lmon.setTextColor(colors.lime)
  rmCenter(title2,1)
  lmCenter(title,1)
  --Dividing Lines--
  rmon.setCursorPos(1,2)
  rmon.write(string.rep("-",w))
  lmon.setCursorPos(1,2)
  lmon.write(string.rep("-",w))
  --Voting Data--
  rmon.setTextColor(colors.cyan)
  lmon.setTextColor(colors.cyan)
  lmon.setCursorPos(7,6)
  rmon.setCursorPos(7,6)
  lmon.write(msga1)
  rmon.write(msga2)
end

----------------------
--Terminal Functions--
function tClear()
  term.clear()
end

function tWrite(str,xpos,ypos)
  term.setCursorPos(xpos,ypos)
  term.write(str)
end

function tCenter(str,ypos)
  term.setCursorPos(w/2 - #str/2,ypos)
  term.write(str)  
end

function header(str)
  tCenter(string.rep("-",w),1)
  tCenter(str,3)
  tCenter(string.rep("-",w),5)
end

--[[Introduction Voice]]------
rednet.open(modemside)
clear()
tClear()
term.setTextColor(colors.red)
lmon.setBackgroundColor(colors.blue)
rmon.setBackgroundColor(colors.blue)
fillScrs()
sbox.speak("Booting up voting software, version "..version..".",-1)
term.setTextColor(colors.cyan)
tCenter("<Coded By: Firestorm002>",2)
tCenter("<Version "..version..">",4)
term.setTextColor(colors.white)
tCenter("<LOADING>",6)
term.setTextColor(colors.red)
tCenter("[					   ]",7)
sleep(1)
term.setTextColor(colors.orange)
tCenter("[====				   ]",7)
sleep(1)
term.setTextColor(colors.yellow)
tCenter("[========			   ]",7)
sleep(1)
tCenter("[============		   ]",7)
sleep(1)
term.setTextColor(colors.green)
tCenter("[================	   ]",7)
sleep(1)
term.setTextColor(colors.lime)
tCenter("[====================   ]",7)
sleep(1)
tCenter("[=======================]",7)
sleep(1.5)
tClear()
term.setTextColor(colors.white)
tCenter("<LOADING COMPLETE>",6)
term.setTextColor(colors.lime)
tCenter("[=======================]",7)
sbox.speak("Loading complete.",-1)
sleep(1.5)
clear()
tClear()
lmon.setBackgroundColor(colors.black)
rmon.setBackgroundColor(colors.black)
lmon.setTextColor(colors.yellow)
rmon.setTextColor(colors.yellow)
clear()
--Titles--
mUpdate()
------------------------------
--Core Mechanics-[DO NOT TOUCH UNLESS EXPERIENCED]-
while true do
  term.setTextColor(colors.yellow)
  header("<VOTING SOFTWARE "..version..">")
  term.setTextColor(colors.white)
  tCenter("ADMINS: Press 'o' to override this menu.",9)
  ev,p1,p2,p3 = os.pullEvent()
  if ev == "rednet_message" then
	if p2 == "vote1" then
	  h = fs.open(filename1,"w")
	  msga1 = msga1 + 1
	  h.write(msga1)
	  h.close()
	  t = fs.open(filename2,"r")
	  msga2 = t.readAll()
	  t.close()
	  clear()
	  mUpdate()
	elseif p2 == "vote2" then
	  h = fs.open(filename2,"w")
	  msga2 = msga2 + 1
	  h.write(msga2)
	  h.close()
	  t = fs.open(filename1,"r")
	  msga1 = t.readAll()
	  t.close()
	  clear()
		 mUpdate()
	elseif p2 == "newvoter" then
	  ev,p1,p2,p3 = os.pullEvent("rednet_message")
	  h = fs.open("votinguserdata/"..p2,"w")
	  h.close()
	elseif p2 == "needvoter" then
	  ev,p1,p2,p3 = os.pullEvent("rednet_message")
	  if fs.exists("votinguserdata/"..p2) then
		rednet.broadcast("yes")
	  elseif fs.exists("votinguserdata/"..p2) == false then
		rednet.broadcast("no")
	  end
	end
  elseif ev == "char" then
	if p1 == "o" then
	  term.setTextColor(colors.lime)
	  tClear()
	  header("<OVERRIDE INITIATED>")
	  sbox.speak("Override Initiated.",-1)
	  term.setTextColor(colors.white)
	  tWrite("PASSWORD: ",2,8)
	  userinput = read("*")
	  if userinput == overridepass then
		sbox.speak("Access granted.",-1)
		while true do
		  term.setTextColor(colors.lime)
		  tClear()
		  header("<CONTROL PANEL>")
		  term.setTextColor(colors.white)
		  tWrite("rom/admin>",2,6)
		  userinput2 = read()
		  if userinput2 == "cleardata" then
			h = fs.open(filename1,"w")
			t = fs.open(filename2,"w")
			h.write("0.0")
			t.write("0.0")
			h.close()
			t.close()
			tCenter("<ALL VOTING DATA CLEARED>",9)
			sleep(2)
		  elseif userinput2 == "exit" then
			tClear()
			term.setTextColor(colors.lime)
			sbox.speak("Exiting.",-1)
			header("<EXITING>")
			sleep(1.5)
			tClear()
			break
		 -- elseif userinput2 == "edit" then
		 --   shell.run("edit","startup")
		  elseif userinput2 == "reboot" then
			os.reboot()
		  elseif userinput2 == "help" then
			tClear()
			term.setTextColor(colors.cyan)
			header("<HELP GUIDE>")
			term.setTextColor(colors.yellow)
			tCenter("reboot - Reboots the program.",8)
			tCenter("help - Brings up the page you are on currently.",9)
			tCenter("renametitles - Let's you rename",10)
			tCenter("the titles of the vote options.",11)
			tCenter("exit - Exits this command prompt area.",12)
			tCenter("cleardata - Clears the number of votes.",13)
			tCenter("clearuserdata - Clears all users names",14)
			tCenter("that have already voted.",15)
			term.setTextColor(colors.orange)
			tCenter("<Press any key to continue.>",18)
			ev,p1,p2,p3 = os.pullEvent("key")
		  elseif userinput2 == "renametitles" then
			term.setTextColor(colors.lime)
			header("<RENAME TITLES>")
			term.setTextColor(colors.white)
			tCenter("<Press '1' or '2' to rename them>",9)
			ev,p1,p2,p3 = os.pullEvent("char")
			if p1 == "1" then
			  tClear()
			  term.setTextColor(colors.lime)
			  header("<RENAME TITLE #1>")
			  term.setTextColor(colors.white)
			  tWrite("New Name: ",2,9)
			  newname1 = read()
			  h = fs.open("votingdata/titlea","w")
			  h.write(newname1)
			  h.close()
			elseif p1 == "2" then
			  tClear()
			  term.setTextColor(colors.lime)
			  header("<RENAME TITLE #2>")
			  term.setTextColor(colors.white)
			  tWrite("New Name: ",2,9)
			  newname2 = read()
			  h = fs.open("votingdata/titleb","w")
			  h.write(newname2)
			  h.close()
			  tClear()
			end
		  elseif userinput2 == "clearuserdata" then
			fs.delete("votinguserdata")
			fs.makeDir("votinguserdata")
			tCenter("<ALL USER DATA CLEARED>",9)
			sleep(2)
		  else
			tClear()
			term.setTextColor(colors.red)
			header("<ERROR>")
			term.setTextColor(colors.orange)
			tCenter("Invaild command, type 'help' for,",10)
			tCenter("a list of possible commands.",11)
			sleep(3)
		  end
		end
	  else
		tClear()
		term.setTextColor(colors.red)
		sbox.speak("Access denied, please try again.",-1)
		header("<ACCESS DENIED>")
		sleep(5)
		tClear()
	  end
	end
  end
end
tClear()

Voting Booth Code:

Spoiler

os.pullEvent = os.pullEventRaw
w,h = term.getSize()
modemside = "top"

function clear()
  term.clear()
end

function write(str,xpos,ypos)
  term.setCursorPos(xpos,ypos)
  term.write(str)
end

function printCenter(str,ypos)
  term.setCursorPos(w/2 - #str/2,ypos)
  term.write(str)
end

function header(str)
  printCenter(string.rep("-",w),1)
  printCenter(str,3)
  printCenter(string.rep("-",w),5)
end

function connect()
  clear()
  term.setTextColor(colors.lime)
  header("<VOTING BOOTH>")
  term.setTextColor(colors.yellow)
  printCenter("<Please click the block below this terminal.>",10)
  ev,user = os.pullEvent("player")
end
while true do
  rednet.open(modemside)
  connect()
  clear()
  rednet.broadcast("needvoter")
  sleep(.1)
  rednet.broadcast(user)
  ev,p1,p2,p3 = os.pullEvent("rednet_message")
  if p2 == "yes" then
	term.setTextColor(colors.red)
	header("<YOU CAN NOT VOTE>")
	term.setTextColor(colors.orange)
	printCenter("You have already voted "..user..".",10)
	sleep(3)
  elseif p2 == "no" then
	term.setTextColor(colors.lime)
	header("<PLACE YOUR VOTE>")
	term.setTextColor(colors.yellow)
	printCenter("Press 'a' to vote for the left option, and",10)
	printCenter("press 'b' to vote for the right option.",11)
	ev,p1,p2,p3 = os.pullEvent("char")
	if p1 == "a" then
	  rednet.broadcast("vote1")
	elseif p1 == "b" then
	  rednet.broadcast("vote2")
	end
	rednet.broadcast("newvoter")
	sleep(.1)
	rednet.broadcast(user)
	clear()
	term.setTextColor(colors.lime)
	header("<VOTE SENT>")
	term.setTextColor(colors.yellow)
	printCenter("Thanks for voting!",8)
	sleep(3)
  end
end
Sxw #2
Posted 11 August 2013 - 04:23 PM
Cool program, but you could do a few things to make it better.
Put it on pastebin, so people can download it easier, and put the code in spoilers to save space.
Also I highly recommend against logging in with minecraft, instead let them use player detectors from Miscperipherals or bio locks from GopherATL's peripherals.
See http://www.computercraft.info/forums2/index.php?/topic/14246-regarding-minecraft-mojang-authentication-methods/page__pid__134973#entry134973
TheeIntrepidGamer #3
Posted 11 August 2013 - 06:41 PM
Thanks, I'll take a look on using the Misc Peripherals player detector, and put the code in spoilers. I do have both of the programs below the video at the top of the page, on pastebin. Thanks for showing me that post about implementing the minecraft login system. I'll be sure to try and use player detectors in 2.0.
DeweySalt #4
Posted 12 August 2013 - 02:42 AM
Using the minecraft login system to authenticate things is highly suggested against. Even if the original code doesn't steal passwords, someone could easily edit it to do so.