public void Apply()
        {
            // informer tout les abonnées que le client viens de se désabonner du map
            List <NetConnection> abonnedPlayers = MainClass.netServer.Connections.FindAll(p => ((Actor)p.Tag).map == _actor.map && ((Actor)p.Tag).Pseudo != _actor.Pseudo && ((Actor)p.Tag).inBattle == 0);

            foreach (NetConnection t in abonnedPlayers)
            {
                ActorDisconnectedResponseMessage playerDisconnectedResponseMessage =
                    new ActorDisconnectedResponseMessage();
                playerDisconnectedResponseMessage.Initialize(new[] { _actor.Pseudo }, t);
                playerDisconnectedResponseMessage.Serialize();
                playerDisconnectedResponseMessage.Send();
            }
            abonnedPlayers.Clear();

            // modification de la bdd
            mysql.connected connected = ((List <mysql.connected>)DataBase.DataTables.connected).Find(f => f.pseudo == _actor.Pseudo);
            connected.pseudo       = "";
            connected.timestamp    = 0;
            connected.map          = "";
            connected.map_position = "";

            // remise a zero tous les données du client
            _actor.SessionZero();
        }
Exemple #2
0
        static void server_LostConnection(NetIncomingMessage im, string reason)
        {
            Console.WriteLine("client " + im.SenderConnection.RemoteUniqueIdentifier + " was diconnected " + reason);
            Actor pi = im.SenderConnection.Tag as Actor;

            if (pi.Username != string.Empty)
            {
                ((List <mysql.connected>)DataBase.DataTables.connected).RemoveAll(f => f.user == pi.Username);
            }

            // il faut informer tous les autre clients abonnées au map de la deconnexion du client
            // seulement si le client n'est pas dans un combat ou dans un combat FreeChallenge
            if (pi.inBattle == 0)
            {
                List <NetConnection> abonnedPlayers = netServer.Connections.FindAll(p => ((Actor)p.Tag).map == pi.map && ((Actor)p.Tag).Pseudo != pi.Pseudo && pi.inBattle == 0);
                for (int cnt = 0; cnt < abonnedPlayers.Count; cnt++)
                {
                    ActorDisconnectedResponseMessage playerDisconnectedResponseMessage = new ActorDisconnectedResponseMessage();
                    playerDisconnectedResponseMessage.Initialize(new[] { pi.Pseudo }, abonnedPlayers[cnt]);
                    playerDisconnectedResponseMessage.Serialize();
                    playerDisconnectedResponseMessage.Send();
                }
                abonnedPlayers.Clear();
            }
            else
            {
                List <NetConnection> abonnedPlayers = MainClass.netServer.Connections.FindAll(p => ((Actor)p.Tag).map == pi.map && ((Actor)p.Tag).Pseudo != pi.Pseudo && ((Actor)p.Tag).idBattle == pi.idBattle);
                foreach (NetConnection t in abonnedPlayers)
                {
                    ActorDisconnectedResponseMessage playerDisconnectedResponseMessage = new ActorDisconnectedResponseMessage();
                    playerDisconnectedResponseMessage.Initialize(new[] { pi.Pseudo }, t);
                    playerDisconnectedResponseMessage.Serialize();
                    playerDisconnectedResponseMessage.Send();
                }
                abonnedPlayers.Clear();
            }

            if (pi.inBattle == 1 && Battle.Battles.Find(f => f.IdBattle == pi.idBattle).BattleType == BattleType.Type.FreeChallenge)
            {
                // le joueur été en combat, il faut annuler le combat s'il ya seulement 2 joueurs
                // check s'il le combat est du type FreeChallenge
                Battle battle = Battle.Battles.Find(f => f.IdBattle == pi.idBattle);
                if (battle != null && battle.BattleType == BattleType.Type.FreeChallenge)
                {
                    // effacement de notre joueur de la combat afin de verifier apres
                    battle.SideA.Remove(battle.SideA.Find(f => f.Pseudo == pi.Pseudo));
                    battle.SideB.Remove(battle.SideB.Find(f => f.Pseudo == pi.Pseudo));
                    // il faut informer les abonnés du map du combat et qui ne sont pas en combat que le combat en cours a été annulé pour supprimer l'objet qui represente le combat
                    // informer les joueurs abonnées au map de combat et qui ne sont pas en combat de la supression des 2 objets
                    List <NetConnection> nc = netServer.Connections.FindAll(f => ((Actor)f.Tag).inBattle == 0 && ((Actor)f.Tag).map == battle.Map);
                    foreach (NetConnection t in nc)
                    {
                        MapObjetRemovedResponseMessage mapObjetRemovedResponseMessage = new MapObjetRemovedResponseMessage();
                        object[] o = new object[2];
                        o[0] = Enums.BattleType.Type.FreeChallenge;
                        o[1] = battle.IdBattle;

                        mapObjetRemovedResponseMessage.Initialize(o, t);
                        mapObjetRemovedResponseMessage.Serialize();
                        mapObjetRemovedResponseMessage.Send();
                    }
                }
                if (CommonCode.IsClosedBattle(battle, true))
                {
                    battle.State = battleState.state.closed;
                    Console.WriteLine("battle closed");
                    foreach (Actor t in battle.AllPlayersByOrder)
                    {
                        t.inBattle = 0;
                        ((List <mysql.players>)DataBase.DataTables.players).Find(f => f.pseudo == t.Pseudo).inBattle = 0;
                    }
                }
            }

            if (pi.PlayerChallengeYou != "")
            {
                //check si le joueur est connecté
                NetConnection nt = netServer.Connections.Find(f => ((Actor)f.Tag).Pseudo == pi.PlayerChallengeYou);
                if (nt != null)
                {
                    ((Actor)nt.Tag).YouChallengePlayer = "";
                    ((Actor)nt.Tag).PlayerChallengeYou = "";
                }
            }
            else if (pi.YouChallengePlayer != "")
            {
                //check si le joueur est connecté
                NetConnection nt = netServer.Connections.Find(f => ((Actor)f.Tag).Pseudo == pi.PlayerChallengeYou);
                if (nt != null)
                {
                    ((Actor)nt.Tag).YouChallengePlayer = "";
                    ((Actor)nt.Tag).PlayerChallengeYou = "";
                }
            }
        }