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 removeOldPeerFromSlot(int slotID, PreGamePeer newPeer) { PreGamePlayerSlot slot = playerSlots[slotID]; if (slot.peer != null && newPeer != slot.peer) { slot.peer.removePlayerSlot(slotID); } }
private bool getIsPreReady(PreGameSlotType type, PreGamePeer peer) { if ((type == PreGameSlotType.TrainingBot || type == PreGameSlotType.Human)) { return(true); } if (type == PreGameSlotType.SelfClone) { return(peer.isReady); } return(false); }
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); }
public void updatePeerReady(IPeer peer, bool ready) { PreGamePeer localPeer = getMatchingPeer(peer.Id); localPeer.isReady = ready; foreach (int slotID in localPeer.playerSlots) { if (playerSlots[slotID].info.type == PreGameSlotType.Player || playerSlots[slotID].info.type == PreGameSlotType.SelfClone) { playerSlots[slotID].info.isReady = ready; } } broadcastUpdate(); }
public void peerLeft(PreGamePeer p) { p.playerSlots.ForEach(i => setplayerSlotEmpty(i)); p.clearReferences(); lock (playerLock) connectedPeers.Remove(p); lock (playerLock) { if (connectedPeers.Count == 0) //Check if Game should be terminated { AlbotPreGameModule.removeGame(this, specs.roomID); } else { broadcastUpdate(); } } }
private void changePlayerSlot(int slotID, PreGameSlotType newType, PlayerInfo newInfo, PreGamePeer newPeer, bool newIsReady) { removeOldPeerFromSlot(slotID, newPeer); playerSlots[slotID].peer = newPeer; playerSlots[slotID].info.belongsToPlayer = newPeer == null ? "" : newPeer.info.username; playerSlots[slotID].info.slotID = slotID; playerSlots[slotID].info.playerInfo = newInfo; playerSlots[slotID].info.type = newType; playerSlots[slotID].info.isReady = newIsReady; }