join.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/stat.h>
  5. #include "help/util.h"
  6. // I have had a nasty problem here, which should be remembered when occuring once again
  7. // Since the change from chroot to a root path, the 64 byte string were too small
  8. // So memory was overwritten, which really shouldnt be
  9. // For now, I made the strings 256 bytes big, but this is just a temp solution
  10. // The best would be to determine the max path length and base the strings lengths on that
  11. // Or create dynamic strings, which grow bigger when filled
  12. int main(int argc, char* argv[]) {
  13. if (argc < 2) {
  14. return 1;
  15. }
  16. char* root = getenv("RELAT_ROOT");
  17. char* name = argv[1];
  18. if (strlen(name) < 3) {
  19. exit(-1);
  20. }
  21. // TODO: improve spawning position
  22. int user_count = get_user_count();
  23. printf("%i\n", user_count);
  24. float pos_x = 10 * user_count;
  25. float pos_y = 10 * user_count;
  26. float pos_z = 0;
  27. char name_dir[256];
  28. sprintf(name_dir, "%s/%s", root, name);
  29. if (mkdir(name_dir) != 0) {
  30. perror("mkdir failed");
  31. return 1;
  32. }
  33. char user_position_file_name[256];
  34. sprintf(user_position_file_name, "%s/%s/position", root, name);
  35. FILE* user_position_file;
  36. if ((user_position_file = fopen(user_position_file_name, "w")) == NULL) {
  37. perror("could not create user position file");
  38. return 1;
  39. }
  40. fprintf(user_position_file, "%.3f %.3f %.3f\n", pos_x, pos_y, pos_z);
  41. fclose(user_position_file);
  42. create_unit(name, "adam", 1, 0);
  43. create_unit(name, "eva", -1, 0);
  44. return 0;
  45. }