Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Dictionary<int, Player> players = new Dictionary<int, Player>();
- public Player[] playerList;
- // EXAMPLE: editing the list
- public void AcceptPlayer( Player player ) {
- lock( playerListLock ) {
- lock( mapLock ) {
- if( map == null ) {
- LoadMap();
- }
- }
- players.Add( player.id, player );
- UpdatePlayerList();
- }
- // *snip*
- }
- // Cache the player list to an array (players -> playerList)
- public void UpdatePlayerList() {
- lock( playerListLock ) {
- Player[] newPlayerList = new Player[players.Count];
- int i = 0;
- foreach( Player player in players.Values ) {
- newPlayerList[i++] = player;
- }
- playerList = newPlayerList;
- }
- }
- // EXAMPLE: fast, safe reading of the list
- // Send a list of players to the specified new player
- internal void SendPlayerList( Player player ) {
- Player[] tempList = playerList;
- for( int i = 0; i < tempList.Length; i++ ) {
- if( tempList[i] != null && tempList[i] != player && !tempList[i].isHidden ) {
- player.session.Send( PacketWriter.MakeAddEntity( tempList[i], tempList[i].pos ) );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement