www.pudn.com > Ftpwork > Manager.cpp
#include "Manager.h" #include "LogInfo.h" #include "String.h" #include#include //##ModelId=3DB10CC703C8 BOOL Manager::Initiate(LogInfo* ploginfo) { monitorobj.Display("Connecting... Please wait!\n"); if(netlayerobj.SetupConnection(ploginfo)==FALSE) { monitorobj.Display("Connecting Error!\n"); monitorobj.Display("The server does not work or connecting is refused!\n"); return FALSE; } monitorobj.Display("Connecting Succeed!\n\n"); char *buffer= new char[255]; ; int trynumber =0; while(trynumber < 3) { trynumber ++; monitorobj.Display("Username:"); fgets(buffer,255,stdin); //replace last \n with \0 buffer[strlen(buffer)-1] = '\0'; ploginfo->SetUserName(buffer); buffer = getpass("Password:"); ploginfo->SetPassWord(buffer); monitorobj.Display("\nValadite your acount...\n"); if(netlayerobj.Validate(ploginfo->GetUserName(),ploginfo->GetPassword())==FALSE) { monitorobj.Display("Access to this server is not permitted!\n"); monitorobj.Display("Plesae try one more time!\n"); } else break; } if( buffer != NULL) delete [] buffer; if(trynumber == 3) { monitorobj.Display("YOUR ACOUNT DOES NOT WORK!\n"); return FALSE; } monitorobj.Display(netlayerobj.GetNetState()->GetErrorInfo()); cmdhdrobj.Initiate(&netlayerobj, &monitorobj); monitorobj.SetIP((char*)ploginfo->GetIpString()->buffer()); monitorobj.SetLocation("/"); return TRUE; } //##ModelId=3DB200BC0129 void Manager::Loop() { char tempbuf[255]; String command; while(1) { monitorobj.ShowIndicator(); fgets(tempbuf, 255, stdin); //replace last \n with \0 tempbuf[strlen(tempbuf)] = '\0'; command=tempbuf; InputCommand(&command); } } //##ModelId=3DB227D3013C Manager::Manager() { } //##ModelId=3DB10EBC02A6 void Manager::InputCommand(String* cmd) { // no input if(strlen(cmd->buffer())< 2) return; if(cmdhdrobj.HandleCommand(cmd)==FALSE) monitorobj.Display("Bad command or argments are not enough!\n"); }