Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 15:44

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Any ideas or suggestions?

Discussion on Any ideas or suggestions? within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
12k's Avatar
 
elite*gold: 0
Join Date: Jul 2011
Posts: 218
Received Thanks: 33
Any ideas or suggestions?

Well, the idea is to sleep all the way up until the next event, to try to save a lot of extra checks that aren't needed. So the events that only occur like once a week wont need to be taking up anything extra until its their time to run. Instead of checking if its time for guild war every 10 seconds for a whole week, just have a idle thread. Not sure if this is a great idea or not, but this is my implementation of the idea. If you have any thoughts or suggestions please shoot . Would also like to hear any of your all's solutions to things like this.


EventPool.cs
Code:
using System;
using System.Threading;
using System.Collections.Generic;
namespace Base
{
    public class EventPool
    {
        private IEvent[] Events = new IEvent[2];
        private byte NextEventToExecute = 0;
        public EventPool()
        {
            Events[0] = new Events.GuildWars_Start();
            Events[1] = new Events.GuildWars_Stop();
        }
        public void Start()
        {
            for(byte i = 0; i < Events.Length; i++)
                if(Events[i] != null)
                    if (DateTime.Now < Events[i].StartTime && DateTime.Now > Events[i - 1].StartTime)
                    { NextEventToExecute = i; break; }
            while (true)
            {
                if (Events[NextEventToExecute] != null)
                    Events[NextEventToExecute].Execute();
                NextEventToExecute++;
                if (NextEventToExecute > Events.Length)
                    NextEventToExecute = 0;
                Thread.Sleep((int)(Events[NextEventToExecute].StartTime - DateTime.Now).TotalMilliseconds);
            }
        }
    }
}
IEvent.cs
Code:
using System;
namespace Base
{
    public interface IEvent
    {
        DateTime StartTime { get; set; }
        void Execute();
    }
}
12k is offline  
Old 12/14/2011, 04:01   #2
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
I kinda like the idea behind it but not the implementation...

Using one thread that sleeps for long time should be a perfectly viable way to deal with things that don't happen that often (say... every hour or couple times a day?).

That being said I would not write it how you have it right now.

Example complaints with your implementation.


#1: Arrays. No easy way to add/remove items from the thread. You want something that can easily be controlled

#2: No/Few helper methods. Adding a new event should re-organize the list so that the first item in the list is always the next item to be processed

#3: No way to handle events being added when a sleep has already been called. Example.. You start the server and only have 1-2 events in there that may not take place for say... a a day or more. If you want to add in another event in say an hour, it will not ever try to run that event until the first sleep has passed (possibly days). You need a way to control this properly.


I'd say that the easiest and most practical way to do this would just be to have the thread run say... once a minute. That's little to no strain on your server and it also opens up the thread to do MANY more things.

Think of all the things that you would want to have run with accuracy to the minute..

Lottery resets, any events (quiz, pk, gw, etc), system messages, etc.

All of these can be combined into one simple thread that just says "Hey, this item is in my list of actions to perform and should be performed this minute, lets run it!". It's easy to deal with and can be expanded to take care of just about anything you want.
pro4never is offline  
Old 12/14/2011, 04:07   #3
 
12k's Avatar
 
elite*gold: 0
Join Date: Jul 2011
Posts: 218
Received Thanks: 33
Hmm, very good idea. I just made this one for events that are like weekly. As far as this class goes, I didnt have any intensions on things being removed, because all of them would always be the same date and time. I just order them by the datetime as I add them to the array. But if anyone else wanted to expand on this idea, i can certainly see the benefit of adding the add/remove events.


#edit, this is kind of a run-off from the idea you gave me.
12k is offline  
Old 12/14/2011, 06:24   #4
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
1. Why do you use an interface?
2. Multithreading is your friend.
BaussHacker is offline  
Old 12/14/2011, 12:40   #5
 
12k's Avatar
 
elite*gold: 0
Join Date: Jul 2011
Posts: 218
Received Thanks: 33
1. That way I can easily do different things with Execute() when the event is started.

