lot of code refactoring, now protocols can choose whether they receive network messages (and more generally events) in a synchronous mode (along with the main loop) or in an asynchronous mode
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13404 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
b394bd9295
commit
55bd9e18fd
@ -70,6 +70,21 @@ void ClientLobbyRoomProtocol::leave()
|
|||||||
|
|
||||||
bool ClientLobbyRoomProtocol::notifyEvent(Event* event)
|
bool ClientLobbyRoomProtocol::notifyEvent(Event* event)
|
||||||
{
|
{
|
||||||
|
assert(m_setup); // assert that the setup exists
|
||||||
|
if (event->type == EVENT_TYPE_MESSAGE)
|
||||||
|
{
|
||||||
|
NetworkString data = event->data();
|
||||||
|
assert(data.size()); // assert that data isn't empty
|
||||||
|
uint8_t message_type = data[0];
|
||||||
|
if (message_type != 0x03) // kart selection update only here (for now)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
event->removeFront(1);
|
||||||
|
if (message_type == 0x03) // kart selection update
|
||||||
|
kartSelectionUpdate(event);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,14 +98,14 @@ bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
|
|||||||
NetworkString data = event->data();
|
NetworkString data = event->data();
|
||||||
assert(data.size()); // assert that data isn't empty
|
assert(data.size()); // assert that data isn't empty
|
||||||
uint8_t message_type = data[0];
|
uint8_t message_type = data[0];
|
||||||
|
if (message_type == 0x03) // kart selection update is synchronous (updates gui)
|
||||||
|
return false;
|
||||||
event->removeFront(1);
|
event->removeFront(1);
|
||||||
Log::info("ClientLobbyRoomProtocol", "Message of type %d", message_type);
|
Log::info("ClientLobbyRoomProtocol", "Message of type %d", message_type);
|
||||||
if (message_type == 0x01) // new player connected
|
if (message_type == 0x01) // new player connected
|
||||||
newPlayer(event);
|
newPlayer(event);
|
||||||
else if (message_type == 0x02) // player disconnected
|
else if (message_type == 0x02) // player disconnected
|
||||||
disconnectedPlayer(event);
|
disconnectedPlayer(event);
|
||||||
else if (message_type == 0x03) // kart selection update
|
|
||||||
kartSelectionUpdate(event);
|
|
||||||
else if (message_type == 0x04) // start race
|
else if (message_type == 0x04) // start race
|
||||||
startGame(event);
|
startGame(event);
|
||||||
else if (message_type == 0x05) // start selection phase
|
else if (message_type == 0x05) // start selection phase
|
||||||
@ -101,10 +116,11 @@ bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
|
|||||||
connectionAccepted(event);
|
connectionAccepted(event);
|
||||||
else if (message_type == 0x82) // kart selection refused
|
else if (message_type == 0x82) // kart selection refused
|
||||||
kartSelectionRefused(event);
|
kartSelectionRefused(event);
|
||||||
|
return true;
|
||||||
} // message
|
} // message
|
||||||
else if (event->type == EVENT_TYPE_CONNECTED)
|
else if (event->type == EVENT_TYPE_CONNECTED)
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
} // connection
|
} // connection
|
||||||
else if (event->type == EVENT_TYPE_DISCONNECTED) // means we left essentially
|
else if (event->type == EVENT_TYPE_DISCONNECTED) // means we left essentially
|
||||||
{
|
{
|
||||||
@ -114,8 +130,9 @@ bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
|
|||||||
m_listener->requestTerminate(this);
|
m_listener->requestTerminate(this);
|
||||||
NetworkManager::getInstance()->reset();
|
NetworkManager::getInstance()->reset();
|
||||||
NetworkManager::getInstance()->removePeer(*event->peer); // prolly the same as m_server
|
NetworkManager::getInstance()->removePeer(*event->peer); // prolly the same as m_server
|
||||||
|
return true;
|
||||||
} // disconnection
|
} // disconnection
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user