Posted 17 January 2015 - 09:11 AM
                Hello!
Currently i am making a program where the client logs in on the host, and the host sends a map to the client (A few checks between it).
Now i am stuck at the part to integrate the touchscreen. I want to read the map through the file, also the touchscreen-positions.
I want to read the file "map1" and place the positions for the touchscreen where 1 stands. (1 is orange i think). But i found no way to do it.
(Map is created by using "paint" on an advanced wireless pocket computer)
The orange button should be used to switch between map1, map2, map3 etc.
Also i want to add buttons inside the map to open/close doors.
All this should be dynamic, that means if i change the layout, it should detect automatically where the buttons should be
                
                    Currently i am making a program where the client logs in on the host, and the host sends a map to the client (A few checks between it).
Now i am stuck at the part to integrate the touchscreen. I want to read the map through the file, also the touchscreen-positions.
Spoiler
--This code is developed by me (onix331) and is available under the GNU General Public License (Version 3)
--For all CC-Versions Universal
--See http://opensource.org/licenses/GPL-3.0
--Have fun
ver = "0.1 Alpha"--For updates
status = "---"--You can modify the init-status that will be transferred to the host at the beginning
--It is usually not necessary to modify the next variables
ishost = "0"
requiredvers = "0.1"
isvers = "0.1"
function clear()--To clear the screen
term.clear()
term.setCursorPos(1,1)
end
function startclient()
clear()
clientid = tostring(os.getComputerID())
rednet.open("back")
hostid = rednet.lookup("TCiP")
if hostid then
  print("Server found! continuining!")
else
  print("Server not found! Might be down right now, please try again later!")
  error()
end
function pair()
  clear()
  print ("Trying to pair with host")
  hostid = rednet.lookup("TCiP")
  rednet.send(hostid, "pair", "TCiP")
  hostid, message, protocol = rednet.receive(0.5)
  if message=="succesfull" then
   print("Succesfully paired, continuing...")
  else
   print("Pairing not successfull, trying again...")
   pair()
  end
end
function getinfo()
  rednet.send(hostid, isvers, "version")
  hostid, message, version = rednet.receive(1)
  if message==nil then
   print("Error, host did not respond in time!")
   error()
  elseif message=="ok" then
   print ("Versioncheck ok")
   getmap()
  else
   print ("Versioncheck not ok, please get the latest version!")
   error()
  end
end
function getmap()
  file = fs.open("map1", "w")
  hostid, map1, TCiP = rednet.receive()
  file.write(map1)
  file.close()
  map1 = paintutils.loadImage("map1")
  clear()
  paintutils.drawImage(map1, 0, 0)
end
function sendinitial()--Send the initial data
  rednet.send(hostid, clientid)
  hostid, message, TCiP = rednet.receive()
  if message=="ok" then
   clear()
   print("Please enter your password!")
   passwd = read()
   rednet.send(hostid, passwd, "pass")
   hostid, response, TCiP = rednet.receive(2)
   if response=="ok" then
	getinfo()
   else
	print ("An error occured. Please reconnect!")
	error()
   end
  else
   print ("Error! Your Computer is not registered!")
   error()
  end
end
--Print header
clear()
print ("Irgendwas by onix331")
print ("Version ", ver)
os.sleep(2)
--Fire up the main program
pair()
sendinitial()
end
function starthost()
print("Initialising...")
rednet.open("top")
rednet.host("TCiP", "authost")
idok = "0"
pwok = "0"
ids = {}
pws = {}
file = fs.open("listedids", "r")
if file then
  local line = file.readLine()
  while line do
   table.insert(ids, line)
   line = file.readLine()
  end
  file.close()
end
file1 = fs.open("passwds", "r")
if file1 then
  local line = file1.readLine()
  while line do
   table.insert(pws, line)
   line = file1.readLine()
  end
  file1.close()
end
function getclientver()
  clientid, clientvers, protocol = rednet.receive(2)
  if clientvers==nil then
   print ("Version check failed")
   receive()
  elseif clientvers==requiredvers then
   print ("Version check ok")
   rednet.send(tonumber(clientid), "ok")
   sendmap()
  end
end
function sendmap()
  file2 = fs.open("map1", "r")
  if file2 then
   rednet.send(tonumber(clientid), file2.readAll())
   file2.close()
  end
  receive()
end
function idcheck()
  senderid, clientid, protocol = rednet.receive(20)
  for i=1,#ids do
   if clientid==ids[i] then
	rednet.send(tonumber(clientid), "ok")
	print("Idcheck ok (", clientid, ")")
	idok = "1"
   end
  end
  if idok=="1" then
   idok = "0"
   passwordcheck()
  else
   rednet.send(tonumber(clientid), "notexist")
   print("Idcheck not ok (", clientid, ")")
   receive()
  end
end
  
function passwordcheck()
  print ("Waiting for pw")
  clientid, passwd, protocol = rednet.receive(10)
  if passwd==nil then
   print ("Client waited too long, continuining...")
   receive()
  end
  for i=1,#pws do
   if passwd==pws[i] then
	rednet.send(tonumber(clientid), "ok")
	pwok = "1"
	print("Passwordcheck ok (", passwd, ")")
	passwd = ""
   end
  end
  if pwok=="1" then
   pwok = "0"
   getclientver()
  else
   rednet.send(tonumber(clientid), "wrong")
   print("Passwordcheck not ok (", passwd, ")")
   receive()
  end
end
function receive()
  while true do
   clientid, message, protocol = rednet.receive(2)
   if message=="pair" then--To pair to the client
	rednet.send(clientid, "succesfull")
	print ("Succesfull paired, continuing...")
	idcheck()
   end
  end
end
clear()
print ("Irgendwas by onix331")
print ("Version ", ver)
print ("Waiting for pair request")
receive()
end
if ishost=="0" then--To find out if program is run as host or client
startclient()
else
starthost()
end
I want to read the file "map1" and place the positions for the touchscreen where 1 stands. (1 is orange i think). But i found no way to do it.
(Map is created by using "paint" on an advanced wireless pocket computer)
The orange button should be used to switch between map1, map2, map3 etc.
Also i want to add buttons inside the map to open/close doors.
											   1
							  0
							  0
							  0
							  0
							  0
							  0
							  0
							  0
							  0
							  0
							  20000000000000000000000000
							  0
1							0
							  0
							  0
							  0
							  0
							  0
							  0
							  0
							  0
(The outstanding 0 seems to be an bug)
All this should be dynamic, that means if i change the layout, it should detect automatically where the buttons should be
Edited on 17 January 2015 - 08:12 AM
                
             
         
                