2. Why multithread when the purpose is to have a thread that sleeps up until its time for a event to be called, then goes back to sleep until its time for another.

#Edit: Ah sorry, didnt realize it didnt show this was running on a separate thread. I have a different handler that runs this on its own thread.
12k is offline  
Old 12/14/2011, 12:52   #6
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
Quote:
Originally Posted by 12k View Post
1. That way I can easily do different things with Execute() when the event is started.

2. Why multithread when the purpose is to have a thread that sleeps up until its time for a event to be called, then goes back to sleep until its time for another.

#Edit: Ah sorry, didnt realize it didnt show this was running on a separate thread. I have a different handler that runs this on its own thread.
Interfaces are used to inheritance, It would be more reasonable making it a class.

The Thread.Sleep will sleep the current thread, so that means the main thread and it will freeze EVERY single procedure untill it's finished. That's why you use multithreading in this case. :P
BaussHacker is offline  
Old 12/14/2011, 15:18   #7
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Quote:
Originally Posted by BaussHacker View Post
Interfaces are used to inheritance, It would be more reasonable making it a class.

The Thread.Sleep will sleep the current thread, so that means the main thread and it will freeze EVERY single procedure untill it's finished. That's why you use multithreading in this case. :P
This entire system would be on its own thread, thats what he was saying xD.
pro4never is offline  
Old 12/14/2011, 15:33   #8


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
If the entire system is to be contained on 1 thread then you would need to have something that does like

Code:
while(true)
{
     if(EventsWaitingToStart.Count > 0)
     {  
           StartEvents();
     }

     if(EventsRunning.Count == 0)
     {  
           Thread.Sleep(1);
           continue;
     }
     else
     {  
           //Run Events
     }
}
This wont use any CPU at all in the grand scheme of things, plus it allows for on the fly creation of events, unlike Thread.Sleep(<insert 5 days of sleep time>);

And if you have to bring the server down or it crashes it equally doesn't need modifying.
Korvacs is offline  
Reply


Similar Threads Similar Threads
Grindroad - Opinions,suggestions & ideas
07/27/2011 - SRO Private Server - 48 Replies
Okay guys,this thread has to be fully peaceful,without flame,hate and spam. Every post caught to be flame/hating post/spam will get reported straight away. I don't want to see here any esro,sjsro,mysro,swsro,zszc bullshit - it is related ONLY to GrindRoad server. I want to know what you guys think about it,what should be changed in your opinion and what could get possibly added - many things are possible as ufonose is really skilled in coding and he already added many new functions that...
Nid Suggestions!!
04/29/2010 - Cabal Private Server - 3 Replies
Is there a easy cabal server w/o reset system??and with good rates??
some suggestions.. ideas.. lemme know what you think about this..
12/21/2009 - Soldier Front - 19 Replies
i have some ideas.. lemme know what you think about this.. • we should have a hack tester.. so we could lessen the spam threads claiming that their release/ hack is working.. before it is released on the members, it should have a go signal from the hack tester and moderator.. hack tester should know coding and stuff about reverse engineering. so malicious files can be controlled and would not be released openly to the public.. this would mean better ratings than other sites:D less...
[Ideas?] Need Some Ideas For My Public Source
09/23/2008 - CO2 Private Server - 11 Replies
hey i need some ideas for the source that im coding (lotf) and when it is done i go public it, so someone got some great ideas? (Serious answers only please:p) Examples: Quests Events NPCs
SUGGESTIONS FOR 127-130
11/26/2006 - Conquer Online 2 - 1 Replies
yea i just hit 127 on my non reborn warrior and i waswondering if tg is truly the best place to lvl :? doesnt seem lke this could possibly be true. i can hunt at alien apes or serpents where i easily one hit even with soc rainys and get way more xp that TG. i DO have ND as well as the hack u can use with QOProxy to stay on infinate superman in TG. and a stig bitch water tao to go with, but anyone got some suggestions? tg= REALLY BORING... anyways thanx in advance.



All times are GMT +1. The time now is 15:44.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.