Skip to content

Commit

Permalink
Move session library inside repository
Browse files Browse the repository at this point in the history
For too long, ntbb-session and ntbb-database have been maintained
outside of this repo, but no longer! All these files are now part of the
repository, making it significantly more self-contained.

If I had to say why it took this long, I think it was mostly inertia. It
was easier leaving them where they were than having to audit them for
private keys in the wrong places, etc.

I'm starting to think of PS more as sim first, website secondary than
the other way around, now. Especially now that we don't have a forum,
the website itself isn't really important... Maybe one day I'll get rid
of the landing page and make the sim itself the first thing you see when
you hit pokemonshowdown.com... but today is not that day!

The repo is still not "batteries-included" since I am not going to teach
anyone how to set up PHP and MySQL or even get the config files working.
But for anyone who wanted their own client, well, it gets a lot easier
to do now.
  • Loading branch information
Zarel committed Oct 20, 2016
1 parent 1c18bf0 commit 82e7a91
Show file tree
Hide file tree
Showing 9 changed files with 860 additions and 9 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,16 @@ Everything else can be tested, though.
Warning
------------------------------------------------------------------------

This repository is not "batteries included". It does NOT include everything
necessary to run a full Pokémon Showdown client.

In particular, it doesn't include a login/authentication server, nor does it
include the database abstraction library used by the ladder library (although
it's similar enough to `mysqli` that you can use that with minimal changes).
This repository is not "batteries included". It does NOT include instructions
to run a full Pokémon Showdown client, and we will not provide them. Please
do not ask for help on this; you will be turned away.

It also doesn't include several resource files (namely, the `/audio/` and
`/sprites/` directories) for size reasons.

In other words, this repository is incomplete and NOT intended for people
who wish to serve their own Pokémon Showdown client (you can, but it'll
require you to rewrite some things). Rather, it's intended for people who
require you figure it out yourself). Rather, it's intended for people who
wish to contribute and submit pull requests to Pokémon Showdown's client.

License
Expand Down
2 changes: 1 addition & 1 deletion action.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
// header("X-Debug: " . @$_SERVER['HTTP_REFERER']);

include_once '../pokemonshowdown.com/lib/ntbb-session.lib.php';
include_once 'lib/ntbb-session.lib.php';
include_once '../pokemonshowdown.com/config/servers.inc.php';
include_once 'lib/dispatcher.lib.php';

Expand Down
46 changes: 46 additions & 0 deletions config/config-example.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

mb_internal_encoding('UTF-8');

$psconfig = [

'sysops' => ['zarel'],

// password and SID hashing settings

'password_cost' => 12,
'sid_length' => 15,
'sid_cost' => 4,

// database

'server' => 'localhost',
'username' => '',
'password' => '',
'database' => '',
'prefix' => 'ps_',
'charset' => 'utf8',

// CORS requests

'cors' => [
'/^http:\/\/smogon\.com$/' => 'smogon.com_',
'/^http:\/\/www\.smogon\.com$/' => 'www.smogon.com_',
'/^http:\/\/logs\.psim\.us$/' => 'logs.psim.us_',
'/^http:\/\/logs\.psim\.us:8080$/' => 'logs.psim.us_',
'/^http:\/\/[a-z0-9]+\.psim\.us$/' => '',
'/^http:\/\/play\.pokemonshowdown\.com$/' => '',
],

// key signing for SSO

'privatekeys' => [

1 => '-----BEGIN PRIVATE KEY-----
[insert RSA private key]
-----END PRIVATE KEY-----
',

]

];
11 changes: 11 additions & 0 deletions config/servers-example.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$PokemonServers = array (
'showdown' =>
array (
'name' => 'Smogon University',
'id' => 'showdown',
'server' => 'sim.psim.us',
'port' => 8000,
),
);
65 changes: 65 additions & 0 deletions lib/ntbb-database.lib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

include_once dirname(__FILE__).'/../config/config.inc.php';

class NTBBDatabase {
var $db = null;

var $server = null;
var $username = null;
var $password = null;
var $database = null;
var $prefix = null;
var $charset = null;
//var $queries = array();

function NTBBDatabase($server, $username, $password, $database, $prefix, $charset) {
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->database = $database;
$this->prefix = $prefix;
$this->charset = $charset;
}

function connect() {
if (!$this->db) {
$this->db = mysqli_connect($this->server, $this->username, $this->password, $this->database);
if ($this->charset) {
mysqli_set_charset($this->db, $this->charset);
}
}
}
function query($query) {
$this->connect();
//$this->queries[] = $query;
return mysqli_query($this->db, $query);
}
function fetch_assoc($resource) {
return mysqli_fetch_assoc($resource);
}
function fetch($resource) {
return mysqli_fetch_assoc($resource);
}
function escape($data) {
$this->connect();
return mysqli_real_escape_string($this->db, $data);
}
function error() {
if ($this->db) {
return mysqli_error($this->db);
}
}
function insert_id() {
if ($this->db) {
return mysqli_insert_id($this->db);
}
}
}

$psdb = new NTBBDatabase($psconfig['server'],
$psconfig['username'],
$psconfig['password'],
$psconfig['database'],
$psconfig['prefix'],
$psconfig['charset']);
2 changes: 1 addition & 1 deletion lib/ntbb-ladder.lib.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// An implementation of the Glicko2 rating system.

@include_once dirname(__FILE__).'/../../pokemonshowdown.com/lib/ntbb-database.lib.php';
@include_once dirname(__FILE__).'/ntbb-database.lib.php';

// connect to the ladder database (if we aren't already connected)
if (empty($ladderdb)) {
Expand Down
Loading

0 comments on commit 82e7a91

Please sign in to comment.