Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Setup monitor
- local monitor = peripheral.wrap( "left" )
- monitor.clear()
- monitor.setCursorPos( 1, 1 )
- term.clear()
- term.setCursorPos( 1, 1 )
- local intro = "Welcome to the Android MineChat Host Program. This program allows allows a server's player's to communicate with the server's host at any time. Type '$$$' at any time to quit the program. Press 'enter' to begin."
- --Instructions
- term.redirect( peripheral.wrap( "left" ) )
- term.setTextColor( colors.green )
- print( intro )
- print( "" )
- term.setTextColor( colors.blue )
- term.setCursorBlink(true)
- term.redirect( term.native() )
- term.setTextColor( colors.green )
- print( intro )
- print( "" )
- term.setTextColor( colors.blue )
- term.setCursorBlink(true)
- while true do
- local event, key = os.pullEvent( "key" )
- if key == keys.enter then
- break
- end
- end
- --Setup server
- cond = true
- logFile = fs.open( "log", fs.exists( "log" ) and "a" or "w")
- outFile = fs.open( "outputServer", "w" )
- outFile.write( "Server is Connected" )
- outFile.write( "" )
- outFile.close()
- --Function for printing the server input
- function output()
- while true do
- sleep(0)
- if fs.exists( "inputServer" ) == true and fs.getSize( "inputServer" ) > 0 then
- sleep(0)
- inFile = fs.open( "inputServer", "r" )
- while fs.exists( "inputServer" ) == true do
- local serverText = inFile.readAll()
- if serverText ~= nil then
- term.redirect( peripheral.wrap( "left" ) )
- term.setTextColor( colors.red )
- print( serverText )
- print( "" )
- term.redirect( term.native() )
- term.setTextColor( colors.red )
- print( serverText )
- print("")
- logFile.write( serverText )
- logFile.writeLine()
- term.setTextColor( colors.blue )
- fs.delete( "inputServer" )
- end
- end
- inFile.close()
- end
- end
- end
- --Function for server output
- function input()
- while true do
- local text = read()
- if ( text ~= nil ) and ( text ~= "$$$" ) and ( text ~= "" )then
- term.redirect( peripheral.wrap( "left" ) )
- term.setTextColor( colors.blue )
- print( "User: "..text )
- print( "" )
- term.redirect( term.native() )
- if fs.exists( "outputServer" ) == false then
- outFile = fs.open( "outputServer", "w" )
- else
- outFile = fs.open( "outputServer", "a" )
- end
- outFile.write( "Server: "..text )
- outFile.writeLine()
- outFile.close()
- logFile.write( "User: "..text )
- logFile.writeLine()
- text = nil
- end
- if text == "$$$" then
- cond = false
- return
- end
- end
- end
- --Function for scrolling (unused)
- function scroll()
- while true do
- local event, key = os.pullEvent( "key" )
- if key == keys.up then
- term.redirect( peripheral.wrap( "left" ) )
- term.scroll( 1 )
- term.redirect( term.native() )
- end
- if key == keys.down then
- term.redirect( peripheral.wrap( "left" ) )
- term.scroll( -1 )
- term.redirect( term.native() )
- end
- end
- end
- --Main body
- while cond do
- parallel.waitForAny( output, input )
- end
- --Clean up
- fs.delete( "inputServer" )
- logFile.write("------------------------------------\n")
- inFile = fs.open( "inputServer", "w" )
- outFile = fs.open( "outputServer", "w" )
- outFile.write( "Server is not Connected" )
- outFile.close()
- inFile.close()
- logFile.close()
- term.clear()
- term.setCursorPos( 0, 0 )
- monitor.clear()
- monitor.setCursorPos( 1, 1 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement