HomePortalRegisterLog in

Share | 
 

 [Guide] Save Character Data Every X Minutes

Go down 
AuthorMessage
Scott
Administrator
Administrator
avatar

Posts : 66
Join date : 2008-06-25

PostSubject: [Guide] Save Character Data Every X Minutes   Wed Jun 25, 2008 9:11 am

Quote :
This guide is not mine i take no credits for it ! I just helpe some people here to get their server more better !

Usage:
/autosave off
To disable autosaving or
/autosave on
to enable autosaving.

First, Let's begin with frmMain.cs. Open up the code of frmMain.cs.

Above line 13, add the following:
Code:
 
using System.Timers;
Around line 36, there should be something that looks like this:
Code:
 
public const int MINTHREADS = 15;
Below that, add:
Code:
public static System.Timers.Timer saveTimer = new System.Timers.Timer();
public const int TimerInterval = X;
Replace the X with the wait time in seconds x 1000.
Search for private void PingLoop(). Above that, add:
Code:
 
        public void SaveChar(object source, ElapsedEventArgs e)
        {
            COClient Client = null;
            foreach (AuthBinder AB in m_GameConnectedClients.Values)
            {
                Client = AB.Client;
                Console.WriteLine("Now Running Save Loop!");
                if (Client.Char != null)
                {
                    Console.WriteLine("Saving Character {0}", Client.Char.Name);
                    BackendDB.SynchronizeCharacter(Client.Char);
                }
            }
        }
Then, within PingLoop(), add this:
Code:
 
private void PingLoop()
{
            saveTimer.AutoReset = true;
            saveTimer.Elapsed += new System.Timers.ElapsedEventHandler(SaveChar);
            saveTimer.Interval = TimerInterval;
            saveTimer.Start();
            try
            {
Finally, open up World.cs.
Go into ParseString, and within the GM-only commands, add:
Code:
else if (Splitter[0] == "/autosave")
                    {
                        if (Splitter[1] == "on")
                        {
                            Client.SendData(PacketBuilder.Message(Client.MessageID, "System", "All", "Auto Save On!", World.ChatType.Center));
                            Chat sm = new Chat(Client.MessageID, Client.Char.Name, "ALL", "Server AutoSave Is Enabled.", ChatType.Center);
                            byte[] test = sm.writeImpl();
                            SendMessageServer(test);
                            frmMain.saveTimer.Interval = 15000;
                            frmMain.saveTimer.Start();
                        }
                        else if (Splitter[1] == "off")
                        {
                            Client.SendData(PacketBuilder.Message(Client.MessageID, "System", "All", "Auto Save Off!", World.ChatType.Center));
                            frmMain.saveTimer.Stop();
                            Chat sm = new Chat(Client.MessageID, Client.Char.Name, "ALL", "Server AutoSave is disabled.", ChatType.Center);
                            byte[] test = sm.writeImpl();
                            SendMessageServer(test);
                            Console.WriteLine("Auto Save is now disabled. Current Status of Timer is {0}.", frmMain.saveTimer.Enabled);
                        }
                        else
                        {
                            Client.SendData(PacketBuilder.Message(Client.MessageID, "System", "All", "Usage: /save on or /save off", World.ChatType.Talk));
                        }
                    }

Code:
XeroRecoil on ragezone forums

_________________


Owner of LeetGamers & UlsterCO
Back to top Go down
View user profile http://leetgamers.forumotion.com
 
[Guide] Save Character Data Every X Minutes
Back to top 
Page 1 of 1
 Similar topics
-
» Surviving Antarctica Reality TV 2083 by Andrea White
» Can You Name This Game Character
» Item Guide--Name and Gifting Level
» My Fantage Character - What do you think?
» How do you make your fantage character, your avatar?

Permissions in this forum:You cannot reply to topics in this forum
Leet Gamers :: Private Server Coding & Discussion :: Conquer 2.0 Private Server Coding & Discussion-
Jump to: