[Release] activeUsers class.
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
Re: [Release] activeUsers class.
Quote:
Originally Posted by
Vusion
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
Re: [Release] activeUsers class.
Re: [Release] activeUsers class.
>mssql
what the fuck are you doing
Re: [Release] activeUsers class.
Quote:
Originally Posted by
rice
>mssql
what the fuck are you doing
Happens that the game I develop uses MSSQL.
Re: [Release] activeUsers class.
Quote:
Originally Posted by
Vusion
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
Re: [Release] activeUsers class.
Quote:
Originally Posted by
rice
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.
Re: [Release] activeUsers class.
Quote:
Originally Posted by
rice
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.
Re: [Release] activeUsers class.
store an unsigned int for me
oh wait
Re: [Release] activeUsers class.
Quote:
Originally Posted by
rice
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.
Re: [Release] activeUsers class.
Quote:
Originally Posted by
mootie
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
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.
Re: [Release] activeUsers class.
Quote:
Originally Posted by
Ron
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.
Re: [Release] activeUsers class.
Quote:
Originally Posted by
Vineyard
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).
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.