Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "game.h"
- //Structures:
- struct object_descriptor objects_descriptor_table[1024];
- struct quest_descriptor quests[64];
- // Networking:
- int status, valread, client_fd;
- struct sockaddr_in serv_addr;
- // funcs:
- bool cardinal_startup();
- bool cardinal_connect();
- void get_resource(char fpath[]);
- bool cardinal_stop();
- bool cardinal_connect(){
- char buffer[1024] = { 0 };
- if ((client_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- printf("\n Socket creation error \n");
- return false;
- }
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_port = htons(PORT);
- inet_pton(AF_INET, "195.133.201.163", &serv_addr.sin_addr);
- if ((status = connect(client_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr))) < 0) {
- printf("\nConnection Failed \n");
- return false;
- }else{
- printf("connected to server. \n");
- return true;
- }
- return false;
- }
- void cardinal_core_thread(){
- get_resource("city/level_b2/geometry/test.scheme%");
- }
- void get_resource(char fpath[]){
- unsigned char *get_buffer = malloc(4 * 1024 * 1024);
- int i = 9; int j = 0;
- char request[256] = "Resource: ";
- i++;
- request[i] = '"';
- i++;
- while(fpath[j-1] != '%'){
- request[i] = fpath[j];
- j++; i++;
- }
- i--;
- request[i] = '"';
- printf("%s\n", request);
- cardinal_connect();
- send(client_fd, request, strlen(request), 0);
- valread = read(client_fd, get_buffer, sizeof(get_buffer)); // Here we got 8 bytes... i have no idea why does it so.
- if(get_buffer[0] != 'e'){
- i = 17; j = 0;
- // Generating name random...
- char save_fpath[256] = "content/loadable/";
- while(j != 8){
- save_fpath[i] = rand() % (90 - 65 + 1) + 65;
- j++; i++;
- }
- // My shame ... ".content" adding.
- 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';
- FILE *get_file = fopen(save_fpath, "w+");
- fwrite(get_buffer, 1, valread, get_file);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement