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

Factionet Chat Program

Started by margeobur, 19 August 2013 - 11:58 PM
margeobur #1
Posted 20 August 2013 - 01:58 AM
Hello all. I'm making a new chat program called FactioNET (am I allowed to have this name?) designed for groups of tekkit/FTB players who want a private chat in their town/faction. This is gonna be it's main page until it's complete. Here's a screenshot:



The program is going to have a server and client, but they're rolled into one program.

What I want to know, is should each player have their own password so that only they can use that username? Or should the server just have one password so that it's secure from other people who the users don't want it to be used by?
margeobur #2
Posted 20 August 2013 - 04:00 PM
I got three questions:
Is there a way to write to a file on a certain line?

If not, would loading the entire conents of a file to a string to edit it with more control be a good idea or would It require far too much resources?

If it is ok, then is there a way to insert a substring into a string at a certain Indice?
Exerro #3
Posted 21 August 2013 - 07:08 AM
I got three questions:
Is there a way to write to a file on a certain line?

If not, would loading the entire conents of a file to a string to edit it with more control be a good idea or would It require far too much resources?

If it is ok, then is there a way to insert a substring into a string at a certain Indice?
Load the lines of a file, then just do lines[the_line_you_want_to_change] = the_text_you_want and then save it back to the file.

-snip-
What I want to know, is should each player have their own password so that only they can use that username? Or should the server just have one password so that it's secure from other people who the users don't want it to be used by?
I would suggest just having a server password so everyone in the faction can be told the password and log on hassle free
margeobur #4
Posted 22 August 2013 - 03:01 AM
I got three questions:
Is there a way to write to a file on a certain line?

If not, would loading the entire conents of a file to a string to edit it with more control be a good idea or would It require far too much resources?

If it is ok, then is there a way to insert a substring into a string at a certain Indice?
Load the lines of a file, then just do lines[the_line_you_want_to_change] = the_text_you_want and then save it back to the file.

Do you mean using fs.readLine() or is there a way to load/save specific lines of a file?

-snip-
What I want to know, is should each player have their own password so that only they can use that username? Or should the server just have one password so that it's secure from other people who the users don't want it to be used by?
I would suggest just having a server password so everyone in the faction can be told the password and log on hassle free

Mm, I agree. That's the better option for what I want to do as it will be secure. It'll also make the login process a whole lot simpler. :)/>
margeobur #5
Posted 22 August 2013 - 09:25 PM
Never mind, I created the following two functions:

local function getLine(filePath,lineNumber)
if not fs.exists(filePath) then
  return false
end
local text = ""
local fileHandle = fs.open(filePath, "r")
for i=1,lineNumber do
  text = fileHandle.readLine()
  if not text then
   break
  end
end
fileHandle.close()
if not text then
  return nil
end
end

local function writeLine(filePath,lineNumber,newText)
if not fs.exists(filePath) then
  return false
end
if type(newText) ~= "string" then
  return false
end
local beforeLine, afterLine = "", ""
local currentLine, i, j = 1, 0, 0   -- i will be the indice of
local fileHandle = fs.open(filePath, "r") -- our wanted newline and j
local wholeFile = fileHandle.readAll()  -- will be the indice of the
fileHandle.close()       -- next newline
for w in string.gmatch(wholeFile, "%a") do
  if w == "\n" then
   currentLine = currentLine + 1
  end
  if currentLine <= lineNumber then
   i = i + 1
  end
  if currentLine <= lineNumber + 1 then
   j = j + 1
  end
end
if currentLine < lineNumber then -- i.e. if lineNumber is past the file
  return nil
else
  beforeLine = string.sub(wholeFile, 1 [, i])
  afterLine = string.sub(wholeFile, j)
  wholeFile = beforeLine .. newText .. afterLine
  fileHandle = fs.open(filePath, "w")
  fileHandle.write(wholeFile)
  fileHandle.close()
  return true -- returns true on success
end
end

The first one simply reads the lines until the desired line is in text.
The second one looks for the indices of our line in wholeFile, loads the text before and after into strings and rewrites wholeFile with the new text. It then writes the file again.
I dunno it seems kinda dodgey like there's a high chance of errors/bugs. Oh well, hopefully they work.
supersammy00 #6
Posted 23 August 2013 - 12:24 AM
you should be able to make a group with it own admin and assigns the accounts to work with that network. all of the accounts have passwords.
margeobur #7
Posted 23 August 2013 - 10:15 PM
you should be able to make a group with it own admin and assigns the accounts to work with that network. all of the accounts have passwords.

Hmm… I'll think about it. That's something I can put in later so I might make a finished, working version then explore that afterwards.