Register for your free account! | Forgot your password?
Rust Cheats

You last visited: Today at 11:39

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

Advertisement



[PHP]Player information lib mit cache

Discussion on [PHP]Player information lib mit cache within the Metin2 PServer Guides & Strategies forum part of the Metin2 Private Server category.

Reply
 
Old   #1
 
.Inya's Avatar
 
elite*gold: 50
Join Date: Mar 2013
Posts: 2,401
Received Thanks: 1,613
[PHP]Player information lib mit cache

Nur für leute mit Php kenntnissen gedacht!

Also wenn ihr auf der hp iwas machen wollt, sei es im ACP details zu einem character auszugeben oder sonstiges könnte euch das hier unterstützen. Habs aus purer lw gemacht aber kommt mir nicht mit kleine rls! Das sind 2h arbeit gewesen ja! xD

Naja die cache files sehen so aus:

PHP Code:
ID:::11159
NAME
:::Rain
LEVEL
:::80
ACC_ID
:::1
EXP
:::277
JOB
:::6
X
:::64184
Y
:::183833
MAP
:::21
E_X
:::64184
E_Y
:::183833
E_MAP
:::21
HP
:::3693
MP
:::1722
PLAYTIME
:::79
VIT
:::3
STR
:::5
INT
:::5
DEX
:::3
STATS
:::238
GOLD
:::0
IP
:::5.148.132.52
SKGRP
:::1
HORSE_LEVEL
:::0
RIDING
:::0
HSTATS
:::0
STATRESET
:::0
CHANGENAME
:::0
SKILL_POINT
:::0
LAST_PLAY
:::2011-05-16 16:02:57
ALIGNMENT
:::491 
Hier der code:


PHP Code:
<?php
class char{
    function 
__construct(){
        
$this->charinfo['id'] = 0;
        
$this->charinfo['name'] = "";
        
$this->charinfo['level'] = 0;
        
$this->charinfo['account_id'] = 0;
        
$this->charinfo['exp'] = 0;
        
$this->charinfo['job'] = 0;
        
$this->charinfo['x'] = 0;
        
$this->charinfo['y'] = 0;
        
$this->charinfo['map_index'] = 0;
        
$this->charinfo['exit_x'] = 0;
        
$this->charinfo['exit_y'] = 0;
        
$this->charinfo['exit_map_index'] = 0;
        
$this->charinfo['hp'] = 0;
        
$this->charinfo['mp'] = 0;
        
$this->charinfo['playtime'] = 0;
        
$this->charinfo['ht'] = 0;
        
$this->charinfo['st'] = 0;
        
$this->charinfo['iq'] = 0;
        
$this->charinfo['dx'] = 0;
        
$this->charinfo['stat_point'] = 0;
        
$this->charinfo['skill_point'] = 0;
        
$this->charinfo['alignment'] = 0;
        
$this->charinfo['last_play'] = "";
        
$this->charinfo['gold'] = 0;
        
$this->charinfo['ip'] = "";
        
$this->charinfo['skill_group'] = 0;
        
$this->charinfo['horse_level'] = 0;
        
$this->charinfo['horse_riding'] = 0;
        
$this->charinfo['horse_skill_point'] = 0;
        
$this->charinfo['stat_reset_count'] = 0;
        
$this->charinfo['change_name'] = 0;
        
$this->cache = new char_cachemanager();
    }
    
