Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync #11

Merged
merged 4 commits into from
Oct 19, 2020
Merged

Sync #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/assets/autoload/playermanager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ extends Node

var inMenu = false
var isintruder = false
var ournumber
29 changes: 15 additions & 14 deletions src/assets/main/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var players = {}
#INCREASE THIS VARIABLE BY ONE EVERY COMMIT TO PREVENT OLD CLIENTS FROM TRYING TO CONNECT TO SERVERS!!!
var version = 5
var intruders = 0
var newnumber
var errdc = false
onready var config = ConfigFile.new()

Expand All @@ -29,6 +30,7 @@ func _enter_tree():
#get_tree().network_peer = peer
get_tree().connect("network_peer_connected", self, "_player_connected")
get_tree().connect("network_peer_disconnected", self, "_player_disconnected")
PlayerManager.ournumber = 0
elif Network.connection == Network.Connection.CLIENT:
get_tree().connect("network_peer_disconnected", self, "_player_disconnected")
#print("Connecting to ", Network.host, " on port ", Network.port)
Expand All @@ -38,12 +40,14 @@ func _enter_tree():

# Called on the server when a new client connects
func _player_connected(id):
rpc_id(id,"getname",id, version)
newnumber = Network.peers.size()
rpc_id(id,"getname",id, version, newnumber)
rpc_id(id,"serverinfo",Network.get_player_name(), version)
remote func serverinfo(sname,sversion):
player_join(1,sname)
remote func getname(id,sversion):
remote func getname(id,sversion,assignednumber):
rpc_id(1,"playerjoin_proper",Network.get_player_name(),id)
PlayerManager.ournumber = assignednumber
if not version == sversion:
print("HEY! YOU! YOU FORGOT TO UPDATE YOUR CLIENT. RE EXPORT AND TRY AGAIN!")
remote func playerjoin_proper(thename,id):
Expand All @@ -63,7 +67,7 @@ remote func playerjoin_proper(thename,id):
players[id] = new_player
$players.add_child(new_player)
print("Got connection: ", id)
print("Players: ", players)
print(Network.peers.size())
func _player_disconnected(id):
players[id].queue_free() #deletes player node when a player disconnects
players.erase(id)
Expand Down Expand Up @@ -122,23 +126,20 @@ signal clientstartgame
func _on_startgamebutton_gamestartpressed():
print("game start triggered")
serverassign()
for other_id in players:
print("pog")
while intruders <= 2:
var rng = RandomNumberGenerator.new()
var isintruder = false
rng.randomize()
var my_random_number = rng.randf_range(0, 10.0)
if intruders <= 2 and my_random_number > 8:
var my_random_number = rng.randi_range(0, Network.peers.size())
#technically should generate a 1 in 10 chance of you being an intruder
isintruder = true
intruders = intruders + 1
rpc_id(other_id,"startgame",isintruder)
intruders = intruders + 1
rpc("startgame",my_random_number)
isintruder = false
# TODO: Looser coupling here would be nice
GameManager.state = GameManager.State.Normal

remote func startgame(areweanintruder):
if areweanintruder:
remote func startgame(intrudernumber):
if intrudernumber == PlayerManager.ournumber:
print("we are the intruder!")
PlayerManager.isintruder = true
else:
Expand All @@ -148,9 +149,9 @@ func serverassign():
var rng = RandomNumberGenerator.new()
var isintruder = false
rng.randomize()
var my_random_number = rng.randf_range(0, 10)
var my_random_number = rng.randf_range(0, Network.peers.size())
print(my_random_number)
if intruders <= 2 and my_random_number > 8:
if intruders <= 2 and my_random_number == 0:
print("host is the intruder!")
PlayerManager.isintruder = true
else:
Expand Down
1 change: 0 additions & 1 deletion src/export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ binary_format/embed_pck=true
custom_template/release=""
custom_template/debug=""
codesign/enable=false
codesign/identity_type=0
codesign/identity=""
codesign/password=""
codesign/timestamp=true
Expand Down