Inheritance: IEntity
示例#1
0
        public void AddPlayer(Player player)
        {
            this.players.Add(player);

            Packet packet = new Packet(PacketType.PlayerDataPacket);
            packet.Message.Write(player.PlayerIndex);
            packet.Message.Write(player.Name);
            packet.Message.Write(player.Level);
            packet.Message.Write(player.Position);
            packet.Message.Write(player.Direction);
            packet.Message.Write(player.TextureNumber);

            foreach (var mPlayer in this.players.Where(mPlayer => mPlayer != player))
            {
                mPlayer.Connection.SendMessage(packet.Message, NetDeliveryMethod.ReliableOrdered, (int)ChannelTypes.WORLD);
            }
        }
        public Player LoadPlayer(string filePath)
        {
            var player = new Player { Position = new Vector() };

            using (var fileStream = new FileStream(filePath + ".dat", FileMode.Open))
            {
                using (var binaryReader = new BinaryReader(fileStream))
                {
                    player.Name = binaryReader.ReadString();
                    player.Password = binaryReader.ReadString();
                    player.TextureNumber = binaryReader.ReadInt32();
                    player.Position.X = binaryReader.ReadInt32();
                    player.Position.Y = binaryReader.ReadInt32();

                    int statCount = binaryReader.ReadInt32();
                    for (int i = 0; i < statCount; i++)
                        player.SetStat((Stats)i, binaryReader.ReadInt32());
                }
            }

            return player;
        }
 public void AddPlayer(Player player, long playerIndex)
 {
     _players.Add(playerIndex, player);
 }
 private void Connection_Received(object sender, Networking.ConnectionEventArgs e)
 {
     var player = new Player(e.Connection.RemoteUniqueIdentifier);
     player.Connection = e.Connection;
     this.AddPlayer(player, e.Connection.RemoteUniqueIdentifier);
 }
        private bool AuthenticateLogin(Player player)
        {
            var actualPlayer = this.LoadPlayer(Constants.FILEPATH_PLAYERS + player.Name);

            if (actualPlayer.Name == player.Name && actualPlayer.Password == player.Password)
            {
                // Alright, the player is a-okay; let's really load him in now, and pass on the connection from the 'temporary' player.
                actualPlayer.Connection = player.Connection;
                player = actualPlayer;

                return true;
            }

            return false;
        }
 public void RemovePlayer(Player player)
 {
     _players.Remove(player.PlayerIndex);
 }
        public bool RegisterPlayer(Player player)
        {
            if (!this.AuthenticateRegistration(player.Name, player.Password)) return false;

            this.AppendPlayerName(player.Name);

            player.AccessLevel = Player.AccessLevels.Player;

            player.Save(Constants.FILEPATH_PLAYERS);

            return true;
        }
示例#8
0
        public void RemovePlayer(Player player, bool leftGame)
        {
            // Free up the tile.
            this.GetTile(player.Position).IsOccupied = false;

            // Remove the player from the map player list.
            this.players.Remove(player);

            Packet packet = new Packet(PacketType.LogoutPacket);
            packet.Message.Write(player.PlayerIndex);
            this.SendPacket(packet, NetDeliveryMethod.ReliableOrdered, ChannelTypes.WORLD);

            if (!leftGame) return;

            foreach (var mapPlayer in this.players)
            {
                mapPlayer.SendMessage(player.Name + " has left " + ServerConfiguration.GameName + ".");
            }
        }