Esempio n. 1
0
        public virtual void Disconnect(GameClient client)
        {
            bool IsOwner = false;

            if (this.Owner == client)
            {
                IsOwner = true;
            }
            this.Leave(client, true);
            client.Character.Status.Update(null);
            Parent.Disconnect(client);
            // Enqueue all disconnect client
            if (IsInGame || !IsInGame)
            {
                var ack2 = new UpdateRoomPlayerCountAck()
                {
                    Room = this
                };
                var ack3 = new PlayerHasLeftRoomAck()
                {
                    Token          = client.Character?.Token,
                    Character      = client.Character,
                    HasOwnerChange = IsOwner,
                    Owner          = this.Owner.GetIdentifier()
                };
                // Invoke only when the room is in Room State and not in Game state
                EventDespatcher.EnqueueRoom(ack3.CreatePacket(), client);
                this.Parent.Broadcast(ack2.CreatePacket());
                // Invoke the despatcher in 10s
                new Task(() => EventDespatcher.Invoke()).Start();
            }
        }
Esempio n. 2
0
        public void Disconnect(GameClient client)
        {
            PlayerManager.Leave(client);
            if (PlayerManager.IsCycleStillOngoing() && PlayerManager.GetCurrentPlayer().GetIdentifier() == client.Character.Token)
            {
                EndPlayerTurn();
            }
            EventDespatcher.Enqueue(client);

            if (Parent.Owner == client && PlayerManager.GetPlayers().Count > 0)
            {
                Parent.Owner = PlayerManager.GetPlayers().ElementAt(Utilities.Random(PlayerManager.GetPlayers().Count)).Client;
            }
            else if (PlayerManager.GetPlayers().Count == 0)
            {
                new Task(() => EndGame()).Start();
            }
            // In case disconnect and owner is equal to client.
            new Task(() => EventDespatcher.Invoke()).Start();

            // Escalate upward to Room
            Parent.Disconnect(client);
        }