Browse Source

Added server verification

tags/crossplatform
Madiwka 3 years ago
parent
commit
d636b73b9b
2 changed files with 55 additions and 5 deletions
  1. +4
    -1
      main.lua
  2. +51
    -4
      src/baseGame.lua

+ 4
- 1
main.lua View File

@@ -1690,7 +1690,10 @@ function split(s, delimiter)
end
address, port = IP, 12345
function checkCurrentServer(dt)
if IP ~= "" then
if GetIPType(IP) ~= 1 then
status = "offline"
end
if GetIPType(IP) == 1 then
if dserverinit == false then
print("Switching IP")
socket = require "socket"


+ 51
- 4
src/baseGame.lua View File

@@ -1,3 +1,4 @@
local counter = 0
function basegame(dt)
if gameMode == "reversegame" then
reversegame(dt)
@@ -706,12 +707,13 @@ function menuDraw()
"Check Server",
function()
IP = IPnew
counter = 0
end
)
)
if status == "offline" then
love.graphics.printf("UNABLE TO CONNECT", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
elseif status == "nettest" then
animateConnection()
elseif status == "nettest" and IP == IPnew then
table.insert(
IPselect,
newButton(
@@ -725,7 +727,7 @@ function menuDraw()
)
)
elseif status == "clienttest" then
elseif status == "clienttest" and IP == IPnew then
table.insert(
IPselect,
newButton(
@@ -1313,4 +1315,49 @@ function clientsBaseGame(dt)
powerAvailability()
player1:update(dt)
player2:update(dt)
end
end

function animateConnection()
if GetIPType(IP) ~= 1 then
love.graphics.printf("WRONG SYNTAX", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
else
counter = counter + 1 / love.timer.getFPS()
if counter < 0.8 then
love.graphics.printf("TRYING TO CONNECT.", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
elseif counter < 1.6 then
love.graphics.printf("TRYING TO CONNECT..", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
elseif counter < 2.4 then
love.graphics.printf("TRYING TO CONNECT...", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
else
love.graphics.printf("NO CONNECTION!", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
end
end
end
function GetIPType(ip)
-- must pass in a string value
if ip == nil or type(ip) ~= "string" then
return 0
end

-- check for format 1.11.111.111 for ipv4
local chunks = {ip:match("(%d+)%.(%d+)%.(%d+)%.(%d+)")}
if (#chunks == 4) then
for _,v in pairs(chunks) do
if (tonumber(v) < 0 or tonumber(v) > 255) then
return 0
end
end
return 1
else
return 0
end

-- check for ipv6 format, should be 8 'chunks' of numbers/letters
local _, chunks = ip:gsub("[%a%d]+%:?", "")
if chunks == 8 then
return 2
end

-- if we get here, assume we've been given a random string
return 3
end

Loading…
Cancel
Save