Tutorial: [508] account creation [508]
Files modified/added: login.java
Difficulty: 5/10? just a guess lol
Ok so i had finished 508 account creation and not many people know how to fix pali's login block so it works
lets start off with the first stage of login
this is pali's current -
Code:
try {
if (!fillStream(p, 2))
return;
} catch (Exception e) {
return;
}
int connectionType = p.stream.readUnsignedByte();
if (connectionType == 15) {
updateServer(p);
p.loginStage = -5;
return;
}
if (connectionType != 14) {
p.loginStage = -1;
return;
}
int longPlayerName = p.stream.readUnsignedByte();
p.stream.writeSignedByte(0);
p.stream.writeQWord(serverSessionKey);
directFlushStream(p);
p.loginStage++;
now whats wrong with this is the
Code:
if (!fillStream(p, 2))
in order for account creation to work we have to read all available incomming bytes
so lets change it to
Code:
if (!fillStream(p, p.socket.avail()))
that way it'll read all incomming bytes
now we need to fix the connection types
lets change:
Code:
if (connectionType == 15) {
updateServer(p);
p.loginStage = -5;
return;
}
if (connectionType != 14) {
p.loginStage = -1;
return;
}
int longPlayerName = p.stream.readUnsignedByte();
p.stream.writeSignedByte(0);
p.stream.writeQWord(serverSessionKey);
directFlushStream(p);
p.loginStage++;
to
Code:
switch(connectionType) {
case 15:
updateServer(p);
p.loginStage = -5;
return;
case 14:
int longPlayerName = p.stream.readUnsignedByte();
p.stream.writeSignedByte(0);
p.stream.writeQWord(serverSessionKey);
directFlushStream(p);
p.loginStage++;
break;
default:
p.loginStage = -1;
return;
}
now we have to add the first step to account creation which is checking and validating the birthdate, so lets add this to the switch statement
Code:
case 85:
int code = 2;
int day = p.stream.readSignedByte();
int month = p.stream.readSignedByte();
int year = p.stream.readDWord();
int country = p.stream.readDWord());
p.stream.writeSignedByte(code);
// some return codes, 11 (invalid birthday), 12 (birthday is in future), 13 (was this year)
// 14 (was last year), 15 (invalid country), 21 (never ending loading)
directFlushStream(p);
p.loginStage = -1;
break;
You can modify it to save the data if you want
Now lets add the second part, chosing the username the person wants (add this to the switch statement also)
Code:
case 118:
int Scode = 2;
String Susername = longToString(p.stream.readQWord()).toLowerCase().replaceAll("_", " ").trim();
if(Susername == null || Susername.equals("invalid name")) {
Scode = 22;
}
File Sfile = new File("../Data/characters/mainsave/" + Susername + ".dat");
if(Sfile.exists()) {
Scode = 20;
}
stream.writeSignedByte(Scode); //20 = username not available, //22 = not valid username
directFlushStream(p);
p.loginStage = -1;
break;
Now we have to move on to the final step, chosing your password (add this to switch statement)
Code:
case 48:
int code = 2;
p.stream.readUnsignedByte();//junk
p.stream.readUnsignedByte();//junk
p.stream.readUnsignedByte();//junk
p.stream.readWord();//junk
int revision = p.stream.readWord();
if(revision != 508) {
code = 37;
}
String username = longToString(p.stream.readQWord()).toLowerCase().replaceAll("_", " ").trim();
p.stream.readDWord();//junk
String passwords = p.stream.readString().toLowerCase();
p.stream.readDWord();//junk
p.stream.readWord();//junk
int Fday = p.stream.readUnsignedByte(); //might be signed
int Fmonth = p.stream.readUnsignedByte(); //might be signed
p.stream.readDWord();//junk
int year = p.stream.readWord();
int location = p.stream.readWord();
p.stream.readDWord();
if(!validString(passwords)) { // you'll have to make your own validString method
code = 31;
}
if(username == null) {
code = 20;
}
if(passwords.length() < 4) {
code = 32;
}
if(passwords.equals(username)) {
code = 34;
}
if(passwords == null || passwords.equals("") || passwords.equals(" ")) {
code = 30;
}
try {
File file = new File("../Data/characters/mainsave/" + Susername + ".dat");
if(file.exists()) {
code = 20;
}
} catch(Exception e) {
System.out.println(e);
}
stream.writeSignedByte(code);//20 = username not available anymore //29 = invalid password length
//30 = invalid characters in password, 31 = password is too easy to guess, 32 = passwords don't match
//34 = password too simliar to username, 37 = runescape ahs been updated
try {
if(code != 2) {
return;
}
//create account method goes here
} catch(Exception e) {
System.out.println(e);
}
directFlushStream(p);
p.loginStage = -1;
break;
now we can change the login stage three so it can see if a account exists instead of auto-account creation
change
Code:
if (password != null && p.password != null && p.password != "" && !p.password.equals(password)) {
returnCode = 3;
to
Code:
File file = new File("../Data/Character/" + username + ".txt");
if (password == null || p.password == null || p.password == "" || !p.password.equals(password) || !file.exists()) {
returnCode = 3;
post any errors so OTHER people can help you
Note:
-you have to create YOUR OWN account creation method that creates the actual account
-You'll have to import java.io.File;
-Some of the reading methods might be wrong because i had to convert from my source