void ReadData(NetIncomingMessage msg)
 {
     var type = msg.ReadTransferType();
     switch (type)
     {
         case Helpers.TransferType.NewConnection: NewServerConnection(msg); break;
         case Helpers.TransferType.PlayerUpdate: UpdateOtherPlayer(msg); break;
         case Helpers.TransferType.ProjectileUpdate: UpdateProjectile(msg); break;
         case Helpers.TransferType.HealthUpdate:UpdateHealthBar(msg); break;
     }
 }
Пример #2
0
        /// <summary>
        /// Hämtar alla nya meddelanden, läggs i
        /// update-funktionen!
        /// </summary>
        public void GetMsgs()
        {
            if (internetConnection)
            {
                while ((im = client.ReadMessage()) != null)
                {
                    switch (im.MessageType)
                    {
                        case NetIncomingMessageType.DiscoveryResponse:
                            //Ansluter om server hittas
                            client.Connect(im.SenderEndpoint);
                            break;
                        case NetIncomingMessageType.Data:
                            //Undersöker vilken sorts meddelande som mottas
                            var type = im.ReadTransferType();
                            switch (type)
                            {
                                //Ny anslutning
                                case Constants.NewConnection:
                                    players = new OtherPlayer[Constants.MAXPLAYERS];
                                    Globals.players = players;
                                    player = Package.MsgToPlayer(im, device);
                                    Console.WriteLine("Constants.NewConnection:" + player.model);
                                    Globals.player = player;
                                    connected = true;
                                    break;

                                //Ngn annan disconnectade
                                case Constants.ClientDisconnect:
                                    Package.PlayerLeft(im, players);
                                    break;

                                //Spelaruppdatering
                                case Constants.PlayerUpdate:
                                    Package.ToOtherPlayers(im, players);
                                    break;

                                //Någon har skjutit
                                case Constants.HitSomeone:
                                    Int32 k = im.ReadInt32();
                                    Int32 shooter = im.ReadInt32();
                                    if (k == Globals.player.id)
                                    {
                                        Globals.player.GotHit(10, shooter);
                                    }
                                    break;

                                case Constants.Status:
                                    Int32 iii = im.ReadInt32();
                                    Int16 st = im.ReadInt16();
                                    if(Globals.players[iii] != null)
                                        Globals.players[iii].activity = st;
                                    break;
                                case Constants.RewardKiller:
                                    /*Int32 jj = im.ReadInt32();
                                    if (Globals.player.id == jj)
                                        Globals.player.killingspree = true;*/
                                    break;
                            }
                            break;
                    }
                    client.Recycle(im);
                }
            }
        }
Пример #3
0
        static void HandleMsgs()
        {
            while ((msg = server.ReadMessage()) != null)
            {
                switch (msg.MessageType)
                {
                    case NetIncomingMessageType.DiscoveryRequest:
                        // Server received a discovery request from a client;
                        server.SendDiscoveryResponse(null, msg.SenderEndpoint);
                        Console.WriteLine("Discovery request!");
                        break;
                    case NetIncomingMessageType.StatusChanged:
                        StatusChanged(msg);
                        break;
                    case NetIncomingMessageType.Data:

                        // broadcast this to all connections, except sender
                        var type = msg.ReadTransferType();
                        if (type == Constants.PlayerUpdate)
                        {
                            Brodcast(msg);
                        }
                        else if (type == Constants.ClientDisconnect)
                        {
                            PlayerLeft(msg);
                        }
                        else if (type == Constants.HitSomeone)
                        {
                            SendHit(msg);
                        }
                        else if (type == Constants.Status)
                        {
                            UpdateStatus(msg);
                        }
                        else if (type == Constants.RewardKiller)
                        {

                        }
                        break;
                }
                server.Recycle(msg);
            }
        }