Files

ChatMain.src
  • import_code("/root/deadlockbuild/libs/chat.src")
  • import_code("/root/deadlockbuild/libs/chatbox.src")
  • ChatBox.chat = new Chat
  • ChatBox.chat.init()
  • clear_screen
  • while true
  • ChatBox.print_messages()
  • end while
ChatInput.src
  • import_code("/root/deadlockbuild/libs/chat.src")
  • import_code("/root/deadlockbuild/libs/chatform.src")
  • ChatForm.chat = new Chat
  • ChatForm.chat.init()
  • while true
  • clear_screen
  • message = user_input(ChatForm.user["name"] + " > ")
  • if message.replace(" ", "") == 0 then continue
  • ChatForm.send_message(message.trim)
  • end while
libs/Chat.src
  • Chat = {}
  • Chat.shell = get_shell
  • Chat.computer = null
  • Chat.chat_folder_path = current_path
  • Chat.chat_folder_name = "general"
  • Chat.chat_folder = null
  • Chat.init = function()
  • self.computer = self.shell.host_computer
  • self.chat_folder_full_path = self.chat_folder_path + "/" + self.chat_folder_name
  • if self.computer.File(self.chat_folder_full_path) == null then
  • self.computer.create_folder(self.chat_folder_path, self.chat_folder_name)
  • end if
  • self.chat_folder = self.computer.File(self.chat_folder_full_path)
  • end function
libs/ChatForm.src
  • ChatForm = {}
  • ChatForm.chat = null
  • ChatForm.user = {"name": "Guest"}
  • ChatForm.send_message = function(message_content)
  • message_id = self.get_last_message_id + 1
  • self.chat.computer.touch(self.chat.chat_folder_full_path, message_id+"")
  • message_file = self.chat.computer.File(self.chat.chat_folder_full_path + "/" + message_id)
  • message_file.set_content(message_content)
  • end function
  • ChatForm.get_last_message_id = function()
  • if self.chat.chat_folder.get_files.len == 0 then return 0
  • return self.chat.chat_folder.get_files[-1].name.to_int
  • end function
libs/ChatBox.src
  • ChatBox = {}
  • ChatBox.chat = null
  • ChatBox.printed_messages = []
  • ChatBox.print_messages = function()
  • messages = self.chat.chat_folder.get_files
  • new_messages = messages[self.printed_messages.len:]
  • for message in new_messages
  • message_content = message.get_content
  • if message_content == "" then return
  • print(message.get_content)
  • end for
  • //print(self.printed_messages)
  • //print(messages)
  • if self.printed_messages.len == messages.len then return
  • self.printed_messages = messages
  • end function