void NetGame::PingHosts() { #if _DEBUG netService().Ping(_port, 500, 250); #else netService().Ping(_port, 3000, 500); #endif }
void NetGame::DisconnectPlayer(NetPlayer* player) { net::INetConnection* connection = netService().GetConnectionById(player->ownerId()); LSL_ASSERT(connection); netService().Disconnect(connection); }
NetGame::NetGame(GameMode* game): _game(game), _race(NULL), _port(58213), _started(false), _isHost(false), _isClient(false), _player(NULL) { _i = this; netService().modelClasses().Add<NetRace>(1); netService().modelClasses().Add<NetPlayer>(2); //netService().modelClasses().Add<NetPlayerResponse>(3); netService().syncRate(70); netService().user(this); netService().profiler(&Profiler::I()); }
void NetGame::Process(unsigned time, float deltaTime) { Profiler::I().Begin("net"); if (netService().IsInit()) { netService().Process(time); for (NetPlayers::iterator iter = _players.begin(); iter != _players.end(); ++iter) (*iter)->Process(deltaTime); } Profiler::I().End(); }
NetGame::~NetGame() { netService().user(NULL); Close(); for (Users::const_iterator iter = _users.begin(); iter != _users.end(); ++iter) (*iter)->Release(); _users.Clear(); }
void NetGame::CreateHost(net::INetAcceptorImpl* impl) { if (_isHost) return; Close(); _started = true; _isHost = true; lsl::appLog.fileName = "appLog.txt"; netService().StartServer(_port, impl); netPlayer()->MakeModel<NetRace>(); }
void NetGame::Close() { if (!isStarted()) return; _started = false; _aiPlayers.clear(); _netPlayers.clear(); _netOpponents.clear(); _players.clear(); _player = NULL; _race = NULL; netService().Close(); _isHost = false; _isClient = false; }
bool NetGame::Connect(const net::Endpoint& endpoint, bool useDefaultPort, net::INetAcceptorImpl* impl) { if (_isClient) return false; Close(); _started = true; _isClient = true; net::Endpoint hostEndpoint = endpoint; if (useDefaultPort) hostEndpoint.port = _port; //lsl::appLog.fileName = "clientLog.txt"; if (!netService().Connect(hostEndpoint, impl)) { Close(); return false; } return true; }
bool NetGame::GetAdapterAddresses(lsl::StringVec& addrVec) { return netService().GetAdapterAddresses(addrVec); }
net::INetPlayer* NetGame::netPlayer() { return netService().player(); }
bool NetGame::IsPingProcess() { return netService().IsPingProcess(); }
void NetGame::CancelPing() { netService().CancelPing(); }
void NetGame::Finalizate() { Close(); netService().Finalizate(); }
void NetGame::Initializate() { netService().Initializate(); }
void UpnpNetworkBuilder::addUPnPDevices( const QList<Cagibi::Device>& upnpDevices ) { QList<NetDevice> addedDevices; QList<NetService> addedServices; QList<NetDevice>& deviceList = mNetworkPrivate->deviceList(); foreach( const Cagibi::Device& upnpDevice, upnpDevices ) { if( upnpDevice.hasParentDevice() ) continue; const QString ipAddress = upnpDevice.ipAddress(); NetDevicePrivate* d = 0; const NetDevice* deviceOfService = 0; foreach( const NetDevice& device, deviceList ) { const bool isSameAddress = ( device.ipAddress() == ipAddress ); kDebug()<<"existing device:"<<device.hostName()<<"at"<<device.ipAddress()<<"vs."<<ipAddress<<":"<<isSameAddress; // TODO: lookup hostname and try to use that if( isSameAddress ) { d = device.dPtr(); deviceOfService = &device; break; } } if( ! d ) { const QString displayName = upnpDevice.friendlyName(); const QString deviceName = displayName; d = new NetDevicePrivate( deviceName ); d->setIpAddress( ipAddress ); NetDevice device( d ); addedDevices.append( device ); deviceList.append( device ); deviceOfService = &deviceList.last(); kDebug()<<"new device:"<<deviceName<<"at"<<ipAddress; } NetServicePrivate* netServicePrivate = 0; // do a priority based lookup who can build the object // TODO: priorisation foreach( const UpnpNetSystemAble* factory, mNetSystemFactoryList ) { if( factory->canCreateNetSystemFromUpnp(upnpDevice) ) { // TODO: here we should rather see if this service already exists netServicePrivate = factory->createNetService( upnpDevice, *deviceOfService ); break; } } NetService netService( netServicePrivate ); d->addService( netService ); addedServices.append( netService ); kDebug()<<"new service:"<<netService.name()<<netService.url(); // try guessing the device type by the services on it // TODO: move into devicefactory const QString serviceType = upnpDevice.type(); NetDevice::Type deviceTypeByService = NetDevice::Unknown; QString deviceName; if( serviceType == QLatin1String("InternetGatewayDevice1") ) deviceTypeByService = NetDevice::Router; else if( serviceType == QLatin1String("PrinterBasic1") || serviceType == QLatin1String("PrinterEnhanced1") ) deviceTypeByService = NetDevice::Printer; else if( serviceType == QLatin1String("Scanner1") ) deviceTypeByService = NetDevice::Scanner; if( deviceTypeByService != NetDevice::Unknown ) { if( deviceTypeByService > d->type() ) { d->setType( deviceTypeByService ); if( ! deviceName.isEmpty() ) d->setName( deviceName ); } } } if( ! addedDevices.isEmpty() ) mNetworkPrivate->emitDevicesAdded( addedDevices ); if( ! addedServices.isEmpty() ) mNetworkPrivate->emitServicesAdded( addedServices ); }
void DNSSDNetworkBuilder::addService( DNSSD::RemoteService::Ptr service ) { QList<NetDevice>& deviceList = mNetworkPrivate->deviceList(); QString hostName = service->hostName(); // TODO: this blocks. and the ip address should be delivered from DNS-SD with resolve const QHostAddress hostAddress = DNSSD::ServiceBrowser::resolveHostName( hostName ); const QString ipAddress = hostAddress.toString(); // forget domain name if just ip address if( hostName == ipAddress ) hostName.clear(); // device TODO: only search for if we can create the service? NetDevicePrivate* d = 0; const NetDevice* deviceOfService = 0; foreach( const NetDevice& device, deviceList ) { const QString deviceHostName = device.hostName(); const bool useIpAddress = ( deviceHostName.isEmpty() || hostName.isEmpty() ); const bool isSameAddress = useIpAddress ? ( device.ipAddress() == ipAddress ) : ( deviceHostName == hostName ); kDebug()<<"existing device:"<<deviceHostName<<"at"<<device.ipAddress()<<"vs."<<hostName<<"at"<<ipAddress<<":"<<isSameAddress; if( isSameAddress ) { d = device.dPtr(); // workaround: KDNSSD currently (4.7.0) emits two signals per service // just relying on service->serviceName() is fragile, but matches // current approach in removeService(...) QString id; const QString serviceType = service->type(); foreach( const DNSSDNetSystemAble* factory, mNetSystemFactoryList ) { if( factory->canCreateNetSystemFromDNSSD(serviceType) ) { id = factory->dnssdId( service ); break; } } if( d->hasService(id) ) return; deviceOfService = &device; break; } } if( !d ) { const QString deviceName = hostName.left( hostName.indexOf(QLatin1Char('.')) ); d = new NetDevicePrivate( deviceName ); d->setHostName( hostName ); d->setIpAddress( ipAddress ); NetDevice device( d ); deviceList.append( device ); deviceOfService = &deviceList.last(); QList<NetDevice> newDevices; newDevices.append( device ); // TODO: the new service will be announced two times, once with the new device and once alone. // what to do about that? which order? okay? for now just do not attach services before. find usecases. mNetworkPrivate->emitDevicesAdded( newDevices ); kDebug()<<"new device:"<<deviceName<<"at"<<hostName<<"by"<<service->type(); } else { if( d->hostName().isEmpty() && ! hostName.isEmpty() ) d->setHostName( hostName ); } const QString serviceType = service->type(); NetServicePrivate* netServicePrivate = 0; // do a priority based lookup who can build the object // TODO: priorisation foreach( const DNSSDNetSystemAble* factory, mNetSystemFactoryList ) { if( factory->canCreateNetSystemFromDNSSD(serviceType) ) { // TODO: here we should rather see if this service already exists netServicePrivate = factory->createNetService( service, *deviceOfService ); break; } } // TODO: create dummy service // if( ! netServicePrivate ) // netServicePrivate = new UnknownService; NetService netService( netServicePrivate ); d->addService( netService ); // try guessing the device type by the services on it // TODO: move into devicefactory NetDevice::Type deviceTypeByService = NetDevice::Unknown; QString deviceName; if( serviceType == QLatin1String("_workstation._tcp") ) { deviceTypeByService = NetDevice::Workstation; deviceName = service->serviceName().left( service->serviceName().lastIndexOf(QLatin1Char('[')) ).trimmed(); } else if( serviceType == QLatin1String("_net-assistant._udp") ) { deviceTypeByService = NetDevice::Workstation; deviceName = service->serviceName(); } else if( serviceType == QLatin1String("_airport._tcp") ) deviceTypeByService = NetDevice::Router; else if( serviceType == QLatin1String("_ipp._tcp") || serviceType == QLatin1String("_printer._tcp") || serviceType == QLatin1String("_pdl-datastream._tcp") ) { deviceTypeByService = NetDevice::Printer; deviceName = service->serviceName(); } if( deviceTypeByService != NetDevice::Unknown ) { if( deviceTypeByService > d->type() ) { d->setType( deviceTypeByService ); if( ! deviceName.isEmpty() ) d->setName( deviceName ); } } QList<NetService> newServices; newServices.append( netService ); mNetworkPrivate->emitServicesAdded( newServices ); }