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

[Request] Inter-world Chatroom

Started by LDDestroier, 31 July 2014 - 08:08 PM
LDDestroier #1
Posted 31 July 2014 - 10:08 PM
Hey, I found out that floppy disks of the same color and the same label always have the same data, so I was thinking: Could anybody make a chatroom/web server off of this? This would help in my space server a lot, since there are many worlds and space is big. Somebody please make a chatroom with different channels that puts data on a labeled floppy and reads from another identical floppy to get the chat log!
Cranium #2
Posted 31 July 2014 - 10:15 PM
Moved to General, for program request.
Geforce Fan #3
Posted 03 August 2014 - 04:23 AM
holy… You're saying store information in floppy names….
that sounds brilliant if it actually works and never gets patched to some 16 characters!
testing right now
edit: Yup, stored exactly 3518 bytes without a problem then added another character and had no issue. Added 2 more characters, still no issue. You sir, are one brilliant person.
edit2: tested and confirmed you can store at least 112640 bytes. I then went insane and tried 230 megabytes(of a repeated character, of course!). This caused the computer to simply reboot and the label was never applied I took it down and tried 7.2MB and it worked just fine. be careful with storing data this way, and bewarned it will certainly be patched.
Now, about storing chat logs on this. first of all I'd like to say that this is an invasion of privacy, so please warn people you're recording chat. depending on the server you are on, moderators may not like this. Logging all chats will also use up quite a lot of space over time on the server. But what peripherals do you have?
Edited on 03 August 2014 - 05:13 AM
LDDestroier #4
Posted 03 August 2014 - 06:48 PM
I have OpenPeripherals, but I plan on getting rid of it as I don't use it. Also, I plan on saving data on identical floppies that have the same label, not in the label itself. That may be what you meant, but I was a bit confused with "holy… You're saying store information in floppy names…." On my server, I configured floppy disks to store a lot of information, more than my hard drive (probably). Any chatroom should have the ability to clear logs.
Geforce Fan #5
Posted 03 August 2014 - 10:37 PM
oh… well the label itsself will be a lot more useful because it has no limit. This is certainly going to be patched
If you don't mind a month's wait, I will be releasing a storage system using floppies

nvm, you said you set floppy disks to store a lot of data.
You cannot log chats with only openperipheral. sorry.
Edited on 03 August 2014 - 08:38 PM
LDDestroier #6
Posted 03 August 2014 - 11:04 PM
No, the chatlogs would be text files on the floppy disk which would be read by other computers with the identical floppy disk!
KingofGamesYami #7
Posted 04 August 2014 - 04:53 AM
I believe LDDestroier is trying to say this:
He wants a system where each connected computer has a disk.
The disks are labeled the same.
The computers will write to a certain file, hence the 'chat log'.
The computers will also read the file contents, and display them.

The flaw:
There is no "file_change" event or some such, you would have to read files constantly to get the chat.

That being said, here's an idea of how to proceed:

local side = peripheral.find( "disk" ) --#CC 1.6+ only
if not disk.getLabel( side ) then
 disk.setLabel( side, "Inter-World" )
end
local chat = fs.combine( disk.getMountPath( side ), "chatlog" )

local function checkUpdates()
  local oldData
  while true do
    local file = fs.open( chat, "r" )
    local data = file.readAll()
    file.close()
    if data ~= oldData then
      os.queueEvent( "chat", data )
      os.pullEvent()
      oldData = data
    end
    sleep( 0.1 ) --#sleep for a tick
  end
end

local function updateScreen()
  while true do
    local event, data = os.pullEvent( "chat" )
    for message in data:gmatch( "[^\r\n]+" ) do
      print( message )
    end
  end
end

local function getInput()
  while true do
    local input = read()
    local file = fs.open( chat, "a" )
    file.writeLine( input )
    file.close()
  end
end

parallel.waitForAny( checkUpdates, updateScreen, getInput )
I'm no good at doing GUI like stuff, but here's a general idea of the file system/disk system
Edited on 04 August 2014 - 03:09 AM
MatthewC529 #8
Posted 04 August 2014 - 07:28 AM
If King is right then this is actually relatively simple to do with Parallel. I had done something similar where I didn't even need parallel. I did it differently (where only upon receiving a rednet message a file write would occur) because if you constantly are updating and reading from a file it is POSSIBLE that a server restart will cause an issue since ComputerCraft has no Persistence.

But then again it depends on if you are planning on using Rednet… you can specify specific messages indicating what function to run and the actual message can either be appended on to the Rednet message or sent immediately after the Rednet Message, which is probably simpler. append the message onto the Chat Log and read the chat log to be displayed on the screen.

This is the basic idea on how I would go forward (and how I have in the past), sorry I do not have the time to write a working example…
LDDestroier #9
Posted 04 August 2014 - 03:48 PM
I believe LDDestroier is trying to say this:
He wants a system where each connected computer has a disk.
The disks are labeled the same.
The computers will write to a certain file, hence the 'chat log'.
The computers will also read the file contents, and display them.

The flaw:
There is no "file_change" event or some such, you would have to read files constantly to get the chat.

That being said, here's an idea of how to proceed:

local side = peripheral.find( "disk" ) --#CC 1.6+ only
if not disk.getLabel( side ) then
disk.setLabel( side, "Inter-World" )
end
local chat = fs.combine( disk.getMountPath( side ), "chatlog" )

local function checkUpdates()
  local oldData
  while true do
	local file = fs.open( chat, "r" )
	local data = file.readAll()
	file.close()
	if data ~= oldData then
	  os.queueEvent( "chat", data )
	  os.pullEvent()
	  oldData = data
	end
	sleep( 0.1 ) --#sleep for a tick
  end
end

local function updateScreen()
  while true do
	local event, data = os.pullEvent( "chat" )
	for message in data:gmatch( "[^\r\n]+" ) do
	  print( message )
	end
  end
end

local function getInput()
  while true do
	local input = read()
	local file = fs.open( chat, "a" )
	file.writeLine( input )
	file.close()
  end
end

parallel.waitForAny( checkUpdates, updateScreen, getInput )
I'm no good at doing GUI like stuff, but here's a general idea of the file system/disk system

You nailed it. By the way, I DO natively speak English, for those who consider otherwise.