    public function 
loadPlayerById($id$reload false){
        
$cached_char $this->cache->loadCharById($id);
        if(
$cached_char != false && $reload == false){
            
$this->charinfo['id'] = $id;
            
$this->charinfo['name'] = $cached_char['NAME'];
            
$this->charinfo['level'] = $cached_char['LEVEL'];
            
$this->charinfo['account_id'] = $cached_char['ACC_ID'];
            
$this->charinfo['exp'] = $cached_char['EXP'];
            
$this->charinfo['job'] = $cached_char['JOB'];
            
$this->charinfo['x'] = $cached_char['X'];
            
$this->charinfo['y'] = $cached_char['Y'];
            
$this->charinfo['map_index'] = $cached_char['MAP'];
            
$this->charinfo['exit_x'] = $cached_char['E_X'];
            
$this->charinfo['exit_y'] = $cached_char['E_Y'];
            
$this->charinfo['exit_map_index'] = $cached_char['E_MAP'];
            
$this->charinfo['hp'] = $cached_char['HP'];
            
$this->charinfo['mp'] = $cached_char['MP'];
            
$this->charinfo['playtime'] = $cached_char['PLAYTIME'];
            
$this->charinfo['ht'] = $cached_char['VIT'];
            
$this->charinfo['st'] = $cached_char['STR'];
            
$this->charinfo['iq'] = $cached_char['INT'];
            
$this->charinfo['dx'] = $cached_char['DEX'];
            
$this->charinfo['stat_point'] = $cached_char['STATS'];
            
$this->charinfo['skill_point'] = $cached_char['SKILL_POINT'];
            
$this->charinfo['alignment'] = $cached_char['ALIGNMENT'];
            
$this->charinfo['last_play'] = $cached_char['LAST_PLAY'];
            
$this->charinfo['gold'] = $cached_char['GOLD'];
            
$this->charinfo['ip'] = $cached_char['IP'];
            
$this->charinfo['skill_group'] = $cached_char['SKGRP'];
            
$this->charinfo['horse_level'] = $cached_char['HORSE_LEVEL'];
            
$this->charinfo['horse_riding'] = $cached_char['RIDING'];
            
$this->charinfo['horse_skill_point'] = $cached_char['HSTATS'];
            
$this->charinfo['stat_reset_count'] = $cached_char['STATRESET'];
            
$this->charinfo['change_name'] = $cached_char['CHANGENAME'];
            return 
$this->charinfo;
        } else {
            
$player_mysql mysql_query("SELECT `id`, `account_id`, `name`, `job`, `voice`, `dir`, `x`, `y`, `z`, `map_index`, `exit_x`, `exit_y`, `exit_map_index`, `hp`, `mp`, `stamina`, `random_hp`, `random_sp`, `playtime`, `level`, `level_step`, `st`, `ht`, `dx`, `iq`, `exp`, `gold`, `stat_point`, `skill_point`, `quickslot`, `ip`, `part_main`, `part_base`, `part_hair`, `skill_group`, `skill_level`, `alignment`, `last_play`, `change_name`, `mobile`, `sub_skill_point`, `stat_reset_count`, `horse_hp`, `horse_stamina`, `horse_level`, `horse_hp_droptime`, `horse_riding`, `horse_skill_point` FROM `player`.`player` WHERE id = ".$id);
            
$player mysql_fetch_array($player_mysql);
            if(!
$player)
                return 
false;
            foreach (
$player as $key => $info){
                if(!
is_numeric($key))
                    
$this->charinfo[$key] = $info;
            }
            
$this->cache->writeCache($this->charinfo);
            return 
$this->charinfo;
        }
    }
    
    public function 
loadPlayerByName($name$reload false){
        
$cached_char $this->cache->loadCharByName($name);
        if(
$cached_char != false && $reload == false){
            
$this->charinfo['id'] = $cached_char['ID'];
            
$this->charinfo['name'] = $cached_char['NAME'];
            
$this->charinfo['level'] = $cached_char['LEVEL'];
            
$this->charinfo['account_id'] = $cached_char['ACC_ID'];
            
$this->charinfo['exp'] = $cached_char['EXP'];
            
$this->charinfo['job'] = $cached_char['JOB'];
            
$this->charinfo['x'] = $cached_char['X'];
            
$this->charinfo['y'] = $cached_char['Y'];
            
$this->charinfo['map_index'] = $cached_char['MAP'];
            
$this->charinfo['exit_x'] = $cached_char['E_X'];
            
$this->charinfo['exit_y'] = $cached_char['E_Y'];
            
$this->charinfo['exit_map_index'] = $cached_char['E_MAP'];
            
$this->charinfo['hp'] = $cached_char['HP'];
            
$this->charinfo['mp'] = $cached_char['MP'];
            
$this->charinfo['playtime'] = $cached_char['PLAYTIME'];
            
$this->charinfo['ht'] = $cached_char['VIT'];
            
$this->charinfo['st'] = $cached_char['STR'];
            
$this->charinfo['iq'] = $cached_char['INT'];
            
$this->charinfo['dx'] = $cached_char['DEX'];
            
$this->charinfo['stat_point'] = $cached_char['STATS'];
            
$this->charinfo['skill_point'] = $cached_char['SKILL_POINT'];
            
$this->charinfo['alignment'] = $cached_char['ALIGNMENT'];
            
$this->charinfo['last_play'] = $cached_char['LAST_PLAY'];
            
$this->charinfo['gold'] = $cached_char['GOLD'];
            
$this->charinfo['ip'] = $cached_char['IP'];
            
$this->charinfo['skill_group'] = $cached_char['SKGRP'];
            
$this->charinfo['horse_level'] = $cached_char['HORSE_LEVEL'];
            
$this->charinfo['horse_riding'] = $cached_char['RIDING'];
            
$this->charinfo['horse_skill_point'] = $cached_char['HSTATS'];
            
$this->charinfo['stat_reset_count'] = $cached_char['STATRESET'];
            
$this->charinfo['change_name'] = $cached_char['CHANGENAME'];
            return 
$this->charinfo;
        } else {
            
$player_mysql mysql_query("SELECT `id`, `account_id`, `name`, `job`, `voice`, `dir`, `x`, `y`, `z`, `map_index`, `exit_x`, `exit_y`, `exit_map_index`, `hp`, `mp`, `stamina`, `random_hp`, `random_sp`, `playtime`, `level`, `level_step`, `st`, `ht`, `dx`, `iq`, `exp`, `gold`, `stat_point`, `skill_point`, `quickslot`, `ip`, `part_main`, `part_base`, `part_hair`, `skill_group`, `skill_level`, `alignment`, `last_play`, `change_name`, `mobile`, `sub_skill_point`, `stat_reset_count`, `horse_hp`, `horse_stamina`, `horse_level`, `horse_hp_droptime`, `horse_riding`, `horse_skill_point` FROM inyaproduction_.`player` WHERE name = '".$name."'") or die(mysql_error());
            
$player mysql_fetch_array($player_mysql);
            if(!
$player)
                return 
false;
            foreach (
$player as $key => $info){
                if(!
is_numeric($key))
                    
$this->charinfo[$key] = $info;
            }
            
$this->cache->writeCache($this->charinfo);
            return 
$this->charinfo;
        }
    }

