local modem = peripheral.wrap('top')
modem.open(65533)

local cache = "nada"
local logicache = "nada"
while true do
  local event = {os.pullEvent('modem_message')}
   if event[5]["player"] and event[5]["message"] and event[5]["player"]..event[5]["message"]..event[5]["type"] ~= cache then
    if event[5]["type"] == "action" then
     print("* "..event[5]["player"].." "..event[5]["message"])
    else
     print("<"..event[5]["player"].."> "..event[5]["message"])
    end
    cache = event[5]["player"]..event[5]["message"]..event[5]["type"]
   end
   if event[5]["player"] and event[5]["player"]..event[5]["type"] ~= logicache then
    term.setTextColor(colors.yellow)
    if event[5]["type"] == "logout" then
     print("* "..event[5]["player"].." has left the game")
    elseif event[5]["type"] == "login" then
     print("* "..event[5]["player"].." has joined the game")
    end
    term.setTextColor(colors.white)
    logicache = event[5]["player"]..event[5]["type"]
   end
--   print(textutils.serialize(event))
end
