| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* zKillboard | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Copyright (C) 2012-2015 EVE-KILL Team and EVSCO. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * This program is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * it under the terms of the GNU Affero General Public License as published by | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  | class StompUtil | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | 	private static $stomp = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | 	public static function getStomp() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | 		if (self::$stomp === null) | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | 		{ | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | 			global $stompServer, $stompUser, $stompPassword; | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | 			// Ensure the class exists | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | 			if (!class_exists("Stomp")) | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  | 				die("ERROR! Stomp not installed!  Check the README to learn how to install Stomp...\n"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | 			self::$stomp = new Stomp($stompServer, $stompUser, $stompPassword);	 | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 		return self::$stomp; | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	public static function sendKill($killID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		if ($killID < 0) return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		$stomp = self::getStomp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		$json = Killmail::get($killID); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		if(!empty($json)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			$destinations = self::getDestinations($json); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 			foreach ($destinations as $destination) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 				$stomp->send($destination, $json); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			$data = json_decode($json, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			$map = json_encode(array("solarSystemID" => $data["solarSystemID"], "killID" => $data["killID"], "characterID" => $data["victim"]["characterID"], "corporationID" => $data["victim"]["corporationID"], "allianceID" => $data["victim"]["allianceID"], "shipTypeID" => $data["victim"]["shipTypeID"], "killTime" => $data["killTime"], "involved" => count($data["attackers"]), "totalValue" => $data["zkb"]["totalValue"], "pointsPrInvolved" => $data["zkb"]["points"])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			$stomp->send("/topic/starmap.systems.active", $map); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		}	 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  | 	} | 
            
                                                                        
                                                                
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	private static function getDestinations($kill) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		$kill = json_decode($kill, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		$destinations = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		$destinations[] = "/topic/kills"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$destinations[] = "/topic/location.solarsystem.".$kill["solarSystemID"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		// victim | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		if($kill["victim"]["characterID"] > 0) $destinations[] = "/topic/involved.character.".$kill["victim"]["characterID"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		if($kill["victim"]["corporationID"] > 0) $destinations[] = "/topic/involved.corporation.".$kill["victim"]["corporationID"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		if($kill["victim"]["factionID"] > 0) $destinations[] = "/topic/involved.faction.".$kill["victim"]["factionID"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		if($kill["victim"]["allianceID"] > 0) $destinations[] = "/topic/involved.alliance.".$kill["victim"]["allianceID"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		// attackers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		foreach($kill["attackers"] as $attacker) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 			if($attacker["characterID"] > 0) $destinations[] = "/topic/involved.character." . $attacker["characterID"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			if($attacker["corporationID"] > 0) $destinations[] = "/topic/involved.corporation." . $attacker["corporationID"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			if($attacker["factionID"] > 0) $destinations[] = "/topic/involved.faction." . $attacker["factionID"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			if($attacker["allianceID"] > 0) $destinations[] = "/topic/involved.alliance." . $attacker["allianceID"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		return $destinations; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 82 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 83 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |  | 
            
                        
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.