Browse Source

Attempting selfhost update - 1

tags/crossplatform
madiwka3 3 years ago
parent
commit
c6ba0a972d
2 changed files with 25 additions and 14 deletions
  1. +15
    -13
      main.lua
  2. +10
    -1
      src/baseGame.lua

+ 15
- 13
main.lua View File

@@ -41,6 +41,7 @@ hitNum[5] = 0
hitNum[6] = 0
GREEN = 255
IP = '45.76.95.31'
IPnew = '45.76.95.31'
BLUE = 255
updateTEXT = "Chalkboard Update"
maxBalls = 1
@@ -719,11 +720,10 @@ function love.update(dt)
--print("IMPORTANT!!!!!" .. globalState .. gameState)
staticanimatorcounter(dt)
musicController('norm', 1)
if gameState == "chooseIP" then
checkCurrentServer(dt)
checkCurrentServer(dt)
end
musicController('norm', 1)
if debug then
displayFPS()
end
@@ -759,7 +759,7 @@ datawaspassedtimer = 0
clientinit = false
function love.textinput(t)
if gameState == "chooseIP" then
IP = IP .. t
IPnew = IPnew .. t
end
end
function nettest(dt)
@@ -1090,12 +1090,12 @@ function love.keypressed(key)
if gameState == "chooseIP" then
if key == "backspace" then
-- get the byte offset to the last UTF-8 character in the string.
local byteoffset = utf8.offset(IP, -1)
local byteoffset = utf8.offset(IPnew, -1)
if byteoffset then
-- remove the last UTF-8 character.
-- string.sub operates on bytes rather than UTF-8 characters, so we couldn't do string.sub(text, 1, -2).
IP = string.sub(IP, 1, byteoffset - 1)
IPnew = string.sub(IPnew, 1, byteoffset - 1)
end
end
end
@@ -1665,24 +1665,25 @@ function split(s, delimiter)
end
address, port = IP, 12345
function checkCurrentServer(dt)
if IP ~= "" then
if dserverinit == false then
local socket = require "socket"
local address, port = IP, 12345
print("Switching IP")
socket = require "socket"
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
if IP ~= address then dserverinit = false print(IP .. " doesnt equal " .. address)
else
ts = ts + dt
--print(ts)
if ts > checkrate then
status = "offline"
print("sent ping")
udp:send("HELLO")
udp:send("HELLO")
local data
data = udp:receive()
if data then
@@ -1695,7 +1696,8 @@ function checkCurrentServer(dt)
end
ts = 0
end
end
end

end



+ 10
- 1
src/baseGame.lua View File

@@ -688,6 +688,15 @@ function menuDraw()
end
if gameState == "chooseIP" then
IPselect = {}
table.insert(
IPselect,
newButton(
"Check Server",
function()
IP = IPnew
end
)
)
if status == "offline" then
love.graphics.printf("UNABLE TO CONNECT", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
elseif status == "nettest" then
@@ -721,7 +730,7 @@ function menuDraw()
love.graphics.printf("SERVER FULL", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
end
mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, IPselect, sounds, "middle")
love.graphics.printf(IP, 0, VIRTUAL_HEIGHT / 4, VIRTUAL_WIDTH, "center")
love.graphics.printf(IPnew, 0, VIRTUAL_HEIGHT / 4, VIRTUAL_WIDTH, "center")
love.keyboard.mouseisReleased = false
end
if gameState == "menu" then


Loading…
Cancel
Save