    public function 
setCacheTime($seconds){
        
$this->cache->setCacheTime($seconds);
    }

    function 
__destruct(){
    }
    
}

class 
char_cachemanager{
    function 
__construct(){
        
$this->cachedir "./cached_chars/";
        if(!
is_dir($this->cachedir)){
            
mkdir($this->cachedir);
        }
        
$this->chars = array();
        if(!
$this->loadCachedChars())
            die(
"Character Cache: Error on loading cache");
        
$this->cachetime 300//5 minutes
    
}

    public function 
setCacheTime($seconds){
        
$this->cachetime $seconds;
    }
    public function 
loadCachedChars(){
        
$cachefiles scandir($this->cachedir);
        foreach (
$cachefiles as $file) {
            if(!(
$file == "." or $file == "..")){
                
$filename $file;
                
$temp explode("."$file);
                
$file $temp[0];
                
$data explode("_"$file);
                
$this->chars[$data[0]]['name'] = $data[1];
                
$this->chars[$data[0]]['time'] = $data[2];
                
$this->chars[$data[0]]['filename'] = $filename;
            }
        };
        return 
true;
    }
    
    public function 
loadFile($filename){
        if(
file_exists($this->cachedir.$filename)){
            
$data file_get_contents($this->cachedir.$filename);
            
$lines explode("\n"$data);
            
$character = array();
            foreach(
$lines as $line){
                
$detail explode(":::"$line);
                
$character[$detail[0]] = $detail[1];
            }
            return 
$character;
        }
        return 
false;
    }
    
    public function 
loadCharById($id){
        if(isset(
$this->chars[$id]) && $this->chars[$id]['time'] + $this->cachetime time())
            return 
$this->loadFile($this->chars[$id]['filename']);

        return 
false;
    }
    
    public function 
loadCharByName($name){
        foreach(
$this->chars as $key => $char){
            if(
$char['name'] == $name && $this->chars[$key]['time'] + $this->$cachetime time())
                return 
$this->loadFile($this->chars[$key]['filename']);
        }
        return 
false;
    }
    
    public function 
writeCache($array){
        
$filename $array['id']."_".$array['name']."_".time();
        
$file fopen($this->cachedir.$filename'w');
        
$text "
ID:::"
.$array['id']."
NAME:::"
.$array['name']."
LEVEL:::"
.$array['level']."
ACC_ID:::"
.$array['account_id']."
EXP:::"
.$array['exp']."
JOB:::"
.$array['job']."
X:::"
.$array['x']."
Y:::"
.$array['y']."
MAP:::"
.$array['map_index']."
E_X:::"
.$array['exit_x']."
E_Y:::"
.$array['exit_y']."
E_MAP:::"
.$array['exit_map_index']."
HP:::"
.$array['hp']."
MP:::"
.$array['mp']."
PLAYTIME:::"
.$array['playtime']."
VIT:::"
.$array['ht']."
STR:::"
.$array['st']."
INT:::"
.$array['iq']."
DEX:::"
.$array['dx']."
STATS:::"
.$array['stat_point']."
GOLD:::"
.$array['gold']."
IP:::"
.$array['ip']."
SKGRP:::"
.$array['skill_group']."
HORSE_LEVEL:::"
.$array['horse_level']."
RIDING:::"
.$array['horse_riding']."
HSTATS:::"
.$array['horse_skill_point']."
STATRESET:::"
.$array['stat_reset_count']."
CHANGENAME:::"
.$array['change_name']."
SKILL_POINT:::"
.$array['skill_point']."
LAST_PLAY:::"
.$array['last_play']."
ALIGNMENT:::"
.$array['alignment'];
        
fwrite($file$text);
    }
    
}

