Register for your free account! | Forgot your password?

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

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

Advertisement



I need Help with my website

Discussion on I need Help with my website within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: May 2010
Posts: 6
Received Thanks: 0
I need Help with my website

How to add status containing players online coded in PHP ?
Avenger100 is offline  
Old 09/23/2012, 14:26   #2
 
marlyandedsel's Avatar
 
elite*gold: 0
Join Date: Aug 2010
Posts: 343
Received Thanks: 21
PHP Code:
<?php
require_once ('config.php');
            echo 
'<font style="color: #808080" size="2">SERVER:</font> ';
            
            
$fp = @fsockopen($serveraddress$serverport$errno$errstr1);
            if (!
$fp) {
                echo 
'<font style="color: red" size="2"><b>MAINT.</b></font><br />';
            }
            else
            {
                echo 
'<font style="color: YellowGreen" size="2"><b>ONLINE</b></font><br />';
                
fclose($fp);
            }             
    
$rank mysql_query("SELECT Online FROM Online WHERE Online > 0 || Online = 0");
    
$row mysql_fetch_array($rank);    
    
$tot $row['Online'];    
echo 
"<font color='#808080' size='2'><b>PLAYER:</font><font color='YellowGreen' size='2'>$tot</font>";

?>
marlyandedsel is offline  
Thanks
1 User
Old 09/23/2012, 22:25   #3
 
InstantAssassination's Avatar
 
elite*gold: 0
Join Date: Sep 2012
Posts: 33
Received Thanks: 6
Quote:
Originally Posted by marlyandedsel View Post
PHP Code:
<?php
require_once ('config.php');
            echo 
'<font style="color: #808080" size="2">SERVER:</font> ';
            
            
$fp = @fsockopen($serveraddress$serverport$errno$errstr1);
            if (!
$fp) {
                echo 
'<font style="color: red" size="2"><b>MAINT.</b></font><br />';
            }
            else
            {
                echo 
'<font style="color: YellowGreen" size="2"><b>ONLINE</b></font><br />';
                
fclose($fp);
            }             
    
$rank mysql_query("SELECT Online FROM Online WHERE Online > 0 || Online = 0");
    
$row mysql_fetch_array($rank);    
    
$tot $row['Online'];    
echo 
"<font color='#808080' size='2'><b>PLAYER:</font><font color='YellowGreen' size='2'>$tot</font>";

?>
Or:

echo '<font style="color: lime"><b>Online</b></font><br />';
}
InstantAssassination is offline  
Old 09/24/2012, 12:24   #4
 
Silent-Death's Avatar
 
elite*gold: 0
Join Date: Jan 2006
Posts: 1,055
Received Thanks: 296
Quote:
Originally Posted by marlyandedsel View Post
PHP Code:
echo "<font color='#808080' size='2'><b>PLAYER:</font><font color='YellowGreen' size='2'>$tot</font>"
one little thing in this code, other then that the process seems about right.
separate php code from html code in echo using quotation marks and dots. same principle as in c# using the plus sign, but in php it's a dot:
PHP Code:
echo "<font color='#808080' size='2'><b>PLAYER:</font><font color='YellowGreen' size='2'>" $tot "</font>"
i believe it would work without doing this, but it's good practice.
Silent-Death is offline  
Thanks
1 User
Old 09/24/2012, 12:44   #5


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
That's actually one of the worst ways of doing it as if the server is down you have to wait, and wait, and wait for the script to time out before the page loads.
Korvacs is offline  
Thanks
1 User
Old 09/24/2012, 12:47   #6
 
Silent-Death's Avatar
 
elite*gold: 0
Join Date: Jan 2006
Posts: 1,055
Received Thanks: 296
also that
PHP Code:
$rank mysql_query("SELECT Online FROM Online WHERE Online > 0 || Online = 0"); 
seems a bit dodgy.. don't get me wrong, it would work if you would have a field named online in the table online, but i would guess you would want to get the char names out of that table. this would also change your where clause field name, and not sure why you would want to take out empty field or have empty fields in there for that matter. the if (!$fp) already checks for that so i would just remove the || Online = 0 .

Quote:
Originally Posted by Korvacs View Post
That's actually one of the worst ways of doing it as if the website is down you have to wait, and wait, and wait for the script to time out before the page loads.
" if the website is down" sorry, do you mean the database?
anyway.. edit max_execution_time value in the php.ini or temper with set_time_limit()
also if the database is down you check that on connection
Silent-Death is offline  
Old 09/24/2012, 13:05   #7


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Sorry, definitely meant server, im at work! And even when editing max_execution_time you dont solve this problem as then it cuts the entire script short, not just the attempt to connects to the remote port.

There is a far superior solution to this problem.
Korvacs is offline  
Old 09/24/2012, 13:14   #8
 
Silent-Death's Avatar
 
elite*gold: 0
Join Date: Jan 2006
Posts: 1,055
Received Thanks: 296
Quote:
Originally Posted by Korvacs View Post
And even when editing max_execution_time you dont solve this problem as then it cuts the entire script short
i agree. but again, a simple mysql connection check would do the trick:

PHP Code:
$connmysql_connect('localhost''mysql_user''mysql_password');
if (!
$conn) {
    die(
'sql is down: ' mysql_error()); // edit if you don't want to post the mysql error out.
}
echo 
'connection established'// edit out or whatnot. 

// manipulate your data here.

mysql_close($conn); 
Silent-Death is offline  
Old 09/24/2012, 13:17   #9


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
And again you dont solve the problem, you still rely on the fact that there is a timeout so this will never be instant.
Korvacs is offline  
Old 09/24/2012, 13:33   #10
 
Silent-Death's Avatar
 
elite*gold: 0
Join Date: Jan 2006
Posts: 1,055
Received Thanks: 296
Quote:
Originally Posted by Korvacs View Post
And again you dont solve the problem, you still rely on the fact that there is a timeout so this will never be instant.
well you could lower the mysql connection time or optimize the MySQL response time (disable MySQL indexes. disable DNS hostname lookup, activate query cache), but you still have to get a response from the database (and time for that is requires) in order to proceed with data in your page.

of course there are many advanced techniques you can use on massive amounts of data, but would this really be required on a co pserver website?
Silent-Death is offline  
Old 09/24/2012, 13:37   #11


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Your looking at this from the wrong direction, you believe the website should check with the game server to see if its online.... this isnt correct.

The website should be told that the server is online...by the server. Once you look at it from that perspective then the solution is obvious and theres suddenly no issues with timeouts.
Korvacs is offline  
Old 09/24/2012, 13:49   #12
 
Silent-Death's Avatar
 
elite*gold: 0
Join Date: Jan 2006
Posts: 1,055
Received Thanks: 296
ok well assuming you have that info stored in a variable already since you need to tell people the status of your server that is easy to implement.

PHP Code:
$sv_status True// server status variable (for example only)
if ($sv_status == TRUE) {
    
// data goes here.

Silent-Death is offline  
Old 09/24/2012, 14:05   #13


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
The best solution is to have the game server update a database stored on the webserver, with a timestamp of when it last wrote, your page then checks the timestamp and if the timestamp is more than say...2 - 5 minutes out of date then you know the server is down. All online player counts and similar statistics are also stored on the webservers database.
Korvacs is offline  
Old 09/24/2012, 14:57   #14
 
Silent-Death's Avatar
 
elite*gold: 0
Join Date: Jan 2006
Posts: 1,055
Received Thanks: 296
Quote:
Originally Posted by Korvacs View Post
The best solution is to have the game server update a database stored on the webserver, with a timestamp of when it last wrote, your page then checks the timestamp and if the timestamp is more than say...2 - 5 minutes out of date then you know the server is down. All online player counts and similar statistics are also stored on the webservers database.
wouldn't that defeat the purpose of going around the time it takes you to connect to the database and check a table from the webpage?

maybe it would be better to talk directly to the server:
PHP Code:
  $address=$_SERVER['REMOTE_ADDR'];
  
  if (isset(
$_REQUEST['port']) and
      (!
strlen($_REQUEST['port'])==0))
    
$port=$_REQUEST['port'];
  else
    unset(
$port);
    
  if (isset(
$port) and
      (
$socket=socket_create(AF_INETSOCK_STREAMSOL_TCP)) and
      (
socket_connect($socket$address$port)))
    {
      
$text="Connection ok on IP $address, port $port";
      
socket_close($socket);
    }
  else
    
$text="Unable to connect<pre>".socket_strerror(socket_last_error())."</pre>";
    
  echo 
"<html><head></head><body>".
       
$text.
       
"</body></html>"
^ make sure you enable php_sockets.dll extension in php.ini

ofc you can alter this so instead of $text you have a bool and take it from there.
Silent-Death is offline  
Old 09/24/2012, 15:13   #15


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
No it wouldnt defeat the purpose, what your trying to avoid is a timeout, that hangs up the page making people unable to use your website, what your want is for people to be able to use your website no matter what the circumstance. The system i describe works no matter what the circumstance without any timeouts. The website being out of date by 60 seconds isnt a concern lol.
Korvacs is offline  
Reply




All times are GMT +1. The time now is 22:52.


Powered by vBulletin®
Copyright ©2000 - 2025, 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 ©2025 elitepvpers All Rights Reserved.