-- TOMOYO I
-- SERVER
-- Developed by Dotsonface / qwzx11 (qwzx11 is my minecraft username)
-- V1.0.1
--[[
Version History:
0.2b Pre-Release B
1.0.0 Initial Release
1.0.1 Single Configuration Mode
Usage:
You will be asked where your modem is located, if not specified the computer will not be able to make a connection. Then once that is completed, You will
be asked what mode to set the server on, there are 2 modes: Private, and Public. Public works currently and private is very outdated and will be fixed later.
Server Modes:
Public ::
--->User Finding Mode
--->Waiting for users
--->User is found
--->Go to Find Prompt
--->Find Prompt
--->Ask for permission to wait for more users.
--- Y = Go to User Finding Mode
--- N = Go to Server Mode
--->Server Mode
--->Display chat
--- W = Go to User Finding Mode
--- C = Go to Command Mode
--- CTRL+T = Terminate
--->Command Mode
--->Act as an administrative mode.
--- help = Brings up list of commands
--- help *command* = Brings up description of how to use command
--- list = Lists all users currently online and their computer id's
--- server = Go to Server Mode
--- wait = Go to User Finding Mode
--]]
term.clear()
term.setCursorPos(1, 1)
print("Tomoyo Server I v1.0.1 - Config")
print("Where is your wireless modem located?")
local rednet_location
rednet_location = io.read()
if rednet_location == "left" then
print("Connected")
elseif rednet_location == "right" then
print("Connected")
elseif rendet_location == "back" then
print("Connected")
else
print("NOT VALID")
end
term.clear()
rednet.open(rednet_location) -- Open Internet
local mode
local server_name
local user1id
local user2id
local user3id
local user4id
local user5id
local user1
local user2
local user3
local user4
local user5
local banned1id
local banned2id
local banned3id
local banned4id
local banned5id
print("Name server.")
server_name = io.read()
term.clear()
user1id = ""
user2id = ""
user3id = ""
user4id = ""
user5id = ""
user1 = ""
user2 = ""
user3 = ""
user4 = ""
user5 = ""
function select_mode ()
print("Please select your mode.")
mode = io.read()
if mode == "help" then
print("Mode List: ")
print("private")
print("public")
print("public ignore") -- NEW
select_mode()
elseif mode == "private" then
print("Select User 1.")
user1id = io.read()
print("Select User 2.")
user2id = io.read()
user1id = tonumber(user1id)
user2id = tonumber(user2id)
timeline=0
server()
elseif mode == "public" then
print("Opening...")
timeline=0
auto_answer=0
users_wait=1
server_public()
elseif mode == "public ignore" then
print("Opening...")
print("How many users to wait for?")
users_wait = tonumber(io.read())
if users_wait >= 5 then
users_wait = 5
end
os.sleep(1)
print("Waiting for users to connect!")
os.sleep(2)
term.clear()
term.setCursorPos(1, 1)
print("Tomoyo Server I v1.0.1 - User-Finding Mode")
timeline=0
auto_answer = 1
server_public()
else
print("Invalid mode, type 'help' for a list of modes.")
os.sleep(1)
select_mode()
end
end
-- Private Server v1.0.1
function server ()
while timeline == 0 do
action, senderID, text = os.pullEvent()
if action == "rednet_message" then
if senderID == user1id then
if user1 ~= "" then
rednet.send(senderID, "006")
print("Returned: In User-Finding Mode.")
else
user1 = text
rednet.send(senderID, "001")
if user2 ~= "" then
timeline = 1
else
print("Waiting on other user.")
end
end
elseif senderID == user2id then
if user2 ~= "" then
rednet.send(senderID, "006")
print("Returned: In User-Finding Mode.")
else
user2 = text
rednet.send(senderID, "001")
if user1 ~= "" then
timeline = 1
else
print("Waiting on other user.")
end
end
else
rednet.send(senderID, "004")
print("Returned: Access Denied!")
end
elseif action == "char" then
if senderID == "s" or senderID == "S" then
print("Skipping to server!")
os.sleep(1)
term.clear()
timeline = 1
elseif senderID == "c" or senderID == "C" then
print("Going to console!")
os.sleep(1)
term.clear()
print("Tomoyo Server I V1.0.0")
timeline = 2
end
end
end
while timeline == 1 do
action, senderID, text = os.pullEvent()
if action == "rednet_message" then
if senderID == user1id then
rednet.send(user1id, "001")
print(user1 .. ": " .. text)
rednet.send(user2id, user1 .. ": " .. text)
elseif senderID == user2id then
rednet.send(user2id, "001")
print(user2 .. ": " .. text)
rednet.send(user1id, user2 .. ": " .. text)
else
rednet.send(senderID, "004")
end
elseif action == "char" then
if senderID == "r" or senderID == "R" then
print("Resetting!")
user1id = ""
user2id = ""
user1 = ""
user2 = ""
select_mode()
elseif senderID == "c" or senderID == "C" then
print("Administrative Mode")
os.sleep(3)
term.clear()
term.setCursorPos(1, 1)
print("Tomoyo Server I V1.0.0")
timeline=2
end
end
end
while timeline == 2 do
command = io.read()
if command == "help" then
print("reset list switch save help server reset_names version")
elseif command == "version" then -- Version 1.0.1
print("Tomoyo Server I v1.0.1")
elseif command == "reset" then
print("Resetting!")
user1id = ""
user2id = ""
user1 = ""
user2 = ""
select_mode()
elseif command == "list" then
print("Computer ID: " .. user1id .. " registered with username: " .. user1)
print("Computer ID: " .. user2id .. " registered with username: " .. user2)
elseif command == "switch" then
print("Select User 1")
user1id = tonumber(io.read())
print("Select User 2")
user2id = tonumber(io.read())
if user1id ~= "" then
print("User 1 test: Success!")
else
print("User 1 test: Failure!")
end
if user2id ~= "" then
print("User 2 test: Success!")
else
print("User 2 test: Failure!")
end
elseif command == "save" then
print("Test 1...")
rednet.broadcast("001")
os.sleep(1)
print("Test 2...")
rednet.broadcast("001")
os.sleep(1)
print("Test 3...")
rednet.broadcast("001")
os.sleep(1)
print("Test 4...")
rednet.broadcast("001")
os.sleep(1)
print("Test 5...")
rednet.broadcast("001")
print("Completed!")
elseif command == "server" then
print("Running main server!")
os.sleep(3)
term.clear()
term.setCursorPos(1, 1)
timeline=1
elseif command == "reset_names" then
print("Resetting names...")
user1 = ""
user2 = ""
print("Waiting for user input...")
timeline=0
elseif command == "help reset" then
print("Resets the entire server, to beginning to select mode.")
elseif command == "help list" then
print("Lists the connected users.")
elseif command == "help save" then
print("A safety measure to prevent computers from freezing.")
elseif command == "help switch" then
print("Allows you to reselect who can connect to the server.")
elseif command == "help server" then
print("Returns to the main server.")
elseif command == "help reset_names" then
print("Waits for the users to change their names.")
else
print("Invalid command.")
end
end
server()
end
-- MOST RECENT VERSION
function server_public ()
-- USER FINDING MODE
while timeline==0 do
action, senderID, text = os.pullEvent()
if action == "rednet_message" then
if user1id == "" then
-- Tomoyo Security Block V1.0.0 :: Banned List
if senderID == banned1id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned2id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned3id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned4id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned5id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
else
user1id = senderID
user1 = text
print(text .. " has logged in with computer id " .. senderID)
rednet.send(senderID, "001")
if auto_answer == 0 then
timeline=1
else
if users_wait == 1 then
print("Main server mode!")
timeline=2
end
end
end
elseif user2id == "" then
if senderID == user1id then
rednet.send(user1id, "006")
elseif senderID == user3id then
rednet.send(user3id, "006")
elseif senderID == user4id then
rednet.send(user4id, "006")
elseif senderID == user5id then
rednet.send(user5id, "006")
else
-- Tomoyo Security Block V1.0.0 :: Banned List
if senderID == banned1id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned2id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned3id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned4id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned5id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
else
user2id = senderID
user2 = text
print(text .. " has logged in with computer id " .. senderID)
rednet.send(senderID, "001")
if auto_answer == 0 then
timeline=1
else
if users_wait == 2 then
print("Main server mode!")
timeline=2
end
end
end
end
elseif user3id == "" then
if senderID == user1id then
rednet.send(user1id, "006")
elseif senderID == user2id then
rednet.send(user2id, "006")
elseif senderID == user4id then
rednet.send(user4id, "006")
elseif senderID == user5id then
rednet.send(user5id, "006")
else
-- Tomoyo Security Block V1.0.0 :: Banned List
if senderID == banned1id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned2id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned3id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned4id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned5id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
else
user3id = senderID
user3 = text
print(text .. " has logged in with computer id " .. senderID)
rednet.send(senderID, "001")
if auto_answer == 0 then
timeline=1
else
if users_wait == 3 then
print("Main server mode!")
timeline=2
end
end
end
end
elseif user4id == "" then
if senderID == user1id then
rednet.send(user1id, "006")
elseif senderID == user2id then
rednet.send(user2id, "006")
elseif senderID == user3id then
rednet.send(user3id, "006")
elseif senderID == user5id then
rednet.send(user5id, "006")
else
-- Tomoyo Security Block V1.0.0 :: Banned List
if senderID == banned1id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned2id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned3id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned4id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned5id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
else
user4id = senderID
user4 = text
print(text .. " has logged in with computer id " .. senderID)
rednet.send(senderID, "001")
if auto_answer == 0 then
timeline=1
else
if users_wait == 4 then
print("Main server mode!")
timeline=2
end
end
end
end
elseif user5id == "" then
if senderID == user1id then
rednet.send(user1id, "006")
elseif senderID == user2id then
rednet.send(user2id, "006")
elseif senderID == user3id then
rednet.send(user3id, "006")
elseif senderID == user4id then
rednet.send(user4id, "006")
else
-- Tomoyo Security Block V1.0.0 :: Banned List
if senderID == banned1id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned2id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned3id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned4id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
elseif senderID == banned5id then
rednet.send(senderID, "008")
if blockmessage ~= "Y" then
print("BLOCKED")
blockmessage = "Y"
end
else
user1id = senderID
user1 = text
print(text .. " has logged in with computer id " .. senderID)
rednet.send(senderID, "001")
print("Out of user slots.")
print("Running main server!")
os.sleep(2)
term.clear()
term.setCursorPos(1,1)
print("Tomoyo Server I v1.0.1 - Main Server Mode")
timeline = 2
end
end
else
print("Returned: Critical Error")
rednet.send(senderID, "010")
timeline=1
end
end
end
-- WAIT PROMPT MODE
while timeline==1 do
print("Wait for more users?")
command = io.read()
if command == "help" then
print("try y/n, y being Yes and n being No.")
elseif command == "y" then
print("Waiting for more users.")
os.sleep(1)
term.clear()
timeline=0
elseif command == "n" then
if user2id == "" then
print("Must wait for more users, only 1 user is logged in with id: " .. user1id .. " and name: " .. user1 .. ".")
else
print("Running main server!")
os.sleep(1)
term.clear()
timeline=2
end
else
print("Invalid command, type help for some help.")
end
end
-- SERVER MODE
while timeline==2 do
action, senderID, text = os.pullEvent()
if action == "rednet_message" then
if senderID == user1id then
if text == "LOGOFF" then
print("User 1 has logged off.")
user1id = ""
user1 = ""
-- User Log Off Fix v1.0.0
if user2id ~= "" then
user1id = user2id
user1 = user2
if user3id ~= "" then
user2id = user3id
user2 = user3
if user4id ~= "" then
user3id = user4id
user3 = user4
if user5id ~= "" then
user4id = user5id
user4 = user5
user5id = ""
user5 = ""
else
user4id = ""
user4 = ""
end
else
user3id = ""
user3 = ""
end
else
user2id = ""
user2 = ""
end
else
print("Waiting for more users.")
timeline = 0
end
if auto_answer == 0 then
print("Do you wish to wait for more users?")
command = io.read()
if command == "y" then
print("Waiting for more users.")
os.sleep(1)
term.clear()
timeline=0
elseif command == "n" then
print("No action taken.")
else
print("No action taken.")
end
else
print("No action taken.")
end
else
print(user1 .. ": " .. text)
rednet.send(senderID, "001")
if user1id ~= "" then
rednet.send(user1id, user1 .. ": " .. text)
end
if user2id ~= "" then
rednet.send(user2id, user1 .. ": " .. text)
end
if user3id ~= "" then
rednet.send(user3id, user1 .. ": " .. text)
end
if user4id ~= "" then
rednet.send(user4id, user1 .. ": " .. text)
end
if user5id ~= "" then
rednet.send(user5id, user1 .. ": " .. text)
end
end
elseif senderID == user2id then
if text == "LOGOFF" then
print("User 2 has logged off.")
user2id = ""
user2 = ""
-- User Log Off Fix v1.0.0
if user3id ~= "" then
user2id = user3id
user2 = user3
if user4id ~= "" then
user3id = user4id
user3 = user4
if user5id ~= "" then
user4id = user5id
user4 = user5
user5id = ""
user5 = ""
else
user4id = ""
user4 = ""
end
else
user3id = ""
user3 = ""
end
end
if auto_answer == 0 then
print("Do you wish to wait for more users?")
command = io.read()
if command == "y" then
print("Waiting for more users.")
os.sleep(1)
term.clear()
timeline=0
elseif command == "n" then
print("No action taken.")
else
print("No action taken.")
end
else
print("No action taken.")
end
else
print(user2 .. ": " .. text)
rednet.send(senderID, "001")
if user1id ~= "" then
rednet.send(user1id, user2 .. ": " .. text)
end
if user2id ~= "" then
rednet.send(user2id, user2 .. ": " .. text)
end
if user3id ~= "" then
rednet.send(user3id, user2 .. ": " .. text)
end
if user4id ~= "" then
rednet.send(user4id, user2 .. ": " .. text)
end
if user5id ~= "" then
rednet.send(user5id, user2 .. ": " .. text)
end
end
elseif senderID == user3id then
if text == "LOGOFF" then
print("User 3 has logged off.")
user3id = ""
user3 = ""
-- User Log Off Fix v1.0.0
if user4id ~= "" then
user3id = user4id
user3 = user4
if user5id ~= "" then
user4id = user5id
user4 = user5
user5id = ""
user5 = ""
else
user4id = ""
user4 = ""
end
end
if auto_answer == 0 then
print("Do you wish to wait for more users?")
command = io.read()
if command == "y" then
print("Waiting for more users.")
os.sleep(1)
term.clear()
timeline=0
elseif command == "n" then
print("No action taken.")
else
print("No action taken.")
end
else
print("No action taken.")
end
else
print(user3 .. ": " .. text)
rednet.send(senderID, "001")
if user1id ~= "" then
rednet.send(user1id, user3 .. ": " .. text)
end
if user2id ~= "" then
rednet.send(user2id, user3 .. ": " .. text)
end
if user3id ~= "" then
rednet.send(user3id, user3 .. ": " .. text)
end
if user4id ~= "" then
rednet.send(user4id, user3 .. ": " .. text)
end
if user5id ~= "" then
rednet.send(user5id, user3 .. ": " .. text)
end
end
elseif senderID == user4id then
if text == "LOGOFF" then
print("User 4 has logged off.")
user4id = ""
user4 = ""
-- User Log Off Fix v1.0.0
if user5id ~= "" then
user4id = user5id
user4 = user5
user5id = ""
user5 = ""
end
if auto_answer == 0 then
print("Do you wish to wait for more users?")
command = io.read()
if command == "y" then
print("Waiting for more users.")
os.sleep(1)
term.clear()
timeline=0
elseif command == "n" then
print("No action taken.")
else
print("No action taken.")
end
else
print("No action taken.")
end
else
print(user4 .. ": " .. text)
rednet.send(senderID, "001")
if user1id ~= "" then
rednet.send(user1id, user4 .. ": " .. text)
end
if user2id ~= "" then
rednet.send(user2id, user4 .. ": " .. text)
end
if user3id ~= "" then
rednet.send(user3id, user4 .. ": " .. text)
end
if user4id ~= "" then
rednet.send(user4id, user4 .. ": " .. text)
end
if user5id ~= "" then
rednet.send(user5id, user4 .. ": " .. text)
end
end
elseif senderID == user5id then
if text == "LOGOFF" then
print("User 5 has logged off.")
user5id = ""
user5 = ""
if auto_answer == 0 then
print("Do you wish to wait for more users?")
command = io.read()
if command == "y" then
print("Waiting for more users.")
os.sleep(1)
term.clear()
timeline=0
elseif command == "n" then
print("No action taken.")
else
print("No action taken.")
end
else
print("No action taken.")
end
else
print(user5 .. ": " .. text)
rednet.send(senderID, "001")
if user1id ~= "" then
rednet.send(user1id, user5 .. ": " .. text)
end
if user2id ~= "" then
rednet.send(user2id, user5 .. ": " .. text)
end
if user3id ~= "" then
rednet.send(user3id, user5 .. ": " .. text)
end
if user4id ~= "" then
rednet.send(user4id, user5 .. ": " .. text)
end
if user5id ~= "" then
rednet.send(user5id, user5 .. ": " .. text)
end
end
else
rednet.send(senderID, "007")
print("Someone tried to connect without being logged on, do you wait to wait for log-in information?")
if auto_answer == 0 then
command = io.read()
if command == "y" then
print("Waiting for more users...")
os.sleep(1)
term.clear()
timeline=0
elseif command == "n" then
print("Taking no action.")
else
print("Taking no action.")
end
else
print("Auto Answer: No")
end
end
elseif action == "char" then
if senderID == "c" then
print("Administrative mode...")
print("While in this mode, no one can connect to the server!")
os.sleep(3)
term.clear()
term.setCursorPos(1, 1)
print("Tomoyo Server I v1.0.0")
timeline=3
elseif senderID == "w" then
print("Waiting for more users.")
os.sleep(1)
term.clear()
timeline=0
else
print("Key:" .. senderID .. " was pressed.")
end
end
end
-- COMMAND PROMPT MODE
while timeline==3 do
command = io.read()
if command == "help" then
print("wait server help list ban banlist version")
elseif command == "version" then -- Version 1.0.1
print("Tomoyo Server I v1.0.1")
elseif command == "server" then
print("Main server mode...")
os.sleep(3)
term.clear()
timeline=2
elseif command == "ban" then
if ban1id ~= "" then
if ban2id ~= "" then
if ban3id ~= "" then
if ban4id ~= "" then
if ban5id ~= "" then
print("Cannot ban anymore computers.")
else
print("Type in the computer ID to ban.")
ban5id = tonumber(io.read())
end
else
print("Type in the computer ID to ban.")
ban4id = tonumber(io.read())
end
else
print("Type in the computer ID to ban.")
ban3id = tonumber(io.read())
end
else
print("Type in the computer ID to ban.")
ban2id = tonumber(io.read())
end
else
print("Type in the computer ID to ban.")
ban1id = tonumber(io.read())
end
elseif command == "banlist" then
if ban1id ~= "" then
print("Computer ID: " .. ban1id .. " is banned.")
end
if ban2id ~= "" then
print("Computer ID: " .. ban2id .. " is banned.")
end
if ban3id ~= "" then
print("Computer ID: " .. ban3id .. " is banned.")
end
if ban4id ~= "" then
print("Computer ID: " .. ban4id .. " is banned.")
end
if ban5id ~= "" then
print("Computer ID: " .. ban5id .. " is banned.")
end
elseif command == "wait" then
print("Waiting for more users...")
os.sleep(3)
term.clear()
timeline=0
elseif command == "list" then
if user1id ~= "" then
print("Computer " .. user1id .. " logged in with username " .. user1 .. ".")
end
if user2id ~= "" then
print("Computer " .. user2id .. " logged in with username " .. user2 .. ".")
end
if user3id ~= "" then
print("Computer " .. user3id .. " logged in with username " .. user3 .. ".")
end
if user4id ~= "" then
print("Computer " .. user4id .. " logged in with username " .. user4 .. ".")
end
if user5id ~= "" then
print("Computer " .. user5id .. " logged in with username " .. user5 .. ".")
end
elseif command == "help list" then
print("Lists all the users connected to the server.")
elseif command == "help wait" then
print("Activates User-Finding Mode.")
elseif command == "help server" then
print("Returns to the main server.")
elseif command == "help ban" then -- Version 1.0.0
print("Prevents a user from connecting to the server.")
elseif command == "help banlist" then -- Version 1.0.0
print("Lists all banned players.")
else
print("Unknown method error.")
end
end
server_public()
end
select_mode()