Browse Source

[WIP] Network games, begin move players to game

The problem I just encountered is that I have to tell the players who
are currently skirmishing that they have a game. This means either:
 1. Telling the skirmish server to move them
 2. Keeping a connection with players
 3. Running the skirmish server on the matchmaker!
Three sounds nice because the matchmaker is sitting on this godot
instance, it might as well do something with it, right? But it's
essentially equivalent to 1, it just doesn't have to think about
networking because they're the same instance. So moving from 3 to 1 if I
realize it's a bad idea is easy, but 2 becomes pretty entrenched.

You're making some pretty big decisions here, take it slow.
master
Luna 7 years ago
parent
commit
955927569c
2 changed files with 36 additions and 8 deletions
  1. +10
    -0
      scripts/lobby.gd
  2. +26
    -8
      scripts/matchmaking.gd

+ 10
- 0
scripts/lobby.gd View File

@ -16,6 +16,8 @@ var is_connected = false # Technically this can be done with ENetcetera but it's
onready var matchmaking = preload("res://scripts/matchmaking.gd").new()
var matchmaker_tcp
func setup_options():
var opts = Options.new()
opts.set_banner(('A non-violent MOBA inspired by Overwatch and Zineth'))
@ -127,6 +129,14 @@ func _server_init():
print("Starting server on port " + str(port))
peer.create_server(port, matchmaking.GAME_SIZE)
get_tree().set_network_peer(peer)
# As soon as we're listening, let the matchmaker know
var matchmaker_peer = StreamPeerTCP.new()
matchmaker_peer.connect_to_host("127.0.0.1", matchmaking.SERVER_TO_SERVER_PORT)
matchmaker_tcp = PacketPeerStream.new()
matchmaker_tcp.set_stream_peer(matchmaker_peer)
# matchmaker_tcp.put_packet([matchmaking.messages.ready_to_connect, port])
matchmaker_tcp.put_var(matchmaking.messages.ready_to_connect)
matchmaker_tcp.put_var(port)
is_connected = true
get_node("CustomGame/Server").set_text("Serving!")
get_node("JoinedGameLobby").show()


+ 26
- 8
scripts/matchmaking.gd View File

@ -14,13 +14,17 @@ var skirmishing_players = []
var skirmish
# To avoid the confusion of the gameSERVERS being CLIENTS,
# we just call them games whenever possible
var games = []
# var games = []
var game_connections = []
var game_streams = []
# Matchmaker to game servers
var matchmaker_to_games
enum messages {
ready_to_connect,
}
onready var lobby = get_node("..")
func _ready():
@ -57,7 +61,13 @@ func _process(delta):
var stream = PacketPeerStream.new()
stream.set_stream_peer(game) # bind peerstream to new client
game_streams.append(stream) # make new data transfer object for game
print("Server has requested connection")
for stream in game_streams:
if stream.get_available_packet_count():
var message = stream.get_var()
if message == messages.ready_to_connect:
var port = stream.get_var()
print("Server " + str(port) + " has requested connection")
skirmish_to_game(port, GAME_SIZE)
func queue(netid):
print("Player " + str(netid) + " connected.")
@ -72,14 +82,22 @@ func queue(netid):
func add_to_game(netid, port):
lobby.rpc_id(netid, "_client_init", port)
func skirmish_to_game(port, count=1):
print("dropping 'em in")
for i in range(count):
if not skirmishing_players.size():
return false
print(skirmishing_players[0])
print("to")
print(port)
add_to_game(skirmishing_players[0], port)
return true
func check_queue():
# Prefer making a full game to backfilling
if skirmishing_players.size() >= GAME_SIZE:
var port = spawn_server()
games.append(port)
for i in range(GAME_SIZE):
var p = skirmishing_players[i]
print("Moving player " + str(p) + " to game " + str(port))
add_to_game(p, port)
spawn_server()
# games.append(port)
func spawn_server():
OS.execute("util/server.sh", ['-port='+str(next_port)], false)


Loading…
Cancel
Save