示例#1
0
void NetGameClient_Impl::process()
{
	MutexSection mutex_lock(&mutex);
	std::vector<NetGameNetworkEvent> new_events;
	new_events.swap(events);
	mutex_lock.unlock();
	for (unsigned int i = 0; i < new_events.size(); i++)
	{
		switch (new_events[i].type)
		{
		case NetGameNetworkEvent::client_connected:
			sig_game_connected();
			break;
		case NetGameNetworkEvent::event_received:
			sig_game_event_received(new_events[i].game_event);
			break;
		case NetGameNetworkEvent::client_disconnected:
			sig_game_disconnected();
			connection.reset();
			break;
		default:
			throw Exception("Unknown server event type");
		}
	}
}
示例#2
0
文件: server.cpp 项目: eoma/gm-engine
void NetGameServer_Impl::process()
{
	MutexSection mutex_lock(&mutex);
	std::vector<NetGameNetworkEvent> new_events;
	new_events.swap(events);
	mutex_lock.unlock();

	for (auto & new_event : new_events)
	{
		switch (new_event.type)
		{
		case NetGameNetworkEvent::client_connected:
			sig_game_client_connected(new_event.connection);
			break;
		case NetGameNetworkEvent::event_received:
			sig_game_event_received(new_event.connection, new_event.game_event);
			break;
		case NetGameNetworkEvent::client_disconnected:
			{
				std::string reason = new_event.game_event.get_name();
				sig_game_client_disconnected(new_event.connection, reason);
			}

			// Destroy connection object
			{
				MutexSection mutex_lock(&mutex);
				std::vector<NetGameConnection *>::iterator connection_it;
				connection_it = std::find(connections.begin(), connections.end(), new_event.connection);
				if (connection_it != connections.end())
				{
					connections.erase( connection_it );
				}
				delete new_event.connection;
			}
			break;
		default:
			throw Exception("Unknown server event type");
		}
	}
}