Welcome to AC Web.
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16

    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.
    Quote Originally Posted by SolitudeGaming View Post
    I think I understand what you mean. The only way I can think of fixing that is loading all of the users upon startup as opposed to accessing the database each time a user connects. Do you have a better method in mind?
    It's fine to access the database when you want to check if an account exists. What he's suggesting is you use true/false only if you can give a certain answer, and you use exceptions to handle exceptional cases (i.e. no database connection). the way it would work:

    Code:
    try
    {
        if (DB.doesUserExist("sundays"))
        {
             // do something with the account here
        }
    }
    catch (SQLException ex)
    {
            // no SQL connection, show an error message to the user, free resources, do nothing, up to you.
    }
    in your current usage scenario, DB::doesUserExist returns false even if there's no connection, and you continue the normal execution path.

    btw it's great that you're using existing wow emulators as a guide for how to do this, they're great for learning, but sometimes old C++ code doesn't "translate" well into java; there might be easier ways of doing the things you're doing in java.

    For example in WanderScript.java you make use of the old mangos idioms of incrementing timer variables, and checking if (currentMS - timer >= interval). This is fine, but your Slick2D framework (im not familiar with it) probably provides some sort of Timer class where you can schedule events.

    If the framework doesn't have a Timer class you could find a library that has one, or you could roll something like this with the java Timer class:

    Code:
    class WanderTask extends TimerTask
    {
        private Entity entity;
    
        public WanderTask(Entity entity)
        {
            this.entity = entity;
        }
    
        @Override
        public void run()
        {
            if (entity.isAlive())
                entity.moveRandomDirection();
        }
    }
    and you would schedule your task like:

    Code:
    Timer timer = new Timer();
    timer.schedule(new WanderTask(entity), 0, 1000);
    where timer could be a member of your Script class.

    The longer you'll work on this the more you'll realise how difficult MMOs are to implement properly Especially if you aim for large player counts, seamless worlds and multiple services
    Last edited by hates_sundays; 10-31-2018 at 10:13 PM.

  2. #17
    Quote Originally Posted by hates_sundays View Post
    It's fine to access the database when you want to check if an account exists. What he's suggesting is you use true/false only if you can give a certain answer, and you use exceptions to handle exceptional cases (i.e. no database connection). the way it would work:

    Code:
    try
    {
        if (DB.doesUserExist("sundays"))
        {
             // do something with the account here
        }
    }
    catch (SQLException ex)
    {
            // no SQL connection, show an error message to the user, free resources, do nothing, up to you.
    }
    in your current usage scenario, DB::doesUserExist returns false even if there's no connection, and you continue the normal execution path.

    btw it's great that you're using existing wow emulators as a guide for how to do this, they're great for learning, but sometimes old C++ code doesn't "translate" well into java; there might be easier ways of doing the things you're doing in java.

    For example in WanderScript.java you make use of the old mangos idioms of incrementing timer variables, and checking if (currentMS - timer >= interval). This is fine, but your Slick2D framework (im not familiar with it) probably provides some sort of Timer class where you can schedule events.

    If the framework doesn't have a Timer class you could find a library that has one, or you could roll something like this with the java Timer class:

    Code:
    class WanderTask extends TimerTask
    {
        private Entity entity;
    
        public WanderTask(Entity entity)
        {
            this.entity = entity;
        }
    
        @Override
        public void run()
        {
            if (entity.isAlive())
                entity.moveRandomDirection();
        }
    }
    and you would schedule your task like:

    Code:
    Timer timer = new Timer();
    timer.schedule(new WanderTask(entity), 0, 1000);
    where timer could be a member of your Script class.

    The longer you'll work on this the more you'll realise how difficult MMOs are to implement properly Especially if you aim for large player counts, seamless worlds and multiple services
    I love how detailed your response is and I really appreciate the perspective. I'll respond in bullet-points:

    • (Database exception-handling): Oh, now that makes much more sense. I haven't really worked with databases' a whole lot so my ideas are very prone to error, although, I still don't necessarily see the problem since, technically, the exception would cause it to return false anyway because we couldn't access the database. In any case, I'll make the change tonight and let you all have a look


    • It's funny that you mention that I'm using the existing emulators to write this when, in-fact, I haven't even looked at them as a reference! Maybe (and unfortunately), the MMO formula is just so stale and obvious these days? Either way, I didn't realize that my code was kind of a "synonym" to existing emulators and I think that's really neat. In any case, they are a great source to learn from and will probably reference them when I start handling more complex network-data.


    • You again reference that I use an old method previously used in MaNGOS when I really just pulled that from Minecraft's initial game-engine loop and slightly modified it to fit my needs ^^ Anyways, Slick2D doesn't not really provide it's own Timer for time-based events but, I tried to use Java's Timer class and I couldn't seem to get it to work properly for my needs. However, I did not try to implement it in the way that you describe so I may go back and give that a whirl because I really like that idea and I appreciate it a lot!


    I've definitely come to realize the level of difficulty involved in adding even base-line multiplayer functionality in but it's been a great learning process, these past 2 months. I look forward to the difficulty the future holds

    Thank you for the very helpful and constructive feedback. It is definitely greatly appreciated and will reflect the future of this project.

  3. #18
    cd ..

    Join Date
    May 2008
    Location
    Europe
    Posts
    2,152
    hates_sundays made my point very well. Maybe I'll fork your project and try to make some small improvements and make a pull request. Keep up the good work. :-)

  4. #19
    Quote Originally Posted by Zaxer View Post
    hates_sundays made my point very well. Maybe I'll fork your project and try to make some small improvements and make a pull request. Keep up the good work. :-)
    You're very welcome to, and thank you, I'll sure try

  5. #20
    To further elaborate on why an exception is not the same as returning false, here's a less contrived example. Let's say you need to check if an account exists before letting players create their own account:

    Code:
    public boolean onCreateAccount(String name)
    {
        try
        {
            if (DB.accountExists(name))
            {
                sendErrorDialog("The account already exists, please use a different name!");
                return false;
            }
            else
            {
                // create the account
                return true;
            }
        }
        catch (SQLException ex)
        {
            sendErrorDialog("The server is unavailable. Try again later.");
            disconnect();
            return false;
        }
    }
    In this case, false means there's no account, so we can create it. True means we need to let the user know they need to choose a different name. A SQL exception means we have a big problem. If we just returned false, we would be trying to create an account when we have no connection to the db. In this case we just drop the connection and tell them to try again later.

    Glad we could help, nice project, good luck!

  6. #21
    Quote Originally Posted by hates_sundays View Post
    To further elaborate on why an exception is not the same as returning false, here's a less contrived example. Let's say you need to check if an account exists before letting players create their own account:

    Code:
    public boolean onCreateAccount(String name)
    {
        try
        {
            if (DB.accountExists(name))
            {
                sendErrorDialog("The account already exists, please use a different name!");
                return false;
            }
            else
            {
                // create the account
                return true;
            }
        }
        catch (SQLException ex)
        {
            sendErrorDialog("The server is unavailable. Try again later.");
            disconnect();
            return false;
        }
    }
    In this case, false means there's no account, so we can create it. True means we need to let the user know they need to choose a different name. A SQL exception means we have a big problem. If we just returned false, we would be trying to create an account when we have no connection to the db. In this case we just drop the connection and tell them to try again later.

    Glad we could help, nice project, good luck!
    Oh! Okay now I see why it was bad practice. Thank you for the example ^^

    EDIT: I appreciate the support and you guys have helped loads. I probably won't attempt to fix that yet as the current structure of the code doesn't allow it but I do plan on changing it in the near future, so that will definitely be something I make more open-ended.

    - - - Updated - - -

    Hey guys!

    Just wanted to post some updated screenshots since WoW-2D has been in-dev for almost 3 months:

    Updated Login Screen:


    GM Tag:


    GM Tag In Chat:


    Basic Server-side Entity AI:


    Entity Names:


    If you have any questions or suggestions for the future, let me know
    Last edited by SolitudeGaming; 11-01-2018 at 11:47 PM.

  7. #22
    cd ..

    Join Date
    May 2008
    Location
    Europe
    Posts
    2,152
    Looks cool, keep up the good work!

  8. #23
    Quote Originally Posted by Zaxer View Post
    Looks cool, keep up the good work!
    Thank you very much! I'll do my best

  9. #24
    This project concept sounds amazing.

  10. #25

    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.
    Quote Originally Posted by id820 View Post
    This project concept sounds amazing.
    I appreciate that, it means a lot!
    Thank you for the support

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •