//============================================================================ // NMessageServer::DisconnectClient : Disconnect a client. //---------------------------------------------------------------------------- void NMessageServer::DisconnectClient(NEntityID clientID) { StLock acquireLock(mLock); // Disconnect the client ClientDisconnected(clientID); RemoveClient( clientID); }
LRESULT CAppWindow::OnPowerBroadcast(WPARAM wParam) { switch (wParam) { case PBT_APMSUSPEND: ClientDisconnected(CR_SUSPEND); break; case PBT_APMRESUMESUSPEND: case PBT_APMRESUMEAUTOMATIC: ClientConnected(CR_SUSPEND); break; } return TRUE; }
LRESULT CAppWindow::OnWTSSessionChange(WPARAM wParam) { switch (wParam) { case WTS_CONSOLE_CONNECT: case WTS_REMOTE_CONNECT: case WTS_SESSION_UNLOCK: ClientConnected(CR_LOCK); break; case WTS_CONSOLE_DISCONNECT: case WTS_REMOTE_DISCONNECT: case WTS_SESSION_LOCK: ClientDisconnected(CR_LOCK); break; } return 0; }
void CNetRender::HandleNewConnection() { while (server->hasPendingConnections()) { WriteLog("NetRender - new client connected"); // push new socket to list sClient client; client.socket = server->nextPendingConnection(); clients.append(client); connect(client.socket, SIGNAL(disconnected()), this, SLOT(ClientDisconnected())); connect(client.socket, SIGNAL(readyRead()), this, SLOT(ReceiveFromClient())); // tell mandelbulber version to client sMessage msg; msg.command = netRender_VERSION; msg.payload.append((char*)&version, sizeof(qint32)); SendData(client.socket, msg); emit ClientsChanged(); } }
bool PGameServer::HandleGameInfo( PClient *Client, PGameState *State, const u8 *Packet ) { // Console->Print("Inside HandleGameInfo");//NEW added static u8 GameInfo[31] = {0xfe, 0x1c, 0x00, 0x83, 0x05, // header 0x00, 0x00, 0x00, 0x00, // account id 0x00, 0x00, 0x00, 0x00, // char id 0x00, 0x00, 0x00, 0x00, // udp ip 0x00, 0x00, // udp port 0x00, 0x00, 0x00, 0x00, // unknown 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // session key }; ConnectionTCP *Socket = Client->getTCPConn(); if ( *( u16* )&Packet[3] == 0x3c87 ) { //int PortFix = Config->GetOptionInt("debug_mode"); ConnectionUDP* udpConn = ServerSock->getUDPConnection( IPStringToDWord( Client->GetAddress() ), Client->GetRemoteUDPPort() ); Client->setUDPConnection( udpConn ); if ( !udpConn ) { Console->Print( RED, BLACK, "Client %d: UDP port setup failed", Client->GetID() ); ClientDisconnected( Client ); } u16 Port = Client->getUDPConn()->getPort(); if ( Port == 0 ) Console->Print( RED, BLACK, "Client->OpenUDP() failed" ); /* if(PortFix == 1) // removed, no more use { Port = Config->GetOptionInt("useudpport"); Console->Print(YELLOW, BLACK, "UDP Port set to non-standard for debugging!"); }; */ u32 IP; std::string IPServerString; // use [server_nat_ip] for server if client is NOT on [no_nat_net] (and [no_nat_net]!=0) if ( strcmp( Config->GetOption( "no_nat_net" ).c_str(), "0" ) && strncmp( Client->GetAddress(), Config->GetOption( "no_nat_net" ).c_str(), strlen( Config->GetOption( "no_nat_net" ).c_str() ) ) ) { IPServerString = Config->GetOption( "server_nat_ip" ); } else // else client is "local" so use [server_ip] { IPServerString = Config->GetOption( "server_ip" ); } IP = IPStringToDWord( IPServerString.c_str() ); //Console->Print("IP-1 %d", IP); if ( IP == 0 ) IP = 0x0100007f; //Console->Print("IP-2 %d", IP); *( u32* )&GameInfo[13] = IP; *( u16* )&GameInfo[17] = Port; Console->Print( GREEN, BLACK, "[Info] Using UDP %s:%d on server", IPServerString.c_str(), Port ); *( u32* )&GameInfo[5] = Client->GetAccountID(); *( u32* )&GameInfo[9] = Client->GetCharID(); Console->Print( GREEN, BLACK, "[Info] Serving char id :%d", Client->GetCharID() ); Socket->write( GameInfo, 31 ); Socket->flushSendBuffer(); static const u8 READY[7] = {0xfe, 0x04, 0x00, 0x83, 0x0d, 0x00, 0x00}; Socket->write( READY, 7 ); State->TCP.mState = PGameState::TCP::GS_INGAME; State->UDP.mState = PGameState::UDP::GUS_SYNC0; //Console->Print("Sync Reset"); Client->ResetTransactionID(); // Mark char as Online PChar *Char = Client->GetChar(); Char->SetOnlineStatus( true ); //Also using this info to check if Char may have to be saved at client disconnect Client->ChangeCharLocation( Char->GetLocation(), true ); // hello-message from server.. /* std::string serverName = Config->GetOption("server_name"); std::string helloMessage = "Welcome to " + serverName + " - A TinNS Neocron Server."; char* message = (char*) helloMessage.c_str(); Chat->send(Client, CHAT_DIRECT, "System", message, false); */ bool SendBC = false; if ( Config->GetOptionInt( "broadcast_new" ) == 1 ) { if ( Config->GetOptionInt( "broadcast_new_hidestaff" ) == 1 ) { if ( Client->GetAccountLevel() > PAL_REGPLAYER ) SendBC = false; else SendBC = true; } else { SendBC = true; } } if ( SendBC == true ) { std::string playerName = Chars->GetChar( Client->GetCharID() )->GetName(); std::string serverName = Config->GetOption( "server_name" ); std::string helloMessage = "Hello " + playerName + "! Welcome to " + serverName + " - A TinNS Neocron Server."; char* message = ( char* ) helloMessage.c_str(); Chat->sendOOCBroadcast( message ); } //Console->Print("UDP Setup: %s", nlGetErrorStr(nlGetError())); } else { Console->Print( RED, BLACK, "[Notice] Gameserver protocol error (GS_GAMEINFO): invalid packet [%04x]", *( u16* )&Packet[3] ); return ( false ); } return ( true ); }
MainController::MainController(MainView *view, QString settingsFilePath, QObject *parent) : QObject(parent) ,m_view(view) ,m_settings(new Settings(this)) ,m_heartbeatText(HEARTBEAT_TEXT) ,m_heartbeatResponseText(HEARTBEAT_RESPONSE_TEXT) ,m_heartbeat_interval(0) ,m_hearbeatTimer(new QTimer(this)) ,m_errorTimer(new QTimer(this)) ,m_appSettings(new ApplicationSettings(this)) { connect(m_appSettings, SIGNAL(error(QString)),this, SLOT(onAppSettingsError(QString))); /* load setting from the json file */ if (m_appSettings->parseJSON(settingsFilePath)) { m_screen = new Screen(view, m_appSettings->screenSaverTimeout(), m_appSettings->screenOriginalBrigtness(), m_appSettings->screenDimBrigtness(), this); m_watchdog = new Watchdog(this, m_appSettings->enableWatchdog()); m_beep = new Beep(this); /* Define objects that can be used in qml */ m_view->rootContext()->setContextProperty("connection",this); m_view->rootContext()->setContextProperty("settings", m_settings); m_view->rootContext()->setContextProperty("screen", m_screen); m_view->rootContext()->setContextProperty("watchdog", m_watchdog); m_view->rootContext()->setContextProperty("beeper", m_beep); /* Enable or disable ack */ if (m_appSettings->enableAck()) enableLookupAck(); else disableLookupAck(); /* Enablle or disable heartbeat */ connect(m_hearbeatTimer,SIGNAL(timeout()),this, SLOT(onHeartbeatTimerTimeout())); if (m_appSettings->enableHeartbeat()) enableHeartbeat(m_appSettings->heartbeatInterval()); else disableHeartbeat(); /* Add a connection to the view statusChanged signal */ connect(m_view, SIGNAL(statusChanged(QQuickView::Status)), this, SLOT(onViewStatusChanged(QQuickView::Status))); m_clients = 0; m_enableTranslator = false; m_startUpError = ""; /* Create the TCP string servers and add connections */ int i = 0; foreach(const StringServerSetting &server, m_appSettings->stringServers()) { StringServer *stringServer = new StringServer(this, server.port(), server.parseJson(), server.translate(), server.translateId(), server.primaryConnection()); if (server.translate()) m_enableTranslator = true; connect(stringServer, SIGNAL(PrimaryConnectionAvailable()), this, SLOT(onPrimaryConnectionAvailable())); connect(stringServer, SIGNAL(MessageAvailable(QByteArray, bool, bool, QString)) , this, SLOT(onMessageAvailable(QByteArray, bool, bool, QString))); connect(stringServer, SIGNAL(ClientConnected()), this, SLOT(onClientConnected())); connect(stringServer, SIGNAL(ClientDisconnected()), this, SLOT(onClientDisconnected())); if (stringServer->Start()) { m_stringServerList.append(stringServer); i += 1; } else { delete stringServer; } } /* Create the Serial Servers and add the connections */ i = 0; foreach(const SerialServerSetting &server, m_appSettings->serialServers()) { SerialServer *serialServer = new SerialServer(server, this); connect(serialServer, SIGNAL(ClientConnected()), this, SLOT(onClientConnected())); connect(serialServer, SIGNAL(PrimaryConnectionAvailable()), this, SLOT(onPrimaryConnectionAvailable())); connect(serialServer, SIGNAL(MessageAvailable(QByteArray, bool, bool, QString)) , this, SLOT(onMessageAvailable(QByteArray, bool, bool, QString))); connect(serialServer, SIGNAL(Error(QString)), this, SLOT(showError(QString))); if (server.translate()) m_enableTranslator = true; if (serialServer->Start()) { m_serialServerList.append(serialServer); i += 1; } else { delete serialServer; } } if (m_enableTranslator){ /* Initialize the Translator object */ m_transLator = new Translator(m_appSettings->translateFile(), m_appSettings->translateMaxMapSize(), this); /* Load and parse the translate file. */ m_transLator->loadTranslations(); } /* check if we need to load a language translate file */ if (m_appSettings->languageFile().length() > 0) { loadLanguageTranslator(m_appSettings->languageFile()); } setMainViewPath(m_appSettings->mainView()); m_view->show(); }