Pages: [1] :: one page |
|
Author |
Thread Statistics | Show CCP posts - 0 post(s) |
Unforgiven Soldier
Order Of The Sentinel Phoenix Rising Alliance
|
Posted - 2007.10.19 22:30:00 -
[1]
This is what I have come up with while designing a new killboard for our alliance. I couldn't find any code to process killmail input so I created one and I have posted it here. If you find this code useful in any way please feel free to donate ISKies to Unforgiven Soldier. I hope this helps everyone out:
<?PHP function process_killmail($mail){
$mail = trim($mail); $mail = explode("\r\n", $mail);
$processMail = array(); $killmail = array(); foreach($mail as $k=>$v){ if(strlen($v) >= 2){ array_push($killmail, $v); } } $date = explode(' ', str_replace('.', '-', $killmail[0])); $processMail['timestamp']['date'] = $date[0]; $processMail['timestamp']['time'] = $date[1]; $processMail['victim']['name'] = str_replace('Victim: ', '', $killmail[1]); $processMail['victim']['alliance'] = str_replace('Alliance: ','', $killmail[2]); $processMail['victim']['corp'] = str_replace('Corp: ','', $killmail[3]); $processMail['victim']['ship'] = str_replace('Destroyed: ','', $killmail[4]); $processMail['system']['name'] = str_replace('System: ','', $killmail[5]); $processMail['system']['security'] = str_replace('Security: ','', $killmail[6]);
$count = count($killmail); for($i = 8; $i < $count; $i++){
if(substr($killmail[$i], 0, 16) !== 'Destroyed items:'){ for($s = 0; $s < 7; $s++){ if(substr($killmail[$i], 0, 5) == 'Name:'){ $m = $i - 6; $processMail['involved parties'][$m]['name'] = str_replace('Name: ', '', $killmail[$i]); }elseif(substr($killmail[$i], 0, 9) == 'Security:'){ $processMail['involved parties'][$m]['security'] = str_replace('Security: ', '', $killmail[$i]); }elseif(substr($killmail[$i], 0, 9) == 'Alliance:'){ $processMail['involved parties'][$m]['alliance'] = str_replace('Alliance: ', '', $killmail[$i]); }elseif(substr($killmail[$i], 0, 5) == 'Corp:'){ $processMail['involved parties'][$m]['corp'] = str_replace('Corp: ', '', $killmail[$i]); }elseif(substr($killmail[$i], 0, 5) == 'Ship:'){ $processMail['involved parties'][$m]['ship'] = str_replace('Ship: ', '', $killmail[$i]); }elseif(substr($killmail[$i], 0, 7) == 'Weapon:'){ $processMail['involved parties'][$m]['Weapon'] = str_replace('Weapon: ', '', $killmail[$i]); }
} }else{ break; }
} foreach($killmail as $k=>$v){ if(substr($v, 0, 16) == 'Destroyed items:'){ $destroyed_key = $k; } }
for($d = $destroyed_key+1; $d < $count; $d++){ if(strpos($killmail[$d], '(Cargo)')){ $processMail['destroyed']['cargo'][$d-$destroyed_key-1-count($processMail['destroyed']['fitting'])] = str_replace('(Cargo)', '', $killmail[$d]); }elseif(strpos($killmail[$d], '(Drone Bay)')){ $processMail['destroyed']['drone bay'][$d-$destroyed_key-1] = str_replace('(Drone Bay)', '', $killmail[$d]); }else{ $processMail['destroyed']['fitting'][$d-$destroyed_key-1] = $killmail[$d]; } }
}
?>
btw, this code only puts killmail data into an associative array, it DOES NOT in anyway validate the killmail. As I go along I will be posting more information and functions into this forum. I hope this helps if you are looking to code a killboard.
|
VaderX
|
Posted - 2007.10.20 00:35:00 -
[2]
kudos for doing it, but what do you expect to offer that eve-dev killboard doesn't to justify building a new one and people paying you isk for it? Also, are you taking into account the new killmail 1.5 that is going to released?
|
AliasXNeo
Gallente
|
Posted - 2007.10.20 00:54:00 -
[3]
Cool, but with new killmail and the API coming out you kind of picked a bad time to make it. ------------------------------ ~ AKA Josh ~ - Battleclinic Staff Developer - ------------------------------
|
Not US
|
Posted - 2007.10.20 05:50:00 -
[4]
Edited by: Not US on 20/10/2007 05:50:47
|
Unforgiven Soldier
Order Of The Sentinel Phoenix Rising Alliance
|
Posted - 2007.10.20 05:51:00 -
[5]
Edited by: Unforgiven Soldier on 20/10/2007 06:02:18 Already have it in the works, basically I am picking up where eve-dev.net left off in late 06. I have already created API websites to run on the IGB, its a pretty easy process. Unfortunately there is very little documentation on the subject of killmails for the new release, so I am forced at this point to continue pushing forward. I have a pretty good feeling they will incorporate the API system into the new kill tracking system with using the corporationID field as the passing argument and be able to pull in a full lists of kills for a given time period, which frankly enough will be easier to program for than a text area like this function I have posted. I did this because people have been asking for it and nobody has either sat down and worked it out or did not want to give their scripts away, to which I say it is open source and this is what makes it so great. The killboard I am working on wont be in the "alpha" phase until the end of the year, features I am toying with is an achievements section, whereas if you so choose you can give an achievement award to players based on a number of different areas (IE no. pod kills, no. solo kills, no. of specific ship type kills etc.). I am still at the drawing board phase and would really like some input on the subject. I know ActionScript as well, so of course a lot of pretty line graphs and such. I hope this sparks some interest in people, I am doing this for our alliance. The prospect of making some isk in the process is always nice of course, but not the driving force. This forum post will be the medium for this killboard, at which time if the EVE-Dev teams decides to go the API route I will of course write a function and post it here for the public. Until my next post, I do hope you find my scripts useful, if not please drop me a line either here or in-game and let me know what you would like to see changed or added.
|
dimensionZ
Reikoku Band of Brothers
|
Posted - 2007.10.20 09:03:00 -
[6]
The code is kinda "dirty" and it doesnt handle "old" killmails, with everything that it means (old date style, old typos (remember cristaline!), ...). ----------------------------------------
|
Ryysa
Caldari
|
Posted - 2007.10.20 11:05:00 -
[7]
You really need to learn to use regex :(
It will make your life a lot easier, this code is pretty awful right now. EW Guide - KB Tool - My Music |
Unforgiven Soldier
Order Of The Sentinel Phoenix Rising Alliance
|
Posted - 2007.10.20 19:31:00 -
[8]
Thanks for the comments, I know its a bit primitive right now, this took about 15 minutes and I really didnt want to put too much effort since I am pretty sure the API system will be introduced next month. I will tweak it a bit and see what I can come up with. I have been programming with PHP for 5 years, so if you could please post the mail that you were having trouble with I will run through it and get it to parse.
|
dimensionZ
Reikoku Band of Brothers
|
Posted - 2007.10.20 23:59:00 -
[9]
Dont mean to be harsh, but 5 years and you code something like that ? You might have coded that in 15 minutes and stuff, but its really not pretty! ----------------------------------------
|
Ryysa
Caldari
|
Posted - 2007.10.21 00:14:00 -
[10]
Originally by: dimensionZ Dont mean to be harsh, but 5 years and you code something like that ? You might have coded that in 15 minutes and stuff, but its really not pretty!
What he said.
I don't understand how after 5 years of "coding" php you don't know usage of regex :( EW Guide - KB Tool - My Music |
|
AliasXNeo
Gallente
|
Posted - 2007.10.21 03:30:00 -
[11]
Edited by: AliasXNeo on 21/10/2007 03:31:31 Here's 2 year of experience:
<?php
/** * A class for parsing Eve Online "killmail" into a logical order * * @author Josh (AliasXNeo) * @copyright BattleClinic 2007 * @package killMailparser * */
class killMailParser {
public static function parse($mail) { if (empty($mail)) { throw new Exception("Invalid killmail supplied"); }
if (!sizeof(explode("\n\n", $mail))) { throw new Exception("Invalid killmail supplied"); }
$parts = explode("\n\n", $mail);
if (preg_match("/(\d*\.\d*\.\d* \d*:\d*)/", $mail, $result)) { $date = $result[1]; }
$victim = array(); if (preg_match_all("/(.*?)\: (.*)/", $parts[1], $result)) { for ($i = 0; $i < sizeof($result[1]); $i++) { $victim[$result[1][$i]] = $result[2][$i]; } }
$hostiles = array();
$i = 4; while (!strpos($parts[$i], "Destroyed items")) { if (preg_match_all("/(.*?)\: (.*)/", $parts[$i], $result)) { for ($j = 0; $j < sizeof($result[1]); $j++) { $hostiles[$i - 4][$result[1][$j]] = $result[2][$j]; } }
$i++; }
$items = explode("\n", $parts[$i + 1]);
$killmail['date'] = $date; $killmail['victim'] = $victim; $killmail['hostiles'] = $hostiles; $killmail['destroyedItems'] = $items;
return $killmail; } }
$content = file_get_contents("killmail.txt"); print_r(killMailParser::parse($content));
?> ------------------------------ ~ AKA Josh ~ - Battleclinic Staff Developer - ------------------------------
|
Cori4n
Caldari Bright New Dawn Artificial Intelligence.
|
Posted - 2007.10.21 04:31:00 -
[12]
Edited by: Cori4n on 21/10/2007 04:30:51 Pointless class definitions ftw :/
|
AliasXNeo
Gallente
|
Posted - 2007.10.21 05:05:00 -
[13]
Originally by: Cori4n Edited by: Cori4n on 21/10/2007 04:30:51 Pointless class definitions ftw :/
Heh, you must still be a PHP 4 user. Practically everything is an object in PHP 5. There is no such thing as a "pointless class definition". Sure if there was another class that maybe saved the killmail details to a database, then this function would easily be put in the same class, but clearly that is not the case. Creating large files filled with functions is a "PHP 4 thing". Hence I do not promote such coding by putting my code in a class.
You might think I'm spouting bs, but you can easily check out devshed and devnetwork and get an identical response. ------------------------------ ~ AKA Josh ~ - Battleclinic Staff Developer - ------------------------------
|
dimensionZ
Reikoku Band of Brothers
|
Posted - 2007.10.21 11:39:00 -
[14]
Originally by: Cori4n Edited by: Cori4n on 21/10/2007 04:30:51 Pointless class definitions ftw :/
Sure he doesnt use all the possibilities of OO coding style, but, its clean, and makes you use functions for about anything and everything. He even uses exceptions. So yeah, I for one like that small parser. My own parser is a class aswell, just quite a bit bigger since i handle every killmails format since release. ----------------------------------------
|
Tonto Auri
|
Posted - 2007.10.21 18:23:00 -
[15]
Originally by: Cori4n Pointless class definitions ftw :/
Nothing pointless in class definithon itself, but way it's used here... I'd agree that it is pretty piontless to have class used in the same place and nowhere else.
Better to have class defined in separate file and load it as need to provide content of template output. -- Thanks CCP for cu<end of sig> |
Ryysa
Caldari
|
Posted - 2007.10.21 19:03:00 -
[16]
Now Josh' parser is a lot nicer.
OP has a thing or two to learn from that :) EW Guide - KB Tool - My Music |
AliasXNeo
Gallente
|
Posted - 2007.10.21 22:20:00 -
[17]
Originally by: Tonto Auri
Originally by: Cori4n Pointless class definitions ftw :/
Nothing pointless in class definithon itself, but way it's used here... I'd agree that it is pretty piontless to have class used in the same place and nowhere else.
Better to have class defined in separate file and load it as need to provide content of template output.
That's quite obvious. I figured the coder would be smart enough to make that distinction :p The reason I put everything together was for sake of saving space in my post. ------------------------------ ~ AKA Josh ~ - Battleclinic Staff Developer - ------------------------------
|
DeTox MinRohim
Madhatters Inc. M. PIRE
|
Posted - 2007.10.22 22:30:00 -
[18]
Edited by: DeTox MinRohim on 22/10/2007 22:33:34
Originally by: Unforgiven Soldier If you find this code useful in any way please feel free to donate ISKies to Unforgiven Soldier.
Dude... Do a few more hundreds of lines before mate. Don't take that as a rant, just a suggestion: Like many others who succeeded in having donations for their outwork, I suggest you build a complete utility. Not something that one can pull from an already existing code. (Ryysa, AliasXNeo and many others built many more lines and have complete utilities on their background).
I also rewrote from scratch the eve-dev killboard myself (like you are apparently doing) for MADH and MPIRE, sure it's not released (if I even release it) but even then, I had no intention to ask Isks for that as I don't really intend to offer anything with it (like hosting or stuff like that).
Seems it's a trend (although understandable) to add the usual line: "If you are happy with it, send me Isks"
------ This sig space is Read-only ! omgalink - Online Skillsheet |
Valandril
Caldari Resurrection R i s e
|
Posted - 2007.10.23 03:28:00 -
[19]
Sooo much exploding in op code o.0 ---
Battlecarriers - lets move carriers to the front line ! |
Shinhan
Phoenix Knights Dark Nebula Galactic Empire
|
Posted - 2007.10.23 07:51:00 -
[20]
Ummm, AliasXNeo, I think it should be \r\n instead of \n\n ...
Wonder if entire killmail could be processed with a single regexp...
-- Selling apples, 1 signature each. ѼѼѼѼѼѼѼ |
|
AliasXNeo
Gallente
|
Posted - 2007.10.23 14:15:00 -
[21]
Originally by: Shinhan Ummm, AliasXNeo, I think it should be \r\n instead of \n\n ...
Wonder if entire killmail could be processed with a single regexp...
Yes I forgot to change that. In Windows using IIS you have to use \n\n, \r\n will not work in most cases. ------------------------------ ~ AKA Josh ~ - Battleclinic Staff Developer - ------------------------------
|
Archonus
Amarr Solar Wind
|
Posted - 2007.10.24 17:19:00 -
[22]
Something you should always keep in mind when writing a parser: Formats may change!
Now of course, when they do change you can always go back and re-work your code, but why waste your time if you can create the same program in a more efficient manner (Using Preg/Ereg). You may still have to make changes for a new format, but only on a few lines instead of many.
Now I'm not a big fan of coding in PHP5 yet, as a large amount of servers I am coding on are still running PHP4, however, simplistic OOP is something I push for.
Having many many different functions scattered across your web site is fine if you can keep track of them, but from a coding standpoint, it becomes much easier in the long run if you keep them organized in Classes.
I've been coding PHP professionally for 6 years now, and I learned my lessons quickly over time. I used to write code much like Unforgiven Soldier's. Not until one of the formats I was coding for changed did I learn the hard way.
So, to Unforgiven Soldier: I'd recommend taking their advice and do some reading on Regexp. Not only does it eliminate the need for many lines of code, it allows for the format of the killmail to change a little as well. (Any changes should be easy to implement.)
|
Shinhan
Phoenix Knights Dark Nebula Galactic Empire
|
Posted - 2007.10.25 07:17:00 -
[23]
Regular-Expressions.info is one nice website dedicated to regexps. One way to start learning them is take some complicated regexp (checkout their examples section) and try to understand what does it do.
-- Selling apples, 1 signature each. ѼѼѼѼѼѼѼ |
Teego
|
Posted - 2007.10.25 16:44:00 -
[24]
On a related note, RegEx Buddy (put together by at least one of the guys behind Regular-Expressions.info is an EXCEPTIONALLY handy tool in learning, creating, debugging, and reverse engineering regular expressions. It's also nice that you can take your standardized regexp statements and export them to PHP or ASP or (Java|ECMA|Action)Script (with their varius and sundry 1% nuance bull**** they all seem to have.)
Highly recommended.
In other news, I'm heartily awaiting Killboard 2.0. Then I'm awaiting some sort of magical market history interface so we can get reliable current weighed values for modules destroyed and retrieved from wrecks. Tra-la, tra-la.
(It's sad when eve metagaming programming is more fun than eve itself...)
|
Ryysa
Caldari
|
Posted - 2007.10.25 17:30:00 -
[25]
Real men know regex by heart anyway ;)
But on a more serious note, if you are doing ANY kind of professional coding and don't know regex, then you should not be doing professional coding :)
It saves you tonnes of time on refactoring code or generating code, etc. EW Guide - KB Tool - My Music |
|
|
|
Pages: [1] :: one page |
First page | Previous page | Next page | Last page |