1 | <? |
---|
2 | require_once( "class.alliance.php" ); |
---|
3 | require_once( "class.corp.php" ); |
---|
4 | require_once( "class.pilot.php" ); |
---|
5 | require_once( "class.kill.php" ); |
---|
6 | require_once( "class.item.php" ); |
---|
7 | |
---|
8 | class Parser |
---|
9 | { |
---|
10 | |
---|
11 | function Parser( $killmail ) |
---|
12 | { |
---|
13 | $this->killmail_ = trim( str_replace( "\r", "", $killmail ) ); |
---|
14 | |
---|
15 | if ( strpos( $this->killmail_, "**** Truncated - mail is too large ****" ) > 0 ) { |
---|
16 | $this->killmail_ = str_replace( "**** Truncated - mail is too large ****", "", $this->killmail_ ); |
---|
17 | } |
---|
18 | |
---|
19 | // if ( strpos( $this->killmail_, "Empty." ) > 0 ) { |
---|
20 | // $this->killmail_ = str_replace( "Empty.\n", "", $this->killmail_ ); |
---|
21 | // } |
---|
22 | |
---|
23 | } |
---|
24 | |
---|
25 | function parse( $checkauth = true ) |
---|
26 | { |
---|
27 | // header |
---|
28 | $involvedpos = strpos( $this->killmail_, "Involved parties:" ); |
---|
29 | |
---|
30 | $header = substr( $this->killmail_, 0, $involvedpos ); |
---|
31 | $timestamp = substr( $header, 0, 16 ); |
---|
32 | preg_match( "/Victim: (.*)/", $header, $matches ); |
---|
33 | $victimname = trim( $matches[1] ); |
---|
34 | preg_match( "/Alliance: (.*)/", $header, $matches ); |
---|
35 | $alliancename = trim( $matches[1] ); |
---|
36 | preg_match( "/Corp: (.*)/", $header, $matches ); |
---|
37 | $corpname = trim( $matches[1] ); |
---|
38 | preg_match( "/Destroyed: (.*)/", $header, $matches ); |
---|
39 | $shipname = trim( $matches[1] ); |
---|
40 | preg_match( "/System: (.*)/", $header, $matches ); |
---|
41 | $systemname = trim( $matches[1] ); |
---|
42 | preg_match( "/Security: (.*)/", $header, $matches ); |
---|
43 | $systemsec = trim( $matches[1] ); |
---|
44 | |
---|
45 | if ( strlen( $timestamp ) < 1 || |
---|
46 | strlen( $alliancename ) < 1 || |
---|
47 | strlen( $corpname ) < 1 || |
---|
48 | strlen( $victimname ) < 1 || |
---|
49 | strlen( $shipname ) < 1 || |
---|
50 | strlen( $systemname ) < 1 || |
---|
51 | strlen( $systemsec ) < 1 ) |
---|
52 | return 0; |
---|
53 | |
---|
54 | if ( $checkauth ) |
---|
55 | $authorized = false; |
---|
56 | else |
---|
57 | $authorized = true; |
---|
58 | |
---|
59 | // populate/update database |
---|
60 | $alliance = new Alliance(); |
---|
61 | $alliance->add( $alliancename ); |
---|
62 | $corp = new Corporation(); |
---|
63 | $corp->add( $corpname, $alliance, $timestamp ); |
---|
64 | $victim = new Pilot(); |
---|
65 | $victim->add( $victimname, $corp, $timestamp ); |
---|
66 | $system = new SolarSystem(); |
---|
67 | $system->lookup( $systemname ); |
---|
68 | $ship = new Ship(); |
---|
69 | $ship->lookup( $shipname ); |
---|
70 | $kill = new Kill(); |
---|
71 | $kill->setTimeStamp( $timestamp ); |
---|
72 | $kill->setVictimID( $victim->getID() ); |
---|
73 | $kill->setVictimCorpID( $corp->getID() ); |
---|
74 | $kill->setVictimAllianceID( $alliance->getID() ); |
---|
75 | $kill->setVictimShip( $ship ); |
---|
76 | $kill->setSolarSystem( $system ); |
---|
77 | |
---|
78 | if ( ALLIANCE_ID != 0 && $alliance->getID() == ALLIANCE_ID ) |
---|
79 | $authorized = true; |
---|
80 | elseif ( CORP_ID != 0 ) { |
---|
81 | $corps = explode( ",", CORP_ID ); |
---|
82 | foreach( $corps as $checkcorp ) { |
---|
83 | if ( $corp->getID() == $checkcorp ) |
---|
84 | $authorized = true; |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | // involved |
---|
89 | $end = strpos( $this->killmail_, "Destroyed items:" ); |
---|
90 | if ( $end == 0 ) $end = strlen( $this->killmail_ ); |
---|
91 | $involved = explode( "\n", trim( substr( $this->killmail_, strpos( $this->killmail_, "Involved parties:" ) + 17, $end - ( strpos( $this->killmail_, "Involved parties:" ) + 17 ) ) ) ); |
---|
92 | |
---|
93 | $i = 0; |
---|
94 | |
---|
95 | $order = 0; |
---|
96 | while ( $i < count( $involved ) ) { |
---|
97 | if ( $involved[$i] == "" ) |
---|
98 | $i++; |
---|
99 | |
---|
100 | preg_match( "/Name: (.*)/", $involved[$i], $matches ); |
---|
101 | $ipname = $matches[1]; |
---|
102 | preg_match( "/(.*) \(laid the final blow\)/", $ipname, $matches ); |
---|
103 | if ( $matches[1] ) { |
---|
104 | $ipname = $matches[1]; |
---|
105 | $finalblow = 1; |
---|
106 | } else $finalblow = 0; |
---|
107 | |
---|
108 | preg_match( "/Security: (.*)/", $involved[$i+1], $matches ); |
---|
109 | $secstatus = $matches[1]; |
---|
110 | |
---|
111 | if ( $secstatus == "" ) { // NPC or POS |
---|
112 | $secstatus = "0.0"; |
---|
113 | preg_match( "/(.*) \/ (.*)/", $ipname, $pmatches ); |
---|
114 | $ipname = $pmatches[1]; |
---|
115 | $icname = $pmatches[2]; |
---|
116 | $isname = "Unknown"; |
---|
117 | $iwname = $pmatches[1]; |
---|
118 | $tmpcorp = new Corporation(); |
---|
119 | $tmpcorp->lookup( $icname ); |
---|
120 | $tmpall = $tmpcorp->getAlliance(); |
---|
121 | if ( $tmpcorp->getID() ) |
---|
122 | $ianame = $tmpall->getName(); |
---|
123 | else |
---|
124 | $ianame = "None"; |
---|
125 | |
---|
126 | $i++; |
---|
127 | } |
---|
128 | else { |
---|
129 | preg_match( "/Alliance: (.*)/", $involved[$i+2], $matches ); |
---|
130 | $ianame = $matches[1]; |
---|
131 | |
---|
132 | preg_match( "/Corp: (.*)/", $involved[$i+3], $matches ); |
---|
133 | $icname = $matches[1]; |
---|
134 | |
---|
135 | preg_match( "/Ship: (.*)/", $involved[$i+4], $matches ); |
---|
136 | $isname = $matches[1]; |
---|
137 | |
---|
138 | preg_match( "/Weapon: (.*)/", $involved[$i+5], $matches ); |
---|
139 | $iwname = $matches[1]; |
---|
140 | $i += 6; |
---|
141 | } |
---|
142 | |
---|
143 | $ialliance = new Alliance(); |
---|
144 | $ialliance->add( $ianame ); |
---|
145 | $icorp = new Corporation(); |
---|
146 | $icorp->add( $icname, $ialliance, $kill->getTimeStamp() ); |
---|
147 | |
---|
148 | if ( ALLIANCE_ID != 0 && $ialliance->getID() == ALLIANCE_ID ) |
---|
149 | $authorized = true; |
---|
150 | elseif ( CORP_ID != 0 ) { |
---|
151 | $corps = explode( ",", CORP_ID ); |
---|
152 | foreach( $corps as $corp ) { |
---|
153 | if ( $icorp->getID() == $corp ) |
---|
154 | $authorized = true; |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | $ipilot = new Pilot(); |
---|
159 | $ipilot->add( $ipname, $icorp, $timestamp ); |
---|
160 | $iship = new Ship(); |
---|
161 | $iship->lookup( $isname ); |
---|
162 | $iweapon = new Item(); |
---|
163 | $iweapon->lookup( $iwname ); |
---|
164 | |
---|
165 | $iparty = new InvolvedParty( $ipilot->getID(), $icorp->getID(), |
---|
166 | $ialliance->getID(), $secstatus, |
---|
167 | $iship, $iweapon ); |
---|
168 | $kill->addInvolvedParty( $iparty ); |
---|
169 | |
---|
170 | if ( $finalblow == 1 ) { |
---|
171 | $kill->setFBPilotID( $ipilot->getID() ); |
---|
172 | $kill->setFBCorpID( $icorp->getID() ); |
---|
173 | $kill->setFBAllianceID( $ialliance->getID() ); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | // destroyed items |
---|
178 | $destroyedpos = strpos( $this->killmail_, "Destroyed items:" ); |
---|
179 | |
---|
180 | if ( $destroyedpos > 0 ) { |
---|
181 | $destroyed = explode( "\n", trim( substr( $this->killmail_, |
---|
182 | strpos( $this->killmail_, "Destroyed items:" ) + 16, |
---|
183 | strlen( $this->killmail_ ) - ( strpos( $this->killmail_, "Destroyed items:" ) + 16 ) ) ) ); |
---|
184 | |
---|
185 | $i=0; |
---|
186 | while ( $i < count( $destroyed ) ) { |
---|
187 | if ( $destroyed[$i] == "" ) |
---|
188 | $i++; |
---|
189 | |
---|
190 | if ( $destroyed[$i] == "Empty." ) { |
---|
191 | $container = false; |
---|
192 | $i++; |
---|
193 | } |
---|
194 | |
---|
195 | $qtypos = 0; |
---|
196 | $locpos = 0; |
---|
197 | $itemname = ""; |
---|
198 | $quantity = ""; |
---|
199 | $location = ""; |
---|
200 | |
---|
201 | if ( strpos( $destroyed[$i], "Container" ) > 0 && |
---|
202 | strpos( $destroyed[$i+1], "(" ) <= 0 && |
---|
203 | strpos( $destroyed[$i+1], "Empty." ) <= 0 ) |
---|
204 | $container = true; |
---|
205 | |
---|
206 | $qtypos = strpos( $destroyed[$i], ", Qty: " ); |
---|
207 | $locpos = strpos( $destroyed[$i], "(" ); |
---|
208 | |
---|
209 | if ( $qtypos <= 0 && !$locpos ) { |
---|
210 | $itemlen = strlen( $destroyed[$i] ); |
---|
211 | if ( $container ) $location = "Cargo"; |
---|
212 | } |
---|
213 | |
---|
214 | if ( $qtypos > 0 && !$locpos ) { |
---|
215 | $itemlen = $qtypos; |
---|
216 | $qtylen = strlen( $destroyed[$i] ) - $qtypos; |
---|
217 | if ( $container ) $location = "Cargo"; |
---|
218 | } |
---|
219 | if ( $locpos > 0 && $qtypos <= 0 ) { |
---|
220 | $itemlen = $locpos - 1; |
---|
221 | $qtylen = 0; |
---|
222 | $loclen = strlen( $destroyed[$i] ) - $locpos - 2; |
---|
223 | if ( !$locpos ) $container = false; |
---|
224 | } |
---|
225 | if ( $locpos > 0 && $qtypos > 0 ) { |
---|
226 | $itemlen = $qtypos; |
---|
227 | $qtylen = $locpos - $qtypos - 7; |
---|
228 | $loclen = strlen( $destroyed[$i] ) - $locpos - 2; |
---|
229 | if ( !$locpos ) $container = false; |
---|
230 | } |
---|
231 | |
---|
232 | $itemname = substr( $destroyed[$i], 0, $itemlen ); |
---|
233 | if ( $qtypos ) $quantity = substr( $destroyed[$i], $qtypos + 6, $qtylen ); |
---|
234 | if ( $locpos ) $location = substr( $destroyed[$i], $locpos + 1, $loclen ); |
---|
235 | |
---|
236 | if ( $quantity == "" ) |
---|
237 | $quantity = 1; |
---|
238 | |
---|
239 | //echo $container." - ".$item." - ".$quantity." - ".$location."<br>"; |
---|
240 | |
---|
241 | $item = new Item(); |
---|
242 | $item->lookup( trim( $itemname ) ); |
---|
243 | $ditem = new DestroyedItem( $item, $quantity, $location ); |
---|
244 | $kill->addDestroyedItem( $ditem ); |
---|
245 | |
---|
246 | $i++; |
---|
247 | } |
---|
248 | } |
---|
249 | |
---|
250 | if ( !$authorized ) |
---|
251 | return -2; |
---|
252 | |
---|
253 | $id = $kill->add(); |
---|
254 | if ( $id == -1 ) |
---|
255 | $this->dupeid_ = $kill->dupeid_; |
---|
256 | |
---|
257 | return $id; |
---|
258 | } |
---|
259 | } |
---|
260 | ?> |
---|