int Authenticate(char *user) { unsigned long x; int userNameLength; int valid = 0; /* write username */ sockfd = NetworkConnection(); userNameLength = strlen(user); write(sockfd, &userNameLength, sizeof(userNameLength)); write(sockfd, user, userNameLength); /* receive response from server if valid */ read(sockfd, &valid, 1); if (valid) printf("valid became one\n"); close(sockfd); x = HashGenerator(user); printf("%lu", x); return 0; }
bool RMENet::Connect() { wxIPV4address ipaddr; ipaddr.Hostname("127.0.0.1");//90.230.54.138")); ipaddr.Service(31312); socket = newd wxSocketClient(wxSOCKET_NOWAIT); connection = newd NetworkConnection(this, socket); socket->SetClientData(connection); socket->SetEventHandler(*this, wxID_ANY); socket->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_OUTPUT_FLAG | wxSOCKET_LOST_FLAG); socket->Notify(true); wxEvtHandler::Connect(wxID_ANY, wxEVT_SOCKET, wxSocketEventHandler(RMENet::HandleEvent)); socket->Connect(ipaddr, false); if(!socket || !socket->WaitOnConnect(5, 0) || !socket || !socket->IsConnected()) { if(socket) socket->Destroy(); socket = nullptr; delete connection; connection = nullptr; return false; } NetworkMessage* nmsg = AllocMessage(); nmsg->AddByte(0x00); // Hello! nmsg->AddU32(__LIVE_NET_VERSION__); nmsg->AddString(g_settings.getString(Config::LIVE_USERNAME)); nmsg->AddString(g_settings.getString(Config::LIVE_PASSWORD)); connection->Send(nmsg); return true; }
/* * nftw takes this as an argument about what to do * what we want is the filename which is in path */ int DirList(const char *path, const struct stat *ptr, int flag, struct FTW *ftwbuf) { isDirectory = 0; while (!uploadAll && updateFile && (fgets(tmp, sizeof(tmp), fp) != NULL)) { if (!strstr(tmp, path)) { printf("Not cached!\n"); return EXIT_FAILURE; } len = strlen(tmp)-1; if (tmp[len] == '\n') tmp[len] = 0; /* read filename and last modified time */ fileName = strtok(tmp, "\t"); cachedFileTime = strtok(NULL, "\t"); isDirectory = atoi(strtok(NULL, "\t")); /* !0 indicates a directory */ /* check if the file read from the file is valid or not */ if ((fp1 = fopen(fileName, "r")) == NULL) { printf("Invalid filename or "); printf("%s has been deleted since last caching.\n", fileName); /* DeleteFileOnServer(p); */ } /* if it exists compare its cached time to its current time */ else { fclose(fp1); /* get its latest modified time and check it to cached */ currentFileTime = GetLastModifiedTime((const char *) fileName); equalTimes = TimeComparsion(currentFileTime, cachedFileTime); if (equalTimes) { fileTransferSucceeded = NetworkConnection(fileName, isDirectory); if (!fileTransferSucceeded) { printf("\nFATAL: Transfer failed in updating %s.\n", fileName); return EXIT_FAILURE; } printf("File: %s has been updated.\n", fileName); } free(currentFileTime); } } /* print the filename and last modified date to .names */ if (updateFile && fp != NULL) { currentFileTime = GetLastModifiedTime(path); fflush(fp); fprintf(fp, "%s\t%s\t%d\tDirectory Level=%d\tFlags=%d\n", path, currentFileTime, ptr->st_mode &S_IFDIR, ftwbuf->level, flag); free(currentFileTime); } /* when no cached file exists */ if (uploadAll) { printf("uploading... %s\n", path); /* is directory? */ if (ptr->st_mode &S_IFDIR) isDirectory = 1; fileTransferSucceeded = NetworkConnection(path, isDirectory); if (!fileTransferSucceeded) printf("\nTransfer failed for %s.\n", path); } return 0; }