Jump to content
  • Advertisement
Sign in to follow this  
Mr_Fhqwhgads

Best Way to manage a list? Problem erasing

This topic is 4219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have a list of players that when one disconnects, I want to erase it.
case ID_NEW_INCOMING_CONNECTION:
{	// New Connection
	CPlayer player = CPlayer( packet->playerId );
	playerList.push_back( player );
	std::cout << "Incoming Connection - ";
	std::cout << packet->playerId.ToString() << "\n";
}

		case ID_DISCONNECTION_NOTIFICATION:
		{	// Player Disconnected
			std::cout << "Player Disconnected";
			for(std::list<CPlayer>::iterator itr = playerList.begin(); itr != playerList.end(); itr++)
			{
				// If we found it
				if( itr->getPlayerID() == packet->playerId )
				{
					std::cout << "\nWe Found It!\n";
					itr = playerList.erase( itr );
					break;
				}
			}
		}
But for some reason the object still exists? How do I delete it? [Edited by - Mr_Fhqwhgads on January 26, 2007 12:12:16 AM]

Share this post


Link to post
Share on other sites
Advertisement
Can you repost the code? It looks like some relevant portions of the example got omitted, and the braces don't appear to be correct.

Share this post


Link to post
Share on other sites
Also, what do you mean by 'the object still exists'? Do you mean that the player targeted for removal is still in the list?

Perhaps you could add some debug output confirming that a player with the specified ID has been found and that erase() has been called.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Can you repost the code? It looks like some relevant portions of the example got omitted, and the braces don't appear to be correct.



Opps, edited it.

Hmmm.....I guess your right. For some reason its not finding the player...lemme stare at the code...:P

EDIT:

Ok, I got it working, now it says that it found it but it stills prints the playerID.


case ID_DISCONNECTION_NOTIFICATION:
{ // Player Disconnected
std::cout << "Player Disconnected";
for(std::list<CPlayer>::iterator itr = playerList.begin(); itr != playerList.end(); ++itr)
{
// If we found it
if( itr->playerID == packet->playerId )
{
std::cout << "\nWe Found It!\n";
itr = playerList.erase( itr );
break;
}
std::cout << "\nDidn't find it\n";
}
}


[Edited by - Mr_Fhqwhgads on January 26, 2007 12:11:45 AM]

Share this post


Link to post
Share on other sites
Make sure you have breaks at the end of your case blocks, or else they'll fall through (although it doesn't seem this would cause the behavior your describe).

Anyway, you should really add some more debug output. Print the size of the list before and after every player addition or deletion, as well as before printing out the player IDs. Also, print the ID of the player that is disconnected. You could also print out the player IDs directly before and after every insertion or removal.

With a little debug output you really should be able to home in on the problem fairly quickly (or at least narrow it down). [Sounds like you already narrowed it down :)]

Share this post


Link to post
Share on other sites
Well...for some very strange reason after I close the client and it says that player disconnected, it says that he connected again. Raknet is making less and less sense every day. Time for a new network library maby?


EDIT::

I think what I need to do is not add the player to the list when he connects, but when he tries to login.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!