View Full Version : [share] PHP <-> CacheD
While working on the user control panel we use at our server, I was fed up to always have to think about cached,
so I've done a PHP file, easy to include, who helped quite a lot.
I think many of you already did that, but no one shared it, so if it's usefull to someone (in fact part of the code is leeched from the cached topic in General, so don't blame me if you see something yours).
I contain 3 PHP classes: CacheD, CacheD_chatterbox and CacheD_color_chatterbox.
The first one output True and False, depending on the success or not of the packet.
The second and third one output a message.
If you're not familiar with PHP objects, here you have an example
include('cached.php');
$char_id = 743;
$cached = new CacheD;
echo (($cached -> CheckCharacterPacket($char_id)? 'The character is online':'The character is offline');
$cached2 = new CacheD_chatterbox;
echo $cached2 -> CheckCharacterPacket($char_id); //print 'ok' or 'Char not in game.'
If you want to change a name, you may do something like that:
include('cached.php');
$char_id = 743;
$newname = 'Eloims';
$cached = new CacheD;
if ($cached -> KickCharacterPacket($char_id)) {
$cached -> ChangeCharacterNamePacket($char_id, $newname);
}
//if the character is correctly kicked (or wasn't online), then change his name
The supported packets are:
#1 CheckCharacterPacket
#2 SetCharacterLocationPacket
#3 SetBuilderCharacterPacket
#4 ChangeCharacterNamePacket
#5 KickCharacterPacket
#6 AddSkillPacket
#7 DelSkillPacket
#8 ModSkillPacket
#13 DelItemPacket
#15 ModCharPacket
#16 ModChar2Packet
#18 PunishCharPacket
#19 SetBuilderAccountPacket
#20 DisableCharacterPacket
#21 EnableCharacterPacket
#29 ModChar3Packet
#31 MoveCharacterPacket
#34 DeleteCharPacket
#37 PledgeChangeOwnerPacket
#38 PledgeDeletePacket
#39 BanCharPacket
#45 SendHomePacket
#46 ChangePledgeLevelPacket
#47 CreatePledgePacket
#48 SetSkillAllPacket
#49 RestoreCharToAccount
#51 ManIntAnnouncePacket
#55 AddItem2Packet
#69 SetSociality
#70 SetInstantAnnouncePacket
#89 ChangeSubJobPacket
#90 StopCharPacket
#101 SendPrivateAnnouncePacket
#104 EternalBanPacket
when I tested
#37 PledgeChangeOwnerPacket
#38 PledgeDeletePacket
#101 SendPrivateAnnouncePacket
nothing happened, but cached returns x1
Вложения из исходного сообщения (сами файлы в копии отсутствуют):
cached.rar — 2460 байт
_Untitled
02.05.2007, 12:37
Nice share
Delete char packet supported .... hmm ....
function RestoreCharToAccount($char_id,$new_char_name,$acco unt_id,$account_name) {
$buf = pack("c", 49);
$buf .= pack("V", $char_id);
$buf .= tounicode($new_char_name);
$buf .= pack("V", $account_id);
$buf .= tounicode($account_name);
$buf .= $this -> tounicode($this -> webadmin);
return $this -> CacheDInteractive($buf);
}
some func's
function AddHennaChar($char_id,$henna_id) {
$buf = pack("c", 72);
$buf .= pack("V", $char_id);
$buf .= pack("V", $henna_id);
$buf .= $this -> tounicode($this -> webadmin);
return $this -> CacheDInteractive($buf);
}
function DelHennaChar($char_id,$henna_id) {
$buf = pack("c", 71);
$buf .= pack("V", $char_id);
$buf .= pack("V", $henna_id);
$buf .= $this -> tounicode($this -> webadmin);
return $this -> CacheDInteractive($buf);
}
function SetQuestToChar($char_id,$quest_id,$queststate) {
$buf = pack("c", 10);
$buf .= pack("V", $char_id);
$buf .= pack("V", $quest_id);
$buf .= pack("V", $queststate);
$buf .= $this -> tounicode($this -> webadmin);
return $this -> CacheDInteractive($buf);
}
function DelQuestToChar($char_id,$quest_id) {
$buf = pack("c", 11);
$buf .= pack("V", $char_id);
$buf .= pack("V", $quest_id);
$buf .= $this -> tounicode($this -> webadmin);
return $this -> CacheDInteractive($buf);
}
GJ. I see my CacheDInteractive function there :D
Your functions looks similar to mine, same style, i suppose you take as reference some of those i show in the cached thread.
ok, I updated the file with RestoreCharToAccount ^^
FidoW> indeed I just copy/pasted the cachedinteractive function from your post ^^
PyroMaker
02.05.2007, 15:12
Thanks for sharing Eloims, I'm sure it will help a lot of people.
Thanks for sharing Eloims, I'm sure it will help a lot of people.(about me) I never used this feature and no want. :) This need only for admins with donations. I never use it, because i dont change gameplay.
What i told? Ah sorry... nvm.
Aikeleer
02.05.2007, 17:34
It's also extraordinary handy for managing multiple servers together with the petition server.
Thanks a bunch for this share, I've made a similar script and a lot looks alike (I also copied FidoW's function :x)
(about me) I never used this feature and no want. :) This need only for admins with donations. I never use it, because i dont change gameplay.
What i told? Ah sorry... nvm.
I dont change gameplay, i dont use functions like AddItem... or AddSkill.. etc etc... but is very usefull some like Ban... InstantAnnounce... you know...
[DeV/NuLL]
07.05.2007, 01:25
I love how you guys dont add any type of Security Checks into your Cached working code, that's so cool, really....
;85411']I love how you guys dont add any type of Security Checks into your Cached working code, that's so cool, really....
yah! thats true... this script dont have security checks... some people maybe use protected directorys... in my case i have a table in database with allowed accounts, in the past i was using builder_account table but we required different permisions for web and game.. so... i create a new one... thats an idea for you Eloims ;)
[DeV/NuLL]
07.05.2007, 02:15
Add builder level checks to those Packet funcs will be also a good idea. You can think, my Site code prevent any unleveled builder to use some func, but as far as I know is better if you add the security checks at Object Implemetation than Site implementation.
This is only a Tip.
Aikeleer
07.05.2007, 06:24
These are only classes waited to be implemented into a bigger script. I don't think Eloims originally intended to fix security for all the leechers.
[DeV/NuLL]
07.05.2007, 12:27
These are only classes waited to be implemented into a bigger script. I don't think Eloims originally intended to fix security for all the leechers.
I remember when this forum was a developers place discussion, old times, isn't it?
Btw, you stole my sign :P
tpuNIsher
08.05.2007, 11:59
Can i leech? XD
wow
I didn't exept to have so many answer with just that little share
I didn't include security on the object because I don't use that file only for administrative purpose, and my users can use some cached functions (with a lot a restrictions of course :p )
I explain:
maybe many l2off servers have solved that problem but I'm not fond of asm or that kind of things, so I couln't do it "the right way":
many players at my server complained because only the leader of a pledge can get items from the pledge warehouse, and it's quite uncool for big pledges, because the leader does nothing else than being in the CH and managing the warehouse
so (if the pledge leader previously allowed them in the web), any player can move items from his pledge warehouse to his own warehouse with cached functions
the script of course is secure (well I hope that, because I havn't got a lot of experience xD ) and players can do nothing but moving items, if they're allowed to do so.
it is only an example
another packet that could be usefull for players is changename is you have a roleplay server
Changing l2font you can make the underscore "_" look like a space " " and then allow your players to choose a family name (of course you allow that only once per character)
if a player is called "Eloims"
cached can change his name into "Eloims_Alderahim"
It's very usefull for weddings:
if "Eloims_Alderahim" and "Aria_Holia" have gotten married, an admin can change Aria's name to be "Aria_Alderahim" and so on.
I may add some packets if I've got some time to do so, but I've no intention of adding security in this, because I do all the checks in the website
Nevertheless It could be interesting to do that
if someone wants to do it, I will welcome it (an maybe use it)
could be quite easy just adding a class that extends the one I did and that overide the cacheDinteractive function with another one that checks what you need to check for your security
or maybe just adding a Construtor function to the object, that could do the same
edit: sorry for bad english
but hey, it's well known that french people is bad at english
I've got an excuse
[DeV/NuLL]
09.05.2007, 00:43
Well, really you didn't need to explain why you coded with or without security, was just a tip, anyway the actions you allow to your players on your server are extremely danguerous, cos any HTML or PHP (or RAM) scripter can send unauthorized IDs to your code to move anyone item at world to his account, if you want to know how they can do that just pm me.
Greetings.
I do manys checks before moving anything
they cannot move an items if it's not an item from their pledge warehouse
i'm not dumb enought to do something like this to manage the form result
foreach ($_POST as $item) {
moveitem(blablabla);
}
it's very easy to query in the database the list of uids of the items that are in the right pledge warehouse, and only moving these
I cann't be sure @ 100% that my whole website is secure, but no one can, and, if it's true that anyone how read the source could tell me to change this or that for improving security,
without reading the sources it's quite strange to hear someone saying it's insecure
It's like saying to microsoft that hotmail servers are insecure because they allow people to read their mails, and then, maybe bad people to read foreign mails.
The only way to use unautorized cached fonction would be PHP injection I think, and if someone is able to php inject my web, I think that cached doesn't really matters, because they've got full control of the machine
well that's what I believe at least