Skip to content

Commit

Permalink
First release:
Browse files Browse the repository at this point in the history
New pages: create family, join/leave family, manage family.
Updated pages: crimes (cash display), new message's from system.
Big changes: Message from system, new table for family invites
Small changes: more family variables from user class, new crimes, on payment success see how much credits you bought
Bug fixes: none
  • Loading branch information
dees040 committed Nov 30, 2014
1 parent ec7db58 commit c09812e
Show file tree
Hide file tree
Showing 21 changed files with 292 additions and 32 deletions.
1 change: 1 addition & 0 deletions core/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
define("TBL_ITEMS_CC", "items_call_credits");
define("TBL_PAYMENTS", "payments");
define("TBL_SHOUTBOX", "shoutbox");
define("TBL_FAMILY_JOIN", "family_join_invites");


/**
Expand Down
8 changes: 8 additions & 0 deletions core/controllers/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,12 @@ public function checkCaptcha()
{
return $_POST['captcha'] == "" || $_POST['captcha'] != md5($_SESSION['botcheck']);
}

public function sendMessage($subject, $message, $to)
{
global $database;

$items = array(':from' => 0, ':to' => $to, ':date' => time(), ':subject' => $subject, ':content' => $message);
$database->query("INSERT INTO ".TBL_MESSAGE." SET from_id = :from, to_id = :to, date = :date, subject = :subject, content = :content", $items);
}
}
113 changes: 110 additions & 3 deletions core/controllers/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class User

public $in_jail;
public $in_family;
public $family;
public $family;
public $id;
public $in_air;

Expand Down Expand Up @@ -59,8 +59,7 @@ private function setFamily()
$this->family->name = "-";
$this->in_family = false;
} else {
$this->family->id = $family->id;
$this->family->name = $family->name;
$this->family = $family;
$this->in_family = true;
}

Expand Down Expand Up @@ -365,6 +364,14 @@ public function sendMessage($to, $subject, $message)
return $error->errorSmall("Subject can not be empty.");
}

if (strlen($subject) < 3) {
return $error->errorSmall("Subject must contain 3 characters.");
}

if (!ctype_alnum($subject)) {// you may send ":"
//return $error->errorSmall("The subject may online contain letters and digits");
}

$items = array(':from_id' => $this->id, ':to_id' => $userInfo->id, ':date' => time(), ':sub' => $subject, ':mess' => $message);
$database->query(
"INSERT INTO ".TBL_MESSAGE." SET from_id = :from_id, to_id = :to_id, date = :date, subject = :sub, content = :mess",
Expand Down Expand Up @@ -460,4 +467,104 @@ public function attackPlayer($username, $bullets)

return $error->succesSmall("Success");
}

public function createFamily($name)
{
global $database, $error;

if (empty($name)) {
return $error->errorSmall("Please fill in a family name.");
}

if (strlen($name) > 20) {
return $error->errorSmall("Your family is above 20 characters, yours is ".strlen($name).".");
}

if (!ctype_alnum($name)) {
return $error->errorSmall("Your family name may only contain letters or digits.");
}

if ($this->stats->fid != 0) {
return $error->errorSmall("You're already in a family.");
}

$count = $database->query("SELECT id FROM ".TBL_FAMILY." WHERE name = :name", array(':name' => $name))->rowCount();

if ($count != 0) {
return $error->errorSmall("This family name already exists.");
}

$items = array(':name' => $name, ':cash' => 10, ':bank' => 100, ':power' => 100, ':creator' => $this->id, ':max' => 10);
$lastId = $database->query("INSERT INTO ".TBL_FAMILY." SET name = :name, cash = :cash, bank = :bank, power = :power, creator = :creator, max_members = :max", $items, true);

$items = array(':fid' => $lastId, ':uid' => $this->id);
$database->query("UPDATE ".TBL_INFO." SET fid = :fid WHERE uid = :uid", $items);

return $error->succesSmall("You have created the family ".$name." with success!");
}

public function joinFamily($fid)
{
global $database, $error;

if ($this->in_family) {
return $error->errorSmall("You're already in a family. If you want to join this family you first need to leave your own family.");
}

$items = array(':fid' => $fid);
$family = $database->query("SELECT join_status, max_members FROM ".TBL_FAMILY." WHERE id = :fid", $items);

if ($family->rowCount() == 0) {
return $error->errorSmall("This family doesn't exists.");
}

$family = $family->fetchObject();

$members = $database->query("SELECT fid FROM ".TBL_INFO." WHERE fid = :fid", $items)->rowCount();

if ($members >= $family->max_members) {
return $error->errorSmall("This family has already reached his maximum member amount.");
}

$items[':uid'] = $this->id;

if ($family->join_status == 1) {
$database->query("UPDATE ".TBL_INFO." SET fid = :fid WHERE uid = :uid", $items);
return $error->succesSmall("You have joined the family!");
} else if ($family->join_status == 2) {
return $error->errorSmall("This family doesn't accepts join invites.");
} else {
$database->query("INSERT INTO ".TBL_FAMILY_JOIN." SET uid = :uid, fid = :fid", $items);
return $error->succesSmall("An invite to join this family has been sent.");
}
}

public function leaveFamily()
{
global $database, $error;

if ($this->family->creator == $this->id) {
$items = array(':fid' => $this->family->id, ':uid' => $this->id);
$members = $database->query("SELECT fid FROM ".TBL_INFO." WHERE fid = :fid AND uid != :uid", $items)->rowCount();
if ($members == 0) {
$items = array(':fid' => 0, ':uid' => $this->id);
$database->query("UPDATE ".TBL_INFO." SET fid = :fid WHERE uid = :uid", $items);
$items = array(':fid' => $this->family->id, ':uid' => $this->id);
$database->query("DELETE FROM ".TBL_FAMILY." WHERE id = :fid AND creator = :uid", $items);
return $error->succesSmall("You have left and removed your family.");
} else {
$items = array(':fid' => $this->family->id, ':uid' => $this->id);
$highestPlayer = $database->query("SELECT uid FROM ".TBL_INFO." WHERE fid = :fid AND uid != :uid ORDER BY power DESC LIMIT 1", $items)->fetchObject();
$items = array(':uid' => $highestPlayer->uid, ':fid' => $this->family->id);
$database->query("UPDATE ".TBL_FAMILY." SET creator = :uid WHERE id = :fid", $items);
$items = array(':fid' => 0, ':uid' => $this->id);
$database->query("UPDATE ".TBL_INFO." SET fid = :fid WHERE uid = :uid", $items);
return $error->succesSmall("You have left your family.");
}
} else {
$items = array(':fid' => 0, ':uid' => $this->id);
$database->query("UPDATE ".TBL_INFO." SET fid = :fid WHERE uid = :uid", $items);
return $error->succesSmall("You have left your family.");
}
}
}
11 changes: 8 additions & 3 deletions core/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public function userOnline($user) {
* @return mixed
*/
public function paginate($table, $orderBy, $start, $end) {
$query = $this->query("SELECT * FROM ".$table." ORDER BY ".$orderBy." LIMIT ".$start.", ".$end);
$query = $this->query("SELECT * FROM ".$table." ORDER BY ".$orderBy." DESC LIMIT ".$start.", ".$end);
return $query->fetchAll(PDO::FETCH_OBJ);
}

