/** * \fn int main () * \brief entry of the smtpd process */ int main () { struct sigaction sa; memset (&sa, 0, sizeof (sigaction)); sigemptyset (&sa.sa_mask); sa.sa_sigaction = segfault_sigaction; sa.sa_flags = SA_SIGINFO; // sigaction (SIGSEGV, &sa, NULL); setvbuf (stdin, NULL, _IONBF, 0); loadConfig (); init_commands (); plugins_table = NULL; loadAllPlugin ("etc/plugins"); sayWelcome (220); mainLoop (); return 0; }
LIBEXPORT void InitServer(void) { TuxConfig_loadConfig(); #ifndef _WIN32 system("clear"); #endif if (!TuxLang_loadTranslation(config->LANG_FILE)) { printf("Unable to load the file lang/%s\n", config->LANG_FILE); printf("Please verify your config/tuxdroidserver.txt\n\n"); printf( "For more informations see link bellow:\nhttp://sourceforge.net/p/tuxdroidserver/english/ConfigFile_(en)/\n\n"); printf("Type Ctrl+C to close this application.\n\n"); getchar(); exit(0); } char ch = '\0'; char buffer[15]; int char_count; tprintf("*********************************************************\n"); tprintf("* TuxDroidServer (Version %d.%d.%d) revision %d\t\t*\n", TUXSERVER_MAJOR, TUXSERVER_MINOR, TUXSERVER_REVIS, TDS_REVISION); tprintf("*\t\t\t\t\t\t\t*\n"); tprintf("* %s %s\t\t\t*\n", TuxLang_getTranslation("HEADER_L1"), TUXSERVER_AUTHOR); #ifdef TUXSERVER_MAINTENER tprintf("*\t\t\t\t\t\t\t*\n"); tprintf("* %s %s\t\t*\n", TuxLang_getTranslation("HEADER_L2"), TUXSERVER_MAINTENER); #else tprintf("*\t\t\t\t\t\t\t*\n"); #endif #ifdef TUXDRIVER_MAINTENER tprintf("* %s %s\t\t*\n", TuxLang_getTranslation("HEADER_L3"), TUXDRIVER_MAINTENER); #endif #ifdef TUXAUDIO_MAINTENER tprintf("* %s %s\t\t*\n", TuxLang_getTranslation("HEADER_L4"), TUXAUDIO_MAINTENER); #endif tprintf("*\t\t\t\t\t\t\t*\n"); tprintf("* https://sourceforge.net/projects/tuxdroidserver/\t*\n"); tprintf("*********************************************************\n\n"); TuxLogger_Info("TuxDroidServer v%d.%d.%d-rev%d started.", TUXSERVER_MAJOR, TUXSERVER_MINOR, TUXSERVER_REVIS, TDS_REVISION); tprintf("%s %d\n\n", TuxLang_getTranslation("SERVER_LISTENING_PORT"), config->SERVER_PORT); //--------------- plugins part --- loadAllPlugin(); printf("\n%d plugin(s) loaded\n",plugins->count); if(plugins->error > 0) printf(" (%d plugin(s) on loading error)\n\n",plugins->error); else printf("\n\n"); //------------- //plugins ------------ tprintf("start - %s\n", TuxLang_getTranslation("START_CMD")); tprintf("stop - %s\n\n", TuxLang_getTranslation("STOP_CMD")); if (config->AUTO_START) basicStart(); else TuxLogger_Info( "Server waiting for orders..",NULL); do { tprintf("TuxDroidServer> "); ch = getchar(); char_count = 0; while ((ch != '\n') && (char_count < 15)) { buffer[char_count++] = ch; ch = getchar(); } buffer[char_count] = 0x00; /*NULL*/ TuxLogger_Debug( "Received command ------> %s", buffer); if (!strcmp(buffer, "start")) { TuxLogger_Debug( "Asking for server start ! buffer -----> %s", buffer); basicStart(); } if(!strcmp(buffer,"pluginslist")) { printf("\n"); int i; char *plg_infos; for(i = 0; i < plugins->count; i++) { if(plugins->plugins[i] != NULL) printf("%s [v%s] by %s\n",plugins->plugins[i]->name,plugins->plugins[i]->version,plugins->plugins[i]->author); } printf("\n"); } if (!strcmp(buffer, "stop")) { TuxLogger_Info( "Asking for server stop",NULL); tprintf("\n%s", TuxLang_getTranslation("SERVER_STOPPING")); /* Waiting before stopping the server for server_started variable to be updated */ #ifdef _WIN32 Sleep(2000); /* 2 seconds */ #else TuxSleep(2000); /* 2 seconds */ #endif break; } } while (1); if (server_started) { server_started = false; TuxLogger_Info( "Stopping server..",NULL); /* Stop server */ /* Close clients' sockets */ /* Close server's socket */ /* Close application */ isRunning = 0; /* we are stopping the server*/ /* Waiting few seconds to be sure that the first sockets will be closed */ #ifdef _WIN32 Sleep(2000); /* 2 seconds */ #else TuxSleep(2000); /* 2 seconds */ #endif tprintf("\n%s", TuxLang_getTranslation("CONNECTIONS_CLOSING")); TuxLogger_Info( "Closing connections..",NULL); int i; for (i = 0; i < nClients; i++) { TuxLogger_Debug( "Checking if connection's client %d is still alive", clients[i]->id); if (clients[i]->sock) { TuxLogger_Debug( "Closing connection for client %d", clients[i]->id); removeUniqueID(clients[i]->pID); close(clients[i]->sock); int j; for(j = 0; j < plugins->count; j++) { if(plugins->plugins[j]->delClient != NULL) plugins->plugins[j]->delClient(clients[i]); } if (clients[i]->uKey != NULL) { /*free(clients[i]->uKey); clients[i]->uKey=NULL;*/ } if (clients[i]->username != NULL) { /*free(clients[i]->username); clients[i]->username=NULL;*/ } if (clients[i] != NULL) { /*free(clients[i]); clients[i] = NULL;*/ } } } /* free(SocketThreads); */ /* Waiting 2 more seconds to be sure all connections are closed before stopping driver */ #ifdef _WIN32 Sleep(2000); /* 2 seconds */ #else TuxSleep(2000); /* 2 seconds */ #endif tprintf("\n%s", TuxLang_getTranslation("MOTORS_STOPPING")); TuxLogger_Info( "Stopping all Tuxdroid's movements..",NULL); TuxDrv_Mouth_Off(); TuxDrv_Spinning_Off(); TuxDrv_Flippers_Off(); #ifdef _WIN32 TuxDrv_Eyes_Off(); /* disabled to avoid crash on Linux due to au driver's segfault */ #endif #ifdef _WIN32 Sleep(2000); /* 2 seconds */ #else TuxSleep(2000); /* 2 seconds */ #endif tprintf("\n%s", TuxLang_getTranslation("MOTORS_RESETING")); TuxLogger_Info( "Reinitializing motors' positions",NULL); TuxDrv_ResetPositions(); #ifdef _WIN32 Sleep(5000); /* 5 seconds */ #else TuxSleep(5000); /* 5 seconds */ #endif tprintf("\n%s\n\n", TuxLang_getTranslation("AUDIO_STOPPING")); TuxAudio_StopMusic(); TuxAudio_StopTTS(); #ifdef _WIN32 Sleep(2000); /* 2 seconds */ #else TuxSleep(2000); /* 2 seconds */ #endif tprintf("\n%s\n\n", TuxLang_getTranslation("DRIVER_STOPPING")); TuxLogger_Info( "Stopping TuxDroid driver",NULL); /* Stopping driver */ TuxDrv_Stop(); /* Wait to output driver's messages before closing :) */ #ifdef _WIN32 Sleep(2000); /* 2 seconds */ #else TuxSleep(2000); /* 2 seconds */ #endif } /* PROGRAM'S END */ }