 
 #========== Client calls ==========
 # Add a beacon (during setup phase)
-exports.client_addMarker = (location) ->
-	log 'Adding marker: lat=', location.lat, ', lng=', location.lng
-	nextNumber = 0
-	while Db.shared.get('game', 'beacons', nextNumber)?
-		nextNumber++
-
-	Db.shared.set 'game', 'beacons', nextNumber, {location: location}
-	Db.shared.set 'game', 'beacons', nextNumber, 'owner', -1 
-	Db.shared.set 'game', 'beacons', nextNumber, 'nextOwner', -1
-	Db.shared.set 'game', 'beacons', nextNumber, 'percentage', 0
-	Db.shared.set 'game', 'beacons', nextNumber, 'captureValue', 10
-	Db.shared.set 'game', 'beacons', nextNumber, 'action', "none"
-
-exports.client_deleteMarker = (location) ->	
+exports.client_addMarker = (client, location) ->
+	if Db.shared.get('gameState') isnt 0
+		log Plugin.userName(client), ' (id=', client, ') tried to add a marker while game is not in setup phase!'
+	else
+		log 'Adding marker: lat=', location.lat, ', lng=', location.lng
+		nextNumber = 0
+		while Db.shared.get('game', 'beacons', nextNumber)?
+			nextNumber++
+
+		Db.shared.set 'game', 'beacons', nextNumber, {location: location}
+		Db.shared.set 'game', 'beacons', nextNumber, 'owner', -1 
+		Db.shared.set 'game', 'beacons', nextNumber, 'nextOwner', -1
+		Db.shared.set 'game', 'beacons', nextNumber, 'percentage', 0
+		Db.shared.set 'game', 'beacons', nextNumber, 'captureValue', 10
+		Db.shared.set 'game', 'beacons', nextNumber, 'action', "none"
+
+exports.client_deleteMarker = (client, location) ->	
 	#Finding the right beacon
-	log 'Deleting marker: lat=', location.lat, ', lng=', location.lng
-	Db.shared.iterate 'game', 'beacons', (beacon) !->
-		if beacon.get('location', 'lat') == location.lat and beacon.get('location', 'lng') == location.lng
-			Db.shared.remove 'game', 'beacons', beacon.n
+	if Db.shared.get('gameState') isnt 0
+		log Plugin.userName(client), ' (id=', client, ') tried to delete a marker while game is not in setup phase!'
+	else
+		log 'Deleting marker: lat=', location.lat, ', lng=', location.lng
+		Db.shared.iterate 'game', 'beacons', (beacon) !->
+			if beacon.get('location', 'lat') == location.lat and beacon.get('location', 'lng') == location.lng
+				Db.shared.remove 'game', 'beacons', beacon.n
 	
 # Set the round time unit and number
 exports.client_setRoundTime = (roundTimeNumber, roundTimeUnit) ->


# Called by the beacon neutralize timer
exports.onNeutralize = (args) !->
	log 'args=', args
	beacon = Db.shared.ref 'game', 'beacons', args.beacon
	neutralizer = beacon.get('nextOwner')
	log 'Team ', neutralizer, ' has neutralized beacon ', beacon.n, ', players: ', args.players

				Db.shared.iterate 'game', 'beacons', beacon.n, 'inRange', (player) !->
					team = getTeamOfUser(player.n)
					teamMembers[team] = teamMembers[team]+1
				#log 'teamMembers count: ', teamMembers	

				# Determine who is competing
				max = 0
