The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[TUTORIAL] Sphere web status
Author Message
Kanibal
Master
**

Posts: 255
Likes Given: 6
Likes Received: 30 in 28 posts
Joined: Jun 2012
Reputation: 0



Post: #1
[TUTORIAL] Sphere web status
This is a quick and simple tutorial how to make your own sphere web status using Apache, MySQl and PHP.

First of we need is to download software.
1) Apache http server
2) PHP (Thread Safe)
3) MySQL server

Apache:
1) Unpack zip archive to your C:\ drive.
2) Go to C:\Apache24\conf and open httpd.conf
3) Now we need to configure some options here:
Paste
Code:
LoadModule php5_module "C:/php/php7apache2_4.dll"
PHPIniDir "C:/php"
after "LoadModule" section.

Find and uncomment line
Code:
#ServerName www.example.com:80
Change
Code:
www.example.com:80
to
Code:
localhost:80
Find
Code:
DocumentRoot "c:/Apache2/htdocs"
and change it to "c:/web". Than create empty folder web on a C:\ drive

Find block
Code:
<Directory />
    AllowOverride none
    Require all denied
</Directory>
and change it to
Code:
<Directory />
   Options Includes Indexes FollowSymLinks
   AllowOverride All
   Allow from all
</Directory>
Find and comment or remove block starts with <Directory "c:/Apache24/htdocs">

Find block
Code:
<IfModule dir_module>
   DirectoryIndex index.html
</IfModule>
and change it to
Code:
<IfModule dir_module>
   DirectoryIndex index.html index.htm index.shtml index.php
</IfModule>

Now find
Code:
ErrorLog "logs/error.log"
and change it to
Code:
ErrorLog "C:/web/error.log"
Also find
Code:
CustomLog "logs/access.log" common
and change it to
Code:
CustomLog "C:/web/access.log" common

Find block <IfModule mime_module> and add this to the end
Code:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Finally find and uncomment this lines
Code:
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-autoindex.conf
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-manual.conf
Include conf/extra/httpd-default.conf

Now open C:\Apache24\conf\extra\httpd-vhosts.conf, delete all content from it and type there
Code:
NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot "C:/web/localhost/www"
   ServerName localhost
   ErrorLog "C:/web/localhost/error.log"
   CustomLog "C:/web/localhost/access.log" common
</VirtualHost>

Create directories "C:\web\localhost" and "C:\web\localhost\www"

Open command line as administrator type there "C:\Apache24\bin\httpd.exe -k install" and press enter. This will install Apache as service.

PHP:
1) Unpack zip archive to your C:\ drive. It should be C:\php
2) Go to C:\php, find file php.ini-development and rename it to php.ini

Uncomment
Code:
;include_path = ".;c:\php\includes"
Change
Code:
extension_dir = "./"
to
Code:
extension_dir = "C:/php/ext"
Find and uncomment next lines
Code:
extension=php_mbstring.dll
extension=php_mysqli.dll
Find, uncomment and change
Code:
;date.timezone =
to your timezone http://php.net/manual/en/timezones.php

MySQL:
Download and install MySQL server.

Go to installation path and open my.ini file.

In [mysql] section find
Code:
default-character-set
and change it to
Code:
default-character-set=utf8

In [mysqld] section find
Code:
character-set-server
and change it to
Code:
character-set-server=utf8

then find
Code:
default-storage-engine=INNODB
and change it to
Code:
default-storage-engine=MyISAM

also comment this line
Code:
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

PHPMyAdmin
Download "phpMyAdmin-4.6.5.2-all-languages.7z" from https://www.phpmyadmin.net/downloads/
Unpack zip archive to "C:\web\localhost\www" and rename "phpMyAdmin-4.6.5.2-all-languages" to "phpmyadmin".

Then go to "C:\web\localhost\www\phpmyadmin" and create empty file "config.inc.php" with this content
Code:
<?php
  $i = 0;
  $i++;
  $cfg['Servers'][$i]['host'] = 'localhost';
  $cfg['Servers'][$i]['extension'] = 'mysqli';
  $cfg['Servers'][$i]['connect_type'] = 'tcp';
  $cfg['Servers'][$i]['compress'] = false;
  $cfg['Servers'][$i]['auth_type'] = 'config';
  $cfg['Servers'][$i]['user'] = 'root'; // MySQL user
  $cfg['Servers'][$i]['password'] = 'pass'; // MySQL user password
?>

Sphere:
Open Sphere.ini uncomment and change this lines
Code:
// MySql configuration.
MYSQL=1
MySqlHost=127.0.0.1
MySqlUser=root
MySqlPassword=yourpassword
MySqlDatabase=sphere
Find TimerCall=0 and change it to a non zero value

Launch Apache and MySQL service, then go to http://localhost/phpmyadmin, log in with your user/pass and create database "sphere"

Then go to SQL commands and paste this code
Code:
CREATE TABLE IF NOT EXISTS `players_online` (
`uid` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`karma` int(5) NOT NULL,
`fame` int(5) NOT NULL,
`skilltotal` varchar(7) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Now open sphere_serv_triggers.scp, find [FUNCTION f_onserver_timer] (add if not exists) and paste this lines
Code:
if (<db.connected>==0)
  db.connect
  db.query "SET NAMES utf8"
  db.query "SET CHARACTER SET utf8"
  db.query "SET character_set_client='utf8'"
  db.query "SET character_set_connection='utf8'"
  db.query "SET character_set_results='utf8'"
  return 0
endif

db.execute "TRUNCATE TABLE players_online"

serv.allclients f_update_player_status

Create in sme.scp function
Code:
[FUNCTION f_update_player_status]
if (<db.connected>==0)
  db.connect
  db.query "SET NAMES utf8"
  db.query "SET CHARACTER SET utf8"
  db.query "SET character_set_client='utf8'"
  db.query "SET character_set_connection='utf8'"
  db.query "SET character_set_results='utf8'"
  return 0
endif

db.execute "INSERT INTO players_online VALUES(<duid>, '<name>', <karma>, <fame>, '<skilltotal>')"

Now go to "C:\web\localhost\www" and create file status.php with this content
Code:
<?php
$link = mysqli_connect("127.0.0.1", "root", "my_password", "sphere"); //change my_password to your password

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

echo <<<HEADER
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>SPHERE :: STATUS</title>
<style>
#status{
  margin; 0 auto;
  width 50%;
  height: auto;
  border-collapse: collapse;
}

#status th{
  border: 1px solid black;
  font-weight: bold;
}

#status td{
  border: 1px solid black;
}
</style>
</head>

<body>
<table id="status">
<tr><th>Name</th><th>Karma</th><th>Fame</th><th>Skill Total</th></tr>
HEADER;

$result = mysqli_query($link, "SELECT * FROM players_online");
while ($row = mysqli_fetch_assoc($result)) {
  echo '<tr><td>'.$row["name"].'</td><td>'.$row["karma"].'</td><td>'.$row["fame"].'</td><td>'.$row["skilltotal"].'</td></tr>';
}

echo <<<FOOTER
</table>
</body>
</html>
FOOTER;

mysqli_free_result($result);
mysqli_close($link);
?>


Grandmaster Localhost Admin
(This post was last modified: 11-15-2020 10:12 AM by Kanibal.)
12-09-2016 10:09 PM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
Leonidas
Master
**

Posts: 277
Likes Given: 3
Likes Received: 13 in 12 posts
Joined: May 2013
Reputation: 1



Post: #2
RE: [TUTORIAL] Sphere web status
Code:
Parse error: syntax error, unexpected 'while' (T_WHILE) in /usr/www/blah/public/test.php on line 41

Copied your php exactly and I get that error.
12-27-2016 09:05 AM
Find all posts by this user Like Post Quote this message in a reply
Kanibal
Master
**

Posts: 255
Likes Given: 6
Likes Received: 30 in 28 posts
Joined: Jun 2012
Reputation: 0



Post: #3
RE: [TUTORIAL] Sphere web status
(12-27-2016 09:05 AM)Leonidas Wrote:  
Code:
Parse error: syntax error, unexpected 'while' (T_WHILE) in /usr/www/blah/public/test.php on line 41

Copied your php exactly and I get that error.

Thx there is an error in php script. Add ; here
Code:
$result = mysqli_query($link, "SELECT * FROM players_online");  <<<<<<
Updated Tongue

Grandmaster Localhost Admin
12-27-2016 09:24 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
Leonidas
Master
**

Posts: 277
Likes Given: 3
Likes Received: 13 in 12 posts
Joined: May 2013
Reputation: 1



Post: #4
RE: [TUTORIAL] Sphere web status
Lol thanks
12-27-2016 12:02 PM
Find all posts by this user Like Post Quote this message in a reply
Leonidas
Master
**

Posts: 277
Likes Given: 3
Likes Received: 13 in 12 posts
Joined: May 2013
Reputation: 1



Post: #5
RE: [TUTORIAL] Sphere web status
One last question, how would you go about using mysql to display if the server is online or not? Currently I'm just using html to see if it can connect to the server, but when I use that players would be able to just refresh the page and spam the server.
12-27-2016 04:09 PM
Find all posts by this user Like Post Quote this message in a reply
Kanibal
Master
**

Posts: 255
Likes Given: 6
Likes Received: 30 in 28 posts
Joined: Jun 2012
Reputation: 0



Post: #6
RE: [TUTORIAL] Sphere web status
Create somewhere (not in www directory) php script, and launch it every N hours/minutes/seconds from command line
Code:
<?php
$link = mysqli_connect("127.0.0.1", "user", "password", "db_name");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

$fp = @fsockopen("127.0.0.1", 2593, $errno, $errstr, 10);
if (!$fp) {
  $result = mysqli_query($link, "UPDATE `server_status` SET online='Offline'");
}else{
  $result = mysqli_query($link, "UPDATE `server_status` SET online='Online'");
  fclose($fp);
}
mysqli_close($link);
?>

P.S. You can use crontab (see attachment) or use .bat file
Code:
start "C:\PHP\php.exe" -f C:\scripts\sphere_status_update.php

P.P.S. I cant add attachment something is wrong with forum? Confused

Grandmaster Localhost Admin
(This post was last modified: 12-27-2016 11:57 PM by Kanibal.)
12-27-2016 11:04 PM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
Leonidas
Master
**

Posts: 277
Likes Given: 3
Likes Received: 13 in 12 posts
Joined: May 2013
Reputation: 1



Post: #7
RE: [TUTORIAL] Sphere web status
You're awesome man, thank you so much.
12-28-2016 10:01 AM
Find all posts by this user Like Post Quote this message in a reply
anexity
Apprentice
*

Posts: 4
Likes Given: 1
Likes Received: 0 in 0 posts
Joined: Apr 2017
Reputation: 0



Post: #8
RE: [TUTORIAL] Sphere web status
I have also one question: where is this sme.scp file where I should add the [FUNCTION f_update_player_status]?
04-28-2017 08:00 AM
Find all posts by this user Like Post Quote this message in a reply
Kanibal
Master
**

Posts: 255
Likes Given: 6
Likes Received: 30 in 28 posts
Joined: Jun 2012
Reputation: 0



Post: #9
RE: [TUTORIAL] Sphere web status
(04-28-2017 08:00 AM)anexity Wrote:  I have also one question: where is this sme.scp file where I should add the [FUNCTION f_update_player_status]?

Some script that will be loaded at server startup.

Grandmaster Localhost Admin
05-11-2017 07:23 PM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes Kanibal's post
DerParagorn
Apprentice
*

Posts: 3
Likes Given: 0
Likes Received: 0 in 0 posts
Joined: Feb 2015
Reputation: 0



Post: #10
RE: [TUTORIAL] Sphere web status
Thats cool. Thank you!
06-24-2017 07:29 AM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)