コード例 #1
0
        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();
        }
コード例 #2
0
        private void removeOldPeerFromSlot(int slotID, PreGamePeer newPeer)
        {
            PreGamePlayerSlot slot = playerSlots[slotID];

            if (slot.peer != null && newPeer != slot.peer)
            {
                slot.peer.removePlayerSlot(slotID);
            }
        }
コード例 #3
0
 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);
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        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();
                }
            }
        }
コード例 #7
0
        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;
        }