public void updateSlotType(PreGameSlotInfo slot, IPeer peer) { PreGamePlayerSlot oldSlot = playerSlots[slot.slotID]; if (isAdminOrHost(peer) == false && oldSlot.peer != null && peer.Id != oldSlot.peer.peer.Id) //Only allow admin or the same peer to change slot { return; } PreGamePeer localPeer = getMatchingPeer(peer.Id); if (localPeer == null) //Quick fix to wait until player joins game { MainThread.createTimedAction(() => { updateSlotType(slot, peer); }, 0.1f); return; } if (slot.type == PreGameSlotType.Player) { localPeer.removePlayerSlot(slot.slotID); setplayerSlotEmpty(slot.slotID); } else { localPeer.addPlayerSlot(slot.slotID); changePlayerSlot(slot.slotID, slot.type, slot.playerInfo, getMatchingPeer(peer.Id), getIsPreReady(slot.type, localPeer)); } broadcastUpdate(); }
private void addPeerToGame(IPeer peer, PlayerInfo info) { //Debug.LogError("Adding peer: " + info.username + " to game: " + specs.roomID); PreGamePeer newPeer = new PreGamePeer(peer, info, peerLeft); lock (playerLock) connectedPeers.Add(newPeer); int freeSlot = getFreeSlotId(); newPeer.addPlayerSlot(freeSlot); changePlayerSlot(freeSlot, PreGameSlotType.Player, info, newPeer, false); broadcastUpdate(peer.Id); }