Exemple #1
0
        public void Update(Control control, Map map, Player player, GameTime time, Package package)
        {
            UpdatePlayers(control, map);

            NetOutgoingMessage msgout = NetClient.CreateMessage();
            msgout.Write(BuildCommand(player));
            NetClient.SendMessage(msgout, NetDeliveryMethod.Unreliable);

            NetIncomingMessage msg;
            while ((msg = NetClient.ReadMessage()) != null)
            {
                switch(msg.MessageType)
                {
                    case NetIncomingMessageType.DiscoveryResponse:
                        NetClient.Connect(msg.SenderEndpoint);

                        Player newplayer = new Player();
                        newplayer.Initialize(PlayerTexture, BarsTexture, package, map.Spawn);
                        Messages.Add("new player");
                        Players.Add(newplayer);
                        break;
                    case NetIncomingMessageType.Data:

                        HandleData(msg);

                        break;
                    default:
                       // Messages.Add(msg.ReadString());
                        break;
                }
            }
        }
Exemple #2
0
        public void Update(Control control, Map map, Player player, GameTime time, Package package)
        {
            UpdatePlayers(control, map);

            NetOutgoingMessage msgout = NetServer.CreateMessage();
            msgout.Write(BuildCommand(player));
            NetServer.SendToAll(msgout, NetDeliveryMethod.Unreliable);

            Time = time;
            NetIncomingMessage msg;
            while ((msg = NetServer.ReadMessage()) != null)
            {
                switch (msg.MessageType)
                {
                    case NetIncomingMessageType.DiscoveryRequest:
                        NetServer.SendDiscoveryResponse(null, msg.SenderEndpoint);
                        break;
                    case NetIncomingMessageType.StatusChanged:
                        NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
                        if (status == NetConnectionStatus.Connected)
                        {
                            Player newplayer = new Player();
                            newplayer.Initialize(PlayerTexture, BarsTexture, package, map.Spawn);

                            Players.Add(newplayer);

                            Message(NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier) + " connected!");
                        }
                        else if(status == NetConnectionStatus.Disconnected)
                        {
                            Message(NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier) + " disconnected!");
                        }
                        break;
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.ErrorMessage:
                        Messages.Add(new ChatMessage(msg.ReadString(), time));
                        break;
                    case NetIncomingMessageType.Data:
                        HandleData(msg);
                        break;
                    default:
                        Messages.Add(new ChatMessage("Unhandled request ("+msg.MessageType+"): " + msg.ReadString(), time));
                        break;
                }
                NetServer.Recycle(msg);
            }
        }