示例#1
0
int main(int argc, char* argv[]) {
  (void)argc;
  (void)argv;

  try {
  auto console = Core::CLog::GetLogger(Core::log_type::GENERAL);
  if(auto log = console.lock())
    log->info( "Starting up server..." );

  Core::Config& config = Core::Config::getInstance();
  Core::CLog::SetLevel((spdlog::level::level_enum)config.map_server().log_level());
  DisplayTitle();
  CheckUser();

  if(auto log = console.lock()) {
    log->set_level((spdlog::level::level_enum)config.map_server().log_level());
    log->trace("Trace logs are enabled.");
    log->debug("Debug logs are enabled.");
  }
  Core::NetworkThreadPool::GetInstance(config.serverdata().maxthreads());

  CMapServer clientServer;
  CMapServer iscServer(true);
  CMapISC* iscClient = new CMapISC();
  iscClient->Init(config.map_server().charip(), config.map_server().chariscport());
  iscClient->SetType(iscPacket::ServerType::CHAR);

  clientServer.Init(config.serverdata().ip(), config.map_server().clientport());
  clientServer.Listen();
  clientServer.GetISCList().push_front(iscClient);

  iscServer.Init(config.serverdata().ip(), config.map_server().iscport());
  iscServer.Listen();
  iscClient->Connect();

  auto start = Core::Time::GetTickCount();
  while (clientServer.IsActive()) {
      std::chrono::duration<double> diff = Core::Time::GetTickCount() - start;
    clientServer.update(diff.count());
    start = Core::Time::GetTickCount();
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
  }

  if(auto log = console.lock())
    log->info( "Server shutting down..." );
  Core::NetworkThreadPool::DeleteInstance();
  spdlog::drop_all();
  }
  catch (const spdlog::spdlog_ex& ex) {
     std::cout << "Log failed: " << ex.what() << std::endl;
  }
  return 0;
}
示例#2
0
BOOL CCLITerminal::CommandTask(CLISESSION *pSession, BOOL bComplete, BOOL bAddHistory)
{
	CLIHANDLER	*pHandler;
	char		szCommand[256] = "";
	int			nResult, nDepts=0, nCommand;
	int			i, nIndex, argc, nParam, nPos;

	// Make New Line
	WriteStream(pSession, "\n\r");
	pSession->szCommand[pSession->nCmdLength] = '\0';

	if (pSession->nMode == CLIMODE_USER)
	{
		nCommand = atoi(pSession->szCommand);
		pSession->nCmdLength = 0;
		pSession->szCommand[0] = '\0';
		
		switch(nCommand) {
		  case 1 :
			   FirmwareDownload(pSession);
			   WriteStream(pSession, "\n\r");
			   break;
		  case 2 : 
			   pSession->nMode = CLIMODE_COMMAND;
			   DisplayPrompt(pSession);
			   return TRUE; 
		}
		DisplaySplash(pSession);
		return TRUE;
	}

	// Check Login State
	if (!pSession->bLogined)
	{
		if (pSession->bNeedUser)
		{
			if (!CheckUser(pSession))
			{
				// Display Login Error Message
				WriteStream(pSession, "Invalid User.\r\n");
			}

			// Clear Command Buffer
			pSession->nCmdLength 	= 0;
			pSession->szCommand[0]	= '\0';
			DisplayPrompt(pSession);
			return TRUE;

		}
		else if (!CheckLogin(pSession))
		{
			// Clear Command Buffer
			pSession->nCmdLength 	= 0;
			pSession->szCommand[0]	= '\0';
			pSession->bNeedUser		= TRUE;

			// Display Login Error Message
			WriteStream(pSession, "Invalid account or password.\r\n\r\n");
			strcpy(pSession->szPrompt, m_pCLIService->m_szUserPrompt);
			pSession->nLoginRetry++;
			if (pSession->nLoginRetry >= 3)
			{
				if (pSession->nType == CLITYPE_SERIAL)
					sleep(3);
				return FALSE;
			}

			DisplayPrompt(pSession);
			return TRUE;
		}

		// Clear Command Buffer
		pSession->nCmdLength 	= 0;
		pSession->szCommand[0]	= '\0';

		// Callback Login
		if (m_pCLIService->m_pConstruct &&
			m_pCLIService->m_pConstruct->pfnOnLogin)
			m_pCLIService->m_pConstruct->pfnOnLogin(pSession);

		// Login Complete
		pSession->bLogined = TRUE;
		WriteStream(pSession, "\n\r");
		strcpy(pSession->szPrompt, m_pCLIService->m_szDefaultPrompt);
		DisplayPrompt(pSession);
		return TRUE;
	}

	if (pSession->nCmdLength > 0)
	{
		// Find Command
		nResult = CLIERR_OK;
		pSession->szCommand[pSession->nCmdLength] = '\0';

		if (pSession->szCommand[0] == '!')
		{
			if (strcmp(pSession->szCommand, "!!") == 0)
			{
				strcpy(pSession->szCommand, pSession->pszHistory[pSession->nHistoryCount-1]);
				pSession->nCmdLength = strlen(pSession->szCommand);
			}
			else
			{
				nIndex = atoi(&pSession->szCommand[1]);
				if ((nIndex > 0) && (nIndex <= pSession->nHistoryCount))
				{
					strcpy(pSession->szCommand, pSession->pszHistory[nIndex-1]);
					pSession->nCmdLength = strlen(pSession->szCommand);
				}
			}
		}

		pSession->pszArgString = strdup(pSession->szCommand);
		if (bAddHistory)
			AddHistory(pSession, pSession->szCommand);

		SpliteParameter(pSession);
		pHandler = FindCommandHandler(pSession, nDepts, szCommand);
		if (pHandler != NULL)
		{
			// Execute Command
			nParam = GetParamCount(pHandler);
			argc = pSession->argc - (nDepts + 1);
			for(i=0; i<argc; i++)
				pSession->argv[i] = pSession->argv[nDepts+i+1];

			// 파라메터의 갯수가 더 많은 경우를 막을때, add apn 명령 때문에 허용하도록 변경 2007/9/5
			// if ((nParam == argc) || (pHandler->pszParam && (argc >= GetMinParamCount(pHandler)) && (argc <= nParam)))

			if ((nParam == argc) || (pHandler->pszParam && (argc >= GetMinParamCount(pHandler))))
			{
				nPos = ValidateParameter(pSession, pHandler);
				if (nPos == -1)
				{
					pSession->nCmdLength 	= 0;
					pSession->szCommand[0]	= '\0';

					if (m_pCLIService->m_pConstruct &&
						m_pCLIService->m_pConstruct->pfnOnCommand)
						m_pCLIService->m_pConstruct->pfnOnCommand(pSession, argc, pSession->argv, pHandler);

					if (pHandler->nGroup >= pSession->nGroup)
					{
						if (m_pCLIService->m_bEnableLog && pHandler->bLogFlag)
							m_pCLIService->AddLog(pSession->szUser, pSession->szCommand);

						nResult = pHandler->pfnCommand(pSession, argc, pSession->argv, (void *)pHandler);
						WriteStream(pSession, "\xd\xa");
					}
					else
					{
						WriteStream(pSession, "Permission Denied.");					
						WriteStream(pSession, "\xd\xa");
					}
				}
				else
				{
					WriteStream(pSession, "Invalid parameter : '");					
					WriteStream(pSession, pSession->argv[nPos]);					
					WriteStream(pSession, "'\xd\xa");
					WriteStream(pSession, "\xd\xa");
				}
			}
			else
			{
				WriteStream(pSession, "usage: ");
				WriteStream(pSession, szCommand);
				DisplayWideParameter(pSession, pHandler);
				DisplayAllParameter(pSession, pHandler);
				WriteStream(pSession, "\xd\xa");
			}
		}

		if (pSession->pszArgString)
			FREE(pSession->pszArgString);
		pSession->pszArgString = NULL;

		if (nResult == CLIERR_ERROR)
			return FALSE;
	}

	// Clear Command Buffer
	pSession->nCmdLength 	= 0;
	pSession->szCommand[0]	= '\0';

	// Display Prompt
	DisplayPrompt(pSession);
	return TRUE;
}
示例#3
0
文件: main.c 项目: ADTers/Wordament
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;
}