Expand All @@ -473,9 +473,10 @@ public function paginate($table, $orderBy, $start, $end) {
*
* @param string $query - The query that has to be executed
* @param array $items - The placeholders (Default = empty array)
* @param bool $lastId
* @return bool|\PDOStatement : Query result
*/
public function query($query, $items = array()) {
public function query($query, $items = array(), $lastId = false) {
try {
$stmt = $this->connection->prepare($query);
$stmt->execute($items);
Expand All @@ -484,7 +485,11 @@ public function query($query, $items = array()) {
}

if ($stmt) {
return $stmt;
if ($lastId) {
return $this->connection->lastInsertId(TBL_FAMILY);
} else {
return $stmt;
}
} else {
return false;
}
Expand Down
60 changes: 40 additions & 20 deletions db_dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Nov 28, 2014 at 07:33 PM
-- Generation Time: Nov 30, 2014 at 03:17 PM
-- Server version: 5.5.38-MariaDB-cll-lve
-- PHP Version: 5.5.17

Expand Down Expand Up @@ -32,6 +32,7 @@ CREATE TABLE IF NOT EXISTS `active_guests` (
PRIMARY KEY (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


-- --------------------------------------------------------

--
Expand Down Expand Up @@ -129,7 +130,7 @@ CREATE TABLE IF NOT EXISTS `crimes` (
`change` int(3) NOT NULL,
`icon` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

--
-- Dumping data for table `crimes`
Expand All @@ -138,7 +139,13 @@ CREATE TABLE IF NOT EXISTS `crimes` (
INSERT INTO `crimes` (`id`, `name`, `min_payout`, `max_payout`, `change`, `icon`) VALUES
(1, 'Steal from child', 10, 100, 10, 'steal_candy.jpg'),
(2, 'Steal bycile', 50, 150, 25, 'steal_bycile.jpg'),
(3, 'Pickpocket', 150, 300, 40, 'zakkenrollen.jpg');
(3, 'Pickpocket', 150, 300, 40, 'zakkenrollen.jpg'),
(4, 'Carjacking', 1000, 5000, 67, 'auto_inbreken.jpg'),
(5, 'Truck hijacking', 5000, 15000, 82, 'vrachtwagen_kapen.jpg'),
(6, 'Rob a jewelry store', 15000, 30000, 109, 'juwelier_overvallen.jpg'),
(7, 'Rob a museum', 35000, 60000, 129, 'museum_inbreken.jpg'),
(8, 'CIT robbery', 70000, 100000, 173, 'waardetransport_overvallen.jpg'),
(9, 'Rob the bank', 150000, 300000, 200, 'bank_overvallen.jpg');

-- --------------------------------------------------------

Expand All @@ -148,23 +155,30 @@ INSERT INTO `crimes` (`id`, `name`, `min_payout`, `max_payout`, `change`, `icon`

CREATE TABLE IF NOT EXISTS `families` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(40) NOT NULL,
`name` varchar(20) NOT NULL,
`cash` int(11) NOT NULL,
`bank` int(11) NOT NULL,
`power` int(20) NOT NULL,
`bullits` int(11) NOT NULL,
`creator` int(11) NOT NULL,
`max_members` int(11) NOT NULL DEFAULT '10',
`info` text NOT NULL,
`join_status` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

-- --------------------------------------------------------

--
-- Dumping data for table `families`
-- Table structure for table `family_join_invites`
--

INSERT INTO `families` (`id`, `name`, `cash`, `bank`, `power`, `bullits`, `creator`, `max_members`, `info`) VALUES
(1, 'Staff', 10, 1000, 100, 0, 1, 10, '');
CREATE TABLE IF NOT EXISTS `family_join_invites` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) NOT NULL,
`fid` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

-- --------------------------------------------------------

Expand Down Expand Up @@ -300,7 +314,7 @@ CREATE TABLE IF NOT EXISTS `menus` (
`weight` int(11) NOT NULL,
`display` tinyint(4) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=34 ;
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=36 ;

--
-- Dumping data for table `menus`
Expand All @@ -317,7 +331,7 @@ INSERT INTO `menus` (`id`, `pid`, `menu`, `link`, `weight`, `display`) VALUES
(8, 10, 'admin', 'admin/settings', 2, 1),
(9, 11, 'admin', 'admin/users', 3, 1),
(10, 12, 'crime', 'crime/crimes', 0, 1),
(11, 13, 'family', 'family', 0, 1),
(11, 13, 'family', 'family', 1, 1),
(12, 14, 'statistics', 'online', 0, 1),
(13, 15, 'personal', 'personal/user-edit', 2, 1),
(14, 16, 'personal', 'personal/user-info', 1, 0),
Expand All @@ -335,11 +349,13 @@ INSERT INTO `menus` (`id`, `pid`, `menu`, `link`, `weight`, `display`) VALUES
(26, 28, 'extra', 'extra/shoutbox', 0, 1),
(27, 29, 'extra', 'extra/forum', 0, 1),
(28, 30, 'casino', 'casino/crack-the-vault', 0, 1),
(29, 31, 'family', 'family/profile', 0, 0),
(29, 31, 'family', 'family/profile', 3, 0),
(30, 32, 'personal', 'personal/message', 0, 0),
(31, 33, 'call-credits', 'pay/failed', 0, 0),
(32, 34, 'call-credits', 'pay/success', 0, 0),
(33, 35, 'call-credits', 'credits/payments', 0, 1);
(33, 35, 'call-credits', 'credits/payments', 0, 1),
(34, 36, 'family', 'family/create', 0, 1),
(35, 37, 'family', 'family/settings', 2, 1);

-- --------------------------------------------------------

Expand All @@ -357,7 +373,7 @@ CREATE TABLE IF NOT EXISTS `messages` (
`status` tinyint(4) NOT NULL,
`from_status` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

-- --------------------------------------------------------

Expand All @@ -374,7 +390,7 @@ CREATE TABLE IF NOT EXISTS `pages` (
`jail` tinyint(4) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `link` (`link`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=36 ;
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=38 ;

--
-- Dumping data for table `pages`
Expand All @@ -397,8 +413,8 @@ INSERT INTO `pages` (`id`, `title`, `link`, `file`, `groups`, `jail`) VALUES
(16, 'User info', 'personal/user-info', 'userinfo.php', 'a:0:{}', 0),
(17, 'Airport', 'locations/airport', 'airport.php', 'a:0:{}', 1),
(18, 'Messages', 'personal/messages', 'messages.php', 'a:0:{}', 0),
(19, 'Call Credits Market', 'call-credits', 'call-credits.php', 'a:0:{}', 0),
(20, 'Call Credits Shop', 'call-credits/shop', 'call-credits-shop.php', 'a:0:{}', 0),
(19, 'Credits Market', 'call-credits', 'call-credits.php', 'a:0:{}', 0),
(20, 'Credits Shop', 'call-credits/shop', 'call-credits-shop.php', 'a:0:{}', 0),
(21, 'Shop', 'locations/shop', 'shop.php', 'a:0:{}', 1),
(22, 'Jail', 'locations/jail', 'jail.php', 'a:0:{}', 0),
(23, 'Bank', 'locations/bank', 'bank.php', 'a:0:{}', 1),
Expand All @@ -413,7 +429,9 @@ INSERT INTO `pages` (`id`, `title`, `link`, `file`, `groups`, `jail`) VALUES
(32, 'Message', 'personal/message', 'message_load.php', 'a:3:{i:0;s:1:"1";i:1;s:1:"3";i:2;s:1:"2";}', 0),
(33, 'Pay Failed', 'pay/failed', 'failed.php', 'a:0:{}', 0),
(34, 'Pay Success', 'pay/success', 'success.php', 'a:0:{}', 0),
(35, 'Payments', 'credits/payments', 'payments.php', 'a:1:{i:0;s:1:"1";}', 0);
(35, 'Payments', 'credits/payments', 'payments.php', 'a:1:{i:0;s:1:"1";}', 0),
(36, 'Create family', 'family/create', 'family-create.php', 'a:0:{}', 1),
(37, 'Family settings', 'family/settings', 'family-settings.php', 'a:0:{}', 0);

-- --------------------------------------------------------

Expand All @@ -431,7 +449,7 @@ CREATE TABLE IF NOT EXISTS `payments` (
`date_completed` int(11) NOT NULL,
`price` varchar(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;

-- --------------------------------------------------------

Expand All @@ -445,7 +463,7 @@ CREATE TABLE IF NOT EXISTS `shoutbox` (
`message` varchar(600) NOT NULL,
`date` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

-- --------------------------------------------------------

Expand All @@ -467,7 +485,7 @@ CREATE TABLE IF NOT EXISTS `users` (
`regdate` int(11) unsigned NOT NULL,
`groups` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;

-- --------------------------------------------------------

Expand All @@ -488,6 +506,8 @@ CREATE TABLE IF NOT EXISTS `users_info` (
`crime_process` int(5) NOT NULL,
`credits` int(11) NOT NULL,
`house` int(11) NOT NULL,
`bullets` int(11) NOT NULL,
`protection` int(11) NOT NULL,
UNIQUE KEY `id` (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Expand Down
Binary file added files/images/crimes/auto_inbreken.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added files/images/crimes/bank_overvallen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added files/images/crimes/juwelier_overvallen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added files/images/crimes/museum_inbreken.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added files/images/crimes/vrachtwagen_kapen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified files/images/crimes/zakkenrollen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion files/ingame/call-credits/payments.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$payments = $database->query("SELECT * FROM ".TBL_PAYMENTS." ORDER BY date")->fetchAll(PDO::FETCH_OBJ);
$payments = $database->query("SELECT * FROM ".TBL_PAYMENTS." ORDER BY date DESC")->fetchAll(PDO::FETCH_OBJ);
?>
<table width="100%">
<tr>
Expand Down
2 changes: 1 addition & 1 deletion files/ingame/call-credits/success.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
unset($_SESSION['amount']);
unset($_SESSION['hash']);

echo "You have payed with success! Your credits have be added to your account.";
echo "You have payed with success! Your credits (".$_SESSION['amount'].") have be added to your account.";
} catch (PPConnectionException $e) {
echo $e->getData();
}
Expand Down
Loading

0 comments on commit c09812e

Please sign in to comment.