Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. JSAPI_FUNC(my_addProfile)
  2. {
  3. // validate the args...
  4. char *profile, *mode, *gateway, *username, *password, *charname;
  5. profile = mode = gateway = username = password = charname = NULL;
  6. int spdifficulty = 3;
  7.  
  8. if(argc < 6 || argc > 7)
  9. THROW_ERROR(cx, "Invalid arguments passed to addProfile");
  10.  
  11. for(uintN i = 0; i < 7; i++)
  12. if(!JSVAL_IS_STRING(argv[i]))
  13. THROW_ERROR(cx, "All arguments to addProfile besides spdifficulty must be strings!");
  14.  
  15. if(!JSVAL_IS_INT(argv[7]))
  16. THROW_ERROR(cx, "The spdifficulty argument to addProfile must be an integer!");
  17.  
  18. profile = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
  19. mode = JS_GetStringBytes(JSVAL_TO_STRING(argv[1]));
  20. gateway = JS_GetStringBytes(JSVAL_TO_STRING(argv[2]));
  21. username = JS_GetStringBytes(JSVAL_TO_STRING(argv[3]));
  22. password = JS_GetStringBytes(JSVAL_TO_STRING(argv[4]));
  23. charname = JS_GetStringBytes(JSVAL_TO_STRING(argv[5]));
  24. if(argc == 7)
  25. spdifficulty = JSVAL_TO_INT(argv[6]);
  26.  
  27. if(!profile || !mode || !gateway || !username || !password || !charname ||
  28. (argc == 7 && !spdifficulty))
  29. THROW_ERROR(cx, "Failed to convert string");
  30.  
  31. char file[_MAX_FNAME+_MAX_PATH];
  32.  
  33. sprintf_s(file, sizeof(file), "%sd2bs.ini", Vars.szPath);
  34. if(!ProfileExists(profile))
  35. {
  36. char settings[600];
  37. sprintf_s(settings, sizeof(settings),
  38. "mode=%s\0gateway=%s\0username=%s\0password=%s\0character=%s\0spdifficulty=%d\0\0",
  39. mode, gateway, username, password, charname, spdifficulty);
  40.  
  41. WritePrivateProfileSection(profile, settings, file);
  42. }
  43.  
  44. return JS_TRUE;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement