Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 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 < 6; 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[6]))
  16.         THROW_ERROR(cx, "The spdifficulty argument to addProfile must be an integer!");
  17.  
  18.     profile = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
  19.     if(!profile)
  20.         THROW_ERROR(cx, "Failed to convert profile string");
  21.  
  22.     mode = JS_GetStringBytes(JSVAL_TO_STRING(argv[1]));
  23.     if(!mode)
  24.         THROW_ERROR(cx, "Failed to convert mode string");
  25.  
  26.     gateway = JS_GetStringBytes(JSVAL_TO_STRING(argv[2]));
  27.     if(!gateway)
  28.         THROW_ERROR(cx, "Failed to convert gateway string");
  29.  
  30.     username = JS_GetStringBytes(JSVAL_TO_STRING(argv[3]));
  31.     if(!username)
  32.         THROW_ERROR(cx, "Failed to convert username string");
  33.  
  34.     password = JS_GetStringBytes(JSVAL_TO_STRING(argv[4]));
  35.     if(!password)
  36.         THROW_ERROR(cx, "Failed to convert password string");
  37.  
  38.     charname = JS_GetStringBytes(JSVAL_TO_STRING(argv[5]));
  39.     if(!charname)
  40.         THROW_ERROR(cx, "Failed to convert charname string");
  41.  
  42.     if(argc == 7)
  43.         spdifficulty = JSVAL_TO_INT(argv[6]);
  44.  
  45.     char file[_MAX_FNAME+_MAX_PATH];
  46.     sprintf_s(file, sizeof(file), "%sd2bs.ini", Vars.szPath);
  47.  
  48.     if(!ProfileExists(profile))
  49.     {
  50.         char settings[600];
  51.         sprintf_s(settings, sizeof(settings),
  52.                 "mode=%s\0gateway=%s\0username=%s\0password=%s\0character=%s\0spdifficulty=%d\0\0",
  53.                 mode, gateway, username, password, charname, spdifficulty);
  54.        
  55.         WritePrivateProfileSection(profile, settings, file);
  56.     }
  57.  
  58.     return JS_TRUE;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement