Advertisement
electronic_steve

SERVER_CODE

Nov 20th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. local debug_channel = love.thread.getChannel("debug_channel")
  2. local debug_command = love.thread.getChannel("debug_command")
  3. local log
  4. log = function(...)
  5.   local t = ""
  6.   local _list_0 = {
  7.     ...
  8.   }
  9.   for _index_0 = 1, #_list_0 do
  10.     local i = _list_0[_index_0]
  11.     t = t .. " " .. tostring(i)
  12.   end
  13.   print("[" .. os.date() .. "]", t)
  14.   return debug_channel:push(t:sub(2))
  15. end
  16. local socket = require("socket")
  17. local udp = socket.udp()
  18. log("cat23")
  19. udp:setsockname("*", 48655)
  20. udp:settimeout(10)
  21. local clients = { }
  22. local a = debug_command:peek()
  23. log(a)
  24. while not a do
  25.   a = debug_command:peek()
  26.   log(a, "test")
  27.   log(debug_channel:getCount())
  28.   log("clients:", #clients)
  29.   local data, ip, port = udp:receivefrom()
  30.   if data then
  31.     local com = csv(data)
  32.     if com[1] == "login" then
  33.       udp:sendto("ok", ip, port)
  34.       local id = #clients + 1
  35.       clients[id] = {
  36.         ip,
  37.         port
  38.       }
  39.       clients[ip] = id
  40.       log("login cid:", id)
  41.     end
  42.     if com[1] == "move" then
  43.       log("move cid:", clients[ip])
  44.       for _index_0 = 1, #clients do
  45.         local cl = clients[_index_0]
  46.         if ip ~= cl[1] then
  47.           udp:sendto(data, cl[1], cl[2])
  48.         end
  49.       end
  50.     end
  51.   end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement