Example #1
1
 public function SetFaction($id)
 {
     if ($this->faction != null) {
         $this->faction->UnregisterMember($this);
     }
     $this->faction = Factions::FindByID($id);
     if ($this->faction != null) {
         $this->faction->RegisterMember($this);
     } else {
         $this->onduty = true;
     }
 }
Example #2
0
 /**
  ** Default constructor
  **/
 public function __construct($name, $color, $bank, $maxvehicles, $maxmembers, $membercount)
 {
     $this->name = $name;
     $this->color = $color;
     $this->bank = $bank;
     $this->maxvehicles = $maxvehicles;
     $this->maxmembers = $maxmembers;
     $this->membercount = $membercount;
     $this->id = Factions::MakeID($name);
 }
Example #3
0
 function __construct($name, $perms = null)
 {
     $this->name = $name;
     if ($perms != null) {
         $this->perms = $perms;
     } else {
         $path = Factions::getMStorePath() . DIRECTORY_SEPARATOR . "factions_mperm" . DIRECTORY_SEPARATOR . $name . ".json";
         $rawJSON = json_decode(file_get_contents($path));
         $this->perms = $rawJSON->standard;
     }
 }
Example #4
0
 public static function getDefaults()
 {
     if (self::$default_perms == null) {
         $perms = array();
         foreach (scandir(Factions::getMStorePath() . DIRECTORY_SEPARATOR . "factions_mperm") as $key => $permRaw) {
             if (!in_array($permRaw, array(".", ".."))) {
                 $path = Factions::getMStorePath() . DIRECTORY_SEPARATOR . "factions_mperm" . DIRECTORY_SEPARATOR . $permRaw;
                 if (is_file($path)) {
                     $permName = basename($permRaw, ".json");
                     $perm = new Perm($permName);
                     $perms[$permName] = $perm;
                 }
             }
         }
         self::$default_perms = $perms;
     }
     return self::$default_perms;
 }
Example #5
0
 public static function cmdSetfaction(Player $player, $numparams, $params)
 {
     if (!Admin::CheckLevel($player, ADMIN_ADMIN)) {
         return COMMAND_OK;
     }
     if ($target = Core::FindPlayer($player, $params[1])) {
         $facname = implode(' ', array_slice($params, 2));
         if (($faction = $target->GetFaction(false)) && !strcasecmp($facname, 'Civilian')) {
             $faction->SetMemberCount($faction->GetMemberCount() - 1);
             $target->SetFaction(null);
             $target->SetRank(null);
             Admin::Send(COLOR_SETFACTION, "* Admin {$player->name} has kicked {$target->name} from his faction");
             $target->Send(COLOR_SETFACTION, "* Admin {$player->name} has kicked you from your faction");
             Log::Append(LOG_ADMIN, "[{$player->id}] {$player->name} has kicked {$target->name}[{$target->id}] from his faction");
         } else {
             if ($faction = Factions::FindByName($facname)) {
                 $oldfaction = $player->GetFaction(false);
                 if ($oldfaction != null) {
                     $oldfaction->SetMemberCount($oldfaction->GetMemberCount() - 1);
                 }
                 $faction->SetMemberCount($faction->GetMemberCount() + 1);
                 $target->SetFaction($faction->ID());
                 $target->SetRank($faction->LowestRank());
                 Admin::Send(COLOR_SETFACTION, "* Admin {$player->name} has moved {$target->name} to the {$faction->GetName()} faction");
                 $target->Send(COLOR_SETFACTION, "* Admin {$player->name} has moved you to the {$faction->GetName()} faction");
                 Log::Append(LOG_ADMIN, "[{$player->id}] {$player->name} has moved {$target->name}[{$target->id}] to the faction {$faction->GetName()}");
             }
         }
     }
     return COMMAND_OK;
 }
Example #6
0
 public static function SaveData()
 {
     static $numsaves = 0;
     //      echo "*** Starting data save ...\n";
     DB::StartTransaction();
     Accounts::Save();
     Factions::Save();
     Houses::Save();
     DB::Commit();
     //      echo "*** Data saved sucessfully!\n";
     $numsaves++;
     if ($numsaves == 12) {
         //        echo "*** Doing manteinance...\n";
         /* Make manteinance */
         Factions::UpdateMembercount();
         $numsaves = 0;
         //        echo "*** Manteinance complete!\n";
     }
 }
Example #7
0
 public static function cmdRankdown(Player $player, $numparams, $params)
 {
     $faction = $player->GetFaction();
     if ($faction == null) {
         return COMMAND_OK;
     }
     if ($faction->AllowedTo($player, MEMBER_ALLOWRANK) == false) {
         return COMMAND_OK;
     }
     if ($target = Factions::EqualFactions($player, $params[1])) {
         if ($player->id == $target->id) {
             return COMMAND_OK;
         }
         $requested_rank = $target->GetRank() + 1;
         if ($requested_rank > $faction->LowestRank()) {
             $player->Send(COLOR_RANKDOWN_MIN, '[ERROR] Given player already has the lowest faction rank');
             return COMMAND_OK;
         }
         if ($target->GetRank() <= $player->GetRank()) {
             $player->Send(COLOR_RANKDOWN_DISALLOW, '[ERROR] You are not allowed to rank down this player');
             return COMMAND_OK;
         }
         $target->SetRank($requested_rank);
         $faction->Send(COLOR_RANKDOWN_SUCCESS, "[FACTION] {$target->name} has been demoted to " . $faction->GetRankName($requested_rank));
     }
     return COMMAND_OK;
 }
Example #8
0
 public static function SaveFactionData($data)
 {
     $query = 'UPDATE faction SET ';
     foreach ($data as $key_ => $value_) {
         $key = mysql_real_escape_string($key_, DB::$handler);
         $value = mysql_real_escape_string($value_, DB::$handler);
         if ($key != 'id') {
             if ($value == null) {
                 $query .= "{$key}=NULL, ";
             } else {
                 $query .= "{$key}='{$value}', ";
             }
         }
     }
     $id = mysql_real_escape_string($data['id'], DB::$handler);
     $query = substr($query, 0, strlen($query) - 2) . ' WHERE id=' . $id;
     if (!mysql_query($query, DB::$handler)) {
         if (mysql_errno() != 1452) {
             DB::DBdie('Error updating faction data: ' . mysql_error() . "\n");
         }
         echo "WARNING! Saving faction data failed for integrity, setting null HQ and re-saving\n";
         $faction = Factions::Find($data['id']);
         if ($faction) {
             $faction->SetHQ(null);
             $faction->Save();
         }
     }
     return true;
 }