$character = new char();
print_r($character->loadPlayerByName("Rain"));
Have fun with that :P

Methoden:
loadPlayerByName($name)
loadPlayerById($id)
setCacheTime($seconds)

unten drunter istn beispiel mit print_r ;D
mysql verbindung muss stehen
.Inya is offline  
Thanks
7 Users
Old 03/20/2014, 21:25   #2
 
elite*gold: 0
Join Date: Mar 2014
Posts: 17
Received Thanks: 2
Du solltest den Code evtl. in ein Tag packen, so sieht das echt grausam aus und ich mag es gar nicht bewerten ._. Was du dir aber angewöhnen solltest, lass den mysql_query - Kram weg, nutze neuere Methoden dafür.
ლ(ಠ益ಠლ) is offline  
Thanks
1 User
Old 03/20/2014, 21:27   #3


 
.Marcel''s Avatar
 
elite*gold: 100
Join Date: Sep 2009
Posts: 8,143
Received Thanks: 2,763
WIe mein Vorposter schon gesagt hat, bitte die PHP-Tags nutzen, und die mysql_* Funktionen sind veraltet. Das könntest du noch besser machen, aber ansich eine nette Idee.
.Marcel' is offline  
Old 03/20/2014, 21:32   #4
 
.Inya's Avatar
 
elite*gold: 50
Join Date: Mar 2013
Posts: 2,401
Received Thanks: 1,613
Ich weiß mysql query ist kacke.. aber ist halt fürs hen cms. Da es eh nur leute mit ahnung nutzen können, kann man da ja wohl easy eben mysqli oder PDO einbauen
.Inya is offline  
Old 03/21/2014, 12:33   #5
 
Sphinx²'s Avatar
 
elite*gold: 1918
Join Date: Feb 2008
Posts: 1,368
Received Thanks: 1,287
Du schreibst hier echt so ca. 75% deines Codes umsonst....

Das hab ich kurz in 5 Minuten geschrieben.
Kurze Erklärung: Du kannst mit json_encode & json_decode ganz einfach
Arrays in einen String umwandeln und wieder zurück.
Ich versteh einfach nicht warum du im constructor soviele defines machst die einfach kein Mensch braucht.
PHP Code:
<?php

    
class player {        
        public function 
loadData($name) {
            if(
$this->cacheExists()) {
                
$query dbmanager::instance()->query("SELECT * FROM player where name = '".dbmanager::instance()->escape($name)."'");
                if(
$query) {
                    
$this->player dbmanager::instance()->fetcha($query);
                    
$this->writeToCache(3600);
                    return 
$this->player;
                } else {
                    return 
false;    
                }
            } else {
                return 
$this->getCachedPlayer();
            }
        }
        
        public function 
cacheExists() {
            .....
            return 
false;    
        }
        
        public function 
getCachedPlayer() {
            ...
            
$this->player json_decode($data); // Loaded text from text file
            
return $this->player;
        }
        
        public function 
writeToCache($time) {
            .....
            
$data json_encode($this->player);     // Arrrrraay to text (for text file ;*)
            
fwrite($txthandle,$data,strlen($data));
        }
    }

        
$player = new player();
        
$info $player->loadData("Sphinx");
        
var_dump($info);
?>
Und als Cache würde ich dir phpfastcache library empfehlen.
Die Library hat echt eine hohe Performance und schreibt auch in die Memory wenns der Server unterstützt.
Das was du hier machst ist auch nicht wirklich so toll.

Freundliche Grüsse
Sphinx
Sphinx² is offline  
Thanks
1 User
Old 03/21/2014, 12:48   #6
 
.Inya's Avatar
 
elite*gold: 50
Join Date: Mar 2013
Posts: 2,401
Received Thanks: 1,613
Quote:
Originally Posted by Sphinx² View Post
Du schreibst hier echt so ca. 75% deines Codes umsonst....

Das hab ich kurz in 5 Minuten geschrieben.
Kurze Erklärung: Du kannst mit json_encode & json_decode ganz einfach
Arrays in einen String umwandeln und wieder zurück.
Ich versteh einfach nicht warum du im constructor soviele defines machst die einfach kein Mensch braucht.
PHP Code:
<?php

    
class player {        
        public function 
loadData($name) {
            if(
$this->cacheExists()) {
                
$query dbmanager::instance()->query("SELECT * FROM player where name = '".dbmanager::instance()->escape($name)."'");
                if(
$query) {
                    
$this->player dbmanager::instance()->fetcha($query);
                    
$this->writeToCache(3600);
                    return 
$this->player;
                } else {
                    return 
false;    
                }
            } else {
                return 
$this->getCachedPlayer();
            }
        }
        
        public function 
cacheExists() {
            .....
            return 
false;    
        }
        
        public function 
getCachedPlayer() {
            ...
            
$this->player json_decode($data); // Loaded text from text file
            
return $this->player;
        }
        
        public function 
writeToCache($time) {
            .....
            
$data json_encode($this->player);     // Arrrrraay to text (for text file ;*)
            
fwrite($txthandle,$data,strlen($data));
        }
    }

        
$player = new player();
        
$info $player->loadData("Sphinx");
        
var_dump($info);
?>
Und als Cache würde ich dir phpfastcache library empfehlen.
Die Library hat echt eine hohe Performance und schreibt auch in die Memory wenns der Server unterstützt.
Das was du hier machst ist auch nicht wirklich so toll.

Freundliche Grüsse
Sphinx
Ja ich weiß die defines im Constructor sind unnötig.. bin iwie zu sehr an andere sprachen gewöhnt momentan :S an den json kram hatte ich iwie nicht gedacht auch wenn ich andauernd damit arbeiten muss o.o naja wie gesagt war eine lw Sache^^ trd danke für den Gedankenstoß
.Inya is offline  
Old 03/21/2014, 20:25   #7
 
Sphinx²'s Avatar
 
elite*gold: 1918
Join Date: Feb 2008
Posts: 1,368
Received Thanks: 1,287
Kein Thema...

Btw: Mit der Fastcachelibrary kannst du automatisch arrays speichern.
Sie müssen nicht in einen JSON String umgewandelt werden.
Dazu gibt es ne gute Dokumentation.
Mein neues CMS was ich schreibe verwende ich das ziemlich oft für alle Sachen die eigentlich unnötig oft abgerufen werden.

Evtl. Release ich das wenn ich es nicht mehr brauche und mit Metin2 abgeschlossen habe.

Freundliche Grüsse
Sphinx
Sphinx² is offline  
Reply


Similar Threads Similar Threads
GTA 5: new Information regarding Single- and Multi-player Mode
07/13/2013 - Gaming News - EN - 14 Replies
Rockstar Games - developer of GTA 5, which is probably the most famous game of this year - seems to be near and dear to their fanbase. They have answered many interesting and frequently asked question during a Community Q&A (Question & Answer), which were about characters, weapons, vehicles and, of course, the multi-player mode. First of all we would like to shine light on one of the most discussed topics: the multi-player mode. Unfortunately, Rockstar Games provided us with very few...
[Source]Core Server Crash / Cache:destroy player or group
03/26/2011 - Flyff Private Server - 11 Replies
Guten Abend liebe Com., Derzeit arbeite ich ein wenig am Source der hier auf ePvPers verwendet wird. (Direkt voran: Wenns am Source liegt, habt ihr evtl. einen anderen Link?) Doch habe ich schon ein großes Problem. Mein CoreServer.exe schmiert die ganze Zeit ab und die CacheServer.exe sieht dann wie folgt aus: http://www.b-flyff.de/coreserver.png
[Information] Was bedeuten die Zahlen oben?, Was bekomme ich? [Information]
12/16/2010 - WarRock - 3 Replies
Hi com, wie bestimmt schon ihr alle bemerkt habt, gab es ein Update und somit ein neues Event (Habe ich aber auch gestern gegen 02:00 Uhr gepostet. Also ich möchte hier mal Klarstellen, was es mit dem Event aufsich hat. -Was bedeuten diese Zahlen oben Links? Also, Links steht am Anfang 300, das heißt ihr müsst 300 Kills mit Schneebällen erreichen und bekommt Anschließend einen Preis! Nach 300 kommen 500, dannach 700 und Anschließend 900, vielleicht mehr, was ich leider nicht weiss.
cache.csv
08/06/2008 - Dekaron - 2 Replies
Hey, That could be also my problem. (My Problem!) That comes if I 2Moons closes. How can I repair that? http://img384.imageshack.us/img384/9379/unbenannt rm8.png



All times are GMT +1. The time now is 11:42.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.