Welcome to the RaGEZONE - MMORPG development forums.

[Release] activeUsers class.

This is a discussion on [Release] activeUsers class. within the Showcase and Releases forums, part of the Coders' Paradise category; class_activeUsers.php: Code: <?php class activeUsers { /* Variable holding the logged in members count. */ var $membersCount; /* Variable holding ...

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Hi, I'm Omar!
    Rank
    WTF? Overkill!
    Join Date
    Jan 2011
    Location
    Here
    Posts
    1,790
    Liked
    726

    [Release] activeUsers class.

    Click
    class_activeUsers.php:
    Code:
    <?php
    class activeUsers
    {
    	/* Variable holding the logged in members count. */
    	var $membersCount;
    	
    	/* Variable holding the guests count. */
    	var $guestsCount;
    	
    	/* Variable holding the total count. */
    	var $totalCount;
    	
    	public function __construct()
    	{
    		$q = mssql_query("DELETE FROM activeUsers WHERE Time + ".((5 * 60) * 1000)." <= ".time()."");
    		$q = mssql_query("SELECT IP, Time FROM activeUsers WHERE IP = '".$_SERVER['REMOTE_ADDR']."'");
    		
    		if(mssql_num_rows($q) >= 1)
    			$q = mssql_query("UPDATE activeUsers SET UserID = '".((isLoggedIn()) ? $_SESSION['user'] : "")."', Time = ".time()." WHERE IP = '".$_SERVER['REMOTE_ADDR']."'");
    		else
    			$q = mssql_query("INSERT INTO activeUsers (UserID, Time, IP) VALUES ('".((isLoggedIn()) ? $_SESSION['user'] : "")."', ".time().", '".$_SERVER['REMOTE_ADDR']."')");
    			
    		$this->initCounts();
    	}
    	
    	public function initCounts()
    	{
    		$q = mssql_query("SELECT Time FROM activeUsers WHERE UserID != ''");
    		$q2 = mssql_query("SELECT Time FROM activeUsers WHERE UserID = ''");
    
    		$this->membersCount = mssql_num_rows($q);
    		$this->guestsCount = mssql_num_rows($q2);
    		$this->totalCount = $this->membersCount + $this->guestsCount;
    	}
    }
    ?>
    Usage:
    Code:
    <?php
    include("class_activeUsers.php");
    
    mssql_connect("OMAR-PC\SQLEXPRESS", "sa", "password") or die("Errors while attempting to connect to MSSQL.");
    mssql_select_db("GunzDB");
    
    function isLoggedIn()
    {
    	return ((isset($_SESSION['user'])) ? true : false);
    }
    
    $activeU = new activeUsers();
    $activeU->initCounts();
    
    echo "Online Total: $activeU->totalCount. <br />Members Online: $activeU->membersCount<br />Guests Online: $activeU->guestsCount";
    ?>
    Code:
    USE [GunzDB]
    GO
    /****** Object:  Table [dbo].[activeUsers]    Script Date: 06/22/2012 18:50:30 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[activeUsers](
    	[ID] [int] IDENTITY(1,1) NOT NULL,
    	[UserID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    	[Time] [bigint] NOT NULL,
    	[IP] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
    ) ON [PRIMARY]
    
    GO
    SET ANSI_PADDING OFF
    Last edited by Vusion; 28-03-13 at 05:02 PM.

  2. #2
    Account Upgraded | Title Enabled!
    Rank
    Member +
    Join Date
    Apr 2012
    Location
    Egypt/RageZone
    Posts
    228
    Liked
    9

    Re: [Release] activeUsers class.

    Quote Originally Posted by Vusion View Post
    Had written this class a while ago, and when I was posting the thread, I realized how terrible the class was written. So, I gave it a rewrite and here it is.

    Code:
    <?php
    /*--------------------------------------------
    * @author: AUTHOR
    * @framework-author: Omar Wael
    *---------------------------------------------
    ********************USAGE*********************
    *$con = mssql_connect("OMAR-PC\SQLEXPRESS", "sa", "mazemania1") or die("Errors while attempting to connect to MSSQL.");
    *mssql_select_db("GunzDB", $con);
    *
    *function isLoggedIn()
    *{
    *	return ((isset($_SESSION['user'])) ? true : false);
    *}
    *
    *$activeU->initCounts();
    *
    *echo "Online Total: $activeU->totalCount. <br />Members Online: $activeU->membersCount<br />Guests Online: $activeU->guestsCount";
    * --------------------------------------------*/
    class activeUsers
    {
    	/* Variable holding the logged in members count. */
    	var $membersCount;
    	
    	/* Variable holding the guests count. */
    	var $guestsCount;
    	
    	/* Variable holding the total count. */
    	var $totalCount;
    	
    	public function __construct()
    	{
    		$q = mssql_query("DELETE FROM activeUsers WHERE Time + ".((5 * 60) * 1000)." <= ".time()."");
    		$q = mssql_query("SELECT IP, Time FROM activeUsers WHERE IP = '".$_SERVER['REMOTE_ADDR']."'");
    		
    		if(mssql_num_rows($q) >= 1)
    			$q = mssql_query("UPDATE activeUsers SET UserID = '".((isLoggedIn()) ? $_SESSION['user'] : "")."', Time = ".time()." WHERE IP = '".$_SERVER['REMOTE_ADDR']."'");
    		else
    			$q = mssql_query("INSERT INTO activeUsers (UserID, Time, IP) VALUES ('".((isLoggedIn()) ? $_SESSION['user'] : "")."', ".time().", '".$_SERVER['REMOTE_ADDR']."')");
    	}
    	
    	public function initCounts()
    	{
    		$q = mssql_query("SELECT Time FROM activeUsers WHERE UserID != ''");
    		$q2 = mssql_query("SELECT Time FROM activeUsers WHERE UserID = ''");
    
    		$this->membersCount = mssql_num_rows($q);
    		$this->guestsCount = mssql_num_rows($q2);
    		$this->totalCount = $this->membersCount + $this->guestsCount;
    	}
    }
    
    $activeU = new activeUsers();
    ?>
    Good Work Omar

  3. #3
    Admnistrator
    Rank
    Member +
    Join Date
    Aug 2010
    Posts
    640
    Liked
    197

    Re: [Release] activeUsers class.

    very nice
    C/C++/PHP,OOP/MySQL/Java/JS/HTML/HTML5/CSS/AJAX

  4. #4
    the fun stops here
    Rank
    Gamma
    Join Date
    Nov 2009
    Posts
    3,032
    Liked
    1170

    Re: [Release] activeUsers class.

    >mssql
    what the fuck are you doing

    eat some spectrum

  5. #5
    Hi, I'm Omar!
    Rank
    WTF? Overkill!
    Join Date
    Jan 2011
    Location
    Here
    Posts
    1,790
    Liked
    726

    Re: [Release] activeUsers class.

    Quote Originally Posted by rice View Post
    >mssql
    what the fuck are you doing

    Happens that the game I develop uses MSSQL.

  6. #6
    the fun stops here
    Rank
    Gamma
    Join Date
    Nov 2009
    Posts
    3,032
    Liked
    1170

    Re: [Release] activeUsers class.

    Quote Originally Posted by Vusion View Post
    Happens that the game I develop uses MSSQL.
    but WHY would you develop a game that uses that pile of shit known as MSSQL?
    you should change that shit out ASAP

    eat some spectrum

  7. #7
    Hi, I'm Omar!
    Rank
    WTF? Overkill!
    Join Date
    Jan 2011
    Location
    Here
    Posts
    1,790
    Liked
    726

    Re: [Release] activeUsers class.

    Quote Originally Posted by rice View Post
    but WHY would you develop a game that uses that pile of shit known as MSSQL?
    you should change that shit out ASAP
    Changing it from MSSQL to MySQL is pretty easy, you know.
    I'm releasing the class in a section full of coders, I'm pretty sure whoever decides to use this will be able to change it.
    Last edited by Vusion; 15-01-13 at 03:14 PM.

  8. #8
    Pee Aitch Pee
    Rank
    Subscriber
    Join Date
    Mar 2011
    Location
    The Netherlands
    Posts
    573
    Liked
    277

    Re: [Release] activeUsers class.

    Quote Originally Posted by rice View Post
    but WHY would you develop a game that uses that pile of shit known as MSSQL?
    you should change that shit out ASAP
    Give me some reasons why MSSQL is a pile of shit.

    OT:
    You could add $this->initCounts in the constructor so it saves you one line of code. And use { } for the if/else structure.
    When you work with big ass functions and if/else statements then it could be a pain in the ass to debug or edit it.

  9. #9
    the fun stops here
    Rank
    Gamma
    Join Date
    Nov 2009
    Posts
    3,032
    Liked
    1170

    Re: [Release] activeUsers class.

    store an unsigned int for me
    oh wait

    eat some spectrum

  10. #10
    Monster
    Rank
    Member +
    Join Date
    Apr 2009
    Posts
    1,449
    Liked
    463

    Re: [Release] activeUsers class.

    Quote Originally Posted by rice View Post
    store an unsigned int for me
    oh wait
    Store it as an int then cast it as an unsigned int in your code, genius. MySQL MUCH worse than MSSQL in terms of security(look at the huge securtiy flaws that have been published in last few months) and lacking in terms of administration features.

    I honestly can't think of any reason why you would think MSSQL is a pile of shit other than because you can't set it up(you can consider yourself mentally handicapped if this is the case). Other than that, you might be one of those cool kids that thinks everything Microsoft makes is crap when in reality, their software is usually much higher quality than open source alternatives.

  11. #11
    Member
    Rank
    Member
    Join Date
    Jul 2008
    Location
    Finland
    Posts
    55
    Liked
    2

    Re: [Release] activeUsers class.

    Quote Originally Posted by mootie View Post
    Store it as an int then cast it as an unsigned int in your code, genius. MySQL MUCH worse than MSSQL in terms of security(look at the huge securtiy flaws that have been published in last few months) and lacking in terms of administration features.

    I honestly can't think of any reason why you would think MSSQL is a pile of shit other than because you can't set it up(you can consider yourself mentally handicapped if this is the case). Other than that, you might be one of those cool kids that thinks everything Microsoft makes is crap when in reality, their software is usually much higher quality than open source alternatives.
    Yes, but it doesn't run on Linux. If you dislike MySQL you'd be better of with something like PostgreSQL.

    Btw, use PDO. PHP: PDO - Manual
    Last edited by Vineyard; 24-06-12 at 05:12 PM. Reason: whoops quote

  12. #12
    Ron
    ':,,:'
    Rank
    Subscriber
    Join Date
    Apr 2005
    Location
    Dallas, TX
    Posts
    8,234
    Liked
    1860

    Re: [Release] activeUsers class.

    Only downfall is MSSQL is not free and only runs on Windows. Other than that, its a solid database solution used by hundreds of gaming development companies.

    MySQL is more practical for web development solutions but if you have something like a gameserver using a database and all you need to do is push and pull a small about of information, MSSQL is not a bad option at all.

    I wish people in this section would stop blowing shit out their ass when it comes to certain topics. The only reason most people say MySQL FTW OMFG is because they learned to say that. The reason MySQL is so popular is because its free. FREE. Do I need to say it again? FREE

    If MSSQL was so shitty, why does Microsoft still maintain updated versions and sell licenses to the companies who run your favorite MMOs? Something any developer needs to know is practical use. You don't use MySQL for a high load game server or database application and you don't use MSSQL for a low load web server. More with practical use, there are also far better options than MySQL and MSSQL depending on your situation and what you need. Another reason people still use MySQL is because web hosting companies offer nothing else on shared hosts.

    Also, you're only talking about the basics of MSSQL here. MSSQL expands far beyond simple tables and queries, something someone who has never used it extensively wouldn't understand.

    Please, no more mindless MSSQL vs MySQL debates. Oh, and STFU rice.

  13. #13
    Member
    Rank
    Member
    Join Date
    Jul 2008
    Location
    Finland
    Posts
    55
    Liked
    2

    Re: [Release] activeUsers class.

    Quote Originally Posted by Ron View Post
    Only downfall is MSSQL is not free and only runs on Windows. Other than that, its a solid database solution used by hundreds of gaming development companies.

    MySQL is more practical for web development solutions but if you have something like a gameserver using a database and all you need to do is push and pull a small about of information, MSSQL is not a bad option at all.

    I wish people in this section would stop blowing shit out their ass when it comes to certain topics. The only reason most people say MySQL FTW OMFG is because they learned to say that. The reason MySQL is so popular is because its free. FREE. Do I need to say it again? FREE

    If MSSQL was so shitty, why does Microsoft still maintain updated versions and sell licenses to the companies who run your favorite MMOs? Something any developer needs to know is practical use. You don't use MySQL for a high load game server or database application and you don't use MSSQL for a low load web server. More with practical use, there are also far better options than MySQL and MSSQL depending on your situation and what you need. Another reason people still use MySQL is because web hosting companies offer nothing else on shared hosts.

    Also, you're only talking about the basics of MSSQL here. MSSQL expands far beyond simple tables and queries, something someone who has never used it extensively wouldn't understand.

    Please, no more mindless MSSQL vs MySQL debates. Oh, and STFU rice.
    Chill. There's commercial support for MySQL, too. What's wrong with using it for a high load game server, or MSSQL for low load web backends, respectively? Don't you realise that MySQL expands far beyond simple tables and queries as much as MSSQL does?

    If you can't manage the anger, maybe you should just consider browsing away from debates like these. No-one forces you to read all the "mindless" jabbering in here. Next time try to bring in some facts and not some retarded nonsense how licensing directly correlates with the quality of the product.

  14. #14
    Ginger by design.
    Rank
    Alpha Member
    Join Date
    Feb 2007
    Posts
    2,796
    Liked
    708

    Re: [Release] activeUsers class.

    Quote Originally Posted by Vineyard View Post
    Chill. There's commercial support for MySQL, too. What's wrong with using it for a high load game server, or MSSQL for low load web backends, respectively? Don't you realise that MySQL expands far beyond simple tables and queries as much as MSSQL does?

    If you can't manage the anger, maybe you should just consider browsing away from debates like these. No-one forces you to read all the "mindless" jabbering in here. Next time try to bring in some facts and not some retarded nonsense how licensing directly correlates with the quality of the product.
    The query optimizer is much better in MSSQL as are some of the underlying algorithms for storing and retrieving data. It also has significantly better tuning and performance analysis tools and built-in functions. MySQL only recently added a few of these, but still lacks most of them. Real DBA pros can take far more advantage of MSSQL for that very reason.

    MySQL still has commercial use at large and small scale by pretty popular companies. For instance, craigslist is built on MySQL, but they're currently working on transitioning away from it, at the very least for their archiving system (which can take months to re-index in MySQL right now).
    jmerlin.MSN = "jmerlin[at]jmerlin[dot]net";

    var c = 1; c++ < c; // true

  15. #15
    Monster
    Rank
    Member +
    Join Date
    Apr 2009
    Posts
    1,449
    Liked
    463

    Re: [Release] activeUsers class.

    IMO if you or your publishing company can't afford Windows+MSSQL STD. easily, then you shouldn't be developing an MMORPG. Private servers should be able to afford both as well if they have any hopes of making a good player environment. I see where you're coming from, cheaper is better, but for any big game you'll need the commercial license of MySQL anyways. The fee is relatively small considering you would most likely only deploy one physical machine with MSSQL per "realm". Also, MSSQL can communicate easily with linux machines. In fact, my setup atm uses a linux webserver with a MSSQL database.

 

 
Page 1 of 2 12 LastLast

Posting Permissions

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