lobby server broadcast clientlist everyone upon new registration
This commit is contained in:
parent
97124b1e64
commit
6274c6b098
22
lobby.lua
22
lobby.lua
|
@ -16,6 +16,7 @@ oct_lobby_clientlist = {};
|
||||||
oct_lobby_timers = {};
|
oct_lobby_timers = {};
|
||||||
oct_lobby_timers["clientlist"] = 1000; -- Every 1000 calls to lobby_client broadcast client list
|
oct_lobby_timers["clientlist"] = 1000; -- Every 1000 calls to lobby_client broadcast client list
|
||||||
|
|
||||||
|
server_needs_broadcast_client_list = false
|
||||||
function lobby_server(maxplayers)
|
function lobby_server(maxplayers)
|
||||||
msg,addr,port = oct_recv();
|
msg,addr,port = oct_recv();
|
||||||
if (msg ~= "") then
|
if (msg ~= "") then
|
||||||
|
@ -51,9 +52,23 @@ function lobby_server(maxplayers)
|
||||||
OCT_LOG_INFO("Registered new client: " .. req_name .. " @ " .. req_addr .. ":" .. req_port)
|
OCT_LOG_INFO("Registered new client: " .. req_name .. " @ " .. req_addr .. ":" .. req_port)
|
||||||
|
|
||||||
oct_send(response, req_addr, req_port)
|
oct_send(response, req_addr, req_port)
|
||||||
|
-- Everytime client is registered, need to broadcast client list
|
||||||
|
server_needs_broadcast_client_list = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (server_needs_broadcast_client_list == true) then
|
||||||
|
msg = json.encode({
|
||||||
|
{ msg_type = OCT_LOBBY_MSG_CLIENTLIST,
|
||||||
|
clientlist = oct_lobby_clientlist,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
for k,v in pairs(oct_lobby_clientlist) do
|
||||||
|
oct_send(msg, v["addr"], v["port"])
|
||||||
|
end
|
||||||
|
server_needs_broadcast_client_list = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
client_connected = false;
|
client_connected = false;
|
||||||
|
@ -88,7 +103,14 @@ function lobby_client(ip, port, name, my_port)
|
||||||
OCT_LOG_ERROR("Server rejected registration request, try using a different name")
|
OCT_LOG_ERROR("Server rejected registration request, try using a different name")
|
||||||
client_connected = 0
|
client_connected = 0
|
||||||
client_wait_for_reg_response = false
|
client_wait_for_reg_response = false
|
||||||
|
|
||||||
|
-- We received a clientlist from the server
|
||||||
|
elseif (msg_obj["msg_type"] == OCT_LOBBY_MSG_CLIENTLIST) then
|
||||||
|
oct_lobby_clientlist = msg_obj["clientlist"]
|
||||||
|
OCT_LOG_DEBUG("My client list: " .. table_to_string(oct_lobby_clientlist))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,18 @@ require("oct_utils")
|
||||||
require("termbox_defs")
|
require("termbox_defs")
|
||||||
require("lobby")
|
require("lobby")
|
||||||
|
|
||||||
my_ip = ""
|
|
||||||
my_port = ""
|
my_port = ""
|
||||||
|
my_name = ""
|
||||||
|
|
||||||
function oct_init(arg, port)
|
function oct_init(arg, port)
|
||||||
OCT_LOG_INFO("Starting test_lobby_client")
|
OCT_LOG_INFO("Starting test_lobby_client")
|
||||||
|
|
||||||
my_port = port
|
my_port = port
|
||||||
|
if (arg == "") then
|
||||||
|
my_name = "TEST_USER"
|
||||||
|
else
|
||||||
|
my_name = arg
|
||||||
|
end
|
||||||
|
|
||||||
return OCT_NEEDS_NETWORKING, OCT_NOT_NEEDS_TERMBOX;
|
return OCT_NEEDS_NETWORKING, OCT_NOT_NEEDS_TERMBOX;
|
||||||
|
|
||||||
|
@ -17,6 +22,6 @@ end
|
||||||
first = 1
|
first = 1
|
||||||
|
|
||||||
function oct_loop(key)
|
function oct_loop(key)
|
||||||
lobby_client("127.0.0.1", "2048", "TEST_LOBBY", my_port)
|
lobby_client("127.0.0.1", "2048", my_name, my_port)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue