Advertisement
Guest User

client

a guest
Dec 30th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.01 KB | Source Code | 0 0
  1. #include "game.h"
  2.  
  3. //Structures:
  4.     struct object_descriptor objects_descriptor_table[1024];
  5.     struct quest_descriptor quests[64];
  6.  
  7. // Networking:
  8.     int status, valread, client_fd;
  9.     struct sockaddr_in serv_addr;
  10.  
  11. // funcs:
  12. bool cardinal_startup();
  13. bool cardinal_connect();
  14. void get_resource(char fpath[]);
  15.  
  16. bool cardinal_stop();
  17.  
  18.  
  19. bool cardinal_connect(){    
  20.     char buffer[1024] = { 0 };
  21.     if ((client_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
  22.         printf("\n Socket creation error \n");
  23.     return false;
  24.     }
  25.  
  26.     serv_addr.sin_family = AF_INET;
  27.     serv_addr.sin_port = htons(PORT);
  28.  
  29.     inet_pton(AF_INET, "195.133.201.163", &serv_addr.sin_addr);
  30.  
  31.     if ((status = connect(client_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr))) < 0) {
  32.         printf("\nConnection Failed \n");
  33.     return false;
  34.     }else{
  35.         printf("connected to server. \n");
  36.         return true;
  37.     }
  38.     return false;
  39. }
  40.  
  41. void cardinal_core_thread(){
  42.      
  43.     get_resource("city/level_b2/geometry/test.scheme%");
  44. }
  45.  
  46. void get_resource(char fpath[]){
  47.  
  48.     unsigned char *get_buffer = malloc(4 * 1024 * 1024);
  49.    
  50.     int i = 9; int j = 0;
  51.     char request[256] = "Resource: ";
  52.     i++;
  53.     request[i] = '"';
  54.     i++;
  55.     while(fpath[j-1] != '%'){
  56.         request[i] = fpath[j]; 
  57.         j++; i++;
  58.     }
  59.     i--;
  60.     request[i] = '"';
  61.     printf("%s\n", request);
  62.     cardinal_connect();
  63.    
  64.     send(client_fd, request, strlen(request), 0);  
  65.     valread = read(client_fd, get_buffer, sizeof(get_buffer)); // Here we got 8 bytes... i have no idea why does it so.
  66.  
  67.     if(get_buffer[0] != 'e'){
  68.         i = 17; j = 0;
  69.    
  70.         // Generating name random...
  71.         char save_fpath[256] = "content/loadable/";
  72.         while(j != 8){
  73.             save_fpath[i] = rand() % (90 - 65 + 1) + 65;   
  74.             j++; i++;
  75.         }
  76.  
  77.         // My shame ... ".content" adding.
  78.         save_fpath[i] = '.'; save_fpath[i + 1] = 'c'; save_fpath[i + 2] = 'o'; save_fpath[i + 3] = 'n'; save_fpath[i + 4] = 't'; save_fpath[i + 5] = 'e'; save_fpath[i + 6] = 'n'; save_fpath[i + 7] = 't';
  79.        
  80.         FILE *get_file = fopen(save_fpath, "w+");
  81.         fwrite(get_buffer, 1, valread, get_file);
  82.     }
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement