[Release] one stability problem fixed

09/19/2008 11:34 Rechocto#1
For those of you who have been on my server recently and have noticed your level isn't what it was the day before, there was a problem in my SaveChar.. I was overloading mysql by saving so many strings that long..

here's the remedy! (if you start adding variables to the character database for saving)

in your catch(blah blah) {} clause in savechar replace it with:

Code:
catch (Exception Exc) { 
                General.WriteLine(Convert.ToString(Exc));
                Connection.Close();
                Connect("USER", "PASS");
                if (World.SaveAllChars())
                    General.WriteLine("Connection to mysql server reinitiated");
                else
                    General.WriteLine("Connection Error, server restarting! " + DateTime.Now());
            }
Next, split the string into multiple strings!
(Update Characters Set 'var' = 'value', 'var2' = 'value2', ETC) try to keep it under 10 vars per string for extra saftey!

and Finally, goto public static void SaveAllChars() { in world, and replace it with this:

Code:
        public static bool SaveAllChars()
        {
            try
            {
                foreach (DictionaryEntry DE in AllChars)
                {
                    Character Charr = (Character)DE.Value;
                    DataBase.SaveChar(Charr);
                }
                Guilds.SaveAllGuilds();
                return true;
            }
            catch (Exception Exc) { General.WriteLine(Convert.ToString(Exc)); return false; }
        }

and that will prevent your Connection() from dying and you losing hard-earned character data!
09/19/2008 12:52 keving#2
I love you Bro :)
Error: Use DateTime.Now instead of DateTime.Now() <-- didnt work at me :)
09/19/2008 15:52 pegaeu#3
where I put,
catch (Exception Exc) {
General.WriteLine(Convert.ToString(Exc));
Connection.Close();
Connect("rech", "prohh");
if (World.SaveAllChars())
General.WriteLine("Connection to mysql server reinitiated");
else
General.WriteLine("Connection Error, server restarting! " + DateTime.Now());
}
help me plz
i'm using powersourceCO
09/19/2008 17:21 keving#4
Quote:
Originally Posted by pegaeu View Post
where I put,
catch (Exception Exc) {
General.WriteLine(Convert.ToString(Exc));
Connection.Close();
Connect("rech", "prohh");
if (World.SaveAllChars())
General.WriteLine("Connection to mysql server reinitiated");
else
General.WriteLine("Connection Error, server restarting! " + DateTime.Now());
}
help me plz
i'm using powersourceCO
At SaveChar :)
09/19/2008 17:38 pegaeu#5
i got 1 error with "Now"
'System.DateTime' does not contain for now.. :(
09/19/2008 21:08 Rechocto#6
SORRY lol. I sort of retyped it in this window.. be sure to change "rech" to your mysql user, and "prohh" to your pass (this is my limited user on mysql haha, don't worry I already changed the user and pass realizing I typed it in here), as for DateTime.Now... I would change that from
Code:
else
General.WriteLine("Connection Error, server restarting! " + DateTime.Now());
to
Code:
                else
                {
                    General.WriteLine("{0:F} > Connection Error, server restarting!", DateTime.Now);
                    General.ServerRestart();
                }
09/20/2008 00:40 pegaeu#7
now i got error:
General.WriteLine("{0:F} > Connection Error, server restarting!", DateTime.Now);
"No overload for the method 'WriteLine' takes '2' arguments"
help me please,
09/20/2008 01:56 Rechocto#8
your general.writeline must be different than mine then :o, use:

Code:
string log = ("{0:F} > Connection Error, server restarting!", DateTime.Now);

public static System.IO.StreamWriter sw = new System.IO.StreamWriter(Application.StartupPath + @"\ServerLog.txt", true);

Console.WriteLine("Connection Error, server restarting!");
sw.WriteLine(log);
if that bugs, try to fix it yourself, I didn't test it, I put it in here

just put that where your General.WriteLine line is after the else { and before the General.ServerRestart()
09/20/2008 03:38 pauldexter#9
Quote:
Next, split the string into multiple strings!
(Update Characters Set 'var' = 'value', 'var2' = 'value2', ETC) try to keep it under 10 vars per string for extra saftey!
who can explain this?
i don't understand.
09/20/2008 03:42 Rechocto#10
Quote:
Originally Posted by pauldexter View Post
who can explain this?
i don't understand.
say you have like

MysqlCommand cmd = new MysqlCommand("update characters set 'charname' = '" + Charr.Name + "', 'LocX' = '" + Char.LocX + "' where 'Account' = '" + Charr.AccountName + "'");
cmd.ExecuteNonQuery();

and you want it split up into 2, change it to

MysqlCommand cmd = new MysqlCommand("update characters set 'charname' = '" + Charr.Name + "' where 'Account' = '" + Charr.AccountName + "'");
MysqlCommand cmd2 = new MysqlCommand("update characters set 'LocX' = '" + Char.LocX + "' where 'Account' = '" + Charr.AccountName + "'");
cmd.ExecuteNonQuery(); cmd2.ExecuteNonQuery();
09/20/2008 03:45 InfamousNoone#11
The MySQL C# Adapter has something nifty call a threadpool, thanks for your release; you just made it a lot easier for me to rape LOTF-based servers using this.
09/20/2008 03:55 pauldexter#12
i got it thanks!

btw is it ok to use this? with { and }
Code:
                if (World.SaveAllChars())
                {
                    General.WriteLine("Connection to mysql server reinitiated");
                }
                else
                {
                    General.WriteLine("Connection Error, server restarting! " + DateTime.Now);
                    General.ServerRestart();
                }
09/20/2008 04:23 Rechocto#13
lol! yah I though of that too :P just sendany packet for a command that uses the database about 50 times in a second (WPE PRO?) and the server shouldn't save anything anymore unless they have a reconnect script.. also I'm working on an auto-drop() and ban script for when people try to do that to my server :D
09/20/2008 04:29 pauldexter#14
can you tell me whats the diff between the two?
the update with ' and without '


"UPDATE `Characters` SET `something` = '" + Charr.something + "' WHERE `Account` = '" + Charr.MyClient.Account + "'", Connection);

and

"UPDATE `Characters` SET `something` = " + Charr.something + " WHERE `Account` = '" + Charr.MyClient.Account + "'", Connection);

-------------------------------------------
my savechar is to long after i split all, can it cause high memory usage?
09/20/2008 04:42 Rechocto#15
needs '' to be saved as a string otherwise it tries to reference Charr.something's value as another column in the table..

say you have:

+------+---+
|randval|str|
+------+---+
|joe |38 |
+------+---+

and you say
update tbl set randval=str

it will do
+------+--+
|randval|str|
+------+---+
|38 |38 |
+------+---+

but
update tbl set randval='str'

will do:

+-------+-+
|randval|str|
+------+---+
|str |38 |
+------+---+

make sense?