void PLAYER::snap(int snapping_client) { NETOBJ_CLIENT_INFO *client_info = (NETOBJ_CLIENT_INFO *)snap_new_item(NETOBJTYPE_CLIENT_INFO, client_id, sizeof(NETOBJ_CLIENT_INFO)); str_to_ints(&client_info->name0, 6, server_clientname(client_id)); str_to_ints(&client_info->skin0, 6, skin_name); client_info->use_custom_color = use_custom_color; client_info->color_body = color_body; client_info->color_feet = color_feet; NETOBJ_PLAYER_INFO *info = (NETOBJ_PLAYER_INFO *)snap_new_item(NETOBJTYPE_PLAYER_INFO, client_id, sizeof(NETOBJ_PLAYER_INFO)); info->latency = latency.min; info->latency_flux = latency.max-latency.min; info->local = 0; info->cid = client_id; info->score = score; info->team = team; if(client_id == snapping_client) info->local = 1; if((config.sv_rainbow) || (config.sv_rainbow_admin && authed && rb==true)) { game.players[client_id]->use_custom_color = true; client_info->color_body = rbc; client_info->color_feet = rbc; } }
void PLAYER::snap(int snapping_client) { NETOBJ_CLIENT_INFO *client_info = (NETOBJ_CLIENT_INFO *)snap_new_item(NETOBJTYPE_CLIENT_INFO, client_id, sizeof(NETOBJ_CLIENT_INFO)); str_to_ints(&client_info->name0, 6, server_clientname(client_id)); str_to_ints(&client_info->skin0, 6, skin_name); client_info->use_custom_color = use_custom_color; client_info->color_body = color_body; client_info->color_feet = color_feet; NETOBJ_PLAYER_INFO *info = (NETOBJ_PLAYER_INFO *)snap_new_item(NETOBJTYPE_PLAYER_INFO, client_id, sizeof(NETOBJ_PLAYER_INFO)); info->latency = latency.min; info->latency_flux = latency.max-latency.min; info->local = 0; info->cid = client_id; info->score = score; if(client_id == snapping_client) info->local = 1; }
// This is a function that checks out a file from the server // - RETURNS 0 in case of success, 1 otherwise int checkout_file(SSL* ssl, BIO *sslbio, char *buffer) { FILE* file; // pointer to the file to be received int ret; int length; // Sending the client name // BIO_write(sslbio, CLIENT_NAME, strlen(CLIENT_NAME)); // Receive number of options memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; printf("\nSelect file number to check out file.\n"); printf("You have %s option(s):\n", buffer); int opns = atoi(buffer); if ( opns < 1 ) { //No files to choose from. printf("You have ZERO files stored at server...\n"); printf("Unable to check-out file: Choose a different option.\n"); exit(1); } // If files are present, receive file options printf("\nFILE UID | FILE NAME | FILE OWNER\n"); int i; for (i = 0; i < opns; i++) { memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; printf("%s\n", buffer); } // Receive deliminated list of option numbers memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; // Tokenize options int options[opns]; int numtokens = str_to_ints(buffer, options); // Select Option, i.e., file UID choice int filechoice = getintchoice("Select FILE UID to checkout", options, opns); length = floor(log10(abs(filechoice))) + 1; char sfile[length]; sprintf(sfile, "%d", filechoice); // Send File UID to Server BIO_write(sslbio, sfile, length); // Get file name from Server memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; printf("Saving file '%s' to local disk.\n", buffer); // Open file file = fopen(buffer, "w+"); if(file == NULL) { fprintf(stderr, "File not found: '%s'\n", buffer); return 1; } // Get file data from Server memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; printf("Plain text received:\n%s\n",buffer); // Writing to file fwrite(buffer, length, 1, file); // Close file. fclose(file); printf("File Saved.\n"); // Send confirmation to server char message[] = "File Saved."; BIO_write(sslbio, message, strlen(message)); // Receive confirmation from server memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; printf("File Successfully Checked Out: %s\n",buffer); return 0; }
// This is a function that checks in a file to the server int checkin_file(SSL* ssl, BIO *sslbio, char *buffer) { char choice; int ret,length; char filename[BUF_SIZE]; choice = getchoice("Please select an action", cimenu); printf("You have chosen: %c\n", choice); if (choice == 'a') { printf("Check-in By filename (NO File UID)\n"); choiceProcess (sslbio, buffer, choice); getInput(filename, "Enter the filename \n (e.g., 'testfile.txt')", 32); /* Sending the file name */ BIO_write(sslbio, filename, strlen(filename)); // Receive server status memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; printf("BUffer: %s",buffer); if (buffer[0] == '0') { printf("Server confirms file is not already stored; storing file now.\n"); } else { printf("Similiar file found in database...\n"); choice = getchoice("Overwrite your old file?", ynmenu); if ( choice == 'y' ) { char answer[] = "yes"; BIO_write(sslbio,answer,strlen(answer)); } else { char answer[] = "no"; BIO_write(sslbio, answer, strlen(answer)); } } // Send the file to the server ret = send_file(filename, sslbio); // Get Server confirmation memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; printf("Server confirmation: %s\n",buffer); char SecurityFlag[16]; choice = getchoice("Select 'SecurityFlag' for this file",smenu); if (choice == 'a') { strcpy(SecurityFlag, "CONFIDENTIALITY"); } else if (choice == 'b') { strcpy(SecurityFlag, "INTEGRITY"); } else { strcpy(SecurityFlag, "NONE"); } printf("SecurityFlag confirmed as '%s'\n",SecurityFlag); BIO_write(sslbio, SecurityFlag, strlen(SecurityFlag)); } else if (choice == 'b') { printf("Check-in By File UID\n"); choiceProcess (sslbio, buffer, choice); // Receive the number of File UID options memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; printf("You have access to %s file(s) on the server that are\n", buffer); printf("available for you to check in by File UID.\n"); int opns = atoi(buffer); if ( opns < 1 ) { //No files to choose from. printf("You have access to ZERO files stored at server...\n"); printf("Unable to check-in by File UID: Choose a different option.\n"); printf("Recommend check-in by filename instead to receive new UID from server.\n"); exit(1); } // Receive deliminated list of option numbers memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; // Tokenize options int options[opns]; int numtokens = str_to_ints(buffer, options); // Select Option, i.e., file UID choice int filechoice = getintchoice("Enter File UID you wish to check-in", options, opns); length = floor(log10(abs(filechoice))) + 1; char sfile[length]; sprintf(sfile, "%d", filechoice); // Send File UID to Server BIO_write(sslbio, sfile, length); // Receive File Name from Server memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; printf("Preparing to check-in File UID '%d', Filename '%s'\n",filechoice,buffer); printf("Has your filename changed since last upload? (Is it different than listed here?)\n"); choice = getchoice("Please select an action", ynmenu); char filename[BUF_SIZE]; if (choice == 'y') { getInput(filename, "Enter the new filename \n (e.g., 'testfile.txt')", 32); } else //File name hasn't changed { strcpy(filename,buffer); } char SecurityFlag[16]; choice = getchoice("Select 'SecurityFlag' for this file",smenu); if (choice == 'a') { strcpy(SecurityFlag, "CONFIDENTIALITY"); } else if (choice == 'b') { strcpy(SecurityFlag, "INTEGRITY"); } else { strcpy(SecurityFlag, "NONE"); } printf("SecurityFlag confirmed as '%s'\n",SecurityFlag); BIO_write(sslbio, SecurityFlag, strlen(SecurityFlag)); // Send the file to the server ret = send_file(filename, sslbio); // Get Server confirmation memset(buffer,0,4096); length = BIO_read(sslbio, buffer, BUF_SIZE); if(length <= 0) { strcpy(buffer, "No message"); length = strlen(buffer); } buffer[length] = '\0'; printf("Server confirmation: %s\n",buffer); } else { printf("Terminate function will be executed\n"); } }