a quick question.

Newbie Spellweaver
Joined
Jun 29, 2007
Messages
60
Reaction score
0
hey guys, i would like to know how to make a code that will read from MySQL data and put it in the server files, lets say i want to read all of the char. names how can i do that?
aww and another one when lets say i got the code that reads the char. names how can i make a code that will check if the NewCharName != CharName....?? thx
 
hey guys, i would like to know how to make a code that will read from MySQL data and put it in the server files, lets say i want to read all of the char. names how can i do that?
aww and another one when lets say i got the code that reads the char. names how can i make a code that will check if the NewCharName != CharName....?? thx

Are you talking about a check against duplicate character names? That's all I'm getting out of this...
 
Are you talking about a check against duplicate character names? That's all I'm getting out of this...
well basically yeah that's wat i'm talking about :P you helped me last time so i guess you could help me now? ;P or give me some hint on how to code it? thx ;P
 
well basically yeah that's wat i'm talking about :P you helped me last time so i guess you could help me now? ;P or give me some hint on how to code it? thx ;P

Well, in traditional LOTF, go to DataBase.cs and add this new method somewhere.
Code:
public static bool CharExists(string Name)
{
    MySqlDataAdapter DataAdapter = new MySqlDataAdapter("SELECT COUNT(*) FROM `characters` WHERE `CharName` = '" + Name + "' LIMIT 1;", Connection);
    DataSet DSet = new DataSet();
    DataAdapter.Fill(DSet, "CharLookup");
    return (DSet.Tables[0].Rows.Count > 0);
}
The above method queries the character database for the name specified. It returns true or false based on the number of rows returned in the query.

After adding that method, find the Character Creation Packet in Client.cs (dec 1001 / hex 0x3E9). You will see the boolean ValidName referenced several times, checking if the name from the character creation dialog in-game passes the sanity-checks. This is what we want.

You want to place this as the last sanity-check before it tries to make the character. In tradition LOTF, I would lay mine out like this:
Code:
if (CharName.IndexOfAny(new char[3] { ' ', '[', ']' }) > -1)
    ValidName = false;

if (ValidName)
    foreach (string name in DataBase.ForbiddenNames)
    {
        if (name == CharName)
        {
            ValidName = false;
            break;
        }
    }
if (ValidName)
    ValidName = DataBase.CharExists(CharName);

That's about it.. and it's untested.
 
Well, in traditional LOTF, go to DataBase.cs and add this new method somewhere.
Code:
public static bool CharExists(string Name)
{
    MySqlDataAdapter DataAdapter = new MySqlDataAdapter("SELECT COUNT(*) FROM `characters` WHERE `CharName` = '" + Name + "' LIMIT 1;", Connection);
    DataSet DSet = new DataSet();
    DataAdapter.Fill(DSet, "CharLookup");
    return (DSet.Tables[0].Rows.Count > 0);
}
The above method queries the character database for the name specified. It returns true or false based on the number of rows returned in the query.

After adding that method, find the Character Creation Packet in Client.cs (dec 1001 / hex 0x3E9). You will see the boolean ValidName referenced several times, checking if the name from the character creation dialog in-game passes the sanity-checks. This is what we want.

You want to place this as the last sanity-check before it tries to make the character. In tradition LOTF, I would lay mine out like this:
Code:
if (CharName.IndexOfAny(new char[3] { ' ', '[', ']' }) > -1)
    ValidName = false;
 
if (ValidName)
    foreach (string name in DataBase.ForbiddenNames)
    {
        if (name == CharName)
        {
            ValidName = false;
            break;
        }
    }
if (ValidName)
    ValidName = DataBase.CharExists(CharName);

That's about it.. and it's untested.

thx man just tested it and it worked, btw i edited the "
if (ValidName)
ValidName = DataBase.CharExists(CharName);"

thingy to that
Code:
[SIZE=2]
ValidName = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]InternalDatabase[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].CharExists(NewCharName);
{
ValidName = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
[/SIZE]

and thx for the help man tested it and it worked!
 
Back