Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.24 KB | None | 0 0
  1. //v1.1, 5/28/2011
  2. //v1.1 uses getLineCount instead of isFile so if the file is empty it returns "not there."
  3. //This is important because Torque can't delete files, so if someone deletes their account it will leave an empty file behind, and isFile would say the account was still in use.
  4. //v1.1 also uses the username stored inside of the file instead of whatever string the user logs in with, so case won't be an issue.
  5. //v1.1 saves the "guild" variable since I'm gonna start on that in about five minutes.
  6.  
  7. //I'm using messageClient commands so I can see them for now.
  8. //They can be changed later.
  9. //Or, better yet, you can keep those and have the GUIs use message hooks, so non-ennRP people can still get messages and stuff so they won't ragequit immediately.
  10.  
  11. function servercmdNewAccount(%client, %username, %password) {
  12. if(%client.username !$= "") {
  13. messageClient(%client, 'MsgAccountCreationFailure', "You are already logged in. Please log out before creating a new account.");
  14. return;
  15. }
  16. if(getLineCount("ennRP/server/accounts/"@ strLwr(%username) @".txt")) {
  17. messageClient(%client, 'MsgAccountCreationFailure', "Sorry, but that username has already been taken. Please choose another username.");
  18. return;
  19. }
  20. if(getLineCount("ennRP/server/accounts/"@ strLwr(%username) @".txt")) {
  21. messageClient(%client, 'MsgAccountCreationFailure', "Sorry, but that username has already been taken. Please choose another username.");
  22. return;
  23. }
  24. if(strLen(%userName) < 5) {
  25. messageClient(%client, 'MsgAccountCreationFailure', "Sorry, but your username must have at least 5 characters. Please choose a longer username.");
  26. return;
  27. }
  28. if(strLen(%password) < 6) {
  29. messageClient(%client, 'MsgAccountCreationFailure', "Sorry, but your password must have at least 6 characters. Please choose a longer password.");
  30. return;
  31. }
  32. %client.username = %username;
  33. %client.password = %password;
  34. %client.setStuds(100);
  35. %client.level = 1;
  36. %client.class = 1;
  37. messageClient(%client, 'MsgAccountCreation',
  38. "Your new account has been created. Your username is" SPC %username @ ".\n"@
  39. "Your password is" SPC %password @ ". Don't forget your password. It's important.");
  40. }
  41.  
  42. function servercmdLogin(%client, %username, %password) {
  43. //I'll just assume that the username and password are both adequately long, since the only reason that they wouldn't be is because somebody changed it on purpose.
  44. if(!getLineCount("ennRP/server/accounts/"@ strLwr(%username) @".txt")) {
  45. messageClient(%client, 'MsgAccountLoginFailure', "Sorry, but that account does not exist. Please verify that you have spelled your username correctly.");
  46. return;
  47. }
  48. if(!isObject(%f = EnnRP_FileObject))
  49. %f = new FileObject(EnnRp_FileObject);
  50. %f.openForRead("ennRP/server/accounts/"@ strLwr(%username) @".txt");
  51. %n = %f.readLine(); //The first line, I just realized, is the correct username. This is case-sensitive and can handle funny characters that filenames can't.
  52. if(%password !$= %f.readLine()) {
  53. messageClient(%client, 'MsgAccountLoginFailure', "Sorry, but your password is incorrect. Please verify that you have typed your password in correctly.");
  54. %f.close();
  55. return;
  56. }
  57. //Success
  58. messageClient(%client, 'MsgAccountLogin', "You have successfully logged in.");
  59. %client.username = %n;
  60. %client.password = %password; //Save this so we can use it later when we have to save
  61. %client.setStuds(%f.readLine());
  62. %client.level = %f.readLine();
  63. %client.class = %f.readLine();
  64. //Outfit information
  65. %client.colorSkin = %f.readLine();
  66. %client.headCode = %f.readLine();
  67. %client.visorCode = %f.readLine();
  68. %client.backCode = %f.readLine();
  69. %client.leftHandCode = %f.readLine();
  70. %client.chestCode = chestShowImage;
  71. %client.faceCode = faceplateShowImage;
  72. %client.headCodeColor = addTaggedString($legoColor[%f.readLine()]);
  73. %client.visorCodeColor = addTaggedString($legoColor[%f.readLine()]);
  74. %client.backCodeColor = addTaggedString($legoColor[%f.readLine()]);
  75. %client.leftHandCodeColor = addTaggedString($legoColor[%f.readLine()]);
  76. %client.chestdecalcode = addTaggedString(%f.readLine());
  77. %client.facedecalcode = addTaggedString(%f.readLine());
  78. %client.bodytype = %f.readLine();
  79. servercmdarmsncrotch(%client,%client.bodytype);
  80. if(isObject(%player = %client.player)) {
  81. %player.unMountImage($headSlot);
  82. %player.unMountImage($visorSlot);
  83. %player.unMountImage($backSlot);
  84. %player.unMountImage($leftHandSlot);
  85. %player.unMountImage($chestSlot);
  86. %player.unMountImage($faceSlot);
  87. %player.unMountImage(7);
  88. if (%client.team $= "")
  89. %player.setSkinName(%client.colorSkin);
  90. %player.mountImage(%client.headCode, $headSlot, 1, %client.headCodeColor);
  91. %player.mountImage(%client.visorCode, $visorSlot, 1, %client.visorCodeColor);
  92. %player.mountImage(%client.backCode, $backSlot, 1, %client.backCodeColor);
  93. %player.mountImage(%client.leftHandCode, $leftHandSlot, 1, %client.leftHandCodeColor);
  94. %player.mountImage(%client.chestCode, $chestSlot, 1, %client.chestdecalcode);
  95. %player.mountImage(%client.faceCode, $faceSlot, 1, %client.facedecalcode);
  96. }
  97. //Inventory and such
  98. %client.primaryWeapon = %f.readLine();
  99. %client.secondaryWeapon = %f.readLine();
  100. %client.Chest = %f.readLine();
  101. %client.Helmet = %f.readLine();
  102. %client.Ammo = %f.readLine();
  103. if(isObject(%client.player)) { //These should probably be saved to the player
  104. %client.player.primaryWeapon = %client.primaryWeapon;
  105. %client.player.secondaryWeapon = %client.secondaryWeapon;
  106. %client.player.Chest = %client.Chest;
  107. %client.player.Helmet = %client.Helmet;
  108. %client.player.Ammo = %client.Ammo;
  109. }
  110. for(%x = 1; %x <= 28; %x++)
  111. %client.inventory[%x] = %f.readLine();
  112. %client.guild = %f.readLine();
  113. %f.close();
  114. }
  115.  
  116. function saveAccount(%client) {
  117. echo("Saveaccount called.");
  118. if(%client.username $= "") {
  119. echo("Error in saving account: client" SPC %client SPC "is not logged in.");
  120. return;
  121. }
  122. if(!isObject(%f = EnnRP_FileObject))
  123. %f = new FileObject(EnnRp_FileObject);
  124. %f.openForWrite("ennRP/server/accounts/"@ strLwr(%client.username) @".txt");
  125. %f.writeLine(%client.userName); //The first line is just the username, for no good reason. Maybe later it will be the last person who logged into this account
  126. %f.writeLine(%client.password);
  127. %f.writeLine(%client.studMoney);
  128. %f.writeLine(%client.level);
  129. %f.writeLine(%client.class);
  130. %f.writeLine(%client.colorSkin);
  131. %f.writeLine(%client.headCode);
  132. %f.writeLine(%client.visorCode);
  133. %f.writeLine(%client.backCode);
  134. %f.writeLine(%client.leftHandCode);
  135. %f.writeLine(%client.headCodeColorCode);
  136. %f.writeLine(%client.visorCodeColorCode);
  137. %f.writeLine(%client.backCodeColorCode);
  138. %f.writeLine(%client.leftHandCodeColorCode);
  139. %f.writeLine(%client.chestDecalCodeCode);
  140. %f.writeLine(%client.faceDecalCodeCode);
  141. %f.writeLine(%client.bodyType);
  142. %f.writeLine(%client.primaryWeapon);
  143. %f.writeLine(%client.secondaryWeapon);
  144. %f.writeLine(%client.chest);
  145. %f.writeLine(%client.helmet);
  146. %f.writeLine(%client.ammo);
  147. for(%x = 1; %x <= 28; %x++)
  148. %f.writeLine(%client.inventory[%x]);
  149. %f.writeLine(%client.guild);
  150. %f.close();
  151. }
  152.  
  153. package Wiggy_Stupid_ServercmdUpdatePrefs_Color_grabber {
  154. function ServerCmdUpdatePrefs(%client, %name, %skin, %headCode, %visorCode, %backCode, %leftHandCode, %headCodeColor, %visorCodeColor, %backCodeColor, %leftHandCodeColor, %chestdecalcode, %facedecalcode, %bodytype) {
  155. %client.headCodeColorCode = %headCodeColor;
  156. %client.visorCodeColorCode = %visorCodeColor;
  157. %client.backCodeColorCode = %backCodeColor;
  158. %client.leftHandCodeColorCode = %leftHandCodeColor;
  159. %client.chestdecalcodeCode = %chestdecalcode;
  160. %client.facedecalcodeCode = %facedecalcode;
  161. Parent::ServerCmdUpdatePrefs(%client, %name, %skin, %headCode, %visorCode, %backCode, %leftHandCode, %headCodeColor, %visorCodeColor, %backCodeColor, %leftHandCodeColor, %chestdecalcode, %facedecalcode, %bodytype);
  162. }
  163. };
  164. activatepackage(Wiggy_Stupid_ServercmdUpdatePrefs_Color_grabber);
  165.  
  166. package Wiggy_Accounts {
  167. function GameConnection::onDrop(%client, %reason) {
  168. if(%client.username !$= "")
  169. saveAccount(%client);
  170. Parent::onDrop(%client, %reason);
  171. }
  172. function saveBlocks(%a, %b) {
  173. echo("saveBlocks");
  174. for(%i = 0; %i < ClientGroup.getCount(); %i++ ) {
  175. if(ClientGroup.getObject(%i).username !$= "")
  176. saveAccount(ClientGroup.getObject(%i));
  177. }
  178. Parent::saveBlocks(%a, %b);
  179. }
  180. };
  181. activatepackage(Wiggy_Accounts);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement