//전역함수로 선언
//이 함수는 쓰레드에 의해 실행되는 함수이다. 아래 while문안에서 GetQueued함수가 호출됨을 알 수 있는데, 이렇듯 GetQueued함수를 호출하는
//쓰레드를 가리켜 CP오브젝트에 할당된 쓰레드라 한다.
UINT RecvThread(LPVOID lParam){
	SERVER_INFO* serverInfo = (SERVER_INFO*)lParam;
	
	while(TRUE)
	{
		DWORD dwTrans = 0;
		SOCKET clientSocket = 0;
		CUserSocket* pClient = NULL;	//지금 연결된 애
		BOOL bCont = GetQueuedCompletionStatus(*serverInfo->hComPort, &dwTrans, (DWORD *)&clientSocket, (OVERLAPPED **)&pClient, INFINITE);

		//hComPort 가 신호상태가 될때까지 기다림, 아까껍데기만든거. 그안에는 소켓들이 들어감
		//TRUE가 리턴된단 얘기는 껍데기안에 소켓들 중 하나가 신호상태가 된것
		//dwTrans가 읽은 byte수

		if(bCont == FALSE || dwTrans <= 0)	//클라이언트가 작업을 끝냄 
		{
			EnterCriticalSection(&myCS);
			if(serverInfo->mCToonVasServerDlg->GetUserSocketList().IsExist(clientSocket)){
				closesocket(clientSocket);
				serverInfo->mCToonVasServerDlg->DeleteOutUser(pClient);
				serverInfo->mCToonVasServerDlg->DeleteClient(clientSocket);
				serverInfo->mCToonVasServerDlg->GetIDManager().DeleteID(clientSocket);
			}
			LeaveCriticalSection(&myCS);
			continue;	
		}

		char RecvBuf[MAX_BUF_SIZE];
		memset(RecvBuf, NULL, MAX_BUF_SIZE);	//버퍼 비우기

		pClient->AddRecvLen(dwTrans);	//읽은 다음에는 몇byte를 받았는지 CMyClient는 모르니까 알려줘야한다.
		while(pClient->GetPacket(RecvBuf))	//RecvBuf에 메시지 받아옴
		{
			
			//온전한 패킷이면 타입에 맞춰 처리
			CPacketHeader* pHeader = (CPacketHeader*)RecvBuf;
			char* pMsg = RecvBuf + sizeof(CPacketHeader);
			
			switch(pHeader->m_iPacketType)
			{
			case REQ_LOGIN: //로그인
				{
					HandleLogin(pMsg, serverInfo, pClient);
				}
				break;

			case REQ_JOIN:	//회원가입
				{
					HandleJoin(pMsg, serverInfo, pClient);
				}
				break;
				
			case REQ_SENDMESSAGE:	 //방내 메시지 전송
				{
					HandlerChat(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_CREATEROOM:	//방만들기
				{
					HandleCreateRoom(pMsg, serverInfo, pClient, clientSocket);
				}
				break;

			case REQ_ROOMLIST:	//방목록 요청
				{
					HandleReqRoomList(pMsg, serverInfo, pClient);
				}
				break;

			case REQ_ROOM_PW_STATE:	// 방 비번 확인 요청
				{
					HandleReqRoomPwState(pMsg, serverInfo, pClient);
				}
				break;

			case REQ_JOINROOM:	//방 조인
				{
					HandleJoinRoom(pMsg, serverInfo, pClient);
				}
				break;

			case REQ_EXITROOM_FROM_WAITROOM:	//대기방 탈퇴
				{
					HandleExitRoomFromWaitRoom(pMsg, serverInfo, pClient);
				}
				break;

			case REQ_SENDOBJECT: //펜 좌표
				{
					HandlePenObject(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_CLIENTLIST:	//클라이언트 정보 요청
				{
					HandleClientList(pMsg, serverInfo, pClient);
				}
				break;

			case REQ_ROOM_START:	//방 시작 
				{
					HandleRoomStart(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;
			
			case REQ_PEN_UP:	//펜 놨을때				
				{
					HandlePenUp(pMsg, serverInfo, pClient , pHeader->m_iTotalSize);
				}
				break;
				
			case REQ_PENTYPE:		//펜 타입
				{
					HandlePenType(pMsg, serverInfo, pClient);
				}
				break;

			case REQ_REDO:	//REDO
				{
					HandleRedo(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_UNDO:	//UNDO
				{
					HandleUndo(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_START_BITMAP:	//15. START_BITMAP
				{
					HandleStartBitmap(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_BITMAP_DATA:	//16. RECV_BITMAP_DATA
				{
					HandleBitmapData(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_END_BITMAP:	//17. END_BITMAP_DATA
				{
					HandlerEndBitmap(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_OBJECT_CHANGE:	//18. OBJECT_CHANGE
				{
					HandlerBitmapChange(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case RET_IS_ALIVE:	//19. HEART_BIT
				{
					HandlerIsAlive(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_PAGE:	//20. ADD_PAGE
				{
					HandlerMultiPage(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_IMAGE_PROCESSING:	//영상처리
				{
					HandlerImageProcessing(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_EXITROOM:	//진행중 방나가기
				{
					HandlerExitFromWorkingRoom(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;
				
			case REQ_DEL_IMAGE:	//이미지 삭제
				{
					HandlerDelImage(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_GROUP:	//그룹
				{
					HandlerGroupImage(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_UNGROUP:	//언그룹
				{
					HandlerUnGroup(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_OBJECT_START://27. start object 
				{
					HandlerStartData(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_OBJECT_DATA://28. stroke data
				{
					HandlerStrokeData(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;
			case REQ_OBJECT_END://29. end data
				{
					HandlerEndData(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			case REQ_ROOM_ID_LIST: //30. 방의 참가자 아이디 전송
				{
					HandleSendClientIDList(pMsg, serverInfo, pClient, pHeader->m_iTotalSize);
				}
				break;

			default:
				std::cout<<"default 입니다."<<endl;
				break;

			}	
		} // end of while(packet)
		
		pClient->RecvData() ;	//읽어달라고 다시 요청
		CreateIoCompletionPort((HANDLE)clientSocket, *serverInfo->hComPort, (DWORD)clientSocket, 0);
		Sleep(1);

	} // end of while(true)
		
	return 0;
}
예제 #2
0
DWORD
DispatchInitFunctions(po::variables_map argsMap,po::options_description& config)
{
    DWORD dwError = ERROR_SUCCESS;

    dwError = SetSrpAuthenticationInfo();
    BAIL_ON_ERROR(dwError);

    if (argsMap.count("selfca")) {
        if ( ParserConfigFile(config, argConfig) != 0 )  {
            dwError =  VMCA_ARGUMENT_ERROR;
            BAIL_ON_ERROR(dwError);
        }

        if (argPredates > VMCA_MAX_PREDATE_PERMITED || argPredates < 0)
        {
            std::cout << "Invalid start time predate specified it should be between "
                << VMCA_MAX_PREDATE_PERMITED << " and 0 "<<std::endl;
            dwError =  VMCA_ARGUMENT_ERROR;
            BAIL_ON_ERROR(dwError);
        }

        dwError = HandleCreateSelfSignedCA();
        BAIL_ON_ERROR(dwError);
    }
    if (argsMap.count("rootca")) {
        if(!argsMap.count("privkey") ||
                !argsMap.count("cert")) {
            std::cout << "To upload a Root CA Cert, we need both Cert and Private Key.\n\n"
                      << "Example: certool --rootca --cert=root.cert --privkey=privatekey.pem\n"
                      << std::endl;
            dwError =  VMCA_ARGUMENT_ERROR;
            BAIL_ON_ERROR(dwError);
        }
        dwError = HandleRootCACertificate();
        BAIL_ON_ERROR(dwError);
    }

    if (argsMap.count("gencsr") || argsMap.count("initcsr")) {
        if (argsMap.count("initcsr")) {
            std::cout << "This is deprecated. Use gencsr instead.\n";
        }
        if(!argsMap.count("privkey") ||
                !argsMap.count("pubkey")  ||
                !argsMap.count("csrfile")) {
            std::cout << "To create a CSR we need a private key path.\n\n"
                      << "Example : certool --gencsr --privkey=<filename> --pubkey=<filename>"
                      << " --csrfile=<filename>\n";
            dwError =  VMCA_ARGUMENT_ERROR;
            BAIL_ON_ERROR(dwError);
        }

        if ( ParserConfigFile(config, argConfig) != 0 )  {
            dwError =  VMCA_ARGUMENT_ERROR;
            BAIL_ON_ERROR(dwError);
        }

        dwError = HandleInitCSR();
        BAIL_ON_ERROR(dwError);
    }

    if(argsMap.count("getdc")) {
        dwError = HandleGetDC();
        BAIL_ON_ERROR(dwError);
    }


    if(argsMap.count("WaitVMCA")) {
        dwError = HandleWaitVMCA();
        BAIL_ON_ERROR(dwError);
    }

    if(argsMap.count("WaitVMDIR")) {
        dwError = HandleWaitVMDIR();
        BAIL_ON_ERROR(dwError);
    }


    if(argsMap.count("login")){
         if(!argsMap.count("user") ||
            !argsMap.count("password") ||
            !argsMap.count("domain")) {
                std::cout << "To login we need a user name and password.\n"
                      << "Example : certool --login --user=administrator"
                      << " --domain=VSPHERE.LOCAL"
                      << " --password=<password>\n";
            dwError =  VMCA_ARGUMENT_ERROR;
            BAIL_ON_ERROR(dwError);
         }

        dwError = HandleLogin();
        BAIL_ON_ERROR(dwError);
    }

    if(argsMap.count("logout")) {
        dwError = HandleLogout();
        BAIL_ON_ERROR(dwError);
    }

    if(argsMap.count("publish-roots")){
        dwError = HandlePublishRoots();
        BAIL_ON_ERROR(dwError);
    }

    if(argsMap.count("updateschema")) {
        dwError = HandleUpdateSchema();
        BAIL_ON_ERROR(dwError);
    }

error:
    return dwError;
}
예제 #3
0
bool ScmdServer_Impl::HandleScmdMessage( HCLIENT hClient, ILTMessage_Read& msg )
{
	// Check if SCMD commands are not allowed.
	if( !m_bAllowScmdCommands )
	{
		return true;
	}

	// Read the scmd command.
	ScmdCommand eScmdCommand = ( ScmdCommand )msg.Readuint8( );

	// Check if we're not controlled by an admin.  Since Login is the only
	// command you can send without being logged in, it has special handling.
	if( eScmdCommand != kScmdCommandLogin &&
		( m_eAdminControl == kAdminControlNone ) ||
		( m_eAdminControl == kAdminControlClient && hClient != m_hAdminClient ) ||
		( m_eAdminControl == kAdminControlServerapp && hClient != NULL ))
	{
		// Doesn't have privileges.
		SendStatusMessage( hClient, eScmdCommand, kScmdCommandStatusNotLoggedIn );
		return false;
	}


	switch( eScmdCommand )
	{
		case kScmdCommandLogin:
			return HandleLogin( hClient, msg );
			break;

		case kScmdCommandLogout:
			return HandleLogout( hClient, msg );
			break;

		case kScmdCommandListClients:
			return HandleListClients( hClient, msg );
			break;

		case kScmdCommandListMissions:
			return HandleListMissions( hClient, msg );
			break;

		case kScmdCommandNextMission:
			return HandleNextMission( hClient, msg );
			break;

		case kScmdCommandNextRound:
			return HandleNextRound( hClient, msg );
			break;

		case kScmdCommandSetMission:
			return HandleSetMission( hClient, msg );
			break;

		case kScmdCommandBootName:
			return HandleBootName( hClient, msg );
			break;

		case kScmdCommandBootId:
			return HandleBootId( hClient, msg );
			break;

		case kScmdCommandAddBan:
			return HandleAddBan( hClient, msg );
			break;

		case kScmdCommandRemoveBan:
			return HandleRemoveBan( hClient, msg );
			break;

		case kScmdCommandListBans:
			return HandleListBans( hClient, msg );
			break;

		case kScmdCommandBanClient:
			return HandleBanClient( hClient, msg );
			break;

		case kScmdCommandListGameOptions:
			return HandleListGameOptions( hClient, msg );
			break;

		case kScmdCommandSetGameOption:
			return HandleSetGameOption( hClient, msg );
			break;

	}

	return false;
}
예제 #4
0
void HandleClientMsg(SSL_CLIENT_DATA* ssl_data, int epollfd)
{
    if(!ssl_data)
        return;
    cJSON *root=NULL, *cmd=NULL, *attr=NULL, *child=NULL;
    SSL *ssl = ssl_data->ssl;
    char buffer[BUFF_LEN];
    int recvLen;
    bzero(buffer, BUFF_LEN);

    /*Receive information from client*/
    recvLen = SSL_recv(ssl, buffer, BUFF_LEN);
    if(recvLen <= 0 || strncmp(buffer, "quit", 4)==0)
    {
        printf("client quit!\n");
        int connfd = SSL_get_fd(ssl_data->ssl);
        Session_Delete(connfd);
        Session_Print_All();
        SSL_Client_Leave(ssl_data, epollfd);
        return;
    }
    printf("client %d: %s\n", SSL_get_fd(ssl_data->ssl), buffer);
    /*Parse the client message*/
    root = cJSON_Parse(buffer);
    if(!root)
    {
        printf("Error before: [%s]\n",cJSON_GetErrorPtr());
        HandleError(ssl, "JSON format not recognized.");
        return;
    }

    child = root->child;
    while(child)
    {
        if(strcmp(child->string, "cmd")==0)
        {
            cmd = child;
        } else if(strcmp(child->string, "attr")==0)
        {
            attr = child;
        }

        child = child->next;
    }

    if(0==strcmp(cmd->valuestring, "register"))
    {
        HandleRegister(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "cert_status_ok"))
    {
        HandleCertStatusUpdate(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "login"))
    {
        HandleLogin(ssl,attr);
    } else if(0==strcmp(cmd->valuestring, "query_pulse"))
    {
        HandleQueryPulse(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "file_query"))
    {
        HandleFileQuery(ssl,  attr);
    } else if(0==strcmp(cmd->valuestring, "sending_file_next"))
    {
        HandleSendingFile(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "receiving_file_next"))
    {
        HandleReceivingFile(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "open_file"))
    {
        HandleOpenFile(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "revoke_file"))
    {
        HandleRevokeFile(ssl, attr);
    }

    cJSON_Delete(root);
}