Example #9
0
 public function TransferOwnership(Player $player, Ownership $newowner, $price)
 {
     $oldid = $this->GetOwner();
     $newid = $newowner->GetOwner();
     $oldobj = null;
     $newobj = null;
     $oldstats = null;
     $newstats = null;
     switch ($this->GetType()) {
         case OWNERSHIP_ACCOUNT:
             $oldobj = Players::FindByDBID($oldid);
             if (!$oldobj) {
                 $oldstats = Accounts::LoadStats($oldid);
             }
             if (!$oldobj && !$oldstats) {
                 $player->Send(COLOR_RED, '[ERROR] Internal error, a log of this error has been saved to be fixed');
                 echo "WARNING! Trying to transfer ownership from an old owner identified as OWNERSHIP_ACCOUNT({$oldid}), " . "but unable to load their stats (account deleted?)\n";
                 return false;
             }
             break;
         case OWNERSHIP_FACTION:
             $oldobj = Factions::FindByID($oldid);
             if (!$oldobj) {
                 $player->Send(COLOR_RED, '[ERROR] Internal error, a log of this error has been saved to be fixed');
                 echo "WARNING! Trying to transfer ownership from an old owner identified as OWNERSHIP_FACTION({$oldid}), " . "but unable to find the faction (corrupted database?)\n";
                 return false;
             }
             break;
     }
     switch ($newowner->GetType()) {
         case OWNERSHIP_ACCOUNT:
             $newobj = Players::FindByDBID($newid);
             if (!$newobj) {
                 $newstats = Accounts::LoadStats($newid);
             }
             if (!$newobj && !$newstats) {
                 $player->Send(COLOR_RED, '[ERROR] Internal error, a log of this error has been saved to be fixed');
                 echo "WARNING! Trying to transfer ownership to a new owner identified as OWNERSHIP_ACCOUNT({$newid}), " . "but unable to load their stats (account deleted?)\n";
                 return false;
             }
             break;
         case OWNERSHIP_FACTION:
             $newobj = Factions::FindByID($newid);
             if (!$newobj) {
                 $player->Send(COLOR_RED, '[ERROR] Internal error, a log of this error has been saved to be fixed');
                 echo "WARNING! Trying to transfer ownership to a new owner identified as OWNERSHIP_FACTION({$newid}), " . "but unable to find the faction (corrupted database?)\n";
                 return false;
             }
             break;
     }
     /* Check if the bank accounts are frozen */
     if ($oldobj && $oldobj->BankFreezed()) {
         $player->Send(COLOR_BANK_FREEZED, '[ERROR] The current owner of this property has his bank account frozen, operation cancelled');
         return false;
     }
     if ($newobj && $newobj->BankFreezed()) {
         $facstr = ' ';
         if ($newobj instanceof Faction) {
             $facstr = ' faction ';
         }
         $player->Send(COLOR_BANK_FREEZED, "[ERROR] Your{$facstr}bank account has been freezed, operation cancelled");
         return false;
     }
     /* Check if the buyer has enough money */
     $facstr = ' ';
     if ($newobj) {
         $bank_buyer = $newobj->GetBank();
         if ($newobj instanceof Faction) {
             $facstr = ' faction ';
         }
     } else {
         $bank_buyer = $newstats['bank'];
     }
     if ($bank_buyer < $price) {
         $player->Send(COLOR_NOTENOUGH_MONEYBANK, "[ERROR] Your{$facstr}bank account hasn\\'t enough money to buy this property");
         return false;
     }
     /* Perform the transaction */
     $newname = 'Somebody';
     if ($newobj) {
         $newobj->GiveBank(-$price);
         $fixed_price = Core::FixIntegerDots($price);
         if ($newobj instanceof Faction) {
             $newobj->Send(COLOR_OWNERSHIP_ADQUIRED, "[FACTION BANK] {$player->name} adquired a new property for the faction for {$fixed_price}\$", MEMBER_ALLOWBANK);
             $newname = $newobj->GetName() . ' faction';
         } else {
             $newobj->Send(COLOR_OWNERSHIP_ADQUIRED, "[BANK] New property adquired for {$fixed_price}\$");
             $newname = $newobj->name;
         }
     } else {
         if ($newstats != null) {
             $newstats['bank'] -= $price;
             Accounts::SetLoadedStats($newid, $newstats);
         }
     }
     if ($oldobj) {
         $oldobj->GiveBank($price);
         $fixed_price = Core::FixIntegerDots($price);
         if ($oldobj instanceof Faction) {
             $oldobj->Send(COLOR_OWNERSHIP_SOLD, "[FACTION BANK] {$newname} bought one of the faction properties for sale for {$fixed_price}\$", MEMBER_ALLOWBANK);
         } else {
             $oldobj->Send(COLOR_OWNERSHIP_SOLD, "[BANK] {$newname} bought one of your properties for sale for {$fixed_price}\$");
         }
     } else {
         if ($oldstats != null) {
             $oldstats['bank'] += $price;
             Accounts::SetLoadedStats($oldid, $oldstats);
         }
     }
     return true;
 }
Example #10
0
 public static function cmdFtransfer(Player $player, $numparams, $params)
 {
     if ($player->location->ID() == LSBank::$id && ($faction = $player->GetFaction()) && $faction->AllowedTo($player, MEMBER_ALLOWBANK) && LSBank::AllowFaction($player, $faction)) {
         $amount = (int) $params[1];
         $target_name = implode(' ', array_slice($params, 2));
         $target = Factions::FindByName($target_name);
         if ($target && Factions::CheckPaybank($player, $faction, $amount, $target)) {
             $faction->GiveBank(-$amount);
             $target->GiveBank($amount);
             $bank1 = $faction->GetBank();
             $bank2 = $target->GetBank();
             $amount = Core::FixIntegerDots($amount);
             $faction->Send(COLOR_BANK_TRANSFER, "[FACTION BANK] {$player->name} transfered {$amount}\$ to {$target->GetName()} faction", MEMBER_ALLOWBANK);
             $target->Send(COLOR_BANK_TRANSFER, "[FACTION BANK] {$faction->GetName()} faction transfered {$amount}\$ to your faction", MEMBER_ALLOWBANK);
         }
     }
     return COMMAND_OK;
 }