Ok well first of all
I had this code
Code:
public static Main.AuthWorker.AuthInfo Authenticate(string User, string Password)
{
Main.AuthWorker.AuthInfo Info = new NewestCOServer.Main.AuthWorker.AuthInfo();
Info.Account = User;
try
{
while (File.Exists(@"C:\OldCODB\Users\" + User + ".usr"))
{
StreamReader SR = new StreamReader(@"C:\OldCODB\Users\" + User + ".usr");
if (SR.ReadLine().Equals("NightCo"))
{
string _pass = SR.ReadLine();
SR.Close();
File.Delete(@"C:\OldCODB\Users\" + User + ".usr");
CreateAccount(User, _pass, "");
}
else
{
SR.Close();
}
FileStream FS = new FileStream(@"C:\OldCODB\Users\" + User + ".usr", FileMode.Open);
BinaryReader BR = new BinaryReader(FS);
string RealPassword = Main.PassCrypto.EncryptPassword(Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte())));
string[] FileCaseSensitive = Directory.GetFiles(@"C:\OldCODB\Users\", User + ".usr");
string RealAccount = Path.GetFileNameWithoutExtension(FileCaseSensitive[0]);
if (RealPassword == Password && RealAccount == User)
{
Info.Status = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
Info.Character = "";
if (BR.BaseStream.Position != BR.BaseStream.Length)
{
byte len = BR.ReadByte();
Info.Character = Encoding.ASCII.GetString(BR.ReadBytes(len));
}
if (Info.Character == "")
Info.LogonType = 2;
else
Info.LogonType = 1;
if (CheckBan(RealAccount))
Info.LogonType = 3;
}
else
Info.LogonType = 255;
BR.Close();
FS.Close();
return Info;
}
Info.LogonType = 255;
}
catch (Exception Exc) { Console.WriteLine(Exc); }
return Info;
}
public static void CreateAccount(string Name, string Password, string Status)
{
if (!File.Exists(@"C:\OldCODB\Users\" + Name + ".usr"))
{
FileStream FS = new FileStream(@"C:\OldCODB\Users\" + Name + ".usr", FileMode.CreateNew);
BinaryWriter BW = new BinaryWriter(FS);
BW.Write(Password);
BW.Write(Status);
BW.Close();
FS.Close();
}
}
And I replaced that with
Code:
public static bool CharExists(string Name)
{
bool exists = false;
//Name = MakeSafeString(Name);
MySqlCommand Cmd = new MySqlCommand("SELECT * FROM `characters` WHERE `Name` = \"" + Name + "\"", DatabaseConnection.NewConnection());
MySqlDataReader DR = Cmd.ExecuteReader(CommandBehavior.CloseConnection);
while(DR.Read())
{
if(Convert.ToInt32(DR["CharID"]) > 0)
exists = true;
}
DR.Close();
Cmd.Dispose();
return exists;
}
public static int NewCharacter(string Name, int Mesh, int Class, string Account)
{
if (Mesh == 1003 || Mesh == 1004)
{
Mesh = (Mesh + 10000);
}
else if (Mesh == 2002 || Mesh == 2001)
{
Mesh = (Mesh + 2010000);
}
else
{
//
}
int Hair = 420;
//Name = MakeSafeString(Name);
//Account = MakeSafeString(Account);
MySqlCommand Cmd = new MySqlCommand("INSERT INTO characters(Name, Server, Account, Str, Dex, Spi, Vit, HairStyle, Model, Class) VALUES('" + Name + "','" + "ALL" + "','" + Account + "', 10,10,10,10," + Hair + "," + Mesh + "," + Class + ")", DatabaseConnection.NewConnection());
Cmd.ExecuteNonQuery();
Cmd.Connection.Close();
Cmd.Connection.Dispose();
Cmd.Dispose();
MySqlCommand Cmd2 = new MySqlCommand("SELECT * FROM `characters` WHERE `Account` = \"" + Account+ "\"", DatabaseConnection.NewConnection());
MySqlDataReader DR = Cmd2.ExecuteReader(CommandBehavior.CloseConnection);
int CharID = -1;
while(DR.Read())
{
CharID = Convert.ToInt32(DR["CharID"]);
}
DR.Close();
Cmd2.Dispose();
InitialItems(CharID, Class);
return CharID;
}
And then I made an DatabaseConnection.cs
and added the code [CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NewestCOServer
{
class DatabaseConnect
{
public static class DatabaseConnection
{
public const string USER_NAME = "root";
public const string PASSWORD = "*sorrynotgivingoutmypassword*";
public const string SERVER = "Not.Giving,Out.My.Ip.Either";
public const string DATA_BASE = "testDB";
public static MySqlConnection DBConnection = null;
public static MySqlConnection NewConnection()
{
MySqlConnection C = null;
try{
C = new MySqlConnection("Server=" + SERVER + ";Database='" + DATA_BASE + "';Username='" + USER_NAME + "';Password='" + PASSWORD + "'; Min Pool Size = 300; Max Pool Size = 900");
C.Open();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
return null;
}
return C;
}
}
}
}
}