Init
This commit is contained in:
14
Samples/PHPDirectoryServer2/CMakeLists.txt
Normal file
14
Samples/PHPDirectoryServer2/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
#
|
||||
# This file was taken from RakNet 4.082 without any modifications.
|
||||
# Please see licenses/RakNet license.txt for the underlying license and related copyright.
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
GETCURRENTFOLDER()
|
||||
STANDARDSUBPROJECT(${current_folder})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
81
Samples/PHPDirectoryServer2/DirectoryServer.php
Normal file
81
Samples/PHPDirectoryServer2/DirectoryServer.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
// This file was taken from RakNet 4.082 without any modifications.
|
||||
// Please see licenses/RakNet license.txt for the underlying license and related copyright.
|
||||
|
||||
//These vars may be changed to fit your needs.
|
||||
//User executing the script must have write access to the file directory.
|
||||
define("PASSWORD_FILE", "pw");
|
||||
define("RECORD_FILE", "RecordFile.data.php");
|
||||
define("TIMEOUT", 60);
|
||||
|
||||
include("lib/PasswordManager.class.php");
|
||||
include("lib/RecordManager.class.php");
|
||||
|
||||
$pm = new PasswordManager();
|
||||
|
||||
//Check if password exists. If it doesn't exist create the password form for the user
|
||||
//to input their passwords.
|
||||
if(!file_exists(PASSWORD_FILE)){
|
||||
$error = "";
|
||||
$message = "";
|
||||
|
||||
if(!empty($_POST)){
|
||||
$error = $pm->validatePasswords($_POST);
|
||||
if(empty($error)){
|
||||
$pm->savePasswords($_POST);
|
||||
header("Location: DirectoryServer.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
echo $pm->generateCss();
|
||||
echo $error;
|
||||
echo $pm->generatePasswordForm();
|
||||
}
|
||||
else{
|
||||
//If the password file exists use controller logic
|
||||
$rm = new RecordManager();
|
||||
$passwords = $pm->getPasswords();
|
||||
$rm->expireRecords();
|
||||
|
||||
//If upload mode and uploadPassword matches
|
||||
if(!empty($_GET["query"]) && $_GET["query"] == "upload"){
|
||||
if(isset($_GET["uploadPassword"]) && md5($_GET["uploadPassword"]) == $passwords["uploadPassword"]){
|
||||
//Use the following code to read post body. Not regular form posts which would be accessed with $_POST
|
||||
$postText = trim(file_get_contents('php://input'));
|
||||
|
||||
$output = $rm->uploadRecords($postText);
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
//If download mode and downloadPassword matches
|
||||
elseif(!empty($_GET["query"]) && $_GET["query"] == "download"){
|
||||
if(isset($_GET["downloadPassword"]) && md5($_GET["downloadPassword"]) == $passwords["downloadPassword"]){
|
||||
|
||||
$output = $rm->downloadRecords();
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
//If upDown mode and downloadPassword and uploadPassword matches
|
||||
elseif(!empty($_GET["query"]) && $_GET["query"] == "upDown"){
|
||||
if(isset($_GET["downloadPassword"]) && md5($_GET["downloadPassword"]) == $passwords["downloadPassword"]
|
||||
&& isset($_GET["uploadPassword"]) && md5($_GET["uploadPassword"]) == $passwords["uploadPassword"] ){
|
||||
// Use the following code to read post body. Not regular form posts which would be accessed with $_POST
|
||||
$postText = trim(file_get_contents('php://input') );
|
||||
|
||||
$output = $rm->downloadRecords();
|
||||
echo $output;
|
||||
|
||||
$output = $rm->uploadRecords($postText);
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
//Else you're in view mode just display the records with html and css
|
||||
else{
|
||||
echo $rm->generateCss();
|
||||
echo $rm->viewRecords();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
304
Samples/PHPDirectoryServer2/PHPDirectoryServer2.cpp
Normal file
304
Samples/PHPDirectoryServer2/PHPDirectoryServer2.cpp
Normal file
@ -0,0 +1,304 @@
|
||||
/*
|
||||
* Original work: Copyright (c) 2014, Oculus VR, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
|
||||
*
|
||||
*
|
||||
* Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
|
||||
*
|
||||
* This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
|
||||
* license found in the license.txt file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/// \file
|
||||
/// \brief Contains WebGameList, a client for communicating with a HTTP list of game servers
|
||||
///
|
||||
/// Creative Commons Licensees are subject to the
|
||||
/// license found at
|
||||
/// http://creativecommons.org/licenses/by-nc/2.5/
|
||||
/// Single application licensees are subject to the license found at
|
||||
/// http://www.jenkinssoftware.com/SingleApplicationLicense.html
|
||||
/// Custom license users are subject to the terms therein.
|
||||
/// GPL license users are subject to the GNU General Public
|
||||
/// License as published by the Free Software Foundation
|
||||
|
||||
#include "PHPDirectoryServer2.h"
|
||||
#include "slikenet/HTTPConnection.h"
|
||||
#include "slikenet/sleep.h"
|
||||
#include "slikenet/string.h"
|
||||
#include "slikenet/types.h"
|
||||
#include "slikenet/GetTime.h"
|
||||
#include "slikenet/assert.h"
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include "slikenet/Itoa.h"
|
||||
|
||||
// Column with this header contains the name of the game, passed to UploadTable()
|
||||
static const char *GAME_NAME_COMMAND="__GAME_NAME";
|
||||
// Column with this header contains the port of the game, passed to UploadTable()
|
||||
static const char *GAME_PORT_COMMAND="__GAME_PORT";
|
||||
// Column with this header contains the IP address of the game, passed to UploadTable()
|
||||
static const char *SYSTEM_ADDRESS_COMMAND="_System_Address";
|
||||
// Returned from the PHP server indicating when this row was last updated.
|
||||
static const char *LAST_UPDATE_COMMAND="__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE";
|
||||
|
||||
using namespace SLNet;
|
||||
using namespace DataStructures;
|
||||
|
||||
PHPDirectoryServer2::PHPDirectoryServer2()
|
||||
: nextRepost(0)
|
||||
{
|
||||
Map<RakString, RakString>::IMPLEMENT_DEFAULT_COMPARISON();
|
||||
}
|
||||
PHPDirectoryServer2::~PHPDirectoryServer2()
|
||||
{
|
||||
}
|
||||
void PHPDirectoryServer2::Init(HTTPConnection *_http, const char *_path)
|
||||
{
|
||||
http=_http;
|
||||
pathToPHP=_path;
|
||||
}
|
||||
|
||||
void PHPDirectoryServer2::SetField(SLNet::RakString columnName, SLNet::RakString value )
|
||||
{
|
||||
if (columnName.IsEmpty())
|
||||
return;
|
||||
|
||||
if (columnName==GAME_NAME_COMMAND ||
|
||||
columnName==GAME_PORT_COMMAND ||
|
||||
columnName==LAST_UPDATE_COMMAND)
|
||||
{
|
||||
RakAssert("PHPDirectoryServer2::SetField attempted to set reserved column name" && 0);
|
||||
return;
|
||||
}
|
||||
|
||||
fields.Set(columnName, value);
|
||||
}
|
||||
unsigned int PHPDirectoryServer2::GetFieldCount(void) const
|
||||
{
|
||||
return fields.Size();
|
||||
}
|
||||
void PHPDirectoryServer2::GetField(unsigned int index, SLNet::RakString &columnName, SLNet::RakString &value)
|
||||
{
|
||||
RakAssert(index < fields.Size());
|
||||
columnName=fields.GetKeyAtIndex(index);
|
||||
value=fields[index];
|
||||
}
|
||||
void PHPDirectoryServer2::SetFields(DataStructures::Table *table)
|
||||
{
|
||||
ClearFields();
|
||||
|
||||
unsigned columnIndex, rowIndex;
|
||||
DataStructures::Table::Row *row;
|
||||
|
||||
for (rowIndex=0; rowIndex < table->GetRowCount(); rowIndex++)
|
||||
{
|
||||
row = table->GetRowByIndex(rowIndex, 0);
|
||||
for (columnIndex=0; columnIndex < table->GetColumnCount(); columnIndex++)
|
||||
{
|
||||
SetField( table->ColumnName(columnIndex), row->cells[columnIndex]->ToString(table->GetColumnType(columnIndex)) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PHPDirectoryServer2::ClearFields(void)
|
||||
{
|
||||
fields.Clear();
|
||||
nextRepost=0;
|
||||
}
|
||||
|
||||
void PHPDirectoryServer2::UploadTable(SLNet::RakString uploadPassword, SLNet::RakString gameName, unsigned short gamePort, bool autoRepost)
|
||||
{
|
||||
gameNameParam=gameName;
|
||||
gamePortParam=gamePort;
|
||||
currentOperation="";
|
||||
currentOperation="?query=upload&uploadPassword=";
|
||||
currentOperation+=uploadPassword;
|
||||
SendOperation();
|
||||
|
||||
if (autoRepost)
|
||||
nextRepost= SLNet::GetTimeMS()+50000;
|
||||
else
|
||||
nextRepost=0;
|
||||
}
|
||||
void PHPDirectoryServer2::DownloadTable(SLNet::RakString downloadPassword)
|
||||
{
|
||||
currentOperation="?query=download&downloadPassword=";
|
||||
currentOperation+=downloadPassword;
|
||||
SendOperation();
|
||||
}
|
||||
void PHPDirectoryServer2::UploadAndDownloadTable(SLNet::RakString uploadPassword, SLNet::RakString downloadPassword, SLNet::RakString gameName, unsigned short gamePort, bool autoRepost)
|
||||
{
|
||||
gameNameParam=gameName;
|
||||
gamePortParam=gamePort;
|
||||
currentOperation="?query=upDown&downloadPassword=";
|
||||
currentOperation+=downloadPassword;
|
||||
currentOperation+="&uploadPassword=";
|
||||
currentOperation+=uploadPassword;
|
||||
|
||||
SendOperation();
|
||||
|
||||
if (autoRepost)
|
||||
nextRepost= SLNet::GetTimeMS()+50000;
|
||||
else
|
||||
nextRepost=0;
|
||||
}
|
||||
|
||||
HTTPReadResult PHPDirectoryServer2::ProcessHTTPRead(SLNet::RakString httpRead)
|
||||
{
|
||||
const char *c = (const char*) httpRead.C_String(); // current position
|
||||
HTTPReadResult resultCode=HTTP_RESULT_EMPTY;
|
||||
|
||||
lastDownloadedTable.Clear();
|
||||
|
||||
|
||||
if (*c=='\n')
|
||||
c++;
|
||||
char buff[256];
|
||||
int buffIndex;
|
||||
bool isCommand=true;
|
||||
DataStructures::List<SLNet::RakString> columns;
|
||||
DataStructures::List<SLNet::RakString> values;
|
||||
SLNet::RakString curString;
|
||||
bool isComment=false;
|
||||
buffIndex=0;
|
||||
while(c && *c)
|
||||
{
|
||||
// 3 is comment
|
||||
if (*c=='\003')
|
||||
{
|
||||
isComment=!isComment;
|
||||
c++;
|
||||
continue;
|
||||
}
|
||||
if (isComment)
|
||||
{
|
||||
c++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 1 or 2 separates fields
|
||||
// 4 separates rows
|
||||
if (*c=='\001')
|
||||
{
|
||||
if (isCommand)
|
||||
{
|
||||
buff[buffIndex]=0;
|
||||
columns.Push(RakString::NonVariadic(buff), _FILE_AND_LINE_);
|
||||
isCommand=false;
|
||||
if (buff[0]!=0)
|
||||
resultCode=HTTP_RESULT_GOT_TABLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
buff[buffIndex]=0;
|
||||
values.Push(RakString::NonVariadic(buff), _FILE_AND_LINE_);
|
||||
isCommand=true;
|
||||
}
|
||||
buffIndex=0;
|
||||
}
|
||||
else if (*c=='\002')
|
||||
{
|
||||
buff[buffIndex]=0;
|
||||
buffIndex=0;
|
||||
values.Push(RakString::NonVariadic(buff), _FILE_AND_LINE_);
|
||||
isCommand=true;
|
||||
PushColumnsAndValues(columns, values);
|
||||
columns.Clear(true, _FILE_AND_LINE_);
|
||||
values.Clear(true, _FILE_AND_LINE_);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buffIndex<256-1)
|
||||
buff[buffIndex++]=*c;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
if (buff[0] && columns.Size()==values.Size()+1)
|
||||
{
|
||||
buff[buffIndex]=0;
|
||||
values.Push(RakString::NonVariadic(buff), _FILE_AND_LINE_);
|
||||
}
|
||||
|
||||
PushColumnsAndValues(columns, values);
|
||||
|
||||
return resultCode;
|
||||
}
|
||||
void PHPDirectoryServer2::PushColumnsAndValues(DataStructures::List<SLNet::RakString> &columns, DataStructures::List<SLNet::RakString> &values)
|
||||
{
|
||||
DataStructures::Table::Row *row=0;
|
||||
|
||||
unsigned int i;
|
||||
for (i=0; i < columns.Size() && i < values.Size(); i++)
|
||||
{
|
||||
if (columns[i].IsEmpty()==false)
|
||||
{
|
||||
unsigned col = lastDownloadedTable.ColumnIndex(columns[i]);
|
||||
if(col == (unsigned)-1)
|
||||
{
|
||||
col = lastDownloadedTable.AddColumn(columns[i], DataStructures::Table::STRING);
|
||||
}
|
||||
|
||||
if (row==0)
|
||||
{
|
||||
row = lastDownloadedTable.AddRow(lastDownloadedTable.GetAvailableRowId());
|
||||
}
|
||||
row->UpdateCell(col,values[i].C_String());
|
||||
}
|
||||
}
|
||||
}
|
||||
const DataStructures::Table *PHPDirectoryServer2::GetLastDownloadedTable(void) const
|
||||
{
|
||||
return &lastDownloadedTable;
|
||||
}
|
||||
void PHPDirectoryServer2::SendOperation(void)
|
||||
{
|
||||
RakString outgoingMessageBody;
|
||||
char buff[64];
|
||||
|
||||
outgoingMessageBody += GAME_PORT_COMMAND;
|
||||
outgoingMessageBody += '\001';
|
||||
outgoingMessageBody += Itoa(gamePortParam,buff,10);
|
||||
outgoingMessageBody += '\001';
|
||||
outgoingMessageBody += GAME_NAME_COMMAND;
|
||||
outgoingMessageBody += '\001';
|
||||
outgoingMessageBody += gameNameParam;
|
||||
|
||||
for (unsigned i = 0; i < fields.Size(); i++)
|
||||
{
|
||||
RakString value = fields[i];
|
||||
value.URLEncode();
|
||||
outgoingMessageBody += RakString("\001%s\001%s",
|
||||
fields.GetKeyAtIndex(i).C_String(),
|
||||
value.C_String());
|
||||
}
|
||||
|
||||
RakString postURL;
|
||||
postURL+=pathToPHP;
|
||||
postURL+=currentOperation;
|
||||
http->Post(postURL.C_String(), outgoingMessageBody, "application/x-www-form-urlencoded");
|
||||
|
||||
}
|
||||
void PHPDirectoryServer2::Update(void)
|
||||
{
|
||||
if (http->IsBusy())
|
||||
return;
|
||||
|
||||
|
||||
if (nextRepost==0 || fields.Size()==0)
|
||||
return;
|
||||
|
||||
SLNet::TimeMS time = GetTimeMS();
|
||||
|
||||
// Entry deletes itself after 60 seconds, so keep reposting if set to do so
|
||||
if (time > nextRepost)
|
||||
{
|
||||
nextRepost= SLNet::GetTimeMS()+50000;
|
||||
SendOperation();
|
||||
}
|
||||
}
|
||||
150
Samples/PHPDirectoryServer2/PHPDirectoryServer2.h
Normal file
150
Samples/PHPDirectoryServer2/PHPDirectoryServer2.h
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Original work: Copyright (c) 2014, Oculus VR, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
|
||||
*
|
||||
*
|
||||
* Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
|
||||
*
|
||||
* This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
|
||||
* license found in the license.txt file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/// \file
|
||||
/// \brief Contains PHPDirectoryServer2, a client for communicating with a HTTP list of game servers
|
||||
///
|
||||
/// Creative Commons Licensees are subject to the
|
||||
/// license found at
|
||||
/// http://creativecommons.org/licenses/by-nc/2.5/
|
||||
/// Single application licensees are subject to the license found at
|
||||
/// http://www.jenkinssoftware.com/SingleApplicationLicense.html
|
||||
/// Custom license users are subject to the terms therein.
|
||||
/// GPL license users are subject to the GNU General Public
|
||||
/// License as published by the Free
|
||||
/// Software Foundation; either version 2 of the License, or (at your
|
||||
/// option) any later version.
|
||||
|
||||
#ifndef __PHP_DIRECTORY_SERVER_2
|
||||
#define __PHP_DIRECTORY_SERVER_2
|
||||
|
||||
#include "slikenet/Export.h"
|
||||
#include "slikenet/string.h"
|
||||
#include "slikenet/HTTPConnection.h"
|
||||
#include "slikenet/types.h"
|
||||
#include "slikenet/DS_Queue.h"
|
||||
#include "slikenet/DS_Table.h"
|
||||
#include "slikenet/DS_Map.h"
|
||||
|
||||
namespace SLNet {
|
||||
|
||||
struct SystemAddress;
|
||||
|
||||
enum HTTPReadResult
|
||||
{
|
||||
HTTP_RESULT_GOT_TABLE,
|
||||
HTTP_RESULT_EMPTY
|
||||
};
|
||||
|
||||
/// \brief Use PHPDirectoryServer2 as a C++ client to DirectoryServer.php
|
||||
///
|
||||
/// PHPDirectoryServer2 works with the HTTPConnection class (which works with the TCPInterface class) in order to communiate with DirectoryServer.php found under Samples/PHPDirectoryServer2
|
||||
class RAK_DLL_EXPORT PHPDirectoryServer2
|
||||
{
|
||||
public:
|
||||
PHPDirectoryServer2();
|
||||
virtual ~PHPDirectoryServer2();
|
||||
|
||||
/// Associate PHPDirectoryServer2 with the HTTPConnection class it will communicate through
|
||||
/// \param[in] _http The instance of HTTP connection we will communicate through
|
||||
/// \param[in] _path The path to the PHP file on the remote server. For example, if the path is mysite.com/raknet/DirectoryServer.php then you would enter raknet/DirectoryServer.php
|
||||
void Init(HTTPConnection *_http, const char *_path);
|
||||
|
||||
/// Set a parameter (these are passed to the server)
|
||||
/// To delete a column, just pass an empty string for value
|
||||
/// Store the game name and port with UploadTable, rather than SetField, as these columns are required and use reserved column names
|
||||
/// \param[in] columnName The name of the column to store
|
||||
/// \param[in] value What value to hold for the uploaded row (only one row can be uploaded at a time)
|
||||
void SetField(SLNet::RakString columnName, SLNet::RakString value);
|
||||
|
||||
/// Returns the number of fields set with SetField()
|
||||
unsigned int GetFieldCount(void) const;
|
||||
|
||||
/// Returns a field set with SetField()
|
||||
/// \param[in] index The 0 based index into the field list
|
||||
/// \param[out] columnName The \a columnName parameter passed to SetField()
|
||||
/// \param[out] value The \a value parameter passed to SetField()
|
||||
void GetField(unsigned int index, SLNet::RakString &columnName, SLNet::RakString &value);
|
||||
|
||||
/// Set all parameters at once from a table
|
||||
/// \param[in] table A table containing the values you want to send. Note that all values are stored as strings in PHP
|
||||
void SetFields(DataStructures::Table *table);
|
||||
|
||||
/// Clear all fields
|
||||
void ClearFields(void);
|
||||
|
||||
/// Upload the values set with SetFields() or SetField()
|
||||
/// On success:
|
||||
/// 1. HTTPConnection::HasRead() will return true.
|
||||
/// 2. Pass the value returned by HTTPConnection::Read() to PHPDirectoryServer2::ProcessHTTPRead().
|
||||
/// 3. The return value of PHPDirectoryServer2::ProcessHTTPRead() will be HTTP_RESULT_EMPTY
|
||||
/// \param[in] uploadPassword The upload password set in the PHP page itself when you first uploaded and viewed it in the webpage.
|
||||
/// \param[in] gameName Every entry must have a game name. Pass it here.
|
||||
/// \param[in] gamePort Every entry must have a game port. Pass it here. The IP address will be stored automatically, or you can manually set it by passing a field named _System_Address
|
||||
/// \param[in] autoRepost Tables must be uploaded every 60 seconds or they get dropped. Set autoRepost to true to automatically reupload the most recent table.
|
||||
void UploadTable(SLNet::RakString uploadPassword, SLNet::RakString gameName, unsigned short gamePort, bool autoRepost);
|
||||
|
||||
/// Send a download request to the PHP server.
|
||||
/// On success:
|
||||
/// 1. HTTPConnection::HasRead() will return true.
|
||||
/// 2. Pass the value returned by HTTPConnection::Read() to PHPDirectoryServer2::ProcessHTTPRead().
|
||||
/// 3. The return value of PHPDirectoryServer2::ProcessHTTPRead() will be HTTP_RESULT_GOT_TABLE or HTTP_RESULT_EMPTY
|
||||
/// 4. On HTTP_RESULT_GOT_TABLE, use GetLastDownloadedTable() to read the results.
|
||||
/// \param[in] downloadPassword The download password set in the PHP page itself when you first uploaded and viewed it in the webpage.
|
||||
void DownloadTable(SLNet::RakString downloadPassword);
|
||||
|
||||
/// Same as calling DownloadTable immediately followed by UploadTable, except only the download result is returned
|
||||
/// \param[in] uploadPassword The upload password set in the PHP page itself when you first uploaded and viewed it in the webpage.
|
||||
/// \param[in] downloadPassword The download password set in the PHP page itself when you first uploaded and viewed it in the webpage.
|
||||
/// \param[in] gameName Every entry must have a game name. Pass it here.
|
||||
/// \param[in] gamePort Every entry must have a game port. Pass it here. The IP address will be stored automatically, or you can manually set it by passing a field named _System_Address
|
||||
/// \param[in] autoRepost Tables must be uploaded every 60 seconds or they get dropped. Set autoRepost to true to automatically reupload the most recent table.
|
||||
void UploadAndDownloadTable(SLNet::RakString uploadPassword, SLNet::RakString downloadPassword, SLNet::RakString gameName, unsigned short gamePort, bool autoRepost);
|
||||
|
||||
/// When HTTPConnection::ProcessDataPacket() returns true, and not an error, pass HTTPConnection::Read() to this function
|
||||
/// The message will be parsed into DataStructures::Table, and a copy stored internally which can be retrieved by GetLastDownloadedTable();
|
||||
/// \param[in] packetData Returned from HTTPInterface::Read()
|
||||
/// \return One of the values for HTTPReadResult
|
||||
HTTPReadResult ProcessHTTPRead(SLNet::RakString httpRead);
|
||||
|
||||
/// Returns the last value returned from ProcessHTTPString
|
||||
/// Default columns are "__GAME_NAME", "__GAME_PORT", "_System_Address"
|
||||
/// \return The table created by parsing httpString
|
||||
const DataStructures::Table *GetLastDownloadedTable(void) const;
|
||||
|
||||
/// Call this periodically - it will handle connection states and refreshing updates to the server
|
||||
void Update(void);
|
||||
|
||||
private:
|
||||
HTTPConnection *http;
|
||||
SLNet::RakString pathToPHP;
|
||||
|
||||
SLNet::RakString gameNameParam;
|
||||
unsigned short gamePortParam;
|
||||
|
||||
void SendOperation(void);
|
||||
void PushColumnsAndValues(DataStructures::List<SLNet::RakString> &columns, DataStructures::List<SLNet::RakString> &values);
|
||||
|
||||
DataStructures::Table lastDownloadedTable;
|
||||
DataStructures::Map<SLNet::RakString, SLNet::RakString> fields;
|
||||
SLNet::RakString currentOperation;
|
||||
SLNet::TimeMS nextRepost;
|
||||
|
||||
};
|
||||
|
||||
} // namespace SLNet
|
||||
|
||||
#endif
|
||||
|
||||
258
Samples/PHPDirectoryServer2/PHPDirectoryServer2.vcxproj
Normal file
258
Samples/PHPDirectoryServer2/PHPDirectoryServer2.vcxproj
Normal file
@ -0,0 +1,258 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug - Unicode|Win32">
|
||||
<Configuration>Debug - Unicode</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release - Unicode|Win32">
|
||||
<Configuration>Release - Unicode</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Retail - Unicode|Win32">
|
||||
<Configuration>Retail - Unicode</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Retail|Win32">
|
||||
<Configuration>Retail</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{0BC48323-6B49-4B29-9961-044BB129F827}</ProjectGuid>
|
||||
<RootNamespace>PHPDirectoryServer2</RootNamespace>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Retail|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release - Unicode|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Retail - Unicode|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug - Unicode|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Retail|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release - Unicode|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Retail - Unicode|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug - Unicode|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug - Unicode|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug - Unicode|Win32'">true</LinkIncremental>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Retail|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release - Unicode|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Retail - Unicode|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Retail|Win32'">false</LinkIncremental>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release - Unicode|Win32'">false</LinkIncremental>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Retail - Unicode|Win32'">false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Debug_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug - Unicode|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Debug - Unicode_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Release_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Retail|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_RETAIL;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Retail_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release - Unicode|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Release - Unicode_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Retail - Unicode|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_RETAIL;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Retail - Unicode_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="PHPDirectoryServer2.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="PHPDirectoryServer2.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Specification.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Lib\LibStatic\LibStatic.vcxproj">
|
||||
<Project>{6533bdae-0f0c-45e4-8fe7-add0f37fe063}</Project>
|
||||
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="PHPDirectoryServer2.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="PHPDirectoryServer2.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Specification.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
92
Samples/PHPDirectoryServer2/lib/PasswordManager.class.php
Normal file
92
Samples/PHPDirectoryServer2/lib/PasswordManager.class.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// This file was taken from RakNet 4.082 without any modifications.
|
||||
// Please see licenses/RakNet license.txt for the underlying license and related copyright.
|
||||
|
||||
class PasswordManager{
|
||||
|
||||
function PasswordManager(){
|
||||
|
||||
}
|
||||
|
||||
function generateCss(){
|
||||
$output = "<html>
|
||||
<head>
|
||||
<style type='text/css' media='all'>
|
||||
#password-form{
|
||||
border:1px solid #1E3C64;
|
||||
background:#4A8AD1;
|
||||
padding:5px 10px;
|
||||
color:#EFF7FF;
|
||||
}
|
||||
#password-form .text-field{
|
||||
border:1px solid #bbb;
|
||||
padding:3px;
|
||||
}
|
||||
.required{
|
||||
color:red;
|
||||
}
|
||||
.message{
|
||||
display:block;
|
||||
margin:5px 0;
|
||||
padding:5px;
|
||||
}
|
||||
.error{
|
||||
background:#FFEFF0;
|
||||
color:red;
|
||||
}
|
||||
#password-form .submit-button{
|
||||
background:#F6F5F5;
|
||||
color:#666;
|
||||
padding:5px;
|
||||
border: 1px solid #bbb;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>";
|
||||
return $output;
|
||||
}
|
||||
|
||||
function generatePasswordForm(){
|
||||
$output = "<h2>Admin Password Setup</h2><form id='password-form' action='' method='POST' >
|
||||
<p><label>Upload Password<span class='required'>*</span> </label><input class='text-field' type='text' name='uploadPassword' /></p>
|
||||
<p><label>Download Password<span class='required'>*</span> </label><input class='text-field' type='text' name='downloadPassword' /></p>
|
||||
<p><input type='submit' value='Submit' class='submit-button' /></p>
|
||||
</form>
|
||||
</body>
|
||||
</html>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function validatePasswords($post_array){
|
||||
$error = "";
|
||||
if(!isset($post_array["uploadPassword"]) || !preg_match("/^[A-Za-z0-9]+$/", $post_array["uploadPassword"]) ){
|
||||
$error .= "<p class='error message'>Upload Password is a required alphanumeric field.</p> ";
|
||||
}
|
||||
if(!isset($post_array["downloadPassword"]) || !preg_match("/^[A-Za-z0-9]+$/", $post_array["downloadPassword"]) ){
|
||||
$error .= "<p class='error message'>Download Password is a required alphanumeric field.</p> ";
|
||||
}
|
||||
return $error;
|
||||
}
|
||||
|
||||
function savePasswords($post_array){
|
||||
$fp = fopen('pw', 'w+');
|
||||
fwrite($fp, md5($post_array["uploadPassword"])."\n" );
|
||||
fwrite($fp, md5($post_array["downloadPassword"]) );
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
function getPasswords(){
|
||||
if(file_exists(PASSWORD_FILE)){
|
||||
$handle = fopen(PASSWORD_FILE, "r");
|
||||
$uploadPassword = trim(fgets($handle, 1024));
|
||||
$downloadPassword = trim(fgets($handle, 1024));
|
||||
|
||||
return array("uploadPassword"=>$uploadPassword, "downloadPassword"=>$downloadPassword);
|
||||
}
|
||||
else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
206
Samples/PHPDirectoryServer2/lib/RecordManager.class.php
Normal file
206
Samples/PHPDirectoryServer2/lib/RecordManager.class.php
Normal file
@ -0,0 +1,206 @@
|
||||
<?php
|
||||
// This file was taken from RakNet 4.082 without any modifications.
|
||||
// Please see licenses/RakNet license.txt for the underlying license and related copyright.
|
||||
|
||||
class RecordManager{
|
||||
|
||||
//Constructor just creates the RecordFile.data.php
|
||||
function RecordManager(){
|
||||
if(!file_exists(RECORD_FILE)){
|
||||
$fp = fopen(RECORD_FILE, "w");
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
//Called everytime you run DirectoryServer.php to expire record values.
|
||||
function expireRecords(){
|
||||
//IMPORTANT
|
||||
//Include the var_export of the variable $records
|
||||
include("RecordFile.data.php");
|
||||
|
||||
if(!empty($records)){
|
||||
foreach($records as $index => $game){
|
||||
$secs = time() - $game["__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE"];
|
||||
if($secs > TIMEOUT){
|
||||
unset($records[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
//Save the file
|
||||
$fp = fopen(RECORD_FILE, "w");
|
||||
fwrite($fp, '<?php $records = ');
|
||||
fwrite($fp, var_export($records, true));
|
||||
fwrite($fp, '; ?>');
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
function uploadRecords($post_body){
|
||||
//IMPORTANT
|
||||
//Include the var_export of the variable $records
|
||||
include("RecordFile.data.php");
|
||||
$output = "";
|
||||
$post_array = array();
|
||||
|
||||
//Modified code to handle multiple rows separated by \002
|
||||
$post_body_rows = explode("\002", $post_body);
|
||||
foreach($post_body_rows as $row_num => $post_body_row){
|
||||
//row columns and values are separated by \001
|
||||
//Even indexes are columns, the following odd value is the column_value
|
||||
$post_body_array = explode("\001", $post_body_row);
|
||||
foreach($post_body_array as $index => $post_body_item){
|
||||
if($index % 2 == 0){
|
||||
$post_array[$row_num][$post_body_item] = $post_body_array[$index+1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//This places each value pair into a PHP array to be outputted to the Recordfile
|
||||
foreach($post_array as $post_item){
|
||||
if(isset($post_item["__GAME_PORT"]) && isset($post_item["__GAME_NAME"]) ){
|
||||
$record = array();
|
||||
foreach($post_item as $key => $value){
|
||||
//Decode because post values are send with url encoded symbols like %20
|
||||
$record[$key] = rawurldecode($value);
|
||||
}
|
||||
|
||||
//Store the IP address if not included in the POST
|
||||
if(!isset($record["__System_Address"])){
|
||||
$record["__System_Address"] = $_SERVER["REMOTE_ADDR"];
|
||||
}
|
||||
|
||||
$record["__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE"] = time();
|
||||
|
||||
//Search the $records for a matching record. If the GAME_PORT, GAME_NAME, and System Address match replace it
|
||||
//Otherwise just add the record to the $records array.
|
||||
$record_found = false;
|
||||
if(!empty($records)){
|
||||
foreach($records as $index => $save_record){
|
||||
if($save_record["__GAME_PORT"] == $record["__GAME_PORT"]
|
||||
&& $save_record["__GAME_NAME"] == $record["__GAME_NAME"]
|
||||
&& $save_record["__System_Address"] == $record["__System_Address"]){
|
||||
//We found the record so replace it here.
|
||||
$records[$index] = $record;
|
||||
$record_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Record couldn't be found simply add a new record
|
||||
if(!$record_found){
|
||||
$records[] = $record;
|
||||
}
|
||||
|
||||
//Save the file
|
||||
$fp = fopen(RECORD_FILE, "w");
|
||||
fwrite($fp, '<?php $records = ');
|
||||
fwrite($fp, var_export($records, true));
|
||||
fwrite($fp, '; ?>');
|
||||
fclose($fp);
|
||||
}
|
||||
else{
|
||||
$output .= "\003".microtime(true)."\003";
|
||||
$output .= "__GAME_PORT and __GAME_NAME must be provided";
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function downloadRecords(){
|
||||
//IMPORTANT
|
||||
//Include the var_export of the variable $records
|
||||
include("RecordFile.data.php");
|
||||
//Comment prefix
|
||||
$output = "\003".microtime(true)."\003";
|
||||
|
||||
//Output the records. Traverse and output rows separated by \002 and values seperated by \001
|
||||
if(!empty($records)){
|
||||
$row_count = 0;
|
||||
foreach($records as $game){
|
||||
if(!empty($game)){
|
||||
if($row_count > 0){
|
||||
$output .= "\002";
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
foreach($game as $key => $value){
|
||||
if($count > 0){
|
||||
$output .= "\001";
|
||||
}
|
||||
$output .= "$key"."\001"."$value";
|
||||
$count++;
|
||||
}
|
||||
|
||||
}
|
||||
$row_count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function generateCss(){
|
||||
$output = "<html>
|
||||
<head>
|
||||
<style type='text/css' media='all'>
|
||||
.game{
|
||||
border:1px solid #1E3C64;
|
||||
background:#4A8AD1;
|
||||
padding:5px 10px;
|
||||
color:#EFF7FF;
|
||||
margin-bottom:5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>";
|
||||
return $output;
|
||||
}
|
||||
|
||||
function viewRecords(){
|
||||
$output = "";
|
||||
|
||||
//IMPORTANT
|
||||
//Include the var_export of the variable $records
|
||||
include("RecordFile.data.php");
|
||||
|
||||
if(!empty($records)){
|
||||
foreach($records as $game){
|
||||
$vars = "";
|
||||
$secs = $game["__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE"] + TIMEOUT - time();
|
||||
|
||||
$output .= "<div class='game' >
|
||||
<p>Game Port: {$game["__GAME_PORT"]}</p>
|
||||
<p>Game Name: {$game["__GAME_NAME"]}</p>
|
||||
<p>System Address: {$game["__System_Address"]}</p>
|
||||
<p>Time Until Expiration: $secs secs</p>
|
||||
";
|
||||
|
||||
foreach($game as $key => $value){
|
||||
if($key != "__GAME_PORT" && $key != "__GAME_NAME"
|
||||
&& $key != "__System_Address" && $key != "__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE" ){
|
||||
$vars .= "<li>".$key.": $value</li>";
|
||||
}
|
||||
elseif($key == "0"){
|
||||
$vars .= "<li>".$key.": $value</li>";
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($vars)){
|
||||
$output .= "<ul>$vars</ul>";
|
||||
}
|
||||
$output .= "</div>";
|
||||
}
|
||||
}
|
||||
else{
|
||||
$output .= "<div class='game' >
|
||||
<p>Record Table is Empty.</p>
|
||||
</div>";
|
||||
}
|
||||
$output .= "</body></html>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
523
Samples/PHPDirectoryServer2/main.cpp
Normal file
523
Samples/PHPDirectoryServer2/main.cpp
Normal file
@ -0,0 +1,523 @@
|
||||
/*
|
||||
* Original work: Copyright (c) 2014, Oculus VR, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
|
||||
*
|
||||
*
|
||||
* Modified work: Copyright (c) 2016-2020, SLikeSoft UG (haftungsbeschränkt)
|
||||
*
|
||||
* This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
|
||||
* license found in the license.txt file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/// \file
|
||||
/// \brief This file is a sample for using HTTPConnection and PHPDirectoryServer2
|
||||
|
||||
|
||||
#include "slikenet/TCPInterface.h"
|
||||
#include "slikenet/HTTPConnection.h"
|
||||
#include "PHPDirectoryServer2.h"
|
||||
#include "slikenet/sleep.h"
|
||||
#include "slikenet/string.h"
|
||||
#include "slikenet/GetTime.h"
|
||||
#include "slikenet/DS_Table.h"
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include "slikenet/Gets.h"
|
||||
#include "slikenet/Getche.h"
|
||||
#include "slikenet/linux_adapter.h"
|
||||
#include "slikenet/osx_adapter.h"
|
||||
|
||||
using namespace SLNet;
|
||||
|
||||
// Allocate rather than create on the stack or the RakString mutex crashes on shutdown
|
||||
TCPInterface *tcp;
|
||||
HTTPConnection *httpConnection;
|
||||
PHPDirectoryServer2 *phpDirectoryServer2;
|
||||
|
||||
enum ReadResultEnum
|
||||
{
|
||||
RR_EMPTY_TABLE,
|
||||
RR_READ_TABLE,
|
||||
RR_TIMEOUT,
|
||||
};
|
||||
|
||||
ReadResultEnum ReadResult(SLNet::RakString &httpResult)
|
||||
{
|
||||
SLNet::TimeMS endTime= SLNet::GetTimeMS()+10000;
|
||||
httpResult.Clear();
|
||||
while (SLNet::GetTimeMS()<endTime)
|
||||
{
|
||||
Packet *packet = tcp->Receive();
|
||||
if(packet)
|
||||
{
|
||||
httpConnection->ProcessTCPPacket(packet);
|
||||
tcp->DeallocatePacket(packet);
|
||||
}
|
||||
|
||||
if (httpConnection->HasRead())
|
||||
{
|
||||
httpResult = httpConnection->Read();
|
||||
// Good response, let the PHPDirectoryServer2 class handle the data
|
||||
// If resultCode is not an empty string, then we got something other than a table
|
||||
// (such as delete row success notification, or the message is for HTTP only and not for this class).
|
||||
HTTPReadResult readResult = phpDirectoryServer2->ProcessHTTPRead(httpResult);
|
||||
|
||||
if (readResult==HTTP_RESULT_GOT_TABLE)
|
||||
{
|
||||
//printf("RR_READ_TABLE\n");
|
||||
return RR_READ_TABLE;
|
||||
}
|
||||
else if (readResult==HTTP_RESULT_EMPTY)
|
||||
{
|
||||
//printf("HTTP_RESULT_EMPTY\n");
|
||||
return RR_EMPTY_TABLE;
|
||||
}
|
||||
}
|
||||
|
||||
// Update our two classes so they can do time-based updates
|
||||
httpConnection->Update();
|
||||
phpDirectoryServer2->Update();
|
||||
|
||||
// Prevent 100% cpu usage
|
||||
RakSleep(30);
|
||||
}
|
||||
|
||||
return RR_TIMEOUT;
|
||||
}
|
||||
|
||||
bool HaltOnUnexpectedResult(ReadResultEnum result, ReadResultEnum expected)
|
||||
{
|
||||
if (result!=expected)
|
||||
{
|
||||
printf("TEST FAILED. Expected ");
|
||||
|
||||
switch (expected)
|
||||
{
|
||||
|
||||
case RR_EMPTY_TABLE:
|
||||
printf("no results");
|
||||
break;
|
||||
case RR_TIMEOUT:
|
||||
printf("timeout");
|
||||
break;
|
||||
case RR_READ_TABLE:
|
||||
printf("to download result");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case RR_EMPTY_TABLE:
|
||||
printf(". No results were downloaded");
|
||||
break;
|
||||
case RR_READ_TABLE:
|
||||
printf(". Got a result");
|
||||
break;
|
||||
case RR_TIMEOUT:
|
||||
printf(". Timeout");
|
||||
break;
|
||||
}
|
||||
printf("\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DownloadTable()
|
||||
{
|
||||
phpDirectoryServer2->DownloadTable("a");
|
||||
}
|
||||
void UploadTable(SLNet::RakString gameName, unsigned short gamePort)
|
||||
{
|
||||
phpDirectoryServer2->UploadTable("a", gameName, gamePort, false);
|
||||
}
|
||||
void UploadAndDownloadTable(SLNet::RakString gameName, unsigned short gamePort)
|
||||
{
|
||||
phpDirectoryServer2->UploadAndDownloadTable("a", "a", gameName, gamePort, false);
|
||||
}
|
||||
bool PassTestOnEmptyDownloadedTable()
|
||||
{
|
||||
const DataStructures::Table *games = phpDirectoryServer2->GetLastDownloadedTable();
|
||||
|
||||
if (games->GetRowCount()==0)
|
||||
{
|
||||
printf("Test passed.\n");
|
||||
return true;
|
||||
}
|
||||
printf("TEST FAILED. Empty table should have been downloaded.\n");
|
||||
return false;
|
||||
}
|
||||
bool VerifyDownloadMatchesUpload(int requiredRowCount, int testRowIndex)
|
||||
{
|
||||
const DataStructures::Table *games = phpDirectoryServer2->GetLastDownloadedTable();
|
||||
if (games->GetRowCount()!=(unsigned int)requiredRowCount)
|
||||
{
|
||||
printf("TEST FAILED. Expected %i result rows, got %i\n", requiredRowCount, games->GetRowCount());
|
||||
return false;
|
||||
}
|
||||
SLNet::RakString columnName;
|
||||
SLNet::RakString value;
|
||||
unsigned int i;
|
||||
DataStructures::Table::Row *row = games->GetRowByIndex(testRowIndex, nullptr);
|
||||
const DataStructures::List<DataStructures::Table::ColumnDescriptor>& columns = games->GetColumns();
|
||||
unsigned int colIndex;
|
||||
// +4 comes from automatic fields
|
||||
// _GAME_PORT
|
||||
// _GAME_NAME
|
||||
// _SYSTEM_ADDRESS
|
||||
// __SEC_AFTER_EPOCH_SINCE_LAST_UPDATE
|
||||
if (phpDirectoryServer2->GetFieldCount()+4!=games->GetColumnCount())
|
||||
{
|
||||
printf("TEST FAILED. Expected %i columns, got %i\n", phpDirectoryServer2->GetFieldCount()+4, games->GetColumnCount());
|
||||
printf("Expected columns:\n");
|
||||
for (colIndex=0; colIndex < phpDirectoryServer2->GetFieldCount(); colIndex++)
|
||||
{
|
||||
phpDirectoryServer2->GetField(colIndex, columnName, value);
|
||||
printf("%i. %s\n", colIndex+1, columnName.C_String());
|
||||
}
|
||||
printf("%i. _GAME_PORT\n", colIndex++);
|
||||
printf("%i. _GAME_NAME\n", colIndex++);
|
||||
printf("%i. _System_Address\n", colIndex++);
|
||||
printf("%i. __SEC_AFTER_EPOCH_SINCE_LAST_UPDATE\n", colIndex++);
|
||||
|
||||
printf("Got columns:\n");
|
||||
for (colIndex=0; colIndex < columns.Size(); colIndex++)
|
||||
{
|
||||
printf("%i. %s\n", colIndex+1, columns[colIndex].columnName);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
for (i=0; i < phpDirectoryServer2->GetFieldCount(); i++)
|
||||
{
|
||||
phpDirectoryServer2->GetField(i, columnName, value);
|
||||
for (colIndex=0; colIndex < columns.Size(); colIndex++)
|
||||
{
|
||||
if (strcmp(columnName.C_String(), columns[colIndex].columnName)==0)
|
||||
break;
|
||||
}
|
||||
if (colIndex==columns.Size())
|
||||
{
|
||||
printf("TEST FAILED. Expected column with name %s\n", columnName.C_String());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(value.C_String(), row->cells[colIndex]->c)!=0)
|
||||
{
|
||||
printf("TEST FAILED. Expected row with value '%s' at index %i for column %s. Got '%s'.\n", value.C_String(), i, columnName.C_String(), row->cells[colIndex]->c);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Test passed.\n");
|
||||
return true;
|
||||
}
|
||||
void PrintHttpResult(SLNet::RakString httpResult)
|
||||
{
|
||||
printf("--- Last result read ---\n");
|
||||
printf("%s", httpResult.C_String());
|
||||
}
|
||||
void PrintFieldColumns(void)
|
||||
{
|
||||
unsigned int colIndex;
|
||||
SLNet::RakString columnName;
|
||||
SLNet::RakString value;
|
||||
for (colIndex=0; colIndex < phpDirectoryServer2->GetFieldCount(); colIndex++)
|
||||
{
|
||||
phpDirectoryServer2->GetField(colIndex, columnName, value);
|
||||
printf("%i. %s\n", colIndex+1, columnName.C_String());
|
||||
}
|
||||
}
|
||||
bool RunTest()
|
||||
{
|
||||
SLNet::RakString httpResult;
|
||||
ReadResultEnum rr;
|
||||
char ch[32];
|
||||
printf("Warning, table must be clear before starting the test.\n");
|
||||
printf("Press enter to start\n");
|
||||
Gets(ch,sizeof(ch));
|
||||
|
||||
printf("*** Testing initial table is empty.\n");
|
||||
// Table should start emptyF
|
||||
DownloadTable();
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_EMPTY_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
if (PassTestOnEmptyDownloadedTable()==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
printf("*** Downloading again, to ensure download does not modify the table.\n");
|
||||
// Downloading should not modify the table
|
||||
DownloadTable();
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_EMPTY_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
if (PassTestOnEmptyDownloadedTable()==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
printf("*** Testing upload.\n");
|
||||
// Upload values likely to mess up PHP
|
||||
phpDirectoryServer2->SetField("TestField1","0");
|
||||
phpDirectoryServer2->SetField("TestField2","");
|
||||
phpDirectoryServer2->SetField("TestField3"," ");
|
||||
phpDirectoryServer2->SetField("TestField4","!@#$%^&*(");
|
||||
phpDirectoryServer2->SetField("TestField5","A somewhat big long string as these things typically go.\nIt even has a linebreak!");
|
||||
phpDirectoryServer2->SetField("TestField6","=");
|
||||
phpDirectoryServer2->UploadTable("a", "FirstGameUpload", 80, false);
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_EMPTY_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
if (PassTestOnEmptyDownloadedTable()==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
printf("*** Testing download, should match upload exactly.\n");
|
||||
// Download what we just uploaded
|
||||
DownloadTable();
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_READ_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
// Check results
|
||||
if (VerifyDownloadMatchesUpload(1,0)==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
printf("*** Testing that download works twice in a row.\n");
|
||||
// Make sure download works twice
|
||||
DownloadTable();
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_READ_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
// Check results
|
||||
if (VerifyDownloadMatchesUpload(1,0)==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
printf("*** Testing reuploading a game to modify fields.\n");
|
||||
// Modify fields
|
||||
phpDirectoryServer2->SetField("TestField1","zero");
|
||||
phpDirectoryServer2->SetField("TestField2","empty");
|
||||
phpDirectoryServer2->SetField("TestField3","space");
|
||||
phpDirectoryServer2->SetField("TestField4","characters");
|
||||
phpDirectoryServer2->SetField("TestField5","A shorter string");
|
||||
phpDirectoryServer2->SetField("TestField6","Test field 6");
|
||||
phpDirectoryServer2->UploadTable("a", "FirstGameUpload", 80, false);
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_EMPTY_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
if (PassTestOnEmptyDownloadedTable()==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
printf("*** Testing that downloading returns modified fields.\n");
|
||||
// Download what we just uploaded
|
||||
DownloadTable();
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_READ_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
// Check results
|
||||
if (VerifyDownloadMatchesUpload(1,0)==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
printf("*** Testing that downloading works twice.\n");
|
||||
// Make sure download works twice
|
||||
DownloadTable();
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_READ_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
// Check results
|
||||
if (VerifyDownloadMatchesUpload(1,0)==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
printf("*** Testing upload of a second game.\n");
|
||||
// Upload another game
|
||||
phpDirectoryServer2->SetField("TestField1","0");
|
||||
phpDirectoryServer2->SetField("TestField2","");
|
||||
phpDirectoryServer2->SetField("TestField3"," ");
|
||||
phpDirectoryServer2->SetField("TestField4","Game two characters !@#$%^&*(");
|
||||
phpDirectoryServer2->UploadTable("a", "SecondGameUpload", 80, false);
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_EMPTY_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
if (PassTestOnEmptyDownloadedTable()==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
SLNet::TimeMS startTime = SLNet::GetTimeMS();
|
||||
|
||||
printf("*** Testing 20 repeated downloads.\n");
|
||||
//printf("Field columns\n");
|
||||
//PrintFieldColumns();
|
||||
|
||||
// Download repeatedly
|
||||
unsigned int downloadCount=0;
|
||||
while (downloadCount < 20)
|
||||
{
|
||||
printf("*** (%i) Downloading 'FirstGameUpload'\n", downloadCount+1);
|
||||
// Download again (First game)
|
||||
DownloadTable();
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_READ_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
// Check results
|
||||
// DOn't have this stored anymore
|
||||
// if (VerifyDownloadMatchesUpload(2,0)==false)
|
||||
// {PrintHttpResult(httpResult); return false;}
|
||||
|
||||
printf("*** (%i) Downloading 'SecondGameUpload'\n", downloadCount+1);
|
||||
// Download again (second game)
|
||||
DownloadTable();
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_READ_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
// Check results
|
||||
if (VerifyDownloadMatchesUpload(2,1)==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
downloadCount++;
|
||||
|
||||
RakSleep(1000);
|
||||
}
|
||||
|
||||
printf("*** Waiting for 70 seconds to have elapsed...\n");
|
||||
RakSleep(70000 - (SLNet::GetTimeMS()-startTime));
|
||||
|
||||
|
||||
printf("*** Testing that table is now clear.\n");
|
||||
// Table should be cleared
|
||||
DownloadTable();
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_EMPTY_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
if (PassTestOnEmptyDownloadedTable()==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
printf("*** Testing upload and download. No games should be downloaded.\n");
|
||||
phpDirectoryServer2->ClearFields();
|
||||
phpDirectoryServer2->SetField("TestField1","NULL");
|
||||
UploadAndDownloadTable("FirstGameUpload", 80);
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_EMPTY_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
if (PassTestOnEmptyDownloadedTable()==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
printf("*** Testing upload and download. One game should be downloaded.\n");
|
||||
UploadAndDownloadTable("ThirdGameUpload", 80);
|
||||
if (HaltOnUnexpectedResult(rr=ReadResult(httpResult), RR_READ_TABLE))
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
if (VerifyDownloadMatchesUpload(1,0)==false)
|
||||
{PrintHttpResult(httpResult); return false;}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OutputBody(HTTPConnection& http, const char *path, const char *data, TCPInterface& tcp);
|
||||
|
||||
void TestPHPDirectoryServer(int argc, char **argv)
|
||||
{
|
||||
printf("PHP Directory server 2.\n");
|
||||
printf("Similar to lightweight database, but uses common shared webservers.\n");
|
||||
printf("Set columns and one row for your game, and upload it to a\nviewable and downloadable webpage.\n");
|
||||
printf("Difficulty: Intermediate\n\n");
|
||||
|
||||
// tcp = SLNet::OP_NEW<TCPInterface>(_FILE_AND_LINE_);
|
||||
// httpConnection = SLNet::OP_NEW<HTTPConnection>(_FILE_AND_LINE_);
|
||||
// phpDirectoryServer2 = SLNet::OP_NEW<PHPDirectoryServer2>(_FILE_AND_LINE_);
|
||||
|
||||
|
||||
|
||||
// SLNet::TimeMS lastTouched = 0;
|
||||
|
||||
|
||||
|
||||
char website[256];
|
||||
char pathToPHP[256];
|
||||
if (argc==3)
|
||||
{
|
||||
strcpy_s(website, argv[1]);
|
||||
strcpy_s(pathToPHP, argv[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Enter website, e.g. jenkinssoftware.com:\n");
|
||||
Gets(website,sizeof(website));
|
||||
if (website[0]==0)
|
||||
strcpy_s(website, "jenkinssoftware.com");
|
||||
|
||||
printf("Enter path to DirectoryServer.php, e.g. raknet/DirectoryServer.php:\n");
|
||||
Gets(pathToPHP,sizeof(pathToPHP));
|
||||
if (pathToPHP[0]==0)
|
||||
strcpy_s(pathToPHP, "/raknet/DirectoryServer.php");
|
||||
}
|
||||
|
||||
if (website[strlen(website)-1]!='/' && pathToPHP[0]!='/')
|
||||
{
|
||||
memmove(pathToPHP+1, pathToPHP, strlen(pathToPHP)+1);
|
||||
pathToPHP[0]='/';
|
||||
}
|
||||
|
||||
// This creates an HTTP connection using TCPInterface. It allows you to Post messages to and parse messages from webservers.
|
||||
// The connection attempt is asynchronous, and is handled automatically as HTTPConnection::Update() is called
|
||||
httpConnection->Init(tcp, website);
|
||||
|
||||
// This adds specific parsing functionality to HTTPConnection, in order to communicate with DirectoryServer.php
|
||||
phpDirectoryServer2->Init(httpConnection, pathToPHP);
|
||||
|
||||
if (RunTest())
|
||||
{
|
||||
printf("All tests passed.\n");
|
||||
}
|
||||
|
||||
char str[256];
|
||||
do
|
||||
{
|
||||
printf("\nPress q to quit.\n");
|
||||
Gets(str, sizeof(str));
|
||||
} while (str[0]!='q');
|
||||
|
||||
// The destructor of each of these references the other, so delete in this order
|
||||
SLNet::OP_DELETE(phpDirectoryServer2,_FILE_AND_LINE_);
|
||||
SLNet::OP_DELETE(httpConnection,_FILE_AND_LINE_);
|
||||
SLNet::OP_DELETE(tcp,_FILE_AND_LINE_);
|
||||
}
|
||||
|
||||
void TestGet(void)
|
||||
{
|
||||
printf("This is NOT a reliable way to download from a website. Use libcurl instead.\n");
|
||||
httpConnection->Init(tcp, "jenkinssoftware.com");
|
||||
httpConnection->Get("/trivia/ranking.php?t=single&places=6&top");
|
||||
for(;;)
|
||||
{
|
||||
Packet *packet = tcp->Receive();
|
||||
if(packet)
|
||||
{
|
||||
//printf((char*) packet->data);
|
||||
httpConnection->ProcessTCPPacket(packet);
|
||||
tcp->DeallocatePacket(packet);
|
||||
}
|
||||
httpConnection->Update();
|
||||
|
||||
if (httpConnection->IsBusy()==false)
|
||||
{
|
||||
RakString fileContents = httpConnection->Read();
|
||||
printf(fileContents.C_String());
|
||||
_getche();
|
||||
return;
|
||||
}
|
||||
// Prevent 100% cpu usage
|
||||
RakSleep(30);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("PHP Directory server 2.\n");
|
||||
printf("Similar to lightweight database, but uses common shared webservers.\n");
|
||||
printf("Set columns and one row for your game, and upload it to a\nviewable and downloadable webpage.\n");
|
||||
printf("Difficulty: Intermediate\n\n");
|
||||
|
||||
tcp = SLNet::OP_NEW<TCPInterface>(__FILE__,__LINE__);
|
||||
httpConnection = SLNet::OP_NEW<HTTPConnection>(__FILE__,__LINE__);
|
||||
phpDirectoryServer2 = SLNet::OP_NEW<PHPDirectoryServer2>(__FILE__,__LINE__);
|
||||
|
||||
|
||||
|
||||
// RakNetTime lastTouched = 0;
|
||||
|
||||
// Start the TCP thread. This is used for general TCP communication, whether it is for webpages, sending emails, or telnet
|
||||
tcp->Start(0, 64);
|
||||
|
||||
TestPHPDirectoryServer(argc,argv);
|
||||
|
||||
//TestGet();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user