当前位置: 首页>>代码示例>>C#>>正文


C# NetConnection.Deny方法代码示例

本文整理汇总了C#中Lidgren.Network.NetConnection.Deny方法的典型用法代码示例。如果您正苦于以下问题:C# NetConnection.Deny方法的具体用法?C# NetConnection.Deny怎么用?C# NetConnection.Deny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lidgren.Network.NetConnection的用法示例。


在下文中一共展示了NetConnection.Deny方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddPlayer

        public void AddPlayer(NetConnection connection, PlayerInformation playerInfo)
        {
            String denyReason;
            Byte slot = AllocateSlot(playerInfo, out denyReason);

            // could not allocate the player if AllocateSlot returns DummySlot
            if (slot == ProtocolInformation.DummySlot)
            {
                Log.InfoFormat("Player \"{0}\" from {1} tried to join, but was rejected ({2}).",
                               playerInfo.Callsign, connection, denyReason);
                connection.Deny(denyReason);
                return;
            }

            // we can now approve the player if we get here
            connection.Approve();

            // add player to our list
            players[slot] = new Player(this, slot, connection, playerInfo);

            // and tell everyone else about this awesome new player
            Log.DebugFormat("Sending MsgAddPlayer to everyone else about player #{0}", slot);

            NetOutgoingMessage packet = Server.CreateMessage();

            MsgAddPlayerPacket message = new MsgAddPlayerPacket(players[slot].PlayerInfo, false);

            packet.Write((Byte)message.MsgType);
            message.Write(packet);

            Log.DebugFormat("MsgAddPlayer Compiled ({0} bytes) and being sent to {1} recipients",
                            packet.LengthBytes, players.Count - 1);

            // send to everyone except our new player, we let Player itself decide when to send the state to the new guy
            Server.SendToAll(packet, connection, NetDeliveryMethod.ReliableOrdered, 0);
        }
开发者ID:aotis,项目名称:AngryTanks,代码行数:36,代码来源:GameKeeper.cs

示例2: Start

        public void Start()
        {
            NetIncomingMessage packetin;
            while (true)
            {
                while ((packetin = _netserver.ReadMessage()) != null)
                {
                    _msgSender = packetin.SenderConnection;
                    switch (packetin.MessageType)
                    {
                        case NetIncomingMessageType.StatusChanged:
                            {
                                NetConnectionStatus status = (NetConnectionStatus)packetin.ReadByte();
                                //Player doesnt want to play anymore
                                if (status == NetConnectionStatus.Disconnected || status == NetConnectionStatus.Disconnecting)
                                {
                                    _mineserver.Console.ConsoleWrite(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender).Name + " Disconnected");
                                    _mineserver.ServerSender.SendPlayerLeft(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                    _mineserver.PlayerManager.RemovePlayer(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                }
                                break;
                            }
                        case NetIncomingMessageType.DiscoveryRequest:
                            {
                                _mineserver.ServerSender.SendDiscoverResponse(packetin.SenderEndpoint);
                                break;
                            }
                        case NetIncomingMessageType.ConnectionApproval:
                            {
                                //If the server is full then deny
                                if (_netserver.ConnectionsCount == _netserver.Configuration.MaximumConnections)
                                {
                                    _msgSender.Deny("serverfull");
                                    break;
                                }

                                int version = packetin.ReadInt32();
                                string name = packetin.ReadString();

                                //If the version is any other then the server deny
                                if(_mineserver.VersionMatch(version) == false)
                                {
                                    _msgSender.Deny("versionmismatch");
                                    break;
                                }

                                ServerPlayer dummy = new ServerPlayer(_msgSender);
                                if (_mineserver.PlayerManager.NameExists(name))
                                {
                                    name += dummy.Id;
                                }

                                dummy.Name = name;
                                _mineserver.PlayerManager.AddPlayer(dummy);
                                _msgSender.Approve();
                                Thread.Sleep(4000);
                                _mineserver.GameWorld.GenerateSpawnPosition(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                _mineserver.ServerSender.SendCurrentWorld(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                _mineserver.ServerSender.SendInitialUpdate(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                _mineserver.ServerSender.SendPlayerJoined(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                _mineserver.ServerSender.SendOtherPlayersInWorld(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                _mineserver.Console.ConsoleWrite(name + " Connected");
                                break;
                            }
                        case NetIncomingMessageType.Data:
                            {
                                PacketType dataType = (PacketType)packetin.ReadByte();

                                switch (dataType)
                                {
                                    case PacketType.PlayerMovementUpdate:
                                        {
                                            _mineserver.PlayerManager.GetPlayerByConnection(_msgSender).Position = packetin.ReadVector3();
                                            _mineserver.ServerSender.SendMovementUpdate(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                            break;
                                        }
                                    case PacketType.PlayerBlockSet:
                                        {
                                            Vector3 pos = packetin.ReadVector3();
                                            _mineserver.MapManager.WorldMap[(int)pos.X, (int)pos.Y, (int)pos.Z] = (BlockTypes)packetin.ReadByte();
                                            break;
                                        }
                                }
                                break;
                            }
                    }
                }
            }
        }
开发者ID:dkfdevil,项目名称:Mine-World,代码行数:89,代码来源:ServerListener.cs

示例3: ConnectionRequest

        private void ConnectionRequest(NetConnection connection, NetIncomingMessage message)
        {
            string playerName = null;
            try
            {
                playerName = message.ReadString();
            }
            catch { }

            if (playerName == null)
                connection.Deny("invalid message");
            else
            {
                NetworkPlayer player = new NetworkPlayer(playerName, connection);
                PendingPlayers.Enqueue(player);
                connection.Tag = player;
            }
        }
开发者ID:jDomantas,项目名称:HeliumThird,代码行数:18,代码来源:NetworkConnection.cs


注:本文中的Lidgren.Network.NetConnection.Deny方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。