Пример #1
0
        /// <summary>
        /// Envoie un message de nouvelle balle au serveur
        /// </summary>
        /// <param name="ID">L'ID du joueur qui a tiré</param>
        /// <param name="angleTir">L'angle de tir</param>
        public void SendNewBullet(long ID, float angleTir)
        {
            NetOutgoingMessage outmsg = GameClient.CreateMessage();
            NewBulletGame      nb     = new NewBulletGame(ID, angleTir);

            nb.EncodeMessage(outmsg);
            GameClient.SendMessage(outmsg, NetDeliveryMethod.ReliableOrdered);
        }
Пример #2
0
 /// <summary>
 /// Transfère les données d'un message client vers ce message
 /// </summary>
 /// <param name="msg">Le message du client</param>
 public void TransferData(NewBulletGame msg)
 {
     PlayerID = msg.PlayerID;
     AngleTir = msg.AngleTir;
 }
Пример #3
0
        /// <summary>
        /// Procédure qui traite les messages de type Data venant des client
        /// </summary>
        /// <param name="inc">Le message entrant</param>
        public void TreatGameMessages(NetIncomingMessage inc)
        {
            GameMessageTypes   messagetype = (GameMessageTypes)inc.ReadByte();
            NetOutgoingMessage outmsg      = GameServer.CreateMessage();

            switch (messagetype)
            {
            case GameMessageTypes.GetMapSeed:
                NetOutgoingMessage outmsg1     = GameServer.CreateMessage();
                SendMapSeed        sendmapseed = new SendMapSeed(GameSeed);
                sendmapseed.EncodeMessage(outmsg1);
                NetSendResult res = GameServer.SendMessage(outmsg1, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered);

                break;

            case GameMessageTypes.SendPlayerData:
                PlayerDataGame playerdatagame = new PlayerDataGame();
                playerdatagame.DecodeMessage(inc);
                PlayerDataServer playerdataserver = new PlayerDataServer();
                playerdataserver.TransferData(playerdatagame);
                foreach (NetConnection co in GameServer.Connections)
                {
                    if (co != inc.SenderConnection)
                    {
                        NetOutgoingMessage outmsg2 = GameServer.CreateMessage();
                        playerdataserver.EncodeMessage(outmsg2);
                        GameServer.SendMessage(outmsg2, co, NetDeliveryMethod.ReliableOrdered);
                    }
                }
                break;

            case GameMessageTypes.SendArrival:
                NetOutgoingMessage outmsg3 = GameServer.CreateMessage();
                SendArrival        msg     = new SendArrival();
                msg.DecodeMessage(inc);
                if (PlayerList.Count > 0)
                {
                    foreach (PlayerSignature ps in PlayerList)
                    {
                        SendPlayerListToNewPlayer(ps, inc);
                    }
                }
                AddNewPlayerToList(msg.Pseudo, msg.TeamNumber, msg.ID, msg.Weapon, inc.SenderConnection);
                SendNewPlayerMessage(inc, msg.Pseudo, msg.ID, msg.TeamNumber, msg.Weapon);
                outmsg3 = GameServer.CreateMessage();
                ConfirmArrival nmsg = new ConfirmArrival();
                nmsg.EncodeMessage(outmsg3);
                GameServer.SendMessage(outmsg3, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered);
                break;

            case GameMessageTypes.NewBulletGame:
                NewBulletGame nbmsg = new NewBulletGame();
                nbmsg.DecodeMessage(inc);
                NewBulletServer nbmsg2 = new NewBulletServer();
                nbmsg2.TransferData(nbmsg);
                foreach (NetConnection co in GameServer.Connections)
                {
                    if (co != inc.SenderConnection)
                    {
                        NetOutgoingMessage outmsg4 = GameServer.CreateMessage();
                        nbmsg2.EncodeMessage(outmsg4);
                        GameServer.SendMessage(outmsg4, co, NetDeliveryMethod.ReliableOrdered);
                    }
                }
                break;

            case GameMessageTypes.SendPlayerRespawn:
                RespawnPlayerGame prmsg = new RespawnPlayerGame();
                prmsg.DecodeMessage(inc);
                RespawnPlayerServer prmsg2 = new RespawnPlayerServer();
                prmsg2.TransferData(prmsg);
                foreach (NetConnection co in GameServer.Connections)
                {
                    if (co != inc.SenderConnection)
                    {
                        NetOutgoingMessage outmsg5 = GameServer.CreateMessage();
                        prmsg2.EncodeMessage(outmsg5);
                        GameServer.SendMessage(outmsg5, co, NetDeliveryMethod.ReliableOrdered);
                    }
                }
                break;

            case GameMessageTypes.SendDeath:
                PlayerDeathGame pdmsg = new PlayerDeathGame();
                pdmsg.DecodeMessage(inc);
                PlayerDeathServer pdmsg2 = new PlayerDeathServer();
                pdmsg2.TransferData(pdmsg);
                foreach (NetConnection co in GameServer.Connections)
                {
                    if (co != inc.SenderConnection)
                    {
                        NetOutgoingMessage outmsg6 = GameServer.CreateMessage();
                        pdmsg2.EncodeMessage(outmsg6);
                        GameServer.SendMessage(outmsg6, co, NetDeliveryMethod.ReliableOrdered);
                    }
                }
                break;

            case GameMessageTypes.SendDisconnection:
                SendDisconnectionMessage(inc.ReadInt64(), inc);
                break;

            default:
                break;
            }
        }