Browse Source

Server Detection

tags/crossplatform
Madiwka 4 years ago
parent
commit
5af7f23dbe
2 changed files with 29 additions and 22 deletions
  1. +27
    -20
      main.lua
  2. +2
    -2
      src/baseGame.lua

+ 27
- 20
main.lua View File

@@ -51,7 +51,7 @@ rotation = 0
TEXT = "Nuclear Pong"
currentKey = " "
ptw = 10
checkrate = 0.5
--CHECKING IF CONTROLS ARE TAKEN
danger = "none"
danger2 = "none"
@@ -751,6 +751,7 @@ function love.update(dt)

end
serverinit = false
dserverinit = false
datawaspassedtimer = 0
clientinit = false
function love.textinput(t)
@@ -1650,32 +1651,38 @@ function split(s, delimiter)
end
return result
end
address, port = IP, 12345
function checkCurrentServer(dt)

if dserverinit == false then
local socket = require "socket"
local address, port = IP, 12345
print(address)
udp = socket.udp()
udp:setpeername(address, port)
udp:settimeout(0)
dserverinit = true
end
if IP ~= address then dserverinit = false print(IP .. " " .. address)
end
ts = ts + dt
local socket = require "socket"
local address, port = IP, 12345
udp = socket.udp()
udp:setpeername(address, port)
udp:settimeout(0)
if ts > updaterate then
--print(ts)
if ts > checkrate then
status = "offline"
print("sent ping")
udp:send("HELLO")
ts = 0
end
status = "offline"
local data
local datanumtest = 0
local datawaspassed = false
data = udp:receive()
repeat
datanumtest = datanumtest + 1
print("LATENCY: " .. tostring(datanumtest))
data = udp:receive()
if data then
datawaspassed = true
print("ReceivedINFO: " .. data)
if data then
print("got answer!")
local p = split(data, '|')
status = p[1]
print("answer is " .. status)
else
print("no response!")
end
ts = 0
end
until not data

end

+ 2
- 2
src/baseGame.lua View File

@@ -688,7 +688,7 @@ function menuDraw()
end
if gameState == "chooseIP" then
IPselect = {}
if status == "offine" then
if status == "offline" then
love.graphics.printf("UNABLE TO CONNECT", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
elseif status == "nettest" then
table.insert(
@@ -708,7 +708,7 @@ function menuDraw()
table.insert(
IPselect,
newButton(
"Guest",
"Connect as Guest",
function()
globalState = "clienttest"
AGAINST_AI = 0


Loading…
Cancel
Save