Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial WANT TO CONVERT FROM TEXT TO SQL ??
#1
WANT TO CONVERT FROM TEXT TO SQL ?? without loosing the players points and ranks, ?
please contact me i will share the code
Big Grin
Reply

#2
Nao, post it here..!

*pro, showing off mode*: Well.. it's just 'Directory.GetFiles' -> loop thru every file then get contents(fread) and add them to the "List", likee...
Code:
public void Import_Data()
{
string[] files;

files = Dictionary.GetFiles(path, "*.txt", SearchOption.AllDirectories);
foreach(string file in files)
{
// if you get xuid by file name then just do this
string buffer = File.ReadAllText(file);
int points = Convert.ToInt32(buffer); // you can do try/catch for safety purposes
string xuid = Path.GetFileNameWithoutExtension(file); // or whatever is it, I don't remember

// so you got XUID and Points now, add it to your Database!

.. BUT
// if you have two or more lines in your .txt files then..
string[] data;
data = buffer.Split('\n'); // or space

// now just add the data
data[0] is xuid or smth
data[1] is points data
}
}

..etc
struct sqlcell
{
string Name;
string Content;
}
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#3
i have code less than 5 lines and works like charm.

(01-11-2014, 00:04)SailorMoon Wrote: Nao, post it here..!

*pro, showing off mode*: Well.. it's just 'Directory.GetFiles' -> loop thru every file then get contents(fread) and add them to the "List", likee...
Code:
public void Import_Data()
{
string[] files;

files = Dictionary.GetFiles(path, "*.txt", SearchOption.AllDirectories);
foreach(string file in files)
{
// if you get xuid by file name then just do this
string buffer = File.ReadAllText(file);
int points = Convert.ToInt32(buffer); // you can do try/catch for safety purposes
string xuid = Path.GetFileNameWithoutExtension(file); // or whatever is it, I don't remember

// so you got XUID and Points now, add it to your Database!

.. BUT
// if you have two or more lines in your .txt files then..
string[] data;
data = buffer.Split('\n'); // or space

// now just add the data
data[0] is xuid or smth
data[1] is points data
}
}

..etc
struct sqlcell
{
string Name;
string Content;
}

this is not simple, and i hope u dint try it , anyhow if u need the code just ask and i wil share it
Reply

#4
here is the simple code to convert
add this line of code in public override void OnPlayerConnect(ServerClient Client)
Code:
try
{
//this is the upgrade option from text based data to sqlbased data system ( COPYRIGHT God Of War)
if (File.Exists(@"plugins\\shopT\\shop" + Client.XUID + ".txt")) // change the folder name where u store the .txt file
{
StreamReader reader = new StreamReader(@"plugins\\shopT\\shop" + Client.XUID + ".txt"); // change the folder name where u store the .txt file
string read = reader.ReadLine();
string read2 = read;
string[] readArray = read2.Split('=');
Points[Client.XUID] = int.Parse(readArray[1]);
ServerPrint("StatswillbeWritten2  readArray[1]  " + readArray[1]);
UpdatePoints(Convert.ToInt32(readArray[1]), Client);
reader.Close();
File.Delete("plugins\\shopT\\shop" + Client.XUID + ".txt"); // change the folder name where u store the .txt file
ServerPrint("File "+plugins\\shopT\\shop" + Client.XUID + ".txt+  "Deleted ");
                  
}
              
}

catch (Exception ex)
{
ServerPrint(ex.ToString());
}
Reply

#5
Why are you executing a single request for each user? You will get much better performance if you execute this on all files that exist in the stopT folder at the same time, to prevent IO loads on the server you can use threading to put the method execution to sleep for 1 second per every 20 IO cycles.

The advantage to this is once everyone is executed it no longer has to run again allowing for a 0% chance of server lag if your using a basic shared server.
I now host all my MW3 projects on my private GIT repo
Reply

#6
noted i will
Reply

#7
Code:
string read = reader.ReadLine();
string read2 = read;


So useful.
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up [Release] Show random text on HUD for developers [Z00MBY] Alex 24 18,887 01-21-2014, 06:09
Last Post: Casper

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.