fixing other pointer multi-thread problems

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13180 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hilnius 2013-07-11 12:22:35 +00:00
parent 66de06e0e5
commit ea8cb2f5c4
7 changed files with 16 additions and 18 deletions

View File

@ -76,7 +76,6 @@ Event::Event(ENetEvent* event)
Event::Event(const Event& event)
{
Log::verbose("Event", "Constructing a copy of the event.");
m_packet = NULL;
data = event.data;
// copy the peer

View File

@ -109,7 +109,6 @@ void NetworkManager::notifyEvent(Event* event)
}
// notify for the event now.
Log::info("NetworkManager", "Notifying the protocol manager.");
ProtocolManager::getInstance()->notifyEvent(event);
if (event->type == EVENT_TYPE_DISCONNECTED)

View File

@ -241,7 +241,6 @@ void ProtocolManager::update()
{
pthread_mutex_lock(&m_events_mutex); // secure threads
Event* event = m_events_to_process.back();
Log::debug("ProtocolManager", "Now processing event of type %d", event->type);
m_events_to_process.pop_back();
pthread_mutex_unlock(&m_events_mutex); // release the mutex
@ -250,7 +249,6 @@ void ProtocolManager::update()
{
if (event->data.size() > 0)
searchedProtocol = (PROTOCOL_TYPE)(event->data.getAndRemoveUInt8());
Log::debug("ProtocolManager", "Message of type %d.", searchedProtocol);
}
if (event->type == EVENT_TYPE_CONNECTED)
{

View File

@ -203,12 +203,6 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event)
// add the player to the game setup
while(m_setup->getProfile(m_next_id)!=NULL)
m_next_id++;
NetworkPlayerProfile* profile = new NetworkPlayerProfile();
profile->race_id = m_next_id;
profile->kart_name = "";
profile->user_profile = new OnlineUser("Unnamed Player");
m_setup->addPlayer(profile);
event->peer->setPlayerProfile(profile);
// notify everybody that there is a new player
NetworkString message;
// new player (1) -- size of id -- id -- size of local id -- local id;
@ -226,7 +220,15 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event)
// connection success (129) -- size of token -- token
message_ack.ai8(0x81).ai8(1).ai8(m_next_id).ai8(4).ai32(token).ai8(4).ai32(player_id);
m_listener->sendMessage(this, event->peer, message_ack);
event->peer->setClientServerToken(token);
NetworkPlayerProfile* profile = new NetworkPlayerProfile();
profile->race_id = m_next_id;
profile->kart_name = "";
profile->user_profile = new OnlineUser("Unnamed Player");
m_setup->addPlayer(profile);
event->peer->setPlayerProfile(profile);
} // accept player
else // refuse the connection with code 0 (too much players)
{

View File

@ -62,7 +62,7 @@ STKHost::~STKHost()
{
if (m_listening_thread)
{
pthread_cancel(*m_listening_thread);//, SIGKILL);
pthread_cancel(*m_listening_thread);//, SIGKILL); with kill
delete m_listening_thread;
m_listening_thread = NULL;
}
@ -86,8 +86,8 @@ void STKHost::setupServer(uint32_t address, uint16_t port, int peer_count,
max_incoming_bandwidth, max_outgoing_bandwidth);
if (m_host == NULL)
{
Log::error("STKHost", "An error occurred while trying to create an ENet \
server host.");
Log::error("STKHost", "An error occurred while trying to create an ENet"
" server host.");
exit (EXIT_FAILURE);
}
}
@ -102,8 +102,8 @@ void STKHost::setupClient(int peer_count, int channel_limit,
max_incoming_bandwidth, max_outgoing_bandwidth);
if (m_host == NULL)
{
Log::error("STKHost", "An error occurred while trying to create an ENet \
client host.");
Log::error("STKHost", "An error occurred while trying to create an ENet"
" client host.");
exit (EXIT_FAILURE);
}
}
@ -140,7 +140,7 @@ void STKHost::sendRawPacket(uint8_t* data, int length, TransportAddress dst)
to.sin_addr.s_addr = htonl(dst.ip);
sendto(m_host->socket, (char*)data, length, 0,(sockaddr*)&to, to_len);
Log::verbose("STKHost", "Raw packet sent to %i.%i.%i.%i:%u\n", ((dst.ip>>24)&0xff)
Log::verbose("STKHost", "Raw packet sent to %i.%i.%i.%i:%u", ((dst.ip>>24)&0xff)
, ((dst.ip>>16)&0xff), ((dst.ip>>8)&0xff), ((dst.ip>>0)&0xff), dst.port);
}

View File

@ -25,7 +25,7 @@
STKPeer::STKPeer()
{
m_peer = NULL;
m_player_profile = NULL;
m_player_profile = new NetworkPlayerProfile();
m_client_server_token = new uint32_t;
*m_client_server_token = 0;
m_token_set = new bool;

View File

@ -38,7 +38,7 @@ class STKPeer
void setClientServerToken(const uint32_t& token) { *m_client_server_token = token; *m_token_set = true; }
void unsetClientServerToken() { *m_token_set = false; }
void setPlayerProfile(NetworkPlayerProfile* profile) { m_player_profile = profile; }
void setPlayerProfile(NetworkPlayerProfile* profile) { *m_player_profile = *profile; }
bool isConnected() const;
uint32_t getAddress() const;