Skip to content

Commit

Permalink
Merge pull request #11 from TheSecondReal0/main
Browse files Browse the repository at this point in the history
Sync
  • Loading branch information
TheSecondReal0 authored Oct 19, 2020
2 parents fdd8f5e + 96a04ff commit 0416ea5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
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

0 comments on commit 0416ea5

Please sign in to comment.