void Init() { AddService(new IR_RST_Interface); AddService(new IR_U_Interface); AddService(new IR_User_Interface); InitUser(); InitRST(); }
/* Add client to struct, Init, print about it, check for start game. */ void ConnectClient (struct clientlist *clList, int fd) { struct client * user; user = (struct client *) malloc (sizeof(struct client)); AddClientToList (user, clList); InitUser (user, clList, fd); printf ("New client connected. FD=%d. #%d.\n", fd, clList->cnt); PrintToFDSuccessConnect (fd); PrintToAll(clList, StatusUsersConnecting(clList)); if ( clList->cnt == clList->maxPlayers ) { ReadyToStartGame (clList); } }
void MainServer() { InitInterfaceLocks(); InitInterface(); /* starts a thread with the window */ WrapInit(); InitMemory(); /* memory needs channels in general, but need to start before config, so just be careful. */ InitConfig(); LoadConfig(); /* must be nearly first since channels use it */ InitDebug(); InitChannelBuffer(); OpenDefaultChannels(); lprintf("Starting %s\n",BlakServLongVersionString()); InitClass(); InitMessage(); InitObject(); InitList(); InitTimer(); InitSession(); InitResource(); InitRoomData(); InitString(); InitUser(); InitAccount(); InitNameID(); InitDLlist(); InitSysTimer(); InitMotd(); InitLoadBof(); InitTime(); InitGameLock(); InitBkodInterpret(); InitBufferPool(); InitTable(); AddBuiltInDLlist(); LoadMotd(); LoadBof(); LoadRsc(); LoadKodbase(); LoadAdminConstants(); PauseTimers(); if (LoadAll() == True) { /* this loaded_game_msg tells it to disconnect all blakod info about sessions, * that were logged on when we saved */ SendTopLevelBlakodMessage(GetSystemObjectID(),LOADED_GAME_MSG,0,NULL); DoneLoadAccounts(); } /* these must be after LoadAll and ClearList */ InitCommCli(); InitParseClient(); InitProfiling(); InitAsyncConnections(); UpdateSecurityRedbook(); UnpauseTimers(); ServiceTimers(); /* returns if server termiated */ MainExitServer(); WrapShutdown(); }
int main() { LoadDict(&M); system("clear"); printf("%s=====================================================================\n", cyan); printf(" _ ______ ____ ____ ___ __ __________ ________ ____ \n"); printf("| | / / __ \\/ __ \\/ __ \\/ | / |/ / ____/ | / /_ __/ / __ \\ \n"); printf("| | /| / / / / / /_/ / / / / /| | / /|_/ / __/ / |/ / / / / / / /\n"); printf("| |/ |/ / /_/ / _ _ / /_/ / ___ |/ / / / /___/ /| / / / / /_/ / \n"); printf("|__/|__/\\____/_/ |_/_____/_/ |_/_/ /_/_____/_/ |_/ /_/ \\____/ \n\n"); printf("=====================================================================\n\n\n"); printf(" %sPress any key to continue%s\n",magenta,normal); getch(); while(opt1 != 5) //OPT1 = 5 adalah QUIT { MainMenu(&opt1); // MENAMPILKAN MAIN MENU switch(opt1) { case 1 : // REGISTER printf("%sEnter user name : ", cyan); do { found = false; // INISIALISASI YANG MENANDAKAN USER BELUM DITEMUKAN DI FILE EKSTERNAL scanf("%s", username.TabKata); username.Length = strlen(username.TabKata); if(strlen(username.TabKata) >= 20 || !(IsAlNumS(username))) // MENGECEK APAKAH LEBIH DARI 20 ATAU ALFANUMERIK printf("Username must be alphanumeric / less or equal to 20 characters\n"); else { *x = "scores/List Users & Highscores 2.txt"; STARTKATA(); while(!EndKata && !found) CheckUser(username,&id,&found); if(found) printf("Sorry, that username already exists\n"); } }while((strlen(username.TabKata) >= 20 || !(IsAlNumS(username))) || found); SalinFile(LU,username); printf("Congratulations! %s has been successfully registered\n",username.TabKata); printf("\n"); printf("%sPress any key to continue%s\n", magenta,cyan); dummygetch = getch(); dummygetch = getch(); break; case 2 : //LOGIN CreateList(&LU); printf("\n"); *x = "scores/List Users & Highscores 2.txt"; STARTKATA(); while(!(EndKata)) InitUser(&LU,&id); // MEMASUKKAN DATA FILE EKSTERNAL KE DALAM LIST InversListU(&LU); ListUsersLengkap(LU); // MENAMPILKAN LIST USER found1 = false; // INISIALISASI YANG MENANDAKAN USERNAME TIDAK DITEMUKAN while(!found1) { printf("=====================================================================\n"); printf("Enter username : "******"%s",username1.TabKata); username1.Length = strlen(username1.TabKata); STARTKATA(); while(!EndKata && !found1) CheckUser(username1,&id,&found1); if(!found1) printf("%s not found. Try again\n",username1.TabKata); } SelectB = true; // INISIALISASI AGAR SETELAH MEMILIH BOARD, MELIHAT SCORE TIDAK KELUAR KE MAIN MENU, MELAINKAN PREP MENU selectT = false; // INISIALISASI YANG MENANDAKAN USER BELUM PILIH BOARD while(SelectB == true) { if(selectT == false) kode = 1; PrepMenu(&opt2, username1); // PREPARATION MENU switch(opt2) { case 1 : // PLAY GAME if(selectT == false) { kode = 1; *y = "boards/1.txt"; } baris = 1; kolom = 1; T = false; used = false; score = 0; CreateEmptyQ(&QFinish); CreateEmpty(&S); CreateListSU(&LSG); CreateListSU(&LSGTemp); ReadSuggestion(&LSG, kode); strcpy(tempsugg, username1.TabKata); PSU = FirstSU(LSG); usersuggfound = false; while (PSU != Nil) { if (strcmp(InfoSU(PSU), tempsugg) == 0) { usersuggfound = true; break; } else { PSU = NextSU(PSU); } } if (!usersuggfound) { InsVSUFirst(&LSG, tempsugg); PSU = FirstSU(LSG); } InsVSUFirst(&LSGTemp, tempsugg); PSE = FirstSE(PSU); if (PSE != Nil) strcpy(tempsugg, InfoSE(PSE)); else { tempsugg[0] = ' '; tempsugg[1] = '\0'; } CreateListSet(&LS); CreateBoard(&B); AmbilBoard(&B); InitKursor(&B); InitSelect(&B, &S); system("clear"); printf("Score = %d\n\n", score); printf("Suggestion = %s\n\n", InfoSE(PSE)); TulisBoard(B); printf("\n\n"); dummygetch = getch(); input = getch(); printf("\n"); while (input != 'm') { system("clear"); ProsesKursor(&B, &baris, &kolom, &T, input, &error); Select(&B, baris, kolom, T, &S, &score, &LS, &QFinish, &used, &LSG, &LSGTemp, &M, PSU); printf("Score = %d\n\n", score); PSE = FirstSE(PSU); printf("Suggestion = %s\n\n", InfoSE(PSE)); TulisBoard(B); printf("\n"); if (used) printf("Invalid Word\n"); else printf("\n"); if (error) printf("error\n"); else printf("\n"); input = getch(); printf("\n"); error = false; used = false; } time(&rawtime); //INISIALISASI WAKTU t = localtime(&rawtime); D.YY = (*t).tm_year+1900; D.MM = (*t).tm_mon+1; D.DD = (*t).tm_mday; J.HH = (*t).tm_hour; J.MM = (*t).tm_min; J.SS = (*t).tm_sec; InsSortScoreU (&LU,D,J,score,username1); //INSERT SCORE KE LIST SCORE SalinInto(LU, kode); // MENYALIN KE FILE EKSTERNAL SelectB = false; system("clear"); addressQ PQ; PQ = Head(QFinish); while (PQ != Nil) { PrintSet(InfoQ(PQ)); printf("\n"); PQ = NextQ(PQ); } printf("Total Score = %d\n", score); PSU = FirstSU(LSG); PSE = FirstSE(PSU); PSUT = FirstSU(LSGTemp); while (PSUT != Nil) { PSET = FirstSE(PSUT); while (PSET != Nil) { InsVSEFirst(&LSG, PSU, InfoSE(PSET)); PSET = NextSE(PSET); } PSUT = NextSU(PSUT); } WriteSuggestion(LSG, kode); printf("Press any key to continue\n"); dummygetch = getch(); getch(); break; case 2 : //SELECT BOARD PilihBoard(&selectT, &kode); CreateList(&LU); STARTKATA(); while(!(EndKata)) InitUser(&LU,&id); // MEMASUKKAN DATA FILE EKSTERNAL KE DALAM LIST InversListU(&LU); SelectB = true; break; case 3 : //VIEW MY HIGH SCORES ViewMyHighScores(LU,username1); printf("%sPress any key to continue%s\n", magenta,cyan); dummygetch = getch(); dummygetch = getch(); SelectB = true; break; case 4 : //VIEW ALL HIGH SCORES ViewAllHighScores(LU); printf("%sPress any key to continue%s\n", magenta,cyan); dummygetch = getch(); dummygetch = getch(); SelectB = true; break; case 5 : //VIEW BOARD STATISTICS CreateEmptyQS(&QS); countuser = 0; countscore = 0; sumscore = 0; PU = FirstU(LU); while (PU != Nil) { PS = FirstS(PU); if((InfoD(PS)).YY != 0) { countuser += 1; } while(PS != Nil) { if((InfoD(PS)).YY != 0) { countscore += 1; sumscore += InfoS(PS); } PS = NextS(PS); } PU = NextU(PU); } //CreateList(&LU); averagescore = sumscore/countscore; printf("%.0f user/s have played in board %d\n",countuser,kode); if(countscore == 0) averagescore = 0; printf("The average score in board %d is %.2f\n",kode,averagescore); AddQS(&QS,kode,averagescore); for(i=0; i<=9;i++) { switch(i) { case 0 : *x = "scores/List Users & Highscores 1.txt"; break; case 1 : *x = "scores/List Users & Highscores 2.txt"; break; case 2 : *x = "scores/List Users & Highscores 3.txt"; break; case 3 : *x = "scores/List Users & Highscores 4.txt"; break; case 4 : *x = "scores/List Users & Highscores 5.txt"; break; case 5 : *x = "scores/List Users & Highscores 6.txt"; break; case 6 : *x = "scores/List Users & Highscores 7.txt"; break; case 7 : *x = "scores/List Users & Highscores 8.txt"; break; case 8 : *x = "scores/List Users & Highscores 9.txt"; break; case 9 : *x = "scores/List Users & Highscores 10.txt"; break; } if(i != kode) { CreateList(&LP); STARTKATA(); while(!EndKata) InitUser(&LP,&id); InversListU(&LP); sumscore = 0; countscore = 0; PX = FirstU(LP); while (PX != Nil) { PZ = FirstS(PX); while(PZ != Nil) { if((InfoD(PZ)).YY != 0) { countscore += 1; sumscore += InfoS(PZ); } PZ = NextS(PZ); } PX = NextU(PX); } if (countscore == 0) averagescore = 0; else averagescore = sumscore/countscore; AddQS(&QS, i, averagescore); } } PX = FirstU(LP); DealokasiU(&PX); PZ = FirstS(PX); DealokasiS(&PZ); P = Head(QS); printf("Difficulty Level of Boards : \n"); for(i=1;i<=10;i++) { printf("%d. Board no.%d with average user scores of %.2f\n",i,InfoQ(P),Prio(P)); P = NextQ(P); if (P == Nil) { break; } } printf("%sPress any key to continue%s\n", magenta,cyan); dummygetch = getch(); dummygetch = getch(); SelectB = true; break; case 6 : // LOG OUT SelectB = false; break; } if(SelectB == false) break; } break; case 3 : // HOW TO PLAY HowToPlay(); break; case 4 : // ABOUT About(); break; } } printf("%s\n", normal); //MENGGANTI WARNA TEXT TERMINAL KE AWAL return 0; }
int main(int argc, char *argv[]) { struct passwd *pw; int i, rc; socklen_t addrlen = sizeof(struct sockaddr_in6); char str[INET6_ADDRSTRLEN]; #ifdef HAVE_GEOIP_H GeoIP *gi; #endif /* * The next trick is to supply a fake environment variable * FTND_ROOT because this program is started from inetd. * This will setup the variable so InitConfig() will work. * The /etc/passwd must point to the correct homedirectory. */ pw = getpwuid(geteuid()); if (getenv("FTND_ROOT") == NULL) { envptr = xstrcpy((char *)"FTND_ROOT="); envptr = xstrcat(envptr, pw->pw_dir); putenv(envptr); } mypid = getpid(); /* * Read the global configuration data, registrate connection */ InitConfig(); InitMsgs(); InitUser(); InitFidonet(); InitNode(); umask(002); memset(&usrconfig, 0, sizeof(usrconfig)); t_start = time(NULL); InitClient(pw->pw_name, (char *)"ftnnntp", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog); Syslog(' ', "FTNNNTP v%s", VERSION); IsDoing("Loging in"); #ifdef USE_NEWSGATE WriteError("FTNd is compiled for full newsgate, you cannot use ftnnntp!"); #endif /* * Catch all the signals we can, and ignore the rest. */ for(i = 0; i < NSIG; i++) { if ((i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGIOT)) signal(i, (void (*))die); else if (i == SIGCHLD) signal(i, SIG_DFL); else if ((i != SIGKILL) && (i != SIGSTOP)) signal(i, SIG_IGN); } if ((rc = rawport()) != 0) WriteError("Unable to set raw mode"); else { if (getpeername(0,(struct sockaddr*)&peeraddr6,&addrlen) == 0) { /* * Copy IPv4 part into the IPv6 structure. There has to be a better way * to deal with mixed incoming sockets ??? */ memcpy(&peeraddr4, &peeraddr6, sizeof(struct sockaddr_in)); if ((peeraddr6.sin6_family == AF_INET6) && (inet_ntop(AF_INET6, &peeraddr6.sin6_addr, str, sizeof(str)))) { Syslog('+', "Incoming IPv6 connection from %s", str); } else if ((peeraddr4.sin_family == AF_INET) && (inet_ntop(AF_INET, &peeraddr4.sin_addr, str, sizeof(str)))) { Syslog('+', "Incoming IPv4 connection from %s", str); } #ifdef HAVE_GEOIP_H _GeoIP_setup_dbfilename(); if (peeraddr6.sin6_family == AF_INET6) { if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) { if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD)) != NULL) { geoiplookup(gi, str, GEOIP_COUNTRY_EDITION_V6); } GeoIP_delete(gi); } } else if (peeraddr6.sin6_family == AF_INET) { if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) { if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD)) != NULL) { geoiplookup(gi, str, GEOIP_COUNTRY_EDITION); } GeoIP_delete(gi); } } #endif #ifdef USE_NEWSGATE send_nntp("400 Server closed"); #else if (! check_free()) { send_nntp("400 Server closed"); } else { send_nntp("200 FTNNNTP v%s server ready -- posting allowed", VERSION); nntp(); } #endif } } cookedport(); die(0); return 0; }