Exemplo n.º 1
0
        //Demande la liste de tout les joueur d'un lobby
        public String ClientAskPlayerInLobby(String lobby)
        {
            Message chat_nameLobby = new Message(Commande.ASKLOBBY, CommandeType.REQUETE, lobby, ClientPlayer.getName());

            clientSocket.SendTo(chat_nameLobby.GetBytes(), serverEP);

            //Reception Message
            byte[] bufferRes = new byte[Message.bufferSize];
            clientSocket.ReceiveFrom(bufferRes, bufferRes.Length, SocketFlags.None, ref serverEP);
            Message msg = new Message(bufferRes);

            return(msg.data);
        }
Exemplo n.º 2
0
 public void FreeThread(String data)
 {
     if (data == "gameform")
     {
         Console.WriteLine("IN FREE GAME FORM");
         Message chat_nameLobby = new Message(Commande.FREETHREAD, CommandeType.REPONSE, "gameform", "server");
         LobbySocket.SendTo(chat_nameLobby.GetBytes(), endPointPlayer);
     }
     else
     {
         Message chat_nameLobby = new Message(Commande.FREETHREAD, CommandeType.REPONSE, "", "server");
         LobbySocket.SendTo(chat_nameLobby.GetBytes(), endPointPlayer);
     }
 }
Exemplo n.º 3
0
        static void ClientJoinLobby(Player player)
        {
            Console.Write("Nom lobby a rejoindre?: ");
            String nameLobby = Console.ReadLine();


            //Envoie message Server
            String data = nameLobby + "||" + player.getName();

            Message chat_nameLobby = new Message(Commande.JOINLOBBY, CommandeType.REQUETE, data, "");

            byte[] buffer_room = chat_nameLobby.GetBytes();
            //clientSocket.SendTo(buffer_room, 0, buffer_room.Length, SocketFlags.None, serverEP);
        }
Exemplo n.º 4
0
        public void Refresh()
        {
            String msg = connectedPlayers.Count + "|";

            foreach (Player p in connectedPlayers)
            {
                msg += p.getName() + "|";
            }

            foreach (EndPoint e in playerSubScribe)
            {
                Message chat_nameLobby = new Message(Commande.REFRESH, CommandeType.REPONSE, msg, "server");
                LobbySocket.SendTo(chat_nameLobby.GetBytes(), e);
            }
        }
Exemplo n.º 5
0
        public Player ClientHandmainEffect(Player target)
        {
            Message HandMaidEffect = new Message(Commande.HANDMAIDEEFFECT, CommandeType.REQUETE, target.getName(), "");

            byte[] buffer_room = HandMaidEffect.GetBytes();
            clientSocket.SendTo(buffer_room, serverEP);

            //Attente reponse
            byte[] bufferRes = new byte[Message.bufferSize];
            clientSocket.ReceiveFrom(bufferRes, bufferRes.Length, SocketFlags.None, ref serverEP);
            Message res = new Message(bufferRes);


            return(target);
        }
Exemplo n.º 6
0
        public String ClientBaronEffect(Player source, Player target)
        {
            Message BaronEffect = new Message(Commande.BARONEFFECT, CommandeType.REQUETE, target.getName(), source.getName());

            byte[] buffer_room = BaronEffect.GetBytes();
            clientSocket.SendTo(buffer_room, serverEP);

            //Attente reponse
            byte[] bufferRes = new byte[Message.bufferSize];
            clientSocket.ReceiveFrom(bufferRes, bufferRes.Length, SocketFlags.None, ref serverEP);
            Message res = new Message(bufferRes);


            return(res.data);
        }
Exemplo n.º 7
0
 public void CheckBegin()
 {
     if (connectedPlayers.Count() == maxPlayers)
     {
         foreach (EndPoint e in playerSubScribe)
         {
             Message chat_begin = new Message(Commande.BEGIN, CommandeType.REPONSE, "ok", "server");
             LobbySocket.SendTo(chat_begin.GetBytes(), e);
         }
     }
     else
     {
         Message chat_begin = new Message(Commande.BEGIN, CommandeType.REPONSE, "no", "server");
         LobbySocket.SendTo(chat_begin.GetBytes(), endPointPlayer);
     }
 }
Exemplo n.º 8
0
        static void ClientCreateLobby()
        {
            Console.Write("Nom lobby ?: ");
            String name = Console.ReadLine();

            Console.Write("Nombre joueur max ?: ");
            int nbPlayer = int.Parse(Console.ReadLine());

            //Envoie message Server

            String data = name + "|" + nbPlayer;

            Message chat_nameLobby = new Message(Commande.CREATELOBBY, CommandeType.REQUETE, data, "");

            byte[] buffer_room = chat_nameLobby.GetBytes();
            //clientSocket.SendTo(buffer_room, 0, buffer_room.Length, SocketFlags.None, serverEP);
        }
Exemplo n.º 9
0
        public int ClientAskLobbyPort(String lbName)
        {
            Message chat_AskLobby = new Message(Commande.ASKLOBBYPORT, CommandeType.REQUETE, lbName, "");

            byte[] buffer_room = chat_AskLobby.GetBytes();
            clientSocket.SendTo(buffer_room, 0, buffer_room.Length, SocketFlags.None, serverEP);

            byte[] bufferRes = new byte[Message.bufferSize];


            Console.WriteLine("Message askPort en attente");
            clientSocket.ReceiveFrom(bufferRes, bufferRes.Length, SocketFlags.None, ref serverEP);
            Message msg = new Message(bufferRes);

            Console.WriteLine("Message askPort recu");
            Console.WriteLine("Ask port recu " + msg.data);
            return(16790);
        }
Exemplo n.º 10
0
        public Card ClientAskCard()
        {
            Message m_askCard = new Message(Commande.ASKCARD, CommandeType.REQUETE, "", ClientPlayer.getName());

            byte[] buffer_room = m_askCard.GetBytes();
            clientSocket.SendTo(buffer_room, 0, buffer_room.Length, SocketFlags.None, serverEP);

            byte[] bufferRes = new byte[Message.bufferSize];
            Console.WriteLine("Before");
            clientSocket.ReceiveFrom(bufferRes, bufferRes.Length, SocketFlags.None, ref serverEP);
            Console.WriteLine("After");
            Message msg = new Message(bufferRes);

            String[] dataArray = msg.data.Split('|');
            Card     c         = Game.Instance.CreatCardByGame(dataArray[1]);

            return(c);
        }
Exemplo n.º 11
0
        public void askPlayerInLobby()
        {
            Console.WriteLine("Un client a fait une demande de joueur dans le lobby: " + portNum);
            //Envoie message Server
            String msg = connectedPlayers.Count + "|";



            foreach (Player p in connectedPlayers)
            {
                msg += p.getName() + "|";
            }



            Message chat_nameLobby = new Message(Commande.REFRESH, CommandeType.REPONSE, msg + "", "");

            LobbySocket.SendTo(chat_nameLobby.GetBytes(), endPointPlayer);
        }
Exemplo n.º 12
0
        public Boolean ClientGuardEffect(Player source, Player target, Card c)
        {
            Message guardEffect = new Message(Commande.GUARDEFFECT, CommandeType.REQUETE, source.getName() + "|" + target.getName() + "|" + c.getValue(), "");

            byte[] buffer_room = guardEffect.GetBytes();
            clientSocket.SendTo(buffer_room, serverEP);

            //Attente reponse
            byte[] bufferRes = new byte[Message.bufferSize];
            clientSocket.ReceiveFrom(bufferRes, bufferRes.Length, SocketFlags.None, ref serverEP);
            Message res = new Message(bufferRes);

            if (res.data.ToLower() == "yes")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 13
0
        //Verifie si un nom est deja utilisé
        public static Boolean CheckForName(String name)
        {
            Client  temp           = new Client(new Player("temp"));
            Message chat_nameLobby = new Message(Commande.CHECKNAME, CommandeType.REQUETE, name, name);

            byte[] buffer_room = chat_nameLobby.GetBytes();
            clientSocket.SendTo(buffer_room, 0, buffer_room.Length, SocketFlags.None, serverEP);

            byte[] bufferRes = new byte[Message.bufferSize];
            clientSocket.ReceiveFrom(bufferRes, bufferRes.Length, SocketFlags.None, ref serverEP);
            Message msg = new Message(bufferRes);

            temp = null;

            if (msg.data.ToLower() == "true")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 14
0
        //Envoie un message au client contenant la liste des lobby
        public static void SendLobbyList()
        {
            Console.WriteLine("Un client a fait une demande de ListLobby");
            //Envoie message Server
            String msg = lobbyConnected.Count + "|";

            Lobby lobbyCurrent;

            for (int i = 0; i < lobbyConnected.Count(); i++)
            {
                lobbyCurrent = lobbyConnected.ElementAt(i);
                msg         += lobbyCurrent.getName() + "&"
                               + lobbyCurrent.getPlayerConnected().Count() + "&"
                               + lobbyCurrent.getMaxPlayer() + "&"
                               + lobbyCurrent.getPort()
                               + "|";
            }

            Console.WriteLine(msg);
            Message chat_nameLobby = new Message(Commande.MSG, CommandeType.REPONSE, msg + "", "");

            serverSocket.SendTo(chat_nameLobby.GetBytes(), lastClientEndPoint);
            Console.WriteLine("Message envoyé");
        }
Exemplo n.º 15
0
        //Traitement des message
        static void ProcessMsg(Message msg, EndPoint clientEP)
        {
            string dataMsg = "";

            string[] dataArray;
            try
            {
                Console.WriteLine(" commande: " + msg.commande.ToString());
                switch (msg.commande)
                {
                case Commande.CREATELOBBY:
                    dataMsg = msg.data;

                    //Split nom + player room
                    dataArray = dataMsg.Split('|');

                    createLobby(dataArray[0], int.Parse(dataArray[1]));
                    break;

                case Commande.JOINLOBBY:
                    dataMsg = msg.data;
                    Console.WriteLine("Le joueur a rejoint: " + msg
                                      .data
                                      );
                    dataArray = dataMsg.Split('|');
                    JoinLobby(dataArray[0], dataArray[1]);

                    break;

                case Commande.LEAVELOBBY:
                    dataMsg   = msg.data;
                    dataArray = dataMsg.Split('|');

                    LeaveLobby(dataArray[0], dataArray[1]);
                    break;

                case Commande.DESUBSCRIBE:

                    clientEndPoint.Remove(lastClientEndPoint);
                    break;


                case Commande.PLAYCARD:


                case Commande.SUBSCRIBE:
                    addClient(lastClientEndPoint);
                    break;

                case Commande.LISTLOBBY:
                    SendLobbyList();
                    break;

                case Commande.FREETHREAD:
                    FreeThread();
                    break;


                case Commande.MSG:
                    messageList.Add(msg);
                    Console.WriteLine(msg.data);

                    dataMsg   = msg.data;
                    dataArray = dataMsg.Split('|');


                    if (dataArray.Length == 1)
                    {
                        //Renvoie du dernier message au client
                        Message chat_SendMessageClient = new Message(Commande.MSG, CommandeType.REPONSE, messageList.ElementAt(messageList.Count - 1).data, msg.pseudo);
                        foreach (EndPoint e in clientEndPoint)
                        {
                            serverSocket.SendTo(chat_SendMessageClient.GetBytes(), e);
                        }
                    }
                    else
                    {
                        Lobby   lob = GetLobbyByName(dataArray[0]);
                        Message chat_SendMessageLobbyClient = new Message(Commande.MSG, CommandeType.REPONSE, messageList.ElementAt(messageList.Count - 1).data, msg.pseudo);
                        foreach (EndPoint e in clientEndPoint)
                        {
                            serverSocket.SendTo(chat_SendMessageLobbyClient.GetBytes(), e);
                        }
                    }


                    break;

                case Commande.ASKLOBBY:
                    Lobby lb = GetLobbyByName(msg.data);


                    break;

                case Commande.ASKLOBBYPORT:
                    Lobby   lobby             = GetLobbyByName(msg.data);
                    Message chat_SendResponse = new Message(Commande.ASKLOBBYPORT, CommandeType.REPONSE, lobby.getPort() + "", msg.pseudo);
                    serverSocket.SendTo(chat_SendResponse.GetBytes(), lastClientEndPoint);


                    break;

                case Commande.CHECKNAME:
                    String res = "";
                    if (pseudoList.Contains(msg.pseudo.ToLower()))
                    {
                        res = "true";
                    }
                    else
                    {
                        res = "false";
                        pseudoList.Add(msg.pseudo.ToLower());
                    }

                    Message m_CheckPseudo = new Message(Commande.ASKLOBBYPORT, CommandeType.REPONSE, res, msg.pseudo);
                    serverSocket.SendTo(m_CheckPseudo.GetBytes(), lastClientEndPoint);
                    break;

                case Commande.DELETENAME:
                    pseudoList.Remove(msg.data.ToLower());
                    break;



                default:
                    Console.WriteLine("Erreur commande inconnu: " + msg.commande.ToString());
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Erreur process msg: " + e.Message);
                Console.ReadKey();
            }
        }
Exemplo n.º 16
0
        //Traitement des message
        static void ProcessMsg(Message msg, EndPoint clientEP)
        {
            string dataMsg = "";

            string[] dataArray;
            try
            {
                switch (msg.commande)
                {
                case Commande.CREATELOBBY:
                    dataMsg = msg.data;

                    //Split nom + player room
                    dataArray = dataMsg.Split('|');

                    createLobby(dataArray[0], int.Parse(dataArray[1]));
                    break;

                case Commande.JOINLOBBY:
                    dataMsg   = msg.data;
                    dataArray = dataMsg.Split('|');
                    JoinLobby(dataArray[0], dataArray[1]);

                    break;

                case Commande.LEAVELOBBY:
                    dataMsg   = msg.data;
                    dataArray = dataMsg.Split('|');
                    Console.Write(dataArray[0] + " fsdfsf");
                    LeaveLobby(dataArray[0], dataArray[1]);
                    break;


                case Commande.PLAYCARD:
                    break;

                case Commande.LISTLOBBY:
                    SendLobbyList();
                    break;

                case Commande.MSG:
                    messageList.Add(msg);
                    Console.WriteLine(msg.data);

                    //Renvoie du dernier message au client
                    Message chat_SendMessageClient = new Message(Commande.MSG, CommandeType.REPONSE, messageList.ElementAt(messageList.Count - 1).data, msg.pseudo);


                    foreach (EndPoint e in clientEndPoint)
                    {
                        serverSocket.SendTo(chat_SendMessageClient.GetBytes(), e);
                    }


                    Console.WriteLine("Message envoyé");
                    break;

                default:
                    Console.WriteLine("Erreur");
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Erreur process msg: " + e.Message);
                Console.ReadKey();
            }
        }
Exemplo n.º 17
0
        public void ProcessMsg(Message msg, EndPoint clientEP)
        {
            string dataMsg = "";

            string[] dataArray;
            try
            {
                Console.WriteLine("Commande: " + msg.commande);
                switch (msg.commande)
                {
                case Commande.LEAVELOBBY:
                    playerSubScribe.Remove(endPointPlayer);
                    Player p = getPlayer(msg.pseudo);
                    RemovePlayerLobby(p);
                    Server.RefreshList(this.getName());
                    Refresh();
                    break;

                case Commande.ASKLOBBY:
                    addClient(endPointPlayer);
                    askPlayerInLobby();

                    break;


                case Commande.FREETHREAD:
                    FreeThread(msg.data);
                    break;

                case Commande.DESUBSCRIBE:
                    playerSubScribe.Remove(endPointPlayer);
                    break;

                case Commande.MSG:
                    msgList.Add(msg);
                    Console.WriteLine("Dans Lobby" + msg.data);

                    dataMsg   = msg.data;
                    dataArray = dataMsg.Split('|');

                    Message chat_SendMessageLobbyClient = new Message(Commande.MSG, CommandeType.REPONSE, msgList.ElementAt(msgList.Count - 1).data, msg.pseudo);
                    foreach (EndPoint e in playerSubScribe)
                    {
                        LobbySocket.SendTo(chat_SendMessageLobbyClient.GetBytes(), e);
                    }
                    break;

                case Commande.BEGIN:
                    CheckBegin();
                    break;

                case Commande.GO:
                    Console.WriteLine("GAME AS START: " + gameAsStart.ToString());
                    if (!gameAsStart)
                    {
                        InitGame();
                        gameAsStart = true;
                    }
                    break;

                case Commande.PICKCARD:
                    GameControllerServer.PlayerPickCard(msg.data, msg.pseudo);
                    break;

                case Commande.ASKCARD:
                    break;

                case Commande.PLAYCARD:
                    GameControllerServer.PlayCard(msg.data, msg.pseudo);
                    break;

                //EFFECT

                case Commande.GUARDEFFECT:
                    String[] guardArray = msg.data.Split('|');
                    GameControllerServer.GuardEffect(guardArray[0], guardArray[1], guardArray[2], endPointPlayer);
                    break;

                case Commande.PRIESTEFFECT:
                    GameControllerServer.PriestEffect(msg.data, msg.pseudo, endPointPlayer);
                    break;

                case Commande.BARONEFFECT:
                    GameControllerServer.BarronEffect(msg.pseudo, msg.data, endPointPlayer);
                    break;


                case Commande.HANDMAIDEEFFECT:
                    GameControllerServer.HandmaidEffect(msg.data, endPointPlayer);
                    break;

                case Commande.PRINCEEFFECT:
                    GameControllerServer.PrinceEffect(msg.pseudo, msg.data, endPointPlayer);
                    break;

                case Commande.KINGEFFECT:
                    GameControllerServer.KingEffect(msg.pseudo, msg.data, endPointPlayer);
                    break;


                case Commande.PRINCESSEFECT:
                    GameControllerServer.PrincessEffect(msg.pseudo, endPointPlayer);
                    break;

                case Commande.COUNTESSEFFECT:
                    GameControllerServer.CountessEffect();
                    break;

                case Commande.PLAYCARDVISUAL:
                    GameControllerServer.PlayCardVisual(msg.pseudo, msg.data, endPointPlayer);
                    break;

                case Commande.NOVALIDTARGET:
                    GameControllerServer.NoTarget();
                    break;

                case Commande.ASKDECK:
                    GameControllerServer.PlayerAskDeck();
                    break;

                case Commande.PLAYERLEAVE:
                    GameControllerServer.PlayerLeave();
                    break;

                case Commande.READYTOHAVECARD:
                    GameControllerServer.ReadyToHaveCard(endPointPlayer);
                    break;

                case Commande.READYTOREMOVECARD:
                    GameControllerServer.ReadyToRemoveCard(endPointPlayer);
                    break;



                default:
                    Console.WriteLine("Erreur commande inconnu: " + msg.commande);
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 18
0
        public static byte[] GetBytes(Commande commande, CommandeType type, String data, String pseudo)
        {
            Message chatCommande = new Message(commande, type, data, pseudo);

            return(chatCommande.GetBytes());
        }