• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[Release] activeUsers class.

Hi, I'm Omar!
Loyal Member
Joined
Jan 6, 2011
Messages
1,345
Reaction score
646
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:
Joined
Apr 13, 2012
Messages
536
Reaction score
32
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
 
Custom Title Activated
Loyal Member
Joined
Nov 27, 2009
Messages
1,905
Reaction score
948
>mssql
what the duck are you doing
 
Custom Title Activated
Loyal Member
Joined
Nov 27, 2009
Messages
1,905
Reaction score
948
Happens that the game I develop uses MSSQL.
but WHY would you develop a game that uses that pile of poop known as MSSQL?
you should change that poop out ASAP
 
Hi, I'm Omar!
Loyal Member
Joined
Jan 6, 2011
Messages
1,345
Reaction score
646
but WHY would you develop a game that uses that pile of poop known as MSSQL?
you should change that poop 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:
Pee Aitch Pee
Joined
Mar 30, 2011
Messages
630
Reaction score
422
but WHY would you develop a game that uses that pile of poop known as MSSQL?
you should change that poop out ASAP

Give me some reasons why MSSQL is a pile of poop.

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 butt functions and if/else statements then it could be a pain in the butt to debug or edit it.
 
Custom Title Activated
Loyal Member
Joined
Nov 27, 2009
Messages
1,905
Reaction score
948
store an unsigned int for me
oh wait
 
Not working on UnitedFlyf
Loyal Member
Joined
Apr 21, 2009
Messages
1,385
Reaction score
934
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 poop 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.
 
Newbie Spellweaver
Joined
Jul 2, 2008
Messages
49
Reaction score
2
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 poop 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.
 
Last edited:
Joined
Apr 28, 2005
Messages
6,953
Reaction score
2,420
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 poop out their butt 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 crappy, 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.
 
Newbie Spellweaver
Joined
Jul 2, 2008
Messages
49
Reaction score
2
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 poop out their butt 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 crappy, 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.
 
Ginger by design.
Loyal Member
Joined
Feb 15, 2007
Messages
2,340
Reaction score
653
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).
 
Not working on UnitedFlyf
Loyal Member
Joined
Apr 21, 2009
Messages
1,385
Reaction score
934
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.
 
Newbie Spellweaver
Joined
Jul 2, 2008
Messages
49
Reaction score
2
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.

Fair enough. MSSQL may offer more optimisation opportunities in the long run, but I'll still have to disagree with having to "be able to afford both as well if they have any hopes of making a good player environment"... Premature optimisation is not very wise and even less when you're planning on spending hard money on multiple windows boxes + MSSQL licenses (in case you're being really serious, you'll need replication, too).

For all intents and purposes, when datasets are huge and performance is critical, go for it. But an average company with even moderate high traffic will probably find MySQL's performance features more than satisfying. That also applies to whatever private server you're developing, the bottleneck ought to be somewhere else than in the database. But when you approach Craigslist's or Twitter's traffic, you can (and should) start thinking about alternative, and in this case more expensive options.

And I'm positive that "cheaper is better" applies almost everywhere. Customers don't simply buy Microsoft's databases when they could have a serious competitor (for example, Postgres) for free, they buy it solely for support and brand recognition. They assume that Microsoft is a stable provider that can give them support if needed.
 
Joined
Apr 28, 2005
Messages
6,953
Reaction score
2,420
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 anger part of that post was mainly directed at rice, but if you keep on it can be directed at you too.


Do you think companies would really pay licensing fees for MSSQL when MySQL is better? If MySQL is free and better, why are they paying for MSSQL? Its not nonsense, it backs up my point. Companies pay for the better product for their situation. Why would they pay for something that sucks?


Most of the people on this forum will never need to understand the differences between database software, however it is important you at least make yourself aware of them before calling one crappy and pointless over another.
 
Back
Top