Version 0.95 BETA

This commit is contained in:
OTCv8
2019-10-02 03:38:52 +02:00
parent 9219c78f15
commit 5220a3bdd2
501 changed files with 38097 additions and 2 deletions

11
api/crash.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
$data = file_get_contents("php://input", false, stream_context_get_default(), 0, $_SERVER["CONTENT_LENGTH"]);
if($_REQUEST['txt'] == 1) {
file_put_contents("crashes/".time()."_".$_SERVER['REMOTE_ADDR'].".txt", $data);
} else if($_REQUEST['txt'] == 2) {
file_put_contents("crashes/".time()."_".$_SERVER['REMOTE_ADDR'].".log", $data);
} else {
file_put_contents("crashes/".time()."_".$_SERVER['REMOTE_ADDR'].".dmp", $data);
}
echo "OK";
?>

11
api/feedback.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
$data = file_get_contents("php://input");
//$data = json_decode($data);
if(empty($data)) {
return http_response_code(400);
}
file_put_contents("feedback.txt", $data."\n\n\n", FILE_APPEND);
echo "OK";
?>

BIN
api/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

182
api/login.php Normal file
View File

@@ -0,0 +1,182 @@
<?php
// author otclient@otclient.ovh
// config
$dbserver = "127.0.0.1";
$username = "otclient";
$password = "otclient";
$dbname = "otclient";
$serverName = "OTClientV8";
$serverIp = "otclient.ovh";
//$serverIp = "proxy"; // if serverIp set to 0.0.0.0 or proxy it will connect to server using proxies, set proxies bellow
$serverPort = 7172; // GAME PORT (7172 usually)
$version = 1099;
$maxLogins = 10; // 0 or null to disable
$blockTime = 60; // after too many logins, in seconds
// CREATE TABLE `login_attmpts` ( `acc` varchar(50) NOT NULL, `ip` varchar(30) NOT NULL, `date` datetime NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
$encryption = "sha1"; // sha1 or md5, everything else == none
// required files in things, type => (filename, md5 checksum in hex)
// $things = null; things can be null if you want to use default values, but then enable auto download of sprites and dat in updater
/* //for 860
$things = array(
"sprites" => array("$version/Tibia.spr", "3db8c0098d34ca3d9a8ec29d40ef1b7b"),
"data" => array("$version/Tibia.dat", "85785b5d67b4c111f780a74895c85c75")
);
*/
// for 1099
$things = array(
"sprites" => array("$version/Tibia.spr", "63d38646597649a55a8be463d6c0fb49"),
"data" => array("$version/Tibia.dat", "ae7157cfff42f14583d6363e77044df7")
);
$customProtocol = nil; // if not nil it will replace client version in protocolgame, may be used to detect outdated client
// executes modules.client_options.setOption(option, value, true)
$settings = array(
);
// it's from src/client/const.h, executes g_game.enableFeature/g_game.disableFeature
$features = array(
22 => true, // GameFormatCreatureName
25 => true, // GameExtendedClientPing
30 => true, // GameChangeMapAwareRange
// 56 => true, // GameSpritesAlphaChannel
80 => true,
90 => true, // GameNewWalking
// 91 => true, // GameSmootherWalking
95 => true, // GameBot
97 => true, // light
);
$rsa = "1091201329673994292788609605089955415282375029027981291234687579" .
"3726629149257644633073969600111060390723088861007265581882535850" .
"3429057592827629436413108566029093628212635953836686562675849720" .
"6207862794310902180176810615217550567108238764764442605581471797" .
"07119674283982419152118103759076030616683978566631413";
// proxies (it's custom feature, not available for free)
$proxies = array(
array(
"localPort" => 7172,
"host" => "51.158.184.57",
"port" => 7162,
"priority" => 0
),
array(
"localPort" => 7172,
"host" => "54.39.190.20",
"port" => 7162,
"priority" => 0
),
array(
"localPort" => 7172,
"host" => "51.83.226.109",
"port" => 7162,
"priority" => 0,
),
array(
"localPort" => 7172,
"host" => "35.247.201.100",
"port" => 443,
"priority" => 0
)
);
// config end
$data = file_get_contents("php://input");
$data = json_decode($data);
if(empty($data)) {
http_response_code(400);
}
if($data->quick == 1) {
// under development
http_response_code(404);
die();
}
$conn = new mysqli($dbserver, $username, $password, $dbname);
if ($conn->connect_error) {
die("SQL connection failed: " . $conn->connect_error);
}
$account = $data->account;
if($encryption == "sha1")
$password = sha1($data->password);
else if($encryption == "md5")
$password = md5($data->password);
else
$password = $data->password;
$token = $data->token;
$account = preg_replace("/[^A-Za-z0-9 ._-]/", '', $account);
$password = preg_replace("/[^A-Za-z0-9 ._-]/", '', $password);
$token = preg_replace("/[^A-Za-z0-9 ._-]/", '', $token);
$ip = preg_replace("/[^A-Za-z0-9 ._-]/", '', $_SERVER['REMOTE_ADDR']);
if($maxLogins != null && $maxLogins > 0) {
$result = $conn->query("select count(*) as `attempts` from `login_attmpts` where `ip` = '".$ip."' and `date` > NOW() - INTERVAL ".$blockTime." SECOND");
$result = $result->fetch_assoc();
if($result['attempts'] > $maxLogins) {
die(json_encode(array("error" => "Too many login attempts, please wait ".$blockTime." seconds.")));
}
$conn->query("INSERT INTO `login_attmpts` (`acc`, `ip`, `date`) VALUES ('".$conn->real_escape_string($account)."', '".$ip."', NOW())");
}
$result = $conn->query("select * from accounts where `name` = '".$conn->real_escape_string($account)."' and `password` = '".$conn->real_escape_string($password)."'");
if ($result->num_rows != 1) {
die(json_encode(array("error" => "Invalid account/password")));
}
$acc = $result->fetch_assoc();
$session = "".$data->account."\n".$data->password."\n$token\n".time();
if($serverIp != "proxy" && $serverIp != "0.0.0.0") {
$proxies = null;
}
$response = array(
"error" => "",
"rsa" => $rsa,
"version" => $version,
"things" => $things,
"customProtocol" => $customProtocol,
"session" => $session,
"characters" => array(),
"account" => array(),
"settings" => $settings,
"features" => $features,
"proxies" => $proxies
);
$response["account"]["status"] = 0; // 0=ok, 1=frozen, 2=supsended
$response["account"]["subStatus"] = 1; // 0=free, 1=premium
$response["account"]["premDays"] = 65535;
$characters = $conn->query("select * from `players` where `account_id` = '".$acc['id']."'");
if ($characters->num_rows == 0) {
die(json_encode(array("error" => "Account doesn't have any characters")));
}
while($character = $characters->fetch_assoc()) {
$response["characters"][] = array(
"name" => $character['name'],
"worldName" => $serverName,
"worldIp" => $serverIp,
"worldPort" => $serverPort
// if you are good enough and can code it in lua, you can add outfit, level, vocation, whatever you want here
);
}
echo json_encode($response);
?>

28
api/newlogin.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
function generateRandomString($length = 6) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$code = generateRandomString();
require_once("phpqrcode.php");
ob_start();
QRCode::png($code, null, QR_ECLEVEL_H, 7, 1);
$qrcode = base64_encode( ob_get_contents() );
ob_end_clean();
$data = array(
"qrcode" => $qrcode,
"code" => $code,
"status" => "waiting"
);
echo json_encode($data);
?>

35
api/news.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
$news = array();
$lang = "en";
if(isset($_GET['lang']))
$lang = $_GET['lang'];
$jokes = array();
$jokes[] = "How do you make a tissue dance? You put a little boogie in it.";
$jokes[] = "Why did the policeman smell bad? He was on duty.";
$jokes[] = "Why does Snoop Dogg carry an umbrella? FO DRIZZLE!";
$jokes[] = "Why can't you hear a pterodactyl in the bathroom? Because it has a silent pee.";
$jokes[] = "What did the Zen Buddist say to the hotdog vendor? Make me one with everything.";
$jokes[] = "What kind of bees make milk instead of honey? Boobies.";
$jokes[] = "Horse walks into a bar. Bartender says, 'Why the long face?'";
$jokes[] = "A mushroom walks into a bar. The bartender says, 'Hey, get out of here! We don't serve mushrooms here'. Mushroom says, 'why not? I'm a fungai!'";
$jokes[] = "I never make mistakes…I thought I did once; but I was wrong.";
$jokes[] = "What's Beethoven's favorite fruit? Ba-na-na-naaa!";
$jokes[] = "What did the little fish say when he swam into a wall? DAM!";
$jokes[] = "Knock knock. Who's there? Smell mop. (finish this joke in your head)";
$jokes[] = "Where does a sheep go for a haircut? To the baaaaa baaaaa shop!";
$jokes[] = "What does a nosey pepper do? Gets jalapeno business!";
$jokes[] = "Your mom is so poor, she even can't pay attention";
$news[] = array("title" => "TEST SERVERS", "text" => "OTCLIENTV8 Accs:\nacc1/acc\nacc2/acc\nacc3/acc");
$news[] = array("title" => "First title",
"text" => "This is example of lua g_http api. Those news are from http://otclient.ovh/news.php
\nRequest was for language '".$lang."', however, there's only english version of this, don't have time to create more versions");
$news[] = array("title" => "Random joke", "text" => $jokes[array_rand($jokes)]);
$news[] = array("title" => "Image test", "image" => base64_encode(file_get_contents("image.png")));
echo json_encode($news);
?>

3312
api/phpqrcode.php Normal file

File diff suppressed because it is too large Load Diff

13
api/stats.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
$data = file_get_contents("php://input");
$json = json_decode($data);
if(!$json || !$json->uid) {
die();
}
if($json->uid) {
file_put_contents("stats/".($json->uid).".log", "\n".$data."\n", FILE_APPEND);
}
echo "OK";
?>

96
api/updater.php Normal file
View File

@@ -0,0 +1,96 @@
<?php
// set chmod 777 to dir with this file to create checksum files
$data = file_get_contents("php://input");
$data = json_decode($data);
if(!empty($data)) {
$platform = $data->platform;
$version = $data->version; // currently not used
}
if($platform == "WIN32-WGL") { // opengl
$binary_path = "/otclient_gl.exe";
$checksums_file = "checksums_gl.txt";
} else if($platform == "WIN32-EGL") { // dx
$binary_path = "/otclient_dx.exe";
$checksums_file = "checksums_dx.txt";
} else {
$binary_path = "";
$checksums_file = "checksums.txt";
}
$data_dir = "/var/www/otclient/files";
$things_dir = "/data/things"; // files from that dir won't be downloaded automaticly, you can set it to null to download everything automaticly (useful if you have only 1 version of data/sprites)
$files_url = "http://otclient.ovh/files";
$update_checksum_interval = 60; // caling updater 100x/s would lag disc, we need to cache it
$main_files_and_dirs = array("data", "modules", "init.lua"); // used to ignore other files/dirs in data_dir
// CONFIG END
$data = array("url" => $files_url, "files" => array(), "things" => array(), "binary" => $binary_path);
function getDirFiles($dir, &$results = array()){
$files = scandir($dir);
foreach($files as $key => $value){
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
if(!is_dir($path)) {
$results[] = $path;
} else if($value != "." && $value != "..") {
getDirFiles($path, $results);
}
}
return $results;
}
function updateChecksums() {
global $data_dir;
global $main_files_and_dirs;
global $binary_path;
global $checksums_file;
global $data;
global $things_dir;
$ret = array();
$data_dir_realpath = realpath($data_dir);
$files = getDirFiles($data_dir);
foreach($files as $file) {
$relative_path = str_replace($data_dir_realpath, "", $file);
$ps = explode("/", $relative_path);
if($relative_path == $binary_path || (count($ps) >= 2 && in_array($ps[1], $main_files_and_dirs)))
$ret[$relative_path] = md5_file($file);
}
foreach($ret as $file => $checksum) {
if($things_dir != null && !empty($things_dir) && strpos($file, $things_dir) === 0) {
$data["things"][$file] = $checksum;
} else {
$data["files"][$file] = $checksum;
}
}
$ret = json_encode($data);
if(file_put_contents($checksums_file, $ret) === FALSE) {
echo "Can't create checksum file (try to set correct chmod) ". - $checksums_file;
exit();
}
return $ret;
}
if (function_exists('sem_get')) {
$semaphore = sem_get(18237192837, 1, 0666, 1);
if(!$semaphore)
{
echo "Failed to get semaphore - sem_get().\n";
exit();
}
sem_acquire($semaphore);
}
$ft = filemtime($checksums_file);
if($ft === false || $ft + $update_checksum_interval < time()) {
echo updateChecksums();
} else {
echo file_get_contents($checksums_file);
}
if (function_exists('sem_get')) {
sem_release($semaphore);
